From a4bfce7874c004c93bb90cd120383e2cc3e9eea9 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Mon, 6 Jun 2016 19:49:39 -0700 Subject: [PATCH] Imported SettingsActivity and related classes --- app/src/main/AndroidManifest.xml | 12 ++- .../com/philliphsu/clock2/BaseActivity.java | 3 +- .../com/philliphsu/clock2/MainActivity.java | 2 + .../clock2/settings/SettingsActivity.java | 44 +++++++++++ .../clock2/settings/SettingsFragment.java | 75 +++++++++++++++++++ app/src/main/res/layout/activity_settings.xml | 17 +++++ app/src/main/res/layout/content_settings.xml | 6 ++ app/src/main/res/values/prefs.xml | 54 +++++++++++++ app/src/main/res/values/strings.xml | 35 +++++++++ app/src/main/res/values/styles.xml | 7 +- app/src/main/res/xml/preferences.xml | 66 ++++++++++++++++ 11 files changed, 311 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/philliphsu/clock2/settings/SettingsActivity.java create mode 100644 app/src/main/java/com/philliphsu/clock2/settings/SettingsFragment.java create mode 100644 app/src/main/res/layout/activity_settings.xml create mode 100644 app/src/main/res/layout/content_settings.xml create mode 100644 app/src/main/res/values/prefs.xml create mode 100644 app/src/main/res/xml/preferences.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7a36846..44a5356 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,6 @@ @@ -22,7 +21,6 @@ @@ -44,12 +42,20 @@ android:name=".editalarm.EditAlarmActivity" android:label="@string/title_activity_edit_alarm" android:parentActivityName=".MainActivity" - android:theme="@style/AppTheme.NoActionBar" android:windowSoftInputMode="adjustNothing"> + + + + \ No newline at end of file diff --git a/app/src/main/java/com/philliphsu/clock2/BaseActivity.java b/app/src/main/java/com/philliphsu/clock2/BaseActivity.java index 88b439f..9b0b19c 100644 --- a/app/src/main/java/com/philliphsu/clock2/BaseActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/BaseActivity.java @@ -2,6 +2,7 @@ package com.philliphsu.clock2; import android.media.AudioManager; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.CallSuper; import android.support.annotation.LayoutRes; import android.support.annotation.MenuRes; @@ -35,7 +36,7 @@ public abstract class BaseActivity extends AppCompatActivity { // When false, the system sets the default values only if this method has // never been called in the past (or the KEY_HAS_SET_DEFAULT_VALUES in the // default value shared preferences file is false). -//TODO PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Direct volume changes to the alarm stream setVolumeControlStream(AudioManager.STREAM_ALARM); ButterKnife.bind(this); diff --git a/app/src/main/java/com/philliphsu/clock2/MainActivity.java b/app/src/main/java/com/philliphsu/clock2/MainActivity.java index a2817e0..7c8e172 100644 --- a/app/src/main/java/com/philliphsu/clock2/MainActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/MainActivity.java @@ -18,6 +18,7 @@ import android.widget.TextView; import com.philliphsu.clock2.alarms.AlarmsFragment; import com.philliphsu.clock2.editalarm.EditAlarmActivity; +import com.philliphsu.clock2.settings.SettingsActivity; public class MainActivity extends BaseActivity implements AlarmsFragment.OnAlarmInteractionListener { private static final String TAG = "MainActivity"; @@ -85,6 +86,7 @@ public class MainActivity extends BaseActivity implements AlarmsFragment.OnAlarm //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { + startActivity(new Intent(this, SettingsActivity.class)); return true; } diff --git a/app/src/main/java/com/philliphsu/clock2/settings/SettingsActivity.java b/app/src/main/java/com/philliphsu/clock2/settings/SettingsActivity.java new file mode 100644 index 0000000..5ffbc33 --- /dev/null +++ b/app/src/main/java/com/philliphsu/clock2/settings/SettingsActivity.java @@ -0,0 +1,44 @@ +package com.philliphsu.clock2.settings; + +import android.os.Bundle; + +import com.philliphsu.clock2.BaseActivity; +import com.philliphsu.clock2.R; + +/** + * Created by Phillip Hsu on 6/6/2016. + */ +public class SettingsActivity extends BaseActivity { + /* + * TODO: Define these keys as string resources instead and then delete these. + * TODO: Move the existing string resources for the preferences below from strings.xml to prefs.xml + */ + // World Clock preference keys + public static final String KEY_PREF_SHOW_TIME_OFFSETS_FROM = "pref_show_time_offsets_from"; + // Alarms preference keys + public static final String KEY_PREF_TIME_PICKER_STYLE = "pref_time_picker_style"; + public static final String KEY_PREF_SNOOZE_DURATION = "pref_snooze_duration"; + public static final String KEY_PREF_FIRST_DAY_OF_WEEK = "pref_first_day_of_week"; + // Timers preference keys + public static final String KEY_PREF_TIMER_RINGTONE = "pref_timer_ringtone"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected int layoutResId() { + return R.layout.activity_settings; + } + + @Override + protected int menuResId() { + return 0; + } + + @Override + protected boolean isDisplayShowTitleEnabled() { + return true; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/philliphsu/clock2/settings/SettingsFragment.java b/app/src/main/java/com/philliphsu/clock2/settings/SettingsFragment.java new file mode 100644 index 0000000..4b51af9 --- /dev/null +++ b/app/src/main/java/com/philliphsu/clock2/settings/SettingsFragment.java @@ -0,0 +1,75 @@ +package com.philliphsu.clock2.settings; + +import android.content.Context; +import android.content.SharedPreferences; +import android.media.AudioManager; +import android.media.Ringtone; +import android.media.RingtoneManager; +import android.net.Uri; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.RingtonePreference; + +import com.philliphsu.clock2.R; + +public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { + + public SettingsFragment() {} + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.preferences); + // Set ringtone summary + setSummary(getPreferenceScreen().getSharedPreferences(), + SettingsActivity.KEY_PREF_TIMER_RINGTONE); + findPreference(getString(R.string.key_alarm_volume)) + .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + am.adjustStreamVolume( + AudioManager.STREAM_ALARM, + AudioManager.ADJUST_SAME, // no adjustment + AudioManager.FLAG_SHOW_UI); // show the volume toast + return true; + } + }); + } + + @Override + public void onStart() { + super.onStart(); + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onStop() { + super.onStop(); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + setSummary(sharedPreferences, key); + } + + private void setSummary(SharedPreferences prefs, String key) { + Preference pref = findPreference(key); + // Setting a ListPreference's summary value to "%s" in XML automatically updates the + // preference's summary to display the selected value. + if (!(pref instanceof ListPreference)) { + String summary = prefs.getString(key, ""); + if (pref instanceof RingtonePreference) { + Uri ringtoneUri = Uri.parse(summary); + Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), ringtoneUri); + summary = ringtone.getTitle(getActivity()); + } + pref.setSummary(summary); + } + } +} diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000..d9165ab --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,17 @@ + + + + + + + + diff --git a/app/src/main/res/layout/content_settings.xml b/app/src/main/res/layout/content_settings.xml new file mode 100644 index 0000000..fa38834 --- /dev/null +++ b/app/src/main/res/layout/content_settings.xml @@ -0,0 +1,6 @@ + diff --git a/app/src/main/res/values/prefs.xml b/app/src/main/res/values/prefs.xml new file mode 100644 index 0000000..a7e31de --- /dev/null +++ b/app/src/main/res/values/prefs.xml @@ -0,0 +1,54 @@ + + + + key_silence_after + Silence after + + + + 1 minute + 5 minutes + 10 minutes + 15 minutes + 20 minutes + 25 minutes + 30 minutes + + + 1 + 5 + 10 + 15 + 20 + 25 + 30 + + + + key_alarm_volume + Alarm volume + + + key_notify_me_of_upcoming_alarms + Notify me of upcoming alarms + + 1 hour before + 2 hours before + 3 hours before + 4 hours before + 5 hours before + 6 hours before + 7 hours before + 8 hours before + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2d2d25a..83a5340 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,6 +49,41 @@ Undo + + Settings + + World Clock + Show time offsets from + Local time + GMT + + @string/pref_show_time_offsets_from_local + @string/pref_show_time_offsets_from_gmt + + + Alarms + Time picker style + Number pad + Radial clock + + @string/pref_time_picker_style_number_pad + @string/pref_time_picker_style_radial_clock + + Snooze duration + First day of week + Saturday + Sunday + Monday + + @string/pref_first_day_of_week_saturday + @string/pref_first_day_of_week_sunday + @string/pref_first_day_of_week_monday + + + Timers + Ringtone + + Sun Mon Tue diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 7447189..304fc41 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,18 +1,13 @@ - - -