forked from CyanogenMod/android_packages_apps_Mms
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMessagingPreferenceActivity.java
More file actions
executable file
·434 lines (381 loc) · 19.2 KB
/
MessagingPreferenceActivity.java
File metadata and controls
executable file
·434 lines (381 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/*
* Copyright (C) 2007-2008 Esmertec AG.
* Copyright (C) 2007-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.mms.ui;
import com.android.mms.MmsApp;
import com.android.mms.MmsConfig;
import com.android.mms.R;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceChangeListener;
import android.provider.SearchRecentSuggestions;
import android.view.Menu;
import android.view.MenuItem;
import com.android.mms.templates.TemplatesListActivity;
import com.android.mms.util.Recycler;
/**
* With this activity, users can set preferences for MMS and SMS and
* can access and manipulate SMS messages stored on the SIM.
*/
public class MessagingPreferenceActivity extends PreferenceActivity
implements OnPreferenceChangeListener {
// Symbolic names for the keys used for preference lookup
public static final String MMS_DELIVERY_REPORT_MODE = "pref_key_mms_delivery_reports";
public static final String EXPIRY_TIME = "pref_key_mms_expiry";
public static final String PRIORITY = "pref_key_mms_priority";
public static final String READ_REPORT_MODE = "pref_key_mms_read_reports";
public static final String SMS_DELIVERY_REPORT_MODE = "pref_key_sms_delivery_reports";
public static final String SMS_SPLIT_COUNTER = "pref_key_sms_split_counter";
public static final String SMS_SEND_COUNTDOWN = "pref_key_sms_send_countdown";
public static final String SMS_SEND_COUNTDOWN_VALUE = "pref_key_sms_send_countdown_value";
public static final String NOTIFICATION_ENABLED = "pref_key_enable_notifications";
public static final String NOTIFICATION_VIBRATE = "pref_key_vibrate";
public static final String NOTIFICATION_VIBRATE_WHEN= "pref_key_vibrateWhen";
public static final String NOTIFICATION_RINGTONE = "pref_key_ringtone";
public static final String AUTO_RETRIEVAL = "pref_key_mms_auto_retrieval";
public static final String RETRIEVAL_DURING_ROAMING = "pref_key_mms_retrieval_during_roaming";
public static final String AUTO_DELETE = "pref_key_auto_delete";
public static final String MANAGE_TEMPLATES = "pref_key_templates_manage";
public static final String SHOW_GESTURE = "pref_key_templates_show_gesture";
public static final String GESTURE_SENSITIVITY = "pref_key_templates_gestures_sensitivity";
public static final String GESTURE_SENSITIVITY_VALUE= "pref_key_templates_gestures_sensitivity_value";
public static final String STRIP_UNICODE = "pref_key_strip_unicode";
public static final String ENABLE_EMOJIS = "pref_key_enable_emojis";
public static final String FULL_TIMESTAMP = "pref_key_mms_full_timestamp";
public static final String SENT_TIMESTAMP = "pref_key_mms_use_sent_timestamp";
public static final String MOTION_CALL_RECIPIENT = "pref_key_motion_call_recipient";
public static final String NOTIFICATION_VIBRATE_PATTERN = "pref_key_mms_notification_vibrate_pattern";
public static final String NOTIFICATION_VIBRATE_PATTERN_CUSTOM = "pref_key_mms_notification_vibrate_pattern_custom";
public static final String NOTIFICATION_VIBRATE_CALL ="pre_key_mms_notification_vibrate_call";
public static final String INPUT_TYPE = "pref_key_mms_input_type";
// Menu entries
private static final int MENU_RESTORE_DEFAULTS = 1;
private Preference mSmsLimitPref;
private Preference mSmsDeliveryReportPref;
private CheckBoxPreference mSmsSplitCounterPref;
private Preference mMmsLimitPref;
private Preference mMmsDeliveryReportPref;
private Preference mMmsReadReportPref;
private Preference mManageSimPref;
private Preference mClearHistoryPref;
private CheckBoxPreference mEnableMultipartSMS;
private Preference mSmsToMmsTextThreshold;
private ListPreference mVibrateWhenPref;
private CheckBoxPreference mEnableNotificationsPref;
private CheckBoxPreference mMotionCallRecipientPref;
private Recycler mSmsRecycler;
private Recycler mMmsRecycler;
private Preference mManageTemplate;
private ListPreference mGestureSensitivity;
private static final int CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG = 3;
private CharSequence[] mVibrateEntries;
private CharSequence[] mVibrateValues;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.preferences);
mManageSimPref = findPreference("pref_key_manage_sim_messages");
mSmsLimitPref = findPreference("pref_key_sms_delete_limit");
mSmsDeliveryReportPref = findPreference("pref_key_sms_delivery_reports");
mSmsSplitCounterPref = (CheckBoxPreference) findPreference("pref_key_sms_split_counter");
mMmsDeliveryReportPref = findPreference("pref_key_mms_delivery_reports");
mMmsReadReportPref = findPreference("pref_key_mms_read_reports");
mMmsLimitPref = findPreference("pref_key_mms_delete_limit");
mClearHistoryPref = findPreference("pref_key_mms_clear_history");
mEnableNotificationsPref = (CheckBoxPreference) findPreference(NOTIFICATION_ENABLED);
mMotionCallRecipientPref = (CheckBoxPreference) findPreference(MOTION_CALL_RECIPIENT);
mVibrateWhenPref = (ListPreference) findPreference(NOTIFICATION_VIBRATE_WHEN);
mManageTemplate = findPreference(MANAGE_TEMPLATES);
mGestureSensitivity = (ListPreference) findPreference(GESTURE_SENSITIVITY);
mEnableMultipartSMS = (CheckBoxPreference)findPreference("pref_key_sms_EnableMultipartSMS");
mSmsToMmsTextThreshold = findPreference("pref_key_sms_SmsToMmsTextThreshold");
mVibrateEntries = getResources().getTextArray(R.array.prefEntries_vibrateWhen);
mVibrateValues = getResources().getTextArray(R.array.prefValues_vibrateWhen);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
setMessagePreferences();
}
@Override
protected void onResume() {
super.onResume();
// Since the enabled notifications pref can be changed outside of this activity,
// we have to reload it whenever we resume.
setEnabledNotificationsPref();
registerListeners();
}
private void setMessagePreferences() {
if (!MmsApp.getApplication().getTelephonyManager().hasIccCard()) {
// No SIM card, remove the SIM-related prefs
PreferenceCategory smsCategory =
(PreferenceCategory)findPreference("pref_key_sms_settings");
smsCategory.removePreference(mManageSimPref);
}
if (!MmsConfig.getSMSDeliveryReportsEnabled()) {
PreferenceCategory smsCategory =
(PreferenceCategory)findPreference("pref_key_sms_settings");
smsCategory.removePreference(mSmsDeliveryReportPref);
}
if (!MmsConfig.getSplitSmsEnabled()) {
// SMS Split disabled, remove SplitCounter pref
PreferenceCategory smsCategory =
(PreferenceCategory)findPreference("pref_key_sms_settings");
smsCategory.removePreference(mSmsSplitCounterPref);
}
if (!MmsConfig.getMmsEnabled()) {
// No Mms, remove all the mms-related preferences
PreferenceCategory mmsOptions =
(PreferenceCategory)findPreference("pref_key_mms_settings");
getPreferenceScreen().removePreference(mmsOptions);
PreferenceCategory storageOptions =
(PreferenceCategory)findPreference("pref_key_storage_settings");
storageOptions.removePreference(findPreference("pref_key_mms_delete_limit"));
} else {
if (!MmsConfig.getMMSDeliveryReportsEnabled()) {
PreferenceCategory mmsOptions =
(PreferenceCategory)findPreference("pref_key_mms_settings");
mmsOptions.removePreference(mMmsDeliveryReportPref);
}
if (!MmsConfig.getMMSReadReportsEnabled()) {
PreferenceCategory mmsOptions =
(PreferenceCategory)findPreference("pref_key_mms_settings");
mmsOptions.removePreference(mMmsReadReportPref);
}
}
mEnableMultipartSMS.setChecked(!MmsConfig.getMultipartSmsEnabled());
mSmsToMmsTextThreshold.setDefaultValue(MmsConfig.getSmsToMmsTextThreshold()-1);
setEnabledNotificationsPref();
// If needed, migrate vibration setting from a previous version
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if (!sharedPreferences.contains(NOTIFICATION_VIBRATE_WHEN) &&
sharedPreferences.contains(NOTIFICATION_VIBRATE)) {
int stringId = sharedPreferences.getBoolean(NOTIFICATION_VIBRATE, false) ?
R.string.prefDefault_vibrate_true :
R.string.prefDefault_vibrate_false;
mVibrateWhenPref.setValue(getString(stringId));
}
mManageTemplate.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(MessagingPreferenceActivity.this,
TemplatesListActivity.class);
startActivity(intent);
return false;
}
});
String gestureSensitivity = String.valueOf(sharedPreferences.getInt(GESTURE_SENSITIVITY_VALUE, 3));
mGestureSensitivity.setSummary(gestureSensitivity);
mGestureSensitivity.setValue(gestureSensitivity);
mGestureSensitivity.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int value = Integer.parseInt((String) newValue);
sharedPreferences.edit().putInt(GESTURE_SENSITIVITY_VALUE, value).commit();
mGestureSensitivity.setSummary(String.valueOf(value));
return true;
}
});
mSmsRecycler = Recycler.getSmsRecycler();
mMmsRecycler = Recycler.getMmsRecycler();
// Fix up the recycler's summary with the correct values
setSmsDisplayLimit();
setMmsDisplayLimit();
// Fix up the sms to mms treshold
setSmsToMmsTextThreshold();
adjustVibrateSummary(mVibrateWhenPref.getValue());
}
private void setEnabledNotificationsPref() {
// The "enable notifications" setting is really stored in our own prefs. Read the
// current value and set the checkbox to match.
mEnableNotificationsPref.setChecked(getNotificationEnabled(this));
}
private void setSmsDisplayLimit() {
mSmsLimitPref.setSummary(
getString(R.string.pref_summary_delete_limit,
mSmsRecycler.getMessageLimit(this)));
}
private void setMmsDisplayLimit() {
mMmsLimitPref.setSummary(
getString(R.string.pref_summary_delete_limit,
mMmsRecycler.getMessageLimit(this)));
}
private void setSmsToMmsTextThreshold() {
mSmsToMmsTextThreshold.setSummary(
getString(R.string.pref_summary_sms_SmsToMmsTextThreshold,
MmsConfig.getSmsToMmsTextThreshold()-1));
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.clear();
menu.add(0, MENU_RESTORE_DEFAULTS, 0, R.string.restore_default);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_RESTORE_DEFAULTS:
restoreDefaultPreferences();
return true;
case android.R.id.home:
// The user clicked on the Messaging icon in the action bar. Take them back from
// wherever they came from
finish();
return true;
}
return false;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (preference == mSmsLimitPref) {
new NumberPickerDialog(this,
mSmsLimitListener,
mSmsRecycler.getMessageLimit(this),
mSmsRecycler.getMessageMinLimit(),
mSmsRecycler.getMessageMaxLimit(),
R.string.pref_title_sms_delete).show();
} else if (preference == mMmsLimitPref) {
new NumberPickerDialog(this,
mMmsLimitListener,
mMmsRecycler.getMessageLimit(this),
mMmsRecycler.getMessageMinLimit(),
mMmsRecycler.getMessageMaxLimit(),
R.string.pref_title_mms_delete).show();
} else if (preference == mSmsToMmsTextThreshold) {
new NumberPickerDialog(this,
mSmsToMmsTextThresholdListener,
MmsConfig.getSmsToMmsTextThreshold()-1,
MmsConfig.getSmsToMmsTextThresholdMin()-1,
MmsConfig.getSmsToMmsTextThresholdMax()-1,
R.string.pref_title_sms_SmsToMmsTextThreshold).show();
} else if (preference == mManageSimPref) {
startActivity(new Intent(this, ManageSimMessages.class));
} else if (preference == mClearHistoryPref) {
showDialog(CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG);
return true;
} else if (preference == mEnableNotificationsPref) {
// Update the actual "enable notifications" value that is stored in secure settings.
enableNotifications(mEnableNotificationsPref.isChecked(), this);
} else if (preference == mEnableMultipartSMS) {
//should be false when the checkbox is checked
MmsConfig.setEnableMultipartSMS(!mEnableMultipartSMS.isChecked());
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
private void restoreDefaultPreferences() {
PreferenceManager.getDefaultSharedPreferences(this)
.edit().clear().apply();
setPreferenceScreen(null);
addPreferencesFromResource(R.xml.preferences);
setMessagePreferences();
}
NumberPickerDialog.OnNumberSetListener mSmsLimitListener =
new NumberPickerDialog.OnNumberSetListener() {
public void onNumberSet(int limit) {
mSmsRecycler.setMessageLimit(MessagingPreferenceActivity.this, limit);
setSmsDisplayLimit();
}
};
NumberPickerDialog.OnNumberSetListener mMmsLimitListener =
new NumberPickerDialog.OnNumberSetListener() {
public void onNumberSet(int limit) {
mMmsRecycler.setMessageLimit(MessagingPreferenceActivity.this, limit);
setMmsDisplayLimit();
}
};
NumberPickerDialog.OnNumberSetListener mSmsToMmsTextThresholdListener =
new NumberPickerDialog.OnNumberSetListener() {
public void onNumberSet(int limit) {
SharedPreferences.Editor editPrefs =
PreferenceManager.getDefaultSharedPreferences(MessagingPreferenceActivity.this).edit();
editPrefs.putInt("pref_key_sms_SmsToMmsTextThreshold", limit);
editPrefs.apply();
MmsConfig.setSmsToMmsTextThreshold(limit+1);
setSmsToMmsTextThreshold();
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG:
return new AlertDialog.Builder(MessagingPreferenceActivity.this)
.setTitle(R.string.confirm_clear_search_title)
.setMessage(R.string.confirm_clear_search_text)
.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
SearchRecentSuggestions recent =
((MmsApp)getApplication()).getRecentSuggestions();
if (recent != null) {
recent.clearHistory();
}
dialog.dismiss();
}
})
.setNegativeButton(android.R.string.cancel, null)
.setIconAttribute(android.R.attr.alertDialogIcon)
.create();
}
return super.onCreateDialog(id);
}
public static boolean getNotificationEnabled(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean notificationsEnabled =
prefs.getBoolean(MessagingPreferenceActivity.NOTIFICATION_ENABLED, true);
return notificationsEnabled;
}
public static void enableNotifications(boolean enabled, Context context) {
// Store the value of notifications in SharedPreferences
SharedPreferences.Editor editor =
PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(MessagingPreferenceActivity.NOTIFICATION_ENABLED, enabled);
editor.apply();
}
private void registerListeners() {
mVibrateWhenPref.setOnPreferenceChangeListener(this);
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean result = false;
if (preference == mVibrateWhenPref) {
adjustVibrateSummary((String)newValue);
result = true;
}
return result;
}
private void adjustVibrateSummary(String value) {
int len = mVibrateValues.length;
for (int i = 0; i < len; i++) {
if (mVibrateValues[i].equals(value)) {
mVibrateWhenPref.setSummary(mVibrateEntries[i]);
return;
}
}
mVibrateWhenPref.setSummary(null);
}
}