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.app.Activity;
|
2013-01-10 05:06:56 +00:00
|
|
|
import android.app.AlertDialog;
|
2013-07-11 21:58:40 +00:00
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
2013-01-10 05:06:56 +00:00
|
|
|
import android.content.DialogInterface;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2013-12-03 07:10:59 +00:00
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.net.Uri;
|
2013-12-02 20:31:59 +00:00
|
|
|
import android.os.Build;
|
2013-07-11 21:58:40 +00:00
|
|
|
import android.os.AsyncTask;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.os.Bundle;
|
2013-07-01 17:15:36 +00:00
|
|
|
import android.preference.CheckBoxPreference;
|
2012-12-09 00:46:38 +00:00
|
|
|
import android.preference.EditTextPreference;
|
2013-12-03 07:10:59 +00:00
|
|
|
import android.preference.ListPreference;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.preference.Preference;
|
2013-12-02 20:31:59 +00:00
|
|
|
import android.preference.PreferenceGroup;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2013-06-30 01:03:55 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
2013-12-03 07:10:59 +00:00
|
|
|
import android.preference.RingtonePreference;
|
2012-10-23 02:17:08 +00:00
|
|
|
import android.provider.ContactsContract;
|
2013-12-02 20:31:59 +00:00
|
|
|
import android.provider.Telephony;
|
2013-12-03 07:10:59 +00:00
|
|
|
import android.text.TextUtils;
|
2013-01-10 05:06:56 +00:00
|
|
|
import android.util.Log;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2013-06-30 01:03:55 +00:00
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
2013-07-11 21:58:40 +00:00
|
|
|
import com.google.android.gcm.GCMRegistrar;
|
2012-07-20 02:23:49 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
2012-10-23 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
|
2013-10-19 18:15:45 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
2013-08-18 01:37:18 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2013-02-17 19:42:30 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
2013-07-01 17:15:36 +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;
|
2012-07-20 02:23:49 +00:00
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
2013-07-11 21:58:40 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2013-01-10 05:06:56 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Trimmer;
|
2013-12-02 20:31:59 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2013-08-02 19:48:25 +00:00
|
|
|
import org.whispersystems.textsecure.push.AuthorizationFailedException;
|
2013-07-11 21:58:40 +00:00
|
|
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPreferenceActivity
|
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
|
|
|
{
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2013-07-01 17:15:36 +00:00
|
|
|
private static final int PICK_IDENTITY_CONTACT = 1;
|
|
|
|
private static final int ENABLE_PASSPHRASE_ACTIVITY = 2;
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-11-18 23:29:19 +00:00
|
|
|
private static final String DISPLAY_CATEGORY_PREF = "pref_display_category";
|
|
|
|
private static final String PUSH_MESSAGING_PREF = "pref_toggle_push_messaging";
|
|
|
|
private static final String MMS_PREF = "pref_mms_preferences";
|
2013-03-26 04:26:03 +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
|
|
|
|
protected void onCreate(Bundle icicle) {
|
2013-06-21 18:56:59 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
2013-06-30 01:03:55 +00:00
|
|
|
dynamicLanguage.onCreate(this);
|
2011-12-20 18:20:44 +00:00
|
|
|
super.onCreate(icicle);
|
2012-08-03 03:23:41 +00:00
|
|
|
|
|
|
|
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-10-23 02:17:08 +00:00
|
|
|
initializeIdentitySelection();
|
2013-12-02 20:31:59 +00:00
|
|
|
initializePlatformSpecificOptions();
|
2013-07-11 21:58:40 +00:00
|
|
|
initializePushMessagingToggle();
|
2012-10-23 02:17:08 +00:00
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
|
2012-10-23 02:17:08 +00:00
|
|
|
.setOnPreferenceClickListener(new ChangePassphraseClickListener());
|
2013-07-11 21:58:40 +00:00
|
|
|
this.findPreference(TextSecurePreferences.THREAD_TRIM_NOW)
|
2013-01-10 05:06:56 +00:00
|
|
|
.setOnPreferenceClickListener(new TrimNowClickListener());
|
2013-07-11 21:58:40 +00:00
|
|
|
this.findPreference(TextSecurePreferences.THREAD_TRIM_LENGTH)
|
2013-01-10 05:06:56 +00:00
|
|
|
.setOnPreferenceChangeListener(new TrimLengthValidationListener());
|
2013-07-11 21:58:40 +00:00
|
|
|
this.findPreference(TextSecurePreferences.DISABLE_PASSPHRASE_PREF)
|
2013-07-01 17:15:36 +00:00
|
|
|
.setOnPreferenceChangeListener(new DisablePassphraseClickListener());
|
2013-09-16 07:55:01 +00:00
|
|
|
this.findPreference(MMS_PREF)
|
|
|
|
.setOnPreferenceClickListener(new ApnPreferencesClickListener());
|
2013-12-03 07:10:59 +00:00
|
|
|
this.findPreference(LED_COLOR_PREF)
|
|
|
|
.setOnPreferenceChangeListener(new ListSummaryListener());
|
|
|
|
this.findPreference(LED_BLINK_PREF)
|
|
|
|
.setOnPreferenceChangeListener(new ListSummaryListener());
|
|
|
|
this.findPreference(RINGTONE_PREF)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneSummaryListener());
|
|
|
|
|
|
|
|
initializeListSummary((ListPreference) findPreference(LED_COLOR_PREF));
|
|
|
|
initializeListSummary((ListPreference) findPreference(LED_BLINK_PREF));
|
|
|
|
initializeRingtoneSummary((RingtonePreference) findPreference(RINGTONE_PREF));
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
2013-06-30 01:03:55 +00:00
|
|
|
dynamicLanguage.onResume(this);
|
2013-06-21 18:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
2013-02-11 01:30:51 +00:00
|
|
|
public void onDestroy() {
|
2013-05-24 01:54:16 +00:00
|
|
|
MemoryCleaner.clean((MasterSecret) getIntent().getParcelableExtra("master_secret"));
|
2013-02-11 01:30:51 +00:00
|
|
|
super.onDestroy();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
public void onActivityResult(int reqCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(reqCode, resultCode, data);
|
|
|
|
|
2013-07-01 17:15:36 +00:00
|
|
|
Log.w("ApplicationPreferencesActivity", "Got result: " + resultCode + " for req: " + reqCode);
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
switch (reqCode) {
|
2013-07-01 17:15:36 +00:00
|
|
|
case PICK_IDENTITY_CONTACT: handleIdentitySelection(data); break;
|
|
|
|
case ENABLE_PASSPHRASE_ACTIVITY: finish(); break;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2012-08-03 03:23:41 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2013-02-17 19:42:30 +00:00
|
|
|
case android.R.id.home:
|
|
|
|
Intent intent = new Intent(this, ConversationListActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
return true;
|
2012-08-03 03:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-05 23:48:29 +00:00
|
|
|
|
2013-12-02 20:31:59 +00:00
|
|
|
private void initializePlatformSpecificOptions() {
|
|
|
|
PreferenceGroup generalCategory = (PreferenceGroup)findPreference("general_category");
|
|
|
|
Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF);
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
generalCategory.removePreference(findPreference(ALL_SMS_PREF));
|
|
|
|
generalCategory.removePreference(findPreference(ALL_MMS_PERF));
|
|
|
|
|
|
|
|
if (Util.isDefaultSmsProvider(this)) {
|
|
|
|
generalCategory.removePreference(defaultPreference);
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
|
|
|
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
|
|
|
|
|
|
|
|
defaultPreference.setIntent(intent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
generalCategory.removePreference(defaultPreference);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
private void initializeEditTextSummary(final EditTextPreference preference) {
|
|
|
|
if (preference.getText() == null) {
|
|
|
|
preference.setSummary("Not set");
|
|
|
|
} else {
|
|
|
|
preference.setSummary(preference.getText());
|
|
|
|
}
|
|
|
|
|
|
|
|
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
|
|
|
preference.setSummary(newValue == null ? "Not set" : ((String) newValue));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializePushMessagingToggle() {
|
|
|
|
CheckBoxPreference preference = (CheckBoxPreference)this.findPreference(PUSH_MESSAGING_PREF);
|
|
|
|
preference.setChecked(TextSecurePreferences.isPushRegistered(this));
|
|
|
|
preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
|
|
|
|
}
|
|
|
|
|
2012-10-23 02:17:08 +00:00
|
|
|
private void initializeIdentitySelection() {
|
|
|
|
ContactIdentityManager identity = ContactIdentityManager.getInstance(this);
|
|
|
|
|
|
|
|
if (identity.isSelfIdentityAutoDetected()) {
|
|
|
|
Preference preference = this.findPreference(DISPLAY_CATEGORY_PREF);
|
|
|
|
this.getPreferenceScreen().removePreference(preference);
|
|
|
|
} else {
|
|
|
|
Uri contactUri = identity.getSelfIdentityUri();
|
|
|
|
|
|
|
|
if (contactUri != null) {
|
|
|
|
String contactName = ContactAccessor.getInstance().getNameFromContact(this, contactUri);
|
2013-07-11 21:58:40 +00:00
|
|
|
this.findPreference(TextSecurePreferences.IDENTITY_PREF)
|
2012-10-23 02:17:08 +00:00
|
|
|
.setSummary(String.format(getString(R.string.ApplicationPreferencesActivity_currently_s),
|
|
|
|
contactName));
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
this.findPreference(TextSecurePreferences.IDENTITY_PREF)
|
2012-10-23 02:17:08 +00:00
|
|
|
.setOnPreferenceClickListener(new IdentityPreferenceClickListener());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 07:10:59 +00:00
|
|
|
private void initializeListSummary(ListPreference pref) {
|
|
|
|
pref.setSummary(pref.getEntry());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeRingtoneSummary(RingtonePreference pref) {
|
|
|
|
RingtoneSummaryListener listener =
|
|
|
|
(RingtoneSummaryListener) pref.getOnPreferenceChangeListener();
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
|
|
|
listener.onPreferenceChange(pref, sharedPreferences.getString(pref.getKey(), ""));
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void handleIdentitySelection(Intent data) {
|
2012-10-23 02:17:08 +00:00
|
|
|
Uri contactUri = data.getData();
|
|
|
|
|
|
|
|
if (contactUri != null) {
|
2013-07-11 21:58:40 +00:00
|
|
|
TextSecurePreferences.setIdentityContactUri(this, contactUri.toString());
|
2012-10-23 02:17:08 +00:00
|
|
|
initializeIdentitySelection();
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
2013-07-11 21:58:40 +00:00
|
|
|
if (key.equals(TextSecurePreferences.THEME_PREF)) {
|
2013-06-21 18:56:59 +00:00
|
|
|
dynamicTheme.onResume(this);
|
2013-07-11 21:58:40 +00:00
|
|
|
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
|
2013-06-30 01:03:55 +00:00
|
|
|
dynamicLanguage.onResume(this);
|
2013-06-21 18:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
private class PushMessagingClickListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
private static final int SUCCESS = 0;
|
|
|
|
private static final int NETWORK_ERROR = 1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
|
|
|
if (((CheckBoxPreference)preference).isChecked()) {
|
|
|
|
new AsyncTask<Void, Void, Integer>() {
|
|
|
|
private ProgressDialog dialog;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute() {
|
|
|
|
dialog = ProgressDialog.show(ApplicationPreferencesActivity.this,
|
|
|
|
getString(R.string.ApplicationPreferencesActivity_unregistering),
|
|
|
|
getString(R.string.ApplicationPreferencesActivity_unregistering_for_data_based_communication),
|
|
|
|
true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Integer result) {
|
|
|
|
if (dialog != null)
|
|
|
|
dialog.dismiss();
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case NETWORK_ERROR:
|
|
|
|
Toast.makeText(ApplicationPreferencesActivity.this,
|
|
|
|
getString(R.string.ApplicationPreferencesActivity_error_connecting_to_server),
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
break;
|
|
|
|
case SUCCESS:
|
|
|
|
((CheckBoxPreference)preference).setChecked(false);
|
2013-07-22 20:01:30 +00:00
|
|
|
TextSecurePreferences.setPushRegistered(ApplicationPreferencesActivity.this, false);
|
2013-07-11 21:58:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Integer doInBackground(Void... params) {
|
|
|
|
try {
|
2013-10-19 18:15:45 +00:00
|
|
|
Context context = ApplicationPreferencesActivity.this;
|
2013-11-20 08:45:51 +00:00
|
|
|
PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL,
|
|
|
|
TextSecurePushCredentials.getInstance());
|
2013-07-11 21:58:40 +00:00
|
|
|
|
|
|
|
socket.unregisterGcmId();
|
|
|
|
GCMRegistrar.unregister(context);
|
|
|
|
return SUCCESS;
|
2013-08-02 19:48:25 +00:00
|
|
|
} catch (AuthorizationFailedException afe) {
|
|
|
|
Log.w("ApplicationPreferencesActivity", afe);
|
|
|
|
return SUCCESS;
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.w("ApplicationPreferencesActivity", ioe);
|
2013-07-11 21:58:40 +00:00
|
|
|
return NETWORK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
} else {
|
2013-08-15 15:25:30 +00:00
|
|
|
Intent intent = new Intent(ApplicationPreferencesActivity.this, RegistrationActivity.class);
|
|
|
|
intent.putExtra("master_secret", getIntent().getParcelableExtra("master_secret"));
|
|
|
|
startActivity(intent);
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class IdentityPreferenceClickListener implements Preference.OnPreferenceClickListener {
|
2013-02-11 01:30:51 +00:00
|
|
|
@Override
|
2011-12-20 18:20:44 +00:00
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2012-10-23 02:17:08 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_PICK);
|
|
|
|
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
|
2011-12-20 18:20:44 +00:00
|
|
|
startActivityForResult(intent, PICK_IDENTITY_CONTACT);
|
|
|
|
return true;
|
2012-07-20 02:23:49 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class ChangePassphraseClickListener implements Preference.OnPreferenceClickListener {
|
2013-02-11 01:30:51 +00:00
|
|
|
@Override
|
2011-12-20 18:20:44 +00:00
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2013-02-17 19:42:30 +00:00
|
|
|
if (MasterSecretUtil.isPassphraseInitialized(ApplicationPreferencesActivity.this)) {
|
2011-12-20 18:20:44 +00:00
|
|
|
startActivity(new Intent(ApplicationPreferencesActivity.this, PassphraseChangeActivity.class));
|
|
|
|
} else {
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.makeText(ApplicationPreferencesActivity.this,
|
2012-09-20 02:56:04 +00:00
|
|
|
R.string.ApplicationPreferenceActivity_you_havent_set_a_passphrase_yet,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 02:23:49 +00:00
|
|
|
|
2013-01-10 05:06:56 +00:00
|
|
|
private class TrimNowClickListener implements Preference.OnPreferenceClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2013-07-11 21:58:40 +00:00
|
|
|
final int threadLengthLimit = TextSecurePreferences.getThreadTrimLength(ApplicationPreferencesActivity.this);
|
2013-01-10 05:06:56 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationPreferencesActivity.this);
|
|
|
|
builder.setTitle(R.string.ApplicationPreferencesActivity_delete_all_old_messages_now);
|
|
|
|
builder.setMessage(String.format(getString(R.string.ApplicationPreferencesActivity_are_you_sure_you_would_like_to_immediately_trim_all_conversation_threads_to_the_s_most_recent_messages),
|
|
|
|
threadLengthLimit));
|
|
|
|
builder.setPositiveButton(R.string.ApplicationPreferencesActivity_delete,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Trimmer.trimAllThreads(ApplicationPreferencesActivity.this, threadLengthLimit);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
builder.show();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-01 17:15:36 +00:00
|
|
|
private class DisablePassphraseClickListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
|
|
|
if (!((CheckBoxPreference)preference).isChecked()) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationPreferencesActivity.this);
|
|
|
|
builder.setTitle(R.string.ApplicationPreferencesActivity_disable_storage_encryption);
|
|
|
|
builder.setMessage(R.string.ApplicationPreferencesActivity_warning_this_will_disable_storage_encryption_for_all_messages);
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
builder.setPositiveButton(R.string.ApplicationPreferencesActivity_disable, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
MasterSecret masterSecret = getIntent().getParcelableExtra("master_secret");
|
|
|
|
MasterSecretUtil.changeMasterSecretPassphrase(ApplicationPreferencesActivity.this,
|
|
|
|
masterSecret,
|
|
|
|
MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
|
|
|
|
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
TextSecurePreferences.setPasswordDisabled(ApplicationPreferencesActivity.this, true);
|
2013-07-01 17:15:36 +00:00
|
|
|
((CheckBoxPreference)preference).setChecked(true);
|
|
|
|
|
|
|
|
Intent intent = new Intent(ApplicationPreferencesActivity.this, KeyCachingService.class);
|
|
|
|
intent.setAction(KeyCachingService.DISABLE_ACTION);
|
|
|
|
startService(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
builder.show();
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(ApplicationPreferencesActivity.this,
|
|
|
|
PassphraseChangeActivity.class);
|
|
|
|
startActivityForResult(intent, ENABLE_PASSPHRASE_ACTIVITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 05:06:56 +00:00
|
|
|
private class TrimLengthValidationListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
public TrimLengthValidationListener() {
|
2013-07-11 21:58:40 +00:00
|
|
|
EditTextPreference preference = (EditTextPreference)findPreference(TextSecurePreferences.THREAD_TRIM_LENGTH);
|
2013-01-10 05:06:56 +00:00
|
|
|
preference.setSummary(preference.getText() + " " + getString(R.string.ApplicationPreferencesActivity_messages_per_conversation));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
if (newValue == null || ((String)newValue).trim().length() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Integer.parseInt((String)newValue);
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
Log.w("ApplicationPreferencesActivity", nfe);
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-11 01:30:51 +00:00
|
|
|
|
2013-01-14 20:10:57 +00:00
|
|
|
if (Integer.parseInt((String)newValue) < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-10 05:06:56 +00:00
|
|
|
|
2013-07-01 17:15:36 +00:00
|
|
|
preference.setSummary(newValue + " " +
|
2013-01-10 05:06:56 +00:00
|
|
|
getString(R.string.ApplicationPreferencesActivity_messages_per_conversation));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-03-28 12:45:07 +00:00
|
|
|
|
2013-09-16 07:55:01 +00:00
|
|
|
private class ApnPreferencesClickListener implements Preference.OnPreferenceClickListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
startActivity(new Intent(ApplicationPreferencesActivity.this, MmsPreferencesActivity.class));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 07:10:59 +00:00
|
|
|
private class ListSummaryListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
|
|
|
ListPreference asList = (ListPreference) preference;
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
for (; index < asList.getEntryValues().length; index++) {
|
|
|
|
if (value.equals(asList.getEntryValues()[index])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
asList.setSummary(asList.getEntries()[index]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class RingtoneSummaryListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
String value = (String) newValue;
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(value)) {
|
|
|
|
preference.setSummary(R.string.preferences__default);
|
|
|
|
} else {
|
|
|
|
Ringtone tone = RingtoneManager.getRingtone(ApplicationPreferencesActivity.this,
|
|
|
|
Uri.parse(value));
|
|
|
|
if (tone != null) {
|
|
|
|
preference.setSummary(tone.getTitle(ApplicationPreferencesActivity.this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:45:07 +00:00
|
|
|
/* http://code.google.com/p/android/issues/detail?id=4611#c35 */
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
|
|
|
|
{
|
|
|
|
super.onPreferenceTreeClick(preferenceScreen, preference);
|
|
|
|
if (preference!=null)
|
|
|
|
if (preference instanceof PreferenceScreen)
|
|
|
|
if (((PreferenceScreen)preference).getDialog()!=null)
|
|
|
|
((PreferenceScreen)preference).getDialog().getWindow().getDecorView().setBackgroundDrawable(this.getWindow().getDecorView().getBackground().getConstantState().newDrawable());
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-21 18:56:59 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|