Skip to content

Commit

Permalink
timezone text
Browse files Browse the repository at this point in the history
enhances the alarm activity to display the time using the alarm's time zone (e.g. solar time) vs system time (#849)
  • Loading branch information
forrestguice committed Dec 21, 2024
1 parent 372700c commit 26a499d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.TimeZone;

/**
* AlarmDismissActivity
Expand Down Expand Up @@ -119,7 +120,7 @@ public class AlarmDismissActivity extends AppCompatActivity implements AlarmDism
private boolean isTesting = false;
private int testChallengeID = -1;

private TextView alarmTitle, alarmSubtitle, alarmText, clockText, offsetText, infoText, noteText;
private TextView alarmTitle, alarmSubtitle, alarmText, clockText, timezoneText, offsetText, infoText, noteText;
private TextView[] labels;

private FloatingActionButton backButton;
Expand Down Expand Up @@ -219,6 +220,9 @@ protected void initViews(Context context)
clockText = (TextView)findViewById(R.id.txt_clock_time);
clockText.setTextColor(colors.getColor(AlarmColorValues.COLOR_TEXT_TIME));

timezoneText = (TextView)findViewById(R.id.txt_clock_timezone);
timezoneText.setTextColor(colors.getColor(AlarmColorValues.COLOR_TEXT_SECONDARY));

offsetText = (TextView)findViewById(R.id.txt_alarm_offset);
offsetText.setTextColor(colors.getColor(AlarmColorValues.COLOR_TEXT_SECONDARY));

Expand Down Expand Up @@ -782,14 +786,25 @@ public void setAlarmID(Context context, Uri uri, @Nullable final AlarmDatabaseA
}
}

protected TimeZone getTimeZone()
{
if (alarm != null && alarm.timezone != null) {
return AlarmClockItem.AlarmTimeZone.getTimeZone(alarm.timezone, alarm.location);
} else return TimeZone.getDefault();
}

public static final int CLOCK_UPDATE_RATE = 3000;
private final Runnable updateClockTask = new Runnable()
{
@Override
public void run()
{
clockText.setText(formatTimeDisplay(AlarmDismissActivity.this, Calendar.getInstance()));
TimeZone timezone = getTimeZone();
clockText.setText(formatTimeDisplay(AlarmDismissActivity.this, Calendar.getInstance(timezone)));
clockText.postDelayed(this, CLOCK_UPDATE_RATE);

timezoneText.setVisibility((alarm != null && alarm.timezone != null) ? View.VISIBLE : View.GONE);
timezoneText.setText(timezone.getID());
}
};

Expand Down Expand Up @@ -828,7 +843,7 @@ protected int currentTimeColor()
}
protected int currentTextColor()
{
if (clockText != null) {
if (infoText != null) {
return infoText.getCurrentTextColor();
} else {
return colors.getColor(AlarmColorValues.COLOR_TEXT_SECONDARY);
Expand Down Expand Up @@ -907,7 +922,7 @@ public void updateViews(Context context)
animateBackground(new int[] { currentBackgroundColor(), snoozeBackgroundColor }, 1500, new LinearInterpolator());
animateColors(new int[] { currentTitleColor(), snoozeTitleColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(alarmTitle));
animateColors(new int[] { currentTimeColor(), snoozeTimeColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(clockText));
animateColors(new int[] { currentTextColor(), snoozeTextColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(infoText));
animateColors(new int[] { currentTextColor(), snoozeTextColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(infoText), new ColorableTextView(timezoneText));
}

if (Build.VERSION.SDK_INT >= 17) // BUG: on some older devices modifying brightness turns off the screen
Expand Down Expand Up @@ -942,7 +957,7 @@ public void updateViews(Context context)
animateBackground(new int[] { currentBackgroundColor(), timeoutBackgroundColor }, 1500, new AccelerateInterpolator());
animateColors(new int[] { currentTitleColor(), timeoutTitleColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(alarmTitle));
animateColors(new int[] { currentTimeColor(), timeoutTimeColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(clockText));
animateColors(new int[] { currentTextColor(), timeoutTextColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(infoText));
animateColors(new int[] { currentTextColor(), timeoutTextColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(infoText), new ColorableTextView(timezoneText));
}
setBrightness(WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE);

Expand All @@ -962,10 +977,12 @@ public void updateViews(Context context)
int soundingBackgroundColor = colors.getColor(AlarmColorValues.COLOR_BRIGHT_BACKGROUND_END);
int soundingTitleColor = getContrastingTextColor(soundingBackgroundColor, colors, AlarmColorValues.COLOR_TEXT_PRIMARY, AlarmColorValues.COLOR_TEXT_PRIMARY_INVERSE);
int soundingTimeColor = getContrastingTextColor(soundingBackgroundColor, colors, AlarmColorValues.COLOR_TEXT_TIME, AlarmColorValues.COLOR_TEXT_TIME_INVERSE);
int soundingTextColor = getContrastingTextColor(soundingBackgroundColor, colors, AlarmColorValues.COLOR_TEXT_SECONDARY, AlarmColorValues.COLOR_TEXT_SECONDARY_INVERSE);

animateBackground(new int[] { colors.getColor(AlarmColorValues.COLOR_BRIGHT_BACKGROUND_START), soundingBackgroundColor }, AlarmSettings.loadPrefAlarmBrightFadeIn(this), new AccelerateInterpolator());
animateColors(new int[] { currentTitleColor(), soundingTitleColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(alarmTitle));
animateColors(new int[] { currentTimeColor(), soundingTimeColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(clockText));
animateColors(new int[] { currentTextColor(), soundingTextColor }, 1500, false, new LinearInterpolator(), new ColorableTextView(timezoneText));
infoText.setTextColor(Color.TRANSPARENT);
}
setBrightness(WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/layout_activity_dismissalarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@
app:layout_constraintBottom_toTopOf="@+id/btn_dismiss"
tools:text="00:00 AM" />

<TextView
style="@style/TextAppearance.AppCompat.Medium"
android:id="@+id/txt_clock_timezone"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/alarmdismiss_margin" android:layout_marginEnd="@dimen/alarmdismiss_margin"
android:gravity="top|center_horizontal"
app:layout_constraintTop_toBottomOf="@+id/txt_clock_time"
tools:text="Local Mean Time" />

<!--<Button android:id="@+id/btn_snooze" android:visibility="gone"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp" android:layout_height="96dp"
Expand Down

0 comments on commit 26a499d

Please sign in to comment.