2012-07-20 02:23:49 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-20 02:23:49 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-07-20 02:23:49 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.Preference;
|
2014-12-15 20:25:55 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
import android.support.v4.preference.PreferenceFragment;
|
2013-11-27 19:08:58 +00:00
|
|
|
|
2014-11-10 04:35:08 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2014-11-04 14:19:48 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment;
|
|
|
|
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
|
|
|
import org.thoughtcrime.securesms.preferences.AppearancePreferenceFragment;
|
|
|
|
import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment;
|
|
|
|
import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment;
|
|
|
|
import org.thoughtcrime.securesms.preferences.StoragePreferenceFragment;
|
2014-12-11 23:04:32 +00:00
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
2013-06-30 01:03:55 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2013-06-21 18:56:59 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2013-07-11 21:58:40 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2012-10-23 02:17:08 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* The Activity for application preference display and management.
|
2012-07-20 02:23:49 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-06-29 03:40:57 +00:00
|
|
|
public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarActivity
|
2013-06-21 18:56:59 +00:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
|
|
|
{
|
2014-11-04 14:19:48 +00:00
|
|
|
private static final String TAG = ApplicationPreferencesActivity.class.getSimpleName();
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
private static final String PREFERENCE_CATEGORY_SMS_MMS = "preference_category_sms_mms";
|
|
|
|
private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "preference_category_notifications";
|
|
|
|
private static final String PREFERENCE_CATEGORY_APP_PROTECTION = "preference_category_app_protection";
|
|
|
|
private static final String PREFERENCE_CATEGORY_APPEARANCE = "preference_category_appearance";
|
|
|
|
private static final String PREFERENCE_CATEGORY_STORAGE = "preference_category_storage";
|
|
|
|
private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced";
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-06-30 01:03:55 +00:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
2013-06-21 18:56:59 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
2014-12-15 20:25:55 +00:00
|
|
|
protected void onPreCreate() {
|
2013-06-21 18:56:59 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
2013-06-30 01:03:55 +00:00
|
|
|
dynamicLanguage.onCreate(this);
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|
2012-08-03 03:23:41 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
|
2012-08-03 03:23:41 +00:00
|
|
|
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
Bundle fragmentArgs = new Bundle();
|
|
|
|
Fragment fragment = new ApplicationPreferenceFragment();
|
|
|
|
|
|
|
|
fragmentArgs.putParcelable("master_secret", masterSecret);
|
|
|
|
fragment.setArguments(fragmentArgs);
|
|
|
|
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
|
|
|
.replace(android.R.id.content, fragment)
|
|
|
|
.commit();
|
2014-06-29 03:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-22 12:31:54 +00:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
{
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(android.R.id.content);
|
|
|
|
fragment.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean onSupportNavigateUp() {
|
|
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
if (fragmentManager.getBackStackEntryCount() > 0) {
|
|
|
|
fragmentManager.popBackStack();
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(this, ConversationListActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-29 03:40:57 +00:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
if (key.equals(TextSecurePreferences.THEME_PREF)) {
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
|
|
|
|
dynamicLanguage.onResume(this);
|
2014-12-11 23:04:32 +00:00
|
|
|
|
|
|
|
Intent intent = new Intent(this, KeyCachingService.class);
|
|
|
|
intent.setAction(KeyCachingService.LOCALE_CHANGE_EVENT);
|
|
|
|
startService(intent);
|
2014-06-29 03:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class ApplicationPreferenceFragment extends PreferenceFragment {
|
2014-11-04 14:19:48 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
MasterSecret masterSecret = getArguments().getParcelable("master_secret");
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
|
2014-12-15 20:25:55 +00:00
|
|
|
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_SMS_MMS));
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
|
2014-12-15 20:25:55 +00:00
|
|
|
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_NOTIFICATIONS));
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(PREFERENCE_CATEGORY_APP_PROTECTION)
|
2014-12-15 20:25:55 +00:00
|
|
|
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_APP_PROTECTION));
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(PREFERENCE_CATEGORY_APPEARANCE)
|
2014-12-15 20:25:55 +00:00
|
|
|
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_APPEARANCE));
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(PREFERENCE_CATEGORY_STORAGE)
|
2014-12-15 20:25:55 +00:00
|
|
|
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_STORAGE));
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(PREFERENCE_CATEGORY_ADVANCED)
|
2014-12-15 20:25:55 +00:00
|
|
|
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_ADVANCED));
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.text_secure_normal__menu_settings);
|
|
|
|
setCategorySummaries();
|
2014-02-20 22:49:31 +00:00
|
|
|
}
|
2014-03-30 09:28:38 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
private void setCategorySummaries() {
|
|
|
|
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
|
|
|
|
.setSummary(SmsMmsPreferenceFragment.getSummary(getActivity()));
|
|
|
|
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
|
|
|
|
.setSummary(NotificationsPreferenceFragment.getSummary(getActivity()));
|
|
|
|
this.findPreference(PREFERENCE_CATEGORY_APP_PROTECTION)
|
|
|
|
.setSummary(AppProtectionPreferenceFragment.getSummary(getActivity()));
|
|
|
|
this.findPreference(PREFERENCE_CATEGORY_APPEARANCE)
|
|
|
|
.setSummary(AppearancePreferenceFragment.getSummary(getActivity()));
|
|
|
|
this.findPreference(PREFERENCE_CATEGORY_STORAGE)
|
|
|
|
.setSummary(StoragePreferenceFragment.getSummary(getActivity()));
|
2014-03-30 09:28:38 +00:00
|
|
|
}
|
2014-02-20 22:49:31 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
private class CategoryClickListener implements Preference.OnPreferenceClickListener {
|
2014-12-15 20:25:55 +00:00
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private String category;
|
2013-07-11 21:58:40 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
public CategoryClickListener(MasterSecret masterSecret, String category) {
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.category = category;
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Fragment fragment;
|
2013-07-11 21:58:40 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
switch (category) {
|
|
|
|
case PREFERENCE_CATEGORY_SMS_MMS:
|
|
|
|
fragment = new SmsMmsPreferenceFragment();
|
|
|
|
break;
|
|
|
|
case PREFERENCE_CATEGORY_NOTIFICATIONS:
|
|
|
|
fragment = new NotificationsPreferenceFragment();
|
|
|
|
break;
|
|
|
|
case PREFERENCE_CATEGORY_APP_PROTECTION:
|
2014-12-15 20:25:55 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable("master_secret", masterSecret);
|
2014-11-04 14:19:48 +00:00
|
|
|
fragment = new AppProtectionPreferenceFragment();
|
2014-12-15 20:25:55 +00:00
|
|
|
fragment.setArguments(args);
|
2014-11-04 14:19:48 +00:00
|
|
|
break;
|
|
|
|
case PREFERENCE_CATEGORY_APPEARANCE:
|
|
|
|
fragment = new AppearancePreferenceFragment();
|
|
|
|
break;
|
|
|
|
case PREFERENCE_CATEGORY_STORAGE:
|
|
|
|
fragment = new StoragePreferenceFragment();
|
|
|
|
break;
|
|
|
|
case PREFERENCE_CATEGORY_ADVANCED:
|
|
|
|
fragment = new AdvancedPreferenceFragment();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new AssertionError();
|
|
|
|
}
|
2012-10-23 02:17:08 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
|
|
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
|
|
fragmentTransaction.replace(android.R.id.content, fragment);
|
|
|
|
fragmentTransaction.addToBackStack(null);
|
|
|
|
fragmentTransaction.commit();
|
2012-10-23 02:17:08 +00:00
|
|
|
|
2014-11-04 14:19:48 +00:00
|
|
|
return true;
|
2012-10-23 02:17:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-01 22:17:55 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|