|
|
@@ -4,25 +4,23 @@ import android.annotation.TargetApi;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
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.SwitchPreference;
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
import android.preference.PreferenceFragment;
|
|
|
-import android.preference.PreferenceManager;
|
|
|
-import android.preference.RingtonePreference;
|
|
|
-import android.text.TextUtils;
|
|
|
import android.view.MenuItem;
|
|
|
import android.support.v4.app.NavUtils;
|
|
|
|
|
|
import info.knacki.pass.R;
|
|
|
+import info.knacki.pass.settings.SettingsManager;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.logging.Level;
|
|
|
+import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
|
* A {@link PreferenceActivity} that presents a set of application settings. On
|
|
|
@@ -37,58 +35,6 @@ import java.util.List;
|
|
|
*/
|
|
|
public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
|
|
|
- /**
|
|
|
- * 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) {
|
|
|
- // For list preferences, look up the correct display value in
|
|
|
- // the preference's 'entries' list.
|
|
|
- ListPreference listPreference = (ListPreference) preference;
|
|
|
- int index = listPreference.findIndexOfValue(stringValue);
|
|
|
-
|
|
|
- // Set the summary to reflect the new value.
|
|
|
- preference.setSummary(
|
|
|
- index >= 0
|
|
|
- ? listPreference.getEntries()[index]
|
|
|
- : null);
|
|
|
-
|
|
|
- } else if (preference instanceof RingtonePreference) {
|
|
|
- // For ringtone preferences, look up the correct display value
|
|
|
- // using RingtoneManager.
|
|
|
- if (TextUtils.isEmpty(stringValue)) {
|
|
|
- // Empty values correspond to 'silent' (no ringtone).
|
|
|
- preference.setSummary(R.string.pref_ringtone_silent);
|
|
|
-
|
|
|
- } else {
|
|
|
- Ringtone ringtone = RingtoneManager.getRingtone(
|
|
|
- preference.getContext(), Uri.parse(stringValue));
|
|
|
-
|
|
|
- if (ringtone == null) {
|
|
|
- // Clear the summary if there was a lookup error.
|
|
|
- preference.setSummary(null);
|
|
|
- } else {
|
|
|
- // Set the summary to reflect the new ringtone display
|
|
|
- // name.
|
|
|
- String name = ringtone.getTitle(preference.getContext());
|
|
|
- preference.setSummary(name);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- // For all other preferences, set the summary to the value's
|
|
|
- // simple string representation.
|
|
|
- preference.setSummary(stringValue);
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
/**
|
|
|
* Helper method to determine if the device has an extra-large screen. For
|
|
|
* example, 10" tablets are extra-large.
|
|
|
@@ -98,27 +44,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 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(), ""));
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@@ -172,14 +97,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
protected boolean isValidFragment(String fragmentName) {
|
|
|
return PreferenceFragment.class.getName().equals(fragmentName)
|
|
|
|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
|
|
|
- || DataSyncPreferenceFragment.class.getName().equals(fragmentName)
|
|
|
- || NotificationPreferenceFragment.class.getName().equals(fragmentName);
|
|
|
+ || EncryptionPreferenceFragment.class.getName().equals(fragmentName)
|
|
|
+ || VCSPreferenceFragment.class.getName().equals(fragmentName);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * This fragment shows general preferences only. It is used when the
|
|
|
- * activity is showing a two-pane settings UI.
|
|
|
- */
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
|
public static class GeneralPreferenceFragment extends PreferenceFragment {
|
|
|
@Override
|
|
|
@@ -188,12 +109,13 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
addPreferencesFromResource(R.xml.pref_general);
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
- // 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("example_text"));
|
|
|
- bindPreferenceSummaryToValue(findPreference("example_list"));
|
|
|
+ findPreference(getResources().getString(R.string.id_softSettings)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onPreferenceClick(Preference preference) {
|
|
|
+ //FIXME
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -207,23 +129,27 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * This fragment shows notification preferences only. It is used when the
|
|
|
- * activity is showing a two-pane settings UI.
|
|
|
- */
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
|
- public static class NotificationPreferenceFragment extends PreferenceFragment {
|
|
|
+ public static class EncryptionPreferenceFragment extends PreferenceFragment {
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- addPreferencesFromResource(R.xml.pref_notification);
|
|
|
+ addPreferencesFromResource(R.xml.pref_encryption);
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
- // 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("notifications_new_message_ringtone"));
|
|
|
+ ListPreference encTypePref = (ListPreference) findPreference(getResources().getString(R.string.id_enctype));
|
|
|
+ final int encTypeIndex = SettingsManager.GetDefaultEncryptionType(getActivity()).IntValue();
|
|
|
+ encTypePref.setSummary(encTypePref.getEntries()[encTypeIndex]);
|
|
|
+ encTypePref.setValueIndex(encTypeIndex);
|
|
|
+ encTypePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onPreferenceChange(Preference preference, Object o) {
|
|
|
+ int value = Integer.parseInt(o.toString());
|
|
|
+ preference.setSummary(((ListPreference) preference).getEntries()[value]);
|
|
|
+ SettingsManager.SetDefaultEncryptionType(getActivity(), SettingsManager.EncryptionType.FromInt(value));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -237,23 +163,73 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 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 {
|
|
|
+ public static class VCSPreferenceFragment extends PreferenceFragment {
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- addPreferencesFromResource(R.xml.pref_data_sync);
|
|
|
+ addPreferencesFromResource(R.xml.pref_vcs);
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
- // 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"));
|
|
|
+ abstract class PrefListener implements Preference.OnPreferenceChangeListener {
|
|
|
+ @Override
|
|
|
+ public boolean onPreferenceChange(Preference preference, Object o) {
|
|
|
+ savePref(preference, o);
|
|
|
+ VCSPreferenceFragment.this.reload();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ abstract void savePref(Preference preference, Object o);
|
|
|
+ }
|
|
|
+
|
|
|
+ findPreference(getResources().getString(R.string.id_vcs_enable)).setOnPreferenceChangeListener(new PrefListener() {
|
|
|
+ @Override
|
|
|
+ void savePref(Preference preference, Object o) {
|
|
|
+ if ((Boolean)o)
|
|
|
+ SettingsManager.SetVCS(getActivity(), new SettingsManager.Git());
|
|
|
+ else
|
|
|
+ SettingsManager.SetVCS(getActivity(), null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ findPreference(getResources().getString(R.string.id_vcs_list)).setOnPreferenceChangeListener(new PrefListener() {
|
|
|
+ @Override
|
|
|
+ void savePref(Preference preference, Object o) {
|
|
|
+ SettingsManager.VCS vcs = SettingsManager.GetVCS(getActivity());
|
|
|
+ SettingsManager.VCS newVcs;
|
|
|
+
|
|
|
+ switch (Integer.parseInt((String) o)) {
|
|
|
+ case 0:
|
|
|
+ newVcs = new SettingsManager.Git();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!vcs.GetName().equals(newVcs.GetName())) {
|
|
|
+ SettingsManager.SetVCS(getActivity(), newVcs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ reload();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void reload() {
|
|
|
+ SettingsManager.VCS versioning = SettingsManager.GetVCS(getActivity());
|
|
|
+
|
|
|
+ if (versioning != null) {
|
|
|
+ ((SwitchPreference) findPreference(getResources().getString(R.string.id_vcs_enable))).setChecked(true);
|
|
|
+ ListPreference vcsType = (ListPreference) findPreference(getResources().getString(R.string.id_vcs_list));
|
|
|
+ vcsType.setEnabled(true);
|
|
|
+ if (versioning instanceof SettingsManager.Git) {
|
|
|
+ vcsType.setValueIndex(0);
|
|
|
+ vcsType.setSummary(vcsType.getEntries()[0]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ((SwitchPreference) findPreference(getResources().getString(R.string.id_vcs_enable))).setChecked(false);
|
|
|
+ ListPreference vcsType = (ListPreference) findPreference(getResources().getString(R.string.id_vcs_list));
|
|
|
+ vcsType.setEnabled(false);
|
|
|
+ vcsType.setSummary("");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|