Imported SettingsActivity and related classes
This commit is contained in:
parent
c4cd333cf7
commit
a4bfce7874
@ -11,7 +11,6 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
@ -22,7 +21,6 @@
|
||||
<activity
|
||||
android:name=".ringtone.RingtoneActivity"
|
||||
android:label="@string/title_activity_ringtone"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:launchMode="singleTask"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity="com.philliphsu.clock2.RingtoneActivity">
|
||||
@ -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">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.philliphsu.clock2.MainActivity"/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".settings.SettingsActivity"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.philliphsu.clock2.MainActivity"/>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
app/src/main/res/layout/activity_settings.xml
Normal file
17
app/src/main/res/layout/activity_settings.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.philliphsu.clock2.settings.SettingsActivity">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"/>
|
||||
|
||||
<include layout="@layout/content_settings"/>
|
||||
|
||||
</merge>
|
||||
6
app/src/main/res/layout/content_settings.xml
Normal file
6
app/src/main/res/layout/content_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<fragment android:id="@+id/fragment"
|
||||
android:name="com.philliphsu.clock2.settings.SettingsFragment"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize" />
|
||||
54
app/src/main/res/values/prefs.xml
Normal file
54
app/src/main/res/values/prefs.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Silence after -->
|
||||
<string name="key_silence_after">key_silence_after</string>
|
||||
<string name="title_silence_after">Silence after</string>
|
||||
|
||||
<!-- Durations for silence after & snooze duration -->
|
||||
<string-array name="entries_duration">
|
||||
<item>1 minute</item>
|
||||
<item>5 minutes</item>
|
||||
<item>10 minutes</item>
|
||||
<item>15 minutes</item>
|
||||
<item>20 minutes</item>
|
||||
<item>25 minutes</item>
|
||||
<item>30 minutes</item>
|
||||
</string-array>
|
||||
<string-array name="values_duration">
|
||||
<item>1</item>
|
||||
<item>5</item>
|
||||
<item>10</item>
|
||||
<item>15</item>
|
||||
<item>20</item>
|
||||
<item>25</item>
|
||||
<item>30</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Alarm volume -->
|
||||
<string name="key_alarm_volume">key_alarm_volume</string>
|
||||
<string name="title_alarm_volume">Alarm volume</string>
|
||||
|
||||
<!-- Upcoming alarm threshold -->
|
||||
<string name="key_notify_me_of_upcoming_alarms">key_notify_me_of_upcoming_alarms</string>
|
||||
<string name="title_notify_me_of_upcoming_alarms">Notify me of upcoming alarms</string>
|
||||
<string-array name="entries_notify_me_of_upcoming_alarms">
|
||||
<item>1 hour before</item>
|
||||
<item>2 hours before</item>
|
||||
<item>3 hours before</item>
|
||||
<item>4 hours before</item>
|
||||
<item>5 hours before</item>
|
||||
<item>6 hours before</item>
|
||||
<item>7 hours before</item>
|
||||
<item>8 hours before</item>
|
||||
</string-array>
|
||||
<string-array name="values_notify_me_of_upcoming_alarms">
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>8</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@ -49,6 +49,41 @@
|
||||
<string name="snackbar_undo_item_deleted">Undo</string>
|
||||
<!-- ======================================================================================= -->
|
||||
|
||||
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~ Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
<!-- World Clock -->
|
||||
<string name="pref_category_world_clock">World Clock</string>
|
||||
<string name="pref_show_time_offsets_from">Show time offsets from</string>
|
||||
<string name="pref_show_time_offsets_from_local">Local time</string>
|
||||
<string name="pref_show_time_offsets_from_gmt">GMT</string>
|
||||
<string-array name="pref_show_time_offsets_from_array">
|
||||
<item>@string/pref_show_time_offsets_from_local</item>
|
||||
<item>@string/pref_show_time_offsets_from_gmt</item>
|
||||
</string-array>
|
||||
<!-- Alarms -->
|
||||
<string name="pref_category_alarms">Alarms</string>
|
||||
<string name="pref_time_picker_style">Time picker style</string>
|
||||
<string name="pref_time_picker_style_number_pad">Number pad</string>
|
||||
<string name="pref_time_picker_style_radial_clock">Radial clock</string>
|
||||
<string-array name="pref_time_picker_style_array">
|
||||
<item>@string/pref_time_picker_style_number_pad</item>
|
||||
<item>@string/pref_time_picker_style_radial_clock</item>
|
||||
</string-array>
|
||||
<string name="pref_snooze_duration">Snooze duration</string>
|
||||
<string name="pref_first_day_of_week">First day of week</string>
|
||||
<string name="pref_first_day_of_week_saturday">Saturday</string>
|
||||
<string name="pref_first_day_of_week_sunday">Sunday</string>
|
||||
<string name="pref_first_day_of_week_monday">Monday</string>
|
||||
<string-array name="pref_first_day_of_week_array">
|
||||
<item>@string/pref_first_day_of_week_saturday</item>
|
||||
<item>@string/pref_first_day_of_week_sunday</item>
|
||||
<item>@string/pref_first_day_of_week_monday</item>
|
||||
</string-array>
|
||||
<!-- Timers -->
|
||||
<string name="pref_category_timers">Timers</string>
|
||||
<string name="pref_timer_ringtone">Ringtone</string>
|
||||
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
|
||||
|
||||
<string name="sun">Sun</string>
|
||||
<string name="mon">Mon</string>
|
||||
<string name="tue">Tue</string>
|
||||
|
||||
@ -1,18 +1,13 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||
|
||||
66
app/src/main/res/xml/preferences.xml
Normal file
66
app/src/main/res/xml/preferences.xml
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory android:title="@string/pref_category_world_clock">
|
||||
<ListPreference
|
||||
android:key="pref_show_time_offsets_from"
|
||||
android:title="@string/pref_show_time_offsets_from"
|
||||
android:dialogTitle="@string/pref_show_time_offsets_from"
|
||||
android:entries="@array/pref_show_time_offsets_from_array"
|
||||
android:entryValues="@array/pref_show_time_offsets_from_array"
|
||||
android:defaultValue="@string/pref_show_time_offsets_from_local"
|
||||
android:summary="%s"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_category_alarms">
|
||||
<ListPreference
|
||||
android:key="pref_time_picker_style"
|
||||
android:title="@string/pref_time_picker_style"
|
||||
android:dialogTitle="@string/pref_time_picker_style"
|
||||
android:entries="@array/pref_time_picker_style_array"
|
||||
android:entryValues="@array/pref_time_picker_style_array"
|
||||
android:defaultValue="@string/pref_time_picker_style_number_pad"
|
||||
android:summary="%s"/>
|
||||
<ListPreference
|
||||
android:key="@string/key_silence_after"
|
||||
android:title="@string/title_silence_after"
|
||||
android:dialogTitle="@string/title_silence_after"
|
||||
android:entries="@array/entries_duration"
|
||||
android:entryValues="@array/values_duration"
|
||||
android:defaultValue="1"
|
||||
android:summary="%s"/>
|
||||
<ListPreference
|
||||
android:key="pref_snooze_duration"
|
||||
android:title="@string/pref_snooze_duration"
|
||||
android:dialogTitle="@string/pref_snooze_duration"
|
||||
android:entries="@array/entries_duration"
|
||||
android:entryValues="@array/values_duration"
|
||||
android:defaultValue="1"
|
||||
android:summary="%s"/>
|
||||
<Preference
|
||||
android:key="@string/key_alarm_volume"
|
||||
android:title="@string/title_alarm_volume"/>
|
||||
<ListPreference
|
||||
android:key="@string/key_notify_me_of_upcoming_alarms"
|
||||
android:title="@string/title_notify_me_of_upcoming_alarms"
|
||||
android:dialogTitle="@string/title_notify_me_of_upcoming_alarms"
|
||||
android:entries="@array/entries_notify_me_of_upcoming_alarms"
|
||||
android:entryValues="@array/values_notify_me_of_upcoming_alarms"
|
||||
android:defaultValue="2"
|
||||
android:summary="%s"/>
|
||||
<ListPreference
|
||||
android:key="pref_first_day_of_week"
|
||||
android:title="@string/pref_first_day_of_week"
|
||||
android:dialogTitle="@string/pref_first_day_of_week"
|
||||
android:entries="@array/pref_first_day_of_week_array"
|
||||
android:entryValues="@array/pref_first_day_of_week_array"
|
||||
android:defaultValue="@string/pref_first_day_of_week_sunday"
|
||||
android:summary="%s"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_category_timers">
|
||||
<RingtonePreference
|
||||
android:key="pref_timer_ringtone"
|
||||
android:title="@string/pref_timer_ringtone"
|
||||
android:ringtoneType="alarm"
|
||||
android:defaultValue="content://settings/system/alarm_alert"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
Loading…
Reference in New Issue
Block a user