aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml6
-rw-r--r--app/src/main/java/org/rssin/android/SettingsActivity.java153
-rw-r--r--app/src/main/java/org/rssin/android/UnifiedInboxActivity.java (renamed from app/src/main/java/org/rssin/rssin/UnifiedInboxActivity.java)4
-rw-r--r--app/src/main/res/values/strings_activity_settings.xml34
-rw-r--r--app/src/main/res/xml/pref_data_sync.xml21
-rw-r--r--app/src/main/res/xml/pref_headers.xml6
-rw-r--r--app/src/main/res/xml/pref_main.xml3
7 files changed, 225 insertions, 2 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 497f27d..bc95dc9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -8,7 +8,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
- android:name=".UnifiedInboxActivity"
+ android:name="org.rssin.android.UnifiedInboxActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -16,6 +16,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name="org.rssin.android.SettingsActivity"
+ android:label="@string/title_activity_settings" >
+ </activity>
</application>
</manifest>
diff --git a/app/src/main/java/org/rssin/android/SettingsActivity.java b/app/src/main/java/org/rssin/android/SettingsActivity.java
new file mode 100644
index 0000000..99ccdfa
--- /dev/null
+++ b/app/src/main/java/org/rssin/android/SettingsActivity.java
@@ -0,0 +1,153 @@
+package org.rssin.android;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceManager;
+import android.preference.RingtonePreference;
+import android.text.TextUtils;
+
+import org.rssin.rssin.R;
+
+import java.util.List;
+
+public class SettingsActivity extends PreferenceActivity {
+ /**
+ * Determines whether to always show the simplified settings UI, where
+ * settings are presented in a single list. When false, settings are shown
+ * as a master/detail two-pane view on tablets. When true, a single pane is
+ * shown on tablets.
+ *
+ * For now, this is true, so that we don't have to think about tablets.
+ */
+ private static final boolean ALWAYS_SIMPLE_PREFS = true;
+
+ @Override
+ protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ setupSimplePreferencesScreen();
+ }
+
+ /**
+ * Shows the simplified settings UI if the device configuration if the
+ * device configuration dictates that a simplified, single-pane UI should be
+ * shown.
+ */
+ private void setupSimplePreferencesScreen() {
+ if (!isSimplePreferences(this)) {
+ return;
+ }
+
+ // Add 'general' preferences.
+ addPreferencesFromResource(R.xml.pref_main);
+
+ // Add 'data and sync' preferences, and a corresponding header.
+ PreferenceCategory fakeHeader = new PreferenceCategory(this);
+ fakeHeader.setTitle(R.string.pref_header_data_sync);
+ getPreferenceScreen().addPreference(fakeHeader);
+ addPreferencesFromResource(R.xml.pref_data_sync);
+
+ // Bind the summaries of EditText/List/Dialog/Ringtone preferences to
+ // their values. When their values change, their summaries are updated
+ // to reflect the new value, per the Android Design guidelines.
+ bindPreferenceSummaryToValue(findPreference("sync_frequency"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onIsMultiPane() {
+ return isXLargeTablet(this) && !isSimplePreferences(this);
+ }
+
+ /**
+ * Helper method to determine if the device has an extra-large screen. For
+ * example, 10" tablets are extra-large.
+ */
+ private static boolean isXLargeTablet(Context context) {
+ return (context.getResources().getConfiguration().screenLayout
+ & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
+ }
+
+ /**
+ * Determines whether the simplified settings UI should be shown. This is
+ * true if this is forced via {@link #ALWAYS_SIMPLE_PREFS}, or the device
+ * doesn't have newer APIs like {@link PreferenceFragment}, or the device
+ * doesn't have an extra-large screen. In these cases, a single-pane
+ * "simplified" settings UI should be shown.
+ */
+ private static boolean isSimplePreferences(Context context) {
+ return ALWAYS_SIMPLE_PREFS
+ || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
+ || !isXLargeTablet(context);
+ }
+
+ /**
+ * A preference value change listener that updates the preference's summary
+ * to reflect its new value.
+ */
+ private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ String stringValue = value.toString();
+
+ if (preference instanceof ListPreference) {
+ ListPreference listPreference = (ListPreference) preference;
+ int index = listPreference.findIndexOfValue(stringValue);
+
+ preference.setSummary(index >= 0
+ ? listPreference.getEntries()[index]
+ : null);
+ } else {
+ preference.setSummary(stringValue);
+ }
+ return true;
+ }
+ };
+
+ /**
+ * Binds a preference's summary to its value. More specifically, when the
+ * preference's value is changed, its summary (line of text below the
+ * preference title) is updated to reflect the value. The summary is also
+ * immediately updated upon calling this method. The exact display format is
+ * dependent on the type of preference.
+ *
+ * @see #sBindPreferenceSummaryToValueListener
+ */
+ private static void bindPreferenceSummaryToValue(Preference preference) {
+ // Set the listener to watch for value changes.
+ preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
+
+ // Trigger the listener immediately with the preference's
+ // current value.
+ sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
+ PreferenceManager
+ .getDefaultSharedPreferences(preference.getContext())
+ .getString(preference.getKey(), ""));
+ }
+
+ /**
+ * This fragment shows data and sync preferences only. It is used when the
+ * activity is showing a two-pane settings UI.
+ */
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public static class DataSyncPreferenceFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.pref_data_sync);
+ bindPreferenceSummaryToValue(findPreference("sync_frequency"));
+ }
+ }
+}
diff --git a/app/src/main/java/org/rssin/rssin/UnifiedInboxActivity.java b/app/src/main/java/org/rssin/android/UnifiedInboxActivity.java
index b1bf0dc..697a430 100644
--- a/app/src/main/java/org/rssin/rssin/UnifiedInboxActivity.java
+++ b/app/src/main/java/org/rssin/android/UnifiedInboxActivity.java
@@ -1,10 +1,12 @@
-package org.rssin.rssin;
+package org.rssin.android;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
+import org.rssin.rssin.R;
+
public class UnifiedInboxActivity extends ActionBarActivity {
diff --git a/app/src/main/res/values/strings_activity_settings.xml b/app/src/main/res/values/strings_activity_settings.xml
new file mode 100644
index 0000000..73fa482
--- /dev/null
+++ b/app/src/main/res/values/strings_activity_settings.xml
@@ -0,0 +1,34 @@
+<resources>
+ <string name="title_activity_settings">Settings</string>
+
+ <!-- Example General settings -->
+ <string name="pref_header_general">General</string>
+
+ <!-- Example settings for Data & Sync -->
+ <string name="pref_header_data_sync">Data &amp; sync</string>
+
+ <string name="pref_title_sync_frequency">Sync frequency</string>
+ <string-array name="pref_sync_frequency_titles">
+ <item>1 minute</item>
+ <item>2 minutes</item>
+ <item>5 minutes</item>
+ <item>10 minutes</item>
+ <item>15 minutes</item>
+ <item>30 minutes</item>
+ <item>1 hour</item>
+ <item>Never</item>
+ </string-array>
+ <string-array name="pref_sync_frequency_values">
+ <item>1</item>
+ <item>2</item>
+ <item>5</item>
+ <item>10</item>
+ <item>15</item>
+ <item>30</item>
+ <item>60</item>
+ <item>-1</item>
+ </string-array>
+
+ <string name="pref_title_system_sync_settings">System sync settings</string>
+
+</resources>
diff --git a/app/src/main/res/xml/pref_data_sync.xml b/app/src/main/res/xml/pref_data_sync.xml
new file mode 100644
index 0000000..ffda831
--- /dev/null
+++ b/app/src/main/res/xml/pref_data_sync.xml
@@ -0,0 +1,21 @@
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog to
+ dismiss it. -->
+ <!-- NOTE: ListPreference's summary should be set to its value by the activity code. -->
+ <ListPreference
+ android:key="sync_frequency"
+ android:title="@string/pref_title_sync_frequency"
+ android:entries="@array/pref_sync_frequency_titles"
+ android:entryValues="@array/pref_sync_frequency_values"
+ android:defaultValue="180"
+ android:negativeButtonText="@null"
+ android:positiveButtonText="@null" />
+
+ <!-- This preference simply launches an intent when selected. Use this UI sparingly, per
+ design guidelines. -->
+ <Preference android:title="@string/pref_title_system_sync_settings">
+ <intent android:action="android.settings.SYNC_SETTINGS" />
+ </Preference>
+
+</PreferenceScreen>
diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml
new file mode 100644
index 0000000..1c58203
--- /dev/null
+++ b/app/src/main/res/xml/pref_headers.xml
@@ -0,0 +1,6 @@
+<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <header android:fragment="org.rssin.android.SettingsActivity$DataSyncPreferenceFragment"
+ android:title="@string/pref_header_data_sync" />
+
+</preference-headers>
diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml
new file mode 100644
index 0000000..dfc2102
--- /dev/null
+++ b/app/src/main/res/xml/pref_main.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+</PreferenceScreen> \ No newline at end of file