Skip to content

Commit

Permalink
Merge pull request #497 from forrestguice/themes
Browse files Browse the repository at this point in the history
themes
  • Loading branch information
forrestguice authored May 5, 2021
2 parents 4ac8d7d + 202f902 commit e69d284
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 64 deletions.
38 changes: 31 additions & 7 deletions app/src/main/java/com/forrestguice/suntimeswidget/EquinoxView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2017-2019 Forrest Guice
Copyright (C) 2017-2021 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand All @@ -25,6 +25,7 @@
import android.os.Bundle;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.ImageViewCompat;
import android.support.v7.widget.PagerSnapHelper;
Expand Down Expand Up @@ -377,7 +378,7 @@ public void adjustLabelWidth( int labelWidthPx )
labelView.setLayoutParams(layoutParams);
}

public void themeViews(Integer labelColor, Integer timeColor, Integer textColor)
public void themeViews(@Nullable Integer labelColor, @Nullable Integer timeColor, @Nullable Integer textColor, @Nullable Float textSizeSp, @Nullable Float titleSizeSp, boolean titleBold)
{
if (labelColor != null) {
labelView.setTextColor(SuntimesUtils.colorStateList(labelColor, options.disabledColor));
Expand All @@ -390,6 +391,16 @@ public void themeViews(Integer labelColor, Integer timeColor, Integer textColor)
if (textColor != null) {
noteView.setTextColor(SuntimesUtils.colorStateList(textColor, options.disabledColor));
} //else Log.w("EquinoxView", "themeViews: null color, ignoring...");

if (textSizeSp != null) {
noteView.setTextSize(textSizeSp);
timeView.setTextSize(textSizeSp);
} //else Log.w("EquinoxView", "themeViews: null color, ignoring...");

if (titleSizeSp != null) {
labelView.setTextSize(titleSizeSp);
labelView.setTypeface(labelView.getTypeface(), (titleBold ? Typeface.BOLD : Typeface.NORMAL));
} //else Log.w("EquinoxView", "themeViews: null color, ignoring...");
}

public void updateDate( Context context, Calendar time )
Expand Down Expand Up @@ -774,7 +785,7 @@ private EquinoxNote addNote(TextView labelView, TextView timeView, TextView note
{
EquinoxNote note = new EquinoxNote(labelView, timeView, noteView, pageIndex, options);
if (timeColor != null) {
note.themeViews(options.labelColor, timeColor, options.textColor);
note.themeViews(options.labelColor, timeColor, options.textColor, options.timeSizeSp, options.titleSizeSp, options.titleBold);
}
notes.add(note);
return note;
Expand Down Expand Up @@ -890,14 +901,19 @@ public void applyTheme(SuntimesTheme theme, EquinoxViewOptions options)
public void themeViews( EquinoxViewOptions options, int position )
{
title.setTextColor(SuntimesUtils.colorStateList((position < EquinoxViewAdapter.CENTER_POSITION ? options.disabledColor : options.titleColor), options.disabledColor, options.pressedColor));
if (options.titleSizeSp != null)
{
title.setTextSize(options.titleSizeSp);
title.setTypeface(title.getTypeface(), (options.titleBold ? Typeface.BOLD : Typeface.NORMAL));
}

ImageViewCompat.setImageTintList(btn_flipperNext, SuntimesUtils.colorStateList(options.titleColor, options.disabledColor, options.pressedColor));
ImageViewCompat.setImageTintList(btn_flipperPrev, SuntimesUtils.colorStateList(options.titleColor, options.disabledColor, options.pressedColor));

note_equinox_vernal.themeViews(options.labelColor, options.seasonColors[0], options.textColor);
note_solstice_summer.themeViews(options.labelColor, options.seasonColors[1], options.textColor);
note_equinox_autumnal.themeViews(options.labelColor, options.seasonColors[2], options.textColor);
note_solstice_winter.themeViews(options.labelColor, options.seasonColors[3], options.textColor);
note_equinox_vernal.themeViews(options.labelColor, options.seasonColors[0], options.textColor, options.timeSizeSp, options.titleSizeSp, options.titleBold);
note_solstice_summer.themeViews(options.labelColor, options.seasonColors[1], options.textColor, options.timeSizeSp, options.titleSizeSp, options.titleBold);
note_equinox_autumnal.themeViews(options.labelColor, options.seasonColors[2], options.textColor, options.timeSizeSp, options.titleSizeSp, options.titleBold);
note_solstice_winter.themeViews(options.labelColor, options.seasonColors[3], options.textColor, options.timeSizeSp, options.titleSizeSp, options.titleBold);
}
}

Expand All @@ -919,6 +935,10 @@ public static class EquinoxViewOptions
public Integer labelColor, textColor;
public int resID_buttonPressColor;

public Float timeSizeSp = null;
public Float titleSizeSp = null;
public boolean titleBold = false;

private SuntimesTheme themeOverride = null;

@SuppressLint("ResourceType")
Expand All @@ -932,6 +952,7 @@ public void init(Context context)
resID_buttonPressColor = typedArray.getResourceId(2, R.color.btn_tint_pressed_dark);
pressedColor = ContextCompat.getColor(context, resID_buttonPressColor);
labelColor = textColor = seasonColors[0] = seasonColors[1] = seasonColors[2] = seasonColors[3] = null;
titleSizeSp = timeSizeSp = null;
typedArray.recycle();
}

Expand All @@ -948,6 +969,9 @@ public void init(SuntimesTheme theme)
seasonColors[1] = theme.getSummerColor();
seasonColors[2] = theme.getFallColor();
seasonColors[3] = theme.getWinterColor();
timeSizeSp = theme.getTimeSizeSp();
titleSizeSp = theme.getTitleSizeSp();
titleBold = theme.getTitleBold();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2017-2020 Forrest Guice
Copyright (C) 2017-2021 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -362,9 +362,20 @@ public void themeViews(Context context)

} else {
int titleColor = themeOverride.getTitleColor();
float textSizeSp = themeOverride.getTextSizeSp();
float titleSizeSp = themeOverride.getTitleSizeSp();
float timeSizeSp = themeOverride.getTimeSizeSp();
float suffixSizeSp = themeOverride.getTimeSuffixSizeSp();

dialogTitle.setTextColor(titleColor);
dialogTitle.setTextSize(titleSizeSp);
dialogTitle.setTypeface(dialogTitle.getTypeface(), (themeOverride.getTitleBold() ? Typeface.BOLD : Typeface.NORMAL));

sunElevationLabel.setTextColor(titleColor);
sunElevationLabel.setTextSize(suffixSizeSp);

sunAzimuthLabel.setTextColor(titleColor);
sunAzimuthLabel.setTextSize(suffixSizeSp);

lightmap.themeViews(context, themeOverride);
colorNight = themeOverride.getNightColor();
Expand All @@ -382,11 +393,25 @@ public void themeViews(Context context)
field_night.themeViews(themeOverride);

sunAzimuth.setTextColor(themeOverride.getTimeColor());
sunAzimuth.setTextSize(timeSizeSp);
sunAzimuthRising.setTextSize(timeSizeSp);
sunAzimuthSetting.setTextSize(timeSizeSp);

sunElevation.setTextColor(themeOverride.getTimeColor());
sunElevation.setTextSize(timeSizeSp);
sunElevationAtNoon.setTextSize(timeSizeSp);

sunAzimuthAtNoon.setTextColor(themeOverride.getTimeColor());
sunAzimuthAtNoon.setTextSize(timeSizeSp);

sunShadowObj.setTextColor(themeOverride.getTitleColor());
sunShadowObj.setTextSize(timeSizeSp);

sunShadowLength.setTextColor(themeOverride.getTimeColor());
sunShadowLength.setTextSize(timeSizeSp);

sunShadowLengthAtNoon.setTextColor(themeOverride.getSunsetTextColor());
sunShadowLengthAtNoon.setTextSize(timeSizeSp);

SuntimesUtils.tintDrawable((InsetDrawable)riseIcon.getBackground(), themeOverride.getSunriseIconColor(), themeOverride.getSunriseIconStrokeColor(), themeOverride.getSunriseIconStrokePixels(context));
SuntimesUtils.tintDrawable((InsetDrawable)setIcon.getBackground(), themeOverride.getSunsetIconColor(), themeOverride.getSunsetIconStrokeColor(), themeOverride.getSunsetIconStrokePixels(context));
Expand Down Expand Up @@ -644,7 +669,10 @@ public void themeViews(SuntimesTheme theme)
if (theme != null)
{
label.setTextColor(theme.getTextColor());
label.setTextSize(theme.getTextSizeSp());
text.setTextColor(theme.getTimeColor());
text.setTextSize(theme.getTimeSizeSp());
text.setTypeface(text.getTypeface(), (theme.getTimeBold() ? Typeface.BOLD : Typeface.NORMAL));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2018-2019 Forrest Guice
Copyright (C) 2018-2021 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand All @@ -24,6 +24,7 @@
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -187,14 +188,22 @@ public void themeViews(Context context)
setColor = themeOverride.getMoonsetTextColor();

dialogTitle.setTextColor(titleColor);
dialogTitle.setTextSize(themeOverride.getTitleSizeSp());
dialogTitle.setTypeface(dialogTitle.getTypeface(), (themeOverride.getTitleBold() ? Typeface.BOLD : Typeface.NORMAL));

moonriseset.themeViews(context, themeOverride);
currentphase.themeViews(context, themeOverride);
moonphases.themeViews(context, themeOverride);
moonapsis.themeViews(context, themeOverride);

moondistance_label.setTextColor(titleColor);
moondistance_label.setTextSize(themeOverride.getTitleSizeSp());

moondistance.setTextColor(textColor);
moondistance.setTextSize(themeOverride.getTimeSuffixSizeSp());

moondistance_note.setTextColor(timeColor);
moondistance_note.setTextSize(themeOverride.getTextSizeSp());

} else {
int[] colorAttrs = { android.R.attr.textColorPrimary, R.attr.moonriseColor, R.attr.moonsetColor };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.util.AttributeSet;
Expand Down Expand Up @@ -115,11 +116,22 @@ public void themeViews(Context context, SuntimesTheme theme)
{
noteColor = theme.getTimeColor();
int textColor = theme.getTextColor();
int timeColor = theme.getTimeColor();
float suffixSizeSp = theme.getTimeSuffixSizeSp();
float timeSizeSp = theme.getTimeSizeSp();

illumText.setTextColor(textColor);
illumText.setTextSize(suffixSizeSp);

azimuthText.setTextColor(textColor);
azimuthText.setTextSize(suffixSizeSp);

elevationText.setTextColor(textColor);
phaseText.setTextColor(theme.getTimeColor());
elevationText.setTextSize(suffixSizeSp);

phaseText.setTextColor(timeColor);
phaseText.setTextSize(timeSizeSp);
phaseText.setTypeface(phaseText.getTypeface(), (theme.getTimeBold() ? Typeface.BOLD : Typeface.NORMAL));

int[] viewID = getIconViewIDs();
Bitmap[] bitmaps = getThemedBitmaps(context, theme);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2018-2019 Forrest Guice
Copyright (C) 2018-2021 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand All @@ -23,7 +23,9 @@
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.widget.ImageViewCompat;
Expand Down Expand Up @@ -279,6 +281,8 @@ public static class PhaseAdapter extends RecyclerView.Adapter<PhaseField>

private int colorNote, colorTitle, colorTime, colorText, colorWaxing, colorWaning, colorFull, colorNew, colorDisabled;
private float strokePixelsNew, strokePixelsFull;
private Float spTime = null, spText = null, spTitle = null, spSuffix = null;
private boolean boldTime, boldTitle;

public PhaseAdapter(Context context) {
contextRef = new WeakReference<>(context);
Expand Down Expand Up @@ -420,6 +424,12 @@ protected void applyTheme(Context context, SuntimesTheme theme)
colorNew = theme.getMoonNewColor();
strokePixelsNew = theme.getMoonNewStrokePixels(context);
strokePixelsFull = theme.getMoonFullStrokePixels(context);
spTime = theme.getTimeSizeSp();
spText = theme.getTextSizeSp();
spTitle = theme.getTitleSizeSp();
spSuffix = theme.getTimeSuffixSizeSp();
boldTitle = theme.getTitleBold();
boldTime = theme.getTimeBold();
}

protected void themeViews(Context context, @NonNull PhaseField holder, boolean isAgo)
Expand All @@ -438,7 +448,7 @@ protected void themeViews(Context context, @NonNull PhaseField holder, boolean i
int titleColor = isAgo ? colorDisabled : colorTitle;
int timeColor = isAgo ? colorDisabled : colorTime;
int textColor = isAgo ? colorDisabled : colorText;
holder.themeViews(titleColor, timeColor, textColor, bitmap);
holder.themeViews(titleColor, spTitle, boldTitle, timeColor, spTime, boldTime, textColor, bitmap);
}
}

Expand Down Expand Up @@ -525,11 +535,23 @@ public void bindDataToPosition(Context context, SuntimesMoonData1 data, Suntimes
setLabel(phaseLabel);
}

public void themeViews(int labelColor, int timeColor, int textColor, @NonNull Bitmap bitmap)
public void themeViews(int labelColor, @Nullable Float labelSizeSp, boolean labelBold, int timeColor, @Nullable Float timeSizeSp, boolean timeBold, int textColor, @NonNull Bitmap bitmap)
{
label.setTextColor(labelColor);
if (labelSizeSp != null) {
label.setTextSize(labelSizeSp);
label.setTypeface(label.getTypeface(), (labelBold ? Typeface.BOLD : Typeface.NORMAL));
}

field.setTextColor(timeColor);
note.setTextColor(textColor);

if (timeSizeSp != null) {
note.setTextSize(timeSizeSp);
field.setTextSize(timeSizeSp);
field.setTypeface(field.getTypeface(), (timeBold ? Typeface.BOLD : Typeface.NORMAL));
}

icon.setImageBitmap(bitmap);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2018 Forrest Guice
Copyright (C) 2018-2021 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand All @@ -19,6 +19,7 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -431,7 +432,10 @@ public void themeView(SuntimesTheme theme)
{
int color = (rising ? theme.getMoonriseTextColor() : theme.getMoonsetTextColor());
timeView.setTextColor(color);
timeView.setTextSize(theme.getTimeSizeSp());
timeView.setTypeface(timeView.getTypeface(), theme.getTimeBold() ? Typeface.BOLD : Typeface.NORMAL);
positionView.setTextColor(color);
positionView.setTextSize(theme.getTimeSuffixSizeSp());
SuntimesUtils.tintDrawable((LayerDrawable)iconView.getBackground(), color, color, 0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2014-2019 Forrest Guice
Copyright (C) 2014-2021 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,6 +33,7 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
Expand Down Expand Up @@ -776,22 +777,43 @@ protected void themeViews(Context context)
int textColor = appThemeOverride.getTextColor();
int disabledColor = ContextCompat.getColor(context, resID_buttonDisabledColor);
int pressedColor = appThemeOverride.getActionColor();
float suffixSizeSp = appThemeOverride.getTimeSuffixSizeSp();
float textSizeSp = appThemeOverride.getTextSizeSp();
float titleSizeSp = appThemeOverride.getTitleSizeSp();
boolean titleBold = appThemeOverride.getTitleBold();

Toolbar actionBar = (Toolbar) findViewById(R.id.app_menubar);
actionBar.setTitleTextColor(titleColor);
actionBar.setSubtitleTextColor(textColor);

txt_time.setTextColor(timeColor);
txt_time_suffix.setTextColor(timeColor);

txt_timezone.setTextColor(SuntimesUtils.colorStateList(textColor, disabledColor, pressedColor));
txt_timezone.setTextSize(suffixSizeSp);

txt_time1_note1.setTextColor(timeColor);
txt_time1_note2.setTextColor(textColor);
txt_time1_note1.setTextSize(titleSizeSp);
txt_time1_note1.setTypeface(txt_time1_note1.getTypeface(), (titleBold ? Typeface.BOLD : Typeface.NORMAL));
txt_time2_note1.setTextColor(timeColor);
txt_time2_note1.setTextSize(titleSizeSp);
txt_time2_note1.setTypeface(txt_time2_note1.getTypeface(), (titleBold ? Typeface.BOLD : Typeface.NORMAL));

txt_time1_note2.setTextColor(textColor);
txt_time1_note2.setTextSize(textSizeSp);
txt_time2_note2.setTextColor(textColor);
txt_time2_note2.setTextSize(textSizeSp);

txt_time1_note3.setTextSize(titleSizeSp);
txt_time1_note3.setTypeface(txt_time1_note3.getTypeface(), (titleBold ? Typeface.BOLD : Typeface.NORMAL));
txt_time2_note3.setTextSize(titleSizeSp);
txt_time2_note3.setTypeface(txt_time2_note3.getTypeface(), (titleBold ? Typeface.BOLD : Typeface.NORMAL));

txt_datasource.setTextColor(SuntimesUtils.colorStateList(textColor, disabledColor, pressedColor));
txt_datasource.setTextSize(suffixSizeSp);

txt_altitude.setTextColor(timeColor);
txt_altitude.setTextSize(suffixSizeSp);

color_textTimeDelta = appThemeOverride.getTimeColor();
card_adapter.setThemeOverride(appThemeOverride);
Expand Down
Loading

0 comments on commit e69d284

Please sign in to comment.