Loading res/values/strings.xml +17 −0 Original line number Diff line number Diff line Loading @@ -268,6 +268,23 @@ <item>-1</item> <!-- Off --> </string-array> <!-- Week start day preference title. --> <string name="week_start_title">Start week on</string> <!-- Entries listed in ListPreference for start day. --> <string-array name="week_start_entries"> <item>Saturday</item> <item>Sunday</item> <item>Monday</item> </string-array> <!-- Values for ListPreference for start day of week. --> <string-array name="week_start_values" translatable="false"> <item>7</item> <!-- Calendar.SATURDAY --> <item>1</item> <!-- Calendar.SUNDAY --> <item>2</item> <!-- Calendar.MONDAY --> </string-array> <!-- Done button when editing an alarm. --> <string name="done">Done</string> Loading res/xml/settings.xml +7 −0 Original line number Diff line number Diff line Loading @@ -65,5 +65,12 @@ android:entries="@array/volume_button_setting_entries" android:entryValues="@array/volume_button_setting_values" android:defaultValue="0" /> <ListPreference android:key="week_start" android:title="@string/week_start_title" android:dialogTitle="@string/week_start_title" android:entries="@array/week_start_entries" android:entryValues="@array/week_start_values" /> </PreferenceCategory> </PreferenceScreen> src/com/android/deskclock/AlarmClockFragment.java +22 −6 Original line number Diff line number Diff line Loading @@ -514,7 +514,10 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements private final boolean mHasVibrator; private final int mCollapseExpandHeight; // This determines the order in which it is shown and processed in the UI. // Determines the order that days of the week are shown in the UI private int[] mDayOrder; // A reference used to create mDayOrder private final int[] DAY_ORDER = new int[] { Calendar.SUNDAY, Calendar.MONDAY, Loading Loading @@ -593,6 +596,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements .hasVibrator(); mCollapseExpandHeight = (int) res.getDimension(R.dimen.collapse_expand_height); setDayOrder(); } public void removeSelectedId(int id) { Loading Loading @@ -642,6 +647,17 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements return c; } private void setDayOrder() { // Value from preferences corresponds to Calendar.<WEEKDAY> value // -1 in order to correspond to DAY_ORDER indexing final int startDay = Utils.getZeroIndexedFirstDayOfWeek(mContext); mDayOrder = new int[DaysOfWeek.DAYS_IN_A_WEEK]; for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; ++i) { mDayOrder[i] = DAY_ORDER[(startDay + i) % 7]; } } private void setNewHolder(View view) { // standard view holder optimization final ItemHolder holder = new ItemHolder(); Loading @@ -666,8 +682,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements for (int i = 0; i < 7; i++) { final CompoundButton dayButton = (CompoundButton) mFactory.inflate( R.layout.day_button, holder.repeatDays, false /* attachToRoot */); dayButton.setText(Utils.getShortWeekday(i)); dayButton.setContentDescription(Utils.getLongWeekday(i)); dayButton.setText(Utils.getShortWeekday(mContext, i)); dayButton.setContentDescription(Utils.getLongWeekday(mContext, i)); holder.repeatDays.addView(dayButton); holder.dayButtons[i] = dayButton; } Loading Loading @@ -899,7 +915,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements final int bitSet = mPreviousDaysOfWeekMap.getInt("" + alarm.id); alarm.daysOfWeek.setBitSet(bitSet); if (!alarm.daysOfWeek.isRepeating()) { alarm.daysOfWeek.setDaysOfWeek(true, DAY_ORDER); alarm.daysOfWeek.setDaysOfWeek(true, mDayOrder); } updateDaysOfWeekButtons(itemHolder, alarm.daysOfWeek); } else { Loading Loading @@ -928,7 +944,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements public void onClick(View view) { final boolean isActivated = itemHolder.dayButtons[buttonIndex].isActivated(); alarm.daysOfWeek.setDaysOfWeek(!isActivated, DAY_ORDER[buttonIndex]); alarm.daysOfWeek.setDaysOfWeek(!isActivated, mDayOrder[buttonIndex]); if (!isActivated) { turnOnDayOfWeek(itemHolder, buttonIndex); } else { Loading Loading @@ -1005,7 +1021,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements private void updateDaysOfWeekButtons(ItemHolder holder, DaysOfWeek daysOfWeek) { HashSet<Integer> setDays = daysOfWeek.getSetDays(); for (int i = 0; i < 7; i++) { if (setDays.contains(DAY_ORDER[i])) { if (setDays.contains(mDayOrder[i])) { turnOnDayOfWeek(holder, i); } else { turnOffDayOfWeek(holder, i); Loading src/com/android/deskclock/DeskClock.java +13 −1 Original line number Diff line number Diff line Loading @@ -113,6 +113,9 @@ public class DeskClock extends AppCompatActivity implements public static final int RTL_STOPWATCH_TAB_INDEX = 0; public static final String SELECT_TAB_INTENT_EXTRA = "deskclock.select.tab"; // Request code used when SettingsActivity is launched. private static final int REQUEST_CHANGE_SETTINGS = 1; // TODO(rachelzhang): adding a broadcast receiver to adjust color when the timezone/time // changes in the background. Loading Loading @@ -353,10 +356,19 @@ public class DeskClock extends AppCompatActivity implements return super.onOptionsItemSelected(item); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Recreate the activity if any settings have been changed if (requestCode == REQUEST_CHANGE_SETTINGS && resultCode == RESULT_OK) { recreate(); } } private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); startActivityForResult(new Intent(DeskClock.this, SettingsActivity.class), REQUEST_CHANGE_SETTINGS); return true; case R.id.menu_item_help: Intent i = item.getIntent(); Loading src/com/android/deskclock/SettingsActivity.java +16 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public class SettingsActivity extends AppCompatActivity { public static final String KEY_HOME_TZ = "home_time_zone"; public static final String KEY_AUTO_HOME_CLOCK = "automatic_home_clock"; public static final String KEY_VOLUME_BUTTONS = "volume_button_setting"; public static final String KEY_WEEK_START = "week_start"; public static final String DEFAULT_VOLUME_BEHAVIOR = "0"; public static final String VOLUME_BEHAVIOR_SNOOZE = "1"; Loading Loading @@ -117,6 +118,8 @@ public class SettingsActivity extends AppCompatActivity { @Override public void onResume() { super.onResume(); // By default, do not recreate the DeskClock activity getActivity().setResult(RESULT_CANCELED); refresh(); } Loading Loading @@ -144,7 +147,13 @@ public class SettingsActivity extends AppCompatActivity { final ListPreference volumeButtonsPref = (ListPreference) pref; final int index = volumeButtonsPref.findIndexOfValue((String) newValue); volumeButtonsPref.setSummary(volumeButtonsPref.getEntries()[index]); } else if (KEY_WEEK_START.equals(pref.getKey())) { final ListPreference weekStartPref = (ListPreference) findPreference(KEY_WEEK_START); final int idx = weekStartPref.findIndexOfValue((String) newValue); weekStartPref.setSummary(weekStartPref.getEntries()[idx]); } // Set result so DeskClock knows to refresh itself getActivity().setResult(RESULT_OK); return true; } Loading Loading @@ -209,6 +218,13 @@ public class SettingsActivity extends AppCompatActivity { final SnoozeLengthDialog snoozePref = (SnoozeLengthDialog) findPreference(KEY_ALARM_SNOOZE); snoozePref.setSummary(); final ListPreference weekStartPref = (ListPreference) findPreference(KEY_WEEK_START); final CharSequence entry = weekStartPref.getEntry(); // Set the default value programmatically weekStartPref.setSummary( entry == null ? String.valueOf(Utils.DEFAULT_WEEK_START) : entry); weekStartPref.setOnPreferenceChangeListener(this); } private void updateAutoSnoozeSummary(ListPreference listPref, String delay) { Loading @@ -225,7 +241,6 @@ public class SettingsActivity extends AppCompatActivity { getActivity().sendBroadcast(i); } private class TimeZoneRow implements Comparable<TimeZoneRow> { private static final boolean SHOW_DAYLIGHT_SAVINGS_INDICATOR = false; Loading Loading
res/values/strings.xml +17 −0 Original line number Diff line number Diff line Loading @@ -268,6 +268,23 @@ <item>-1</item> <!-- Off --> </string-array> <!-- Week start day preference title. --> <string name="week_start_title">Start week on</string> <!-- Entries listed in ListPreference for start day. --> <string-array name="week_start_entries"> <item>Saturday</item> <item>Sunday</item> <item>Monday</item> </string-array> <!-- Values for ListPreference for start day of week. --> <string-array name="week_start_values" translatable="false"> <item>7</item> <!-- Calendar.SATURDAY --> <item>1</item> <!-- Calendar.SUNDAY --> <item>2</item> <!-- Calendar.MONDAY --> </string-array> <!-- Done button when editing an alarm. --> <string name="done">Done</string> Loading
res/xml/settings.xml +7 −0 Original line number Diff line number Diff line Loading @@ -65,5 +65,12 @@ android:entries="@array/volume_button_setting_entries" android:entryValues="@array/volume_button_setting_values" android:defaultValue="0" /> <ListPreference android:key="week_start" android:title="@string/week_start_title" android:dialogTitle="@string/week_start_title" android:entries="@array/week_start_entries" android:entryValues="@array/week_start_values" /> </PreferenceCategory> </PreferenceScreen>
src/com/android/deskclock/AlarmClockFragment.java +22 −6 Original line number Diff line number Diff line Loading @@ -514,7 +514,10 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements private final boolean mHasVibrator; private final int mCollapseExpandHeight; // This determines the order in which it is shown and processed in the UI. // Determines the order that days of the week are shown in the UI private int[] mDayOrder; // A reference used to create mDayOrder private final int[] DAY_ORDER = new int[] { Calendar.SUNDAY, Calendar.MONDAY, Loading Loading @@ -593,6 +596,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements .hasVibrator(); mCollapseExpandHeight = (int) res.getDimension(R.dimen.collapse_expand_height); setDayOrder(); } public void removeSelectedId(int id) { Loading Loading @@ -642,6 +647,17 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements return c; } private void setDayOrder() { // Value from preferences corresponds to Calendar.<WEEKDAY> value // -1 in order to correspond to DAY_ORDER indexing final int startDay = Utils.getZeroIndexedFirstDayOfWeek(mContext); mDayOrder = new int[DaysOfWeek.DAYS_IN_A_WEEK]; for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; ++i) { mDayOrder[i] = DAY_ORDER[(startDay + i) % 7]; } } private void setNewHolder(View view) { // standard view holder optimization final ItemHolder holder = new ItemHolder(); Loading @@ -666,8 +682,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements for (int i = 0; i < 7; i++) { final CompoundButton dayButton = (CompoundButton) mFactory.inflate( R.layout.day_button, holder.repeatDays, false /* attachToRoot */); dayButton.setText(Utils.getShortWeekday(i)); dayButton.setContentDescription(Utils.getLongWeekday(i)); dayButton.setText(Utils.getShortWeekday(mContext, i)); dayButton.setContentDescription(Utils.getLongWeekday(mContext, i)); holder.repeatDays.addView(dayButton); holder.dayButtons[i] = dayButton; } Loading Loading @@ -899,7 +915,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements final int bitSet = mPreviousDaysOfWeekMap.getInt("" + alarm.id); alarm.daysOfWeek.setBitSet(bitSet); if (!alarm.daysOfWeek.isRepeating()) { alarm.daysOfWeek.setDaysOfWeek(true, DAY_ORDER); alarm.daysOfWeek.setDaysOfWeek(true, mDayOrder); } updateDaysOfWeekButtons(itemHolder, alarm.daysOfWeek); } else { Loading Loading @@ -928,7 +944,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements public void onClick(View view) { final boolean isActivated = itemHolder.dayButtons[buttonIndex].isActivated(); alarm.daysOfWeek.setDaysOfWeek(!isActivated, DAY_ORDER[buttonIndex]); alarm.daysOfWeek.setDaysOfWeek(!isActivated, mDayOrder[buttonIndex]); if (!isActivated) { turnOnDayOfWeek(itemHolder, buttonIndex); } else { Loading Loading @@ -1005,7 +1021,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements private void updateDaysOfWeekButtons(ItemHolder holder, DaysOfWeek daysOfWeek) { HashSet<Integer> setDays = daysOfWeek.getSetDays(); for (int i = 0; i < 7; i++) { if (setDays.contains(DAY_ORDER[i])) { if (setDays.contains(mDayOrder[i])) { turnOnDayOfWeek(holder, i); } else { turnOffDayOfWeek(holder, i); Loading
src/com/android/deskclock/DeskClock.java +13 −1 Original line number Diff line number Diff line Loading @@ -113,6 +113,9 @@ public class DeskClock extends AppCompatActivity implements public static final int RTL_STOPWATCH_TAB_INDEX = 0; public static final String SELECT_TAB_INTENT_EXTRA = "deskclock.select.tab"; // Request code used when SettingsActivity is launched. private static final int REQUEST_CHANGE_SETTINGS = 1; // TODO(rachelzhang): adding a broadcast receiver to adjust color when the timezone/time // changes in the background. Loading Loading @@ -353,10 +356,19 @@ public class DeskClock extends AppCompatActivity implements return super.onOptionsItemSelected(item); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Recreate the activity if any settings have been changed if (requestCode == REQUEST_CHANGE_SETTINGS && resultCode == RESULT_OK) { recreate(); } } private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); startActivityForResult(new Intent(DeskClock.this, SettingsActivity.class), REQUEST_CHANGE_SETTINGS); return true; case R.id.menu_item_help: Intent i = item.getIntent(); Loading
src/com/android/deskclock/SettingsActivity.java +16 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public class SettingsActivity extends AppCompatActivity { public static final String KEY_HOME_TZ = "home_time_zone"; public static final String KEY_AUTO_HOME_CLOCK = "automatic_home_clock"; public static final String KEY_VOLUME_BUTTONS = "volume_button_setting"; public static final String KEY_WEEK_START = "week_start"; public static final String DEFAULT_VOLUME_BEHAVIOR = "0"; public static final String VOLUME_BEHAVIOR_SNOOZE = "1"; Loading Loading @@ -117,6 +118,8 @@ public class SettingsActivity extends AppCompatActivity { @Override public void onResume() { super.onResume(); // By default, do not recreate the DeskClock activity getActivity().setResult(RESULT_CANCELED); refresh(); } Loading Loading @@ -144,7 +147,13 @@ public class SettingsActivity extends AppCompatActivity { final ListPreference volumeButtonsPref = (ListPreference) pref; final int index = volumeButtonsPref.findIndexOfValue((String) newValue); volumeButtonsPref.setSummary(volumeButtonsPref.getEntries()[index]); } else if (KEY_WEEK_START.equals(pref.getKey())) { final ListPreference weekStartPref = (ListPreference) findPreference(KEY_WEEK_START); final int idx = weekStartPref.findIndexOfValue((String) newValue); weekStartPref.setSummary(weekStartPref.getEntries()[idx]); } // Set result so DeskClock knows to refresh itself getActivity().setResult(RESULT_OK); return true; } Loading Loading @@ -209,6 +218,13 @@ public class SettingsActivity extends AppCompatActivity { final SnoozeLengthDialog snoozePref = (SnoozeLengthDialog) findPreference(KEY_ALARM_SNOOZE); snoozePref.setSummary(); final ListPreference weekStartPref = (ListPreference) findPreference(KEY_WEEK_START); final CharSequence entry = weekStartPref.getEntry(); // Set the default value programmatically weekStartPref.setSummary( entry == null ? String.valueOf(Utils.DEFAULT_WEEK_START) : entry); weekStartPref.setOnPreferenceChangeListener(this); } private void updateAutoSnoozeSummary(ListPreference listPref, String delay) { Loading @@ -225,7 +241,6 @@ public class SettingsActivity extends AppCompatActivity { getActivity().sendBroadcast(i); } private class TimeZoneRow implements Comparable<TimeZoneRow> { private static final boolean SHOW_DAYLIGHT_SAVINGS_INDICATOR = false; Loading