From dccfa8af0254503af4e4c14076468c5127feb737 Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 13 Mar 2014 16:24:28 +0100 Subject: [PATCH 01/10] Add Custom Vibrate Patterns to Settings --- res/layout/vibrate_pattern_dialog.xml | 51 ++++++ res/values/arrays.xml | 22 ++- res/values/strings.xml | 13 +- res/xml/preferences.xml | 12 +- .../ApplicationPreferencesActivity.java | 3 + .../notifications/MessageNotifier.java | 21 ++- .../VibratePatternListPreference.java | 172 ++++++++++++++++++ .../securesms/util/TextSecurePreferences.java | 15 +- 8 files changed, 295 insertions(+), 14 deletions(-) create mode 100644 res/layout/vibrate_pattern_dialog.xml create mode 100644 src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java diff --git a/res/layout/vibrate_pattern_dialog.xml b/res/layout/vibrate_pattern_dialog.xml new file mode 100644 index 00000000000..5b6dc0f3acf --- /dev/null +++ b/res/layout/vibrate_pattern_dialog.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 06a106b12b2..6507be6a0ac 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -110,7 +110,7 @@ white none - + @string/preferences__fast @string/preferences__normal @@ -125,6 +125,26 @@ custom + + @string/preferences__default + @string/preferences__pref_vibrate_2x_Short + @string/preferences__pref_vibrate_2x_Long + @string/preferences__pref_vibrate_3x_Short + @string/preferences__pref_vibrate_3x_Long + @string/preferences__custom + @string/preferences__pref_disabled + + + + default + 0,300,200,300 + 0,750,400,750 + 0,300,200,300,200,300 + 0,750,400,750,400,750 + custom + disabled + + @string/arrays__import_export @string/arrays__my_identity_key diff --git a/res/values/strings.xml b/res/values/strings.xml index 6f2418b7ab0..15170f23ee9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -681,12 +681,21 @@ On For: Off For: Custom LED blink pattern set! + Vibrate Pattern + 2x Short + 2x Long + 3x Short + 3x Long + Disabled + Test + Custom Vibrate pattern set! + Custom Vibrate Pattern + Wrong Format of Vibrate Pattern! + <Time Off>,<Time On>,... (in ms)\n\nExample: 0,500,100,500 Sound Change notification sound In-thread notifications Play notification sound when viewing an active conversation. - Vibrate - Also vibrate when notified minutes hours Green diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index cfa9c60f02f..c9ff909d0ed 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -64,11 +64,13 @@ android:dependency="pref_key_enable_notifications" android:defaultValue="true" /> - + diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index af426f05f40..cbecdb97b38 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -122,6 +122,8 @@ protected void onCreate(Bundle icicle) { .setOnPreferenceChangeListener(new ListSummaryListener()); this.findPreference(TextSecurePreferences.LED_BLINK_PREF) .setOnPreferenceChangeListener(new ListSummaryListener()); + this.findPreference(TextSecurePreferences.VIBRATE_PREF) + .setOnPreferenceChangeListener(new ListSummaryListener()); this.findPreference(TextSecurePreferences.RINGTONE_PREF) .setOnPreferenceChangeListener(new RingtoneSummaryListener()); this.findPreference(UPDATE_DIRECTORY_PREF) @@ -134,6 +136,7 @@ protected void onCreate(Bundle icicle) { initializeOutgoingSmsSummary((OutgoingSmsPreference) findPreference(OUTGOING_SMS_PREF)); initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_COLOR_PREF)); initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF)); + initializeListSummary((ListPreference) findPreference(TextSecurePreferences.VIBRATE_PREF)); initializeRingtoneSummary((RingtonePreference) findPreference(TextSecurePreferences.RINGTONE_PREF)); } diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index f0a8e86f98e..3376d67f8cb 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -53,6 +53,7 @@ import org.whispersystems.textsecure.push.IncomingPushMessage; import java.io.IOException; +import java.util.ArrayList; import java.util.List; /** @@ -353,7 +354,8 @@ private static void setNotificationAlarms(Context context, boolean signal) { String ringtone = TextSecurePreferences.getNotificationRingtone(context); - boolean vibrate = TextSecurePreferences.isNotificationVibrateEnabled(context); + String vibrate = TextSecurePreferences.getNotificationVibrate(context); + String vibratePatternCustom = TextSecurePreferences.getNotificationVibratePatternCustom(context); String ledColor = TextSecurePreferences.getNotificationLedColor(context); String ledBlinkPattern = TextSecurePreferences.getNotificationLedPattern(context); String ledBlinkPatternCustom = TextSecurePreferences.getNotificationLedPatternCustom(context); @@ -361,8 +363,10 @@ private static void setNotificationAlarms(Context context, builder.setSound(TextUtils.isEmpty(ringtone) || !signal ? null : Uri.parse(ringtone)); - if (signal && vibrate) { - builder.setDefaults(Notification.DEFAULT_VIBRATE); + if (signal && !vibrate.equals("disabled")) { + if (vibrate.equals("default")) builder.setDefaults(Notification.DEFAULT_VIBRATE); + else if (vibrate.equals("custom")) builder.setVibrate(parseVibratePattern(vibratePatternCustom)); + else builder.setVibrate(parseVibratePattern(vibrate)); } if (!ledColor.equals("none")) { @@ -372,6 +376,17 @@ private static void setNotificationAlarms(Context context, } } + public static long[] parseVibratePattern(String VibratePattern) { + String[] vibratePatternCustomArrayString = VibratePattern.split(","); + long[] vibratePatternCustomArray = new long[vibratePatternCustomArrayString.length]; + + for (int i = 0; i < vibratePatternCustomArrayString.length; i++) { + vibratePatternCustomArray[i] = Long.parseLong(vibratePatternCustomArrayString[i].trim()); + } + + return vibratePatternCustomArray; + } + private static String[] parseBlinkPattern(String blinkPattern, String blinkPatternCustom) { if (blinkPattern.equals("custom")) blinkPattern = blinkPatternCustom; diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java new file mode 100644 index 00000000000..c93c694eef9 --- /dev/null +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -0,0 +1,172 @@ +/** + * Copyright (C) 2014 Whisper Systems + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.thoughtcrime.securesms.preferences; + +import android.app.AlertDialog; +import android.os.Vibrator; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Parcelable; +import android.preference.ListPreference; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.notifications.MessageNotifier; +import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.thoughtcrime.securesms.util.Dialogs; + +/** + * List preference for Vibrate Pattern + * + * @author agrajaghh + */ + +public class VibratePatternListPreference extends ListPreference { + + private Context context; + + private EditText VibratePatternEditText; + + private boolean dialogInProgress; + + public VibratePatternListPreference(Context context) { + super(context); + this.context = context; + } + + public VibratePatternListPreference(Context context, AttributeSet attrs) { + super(context, attrs); + this.context = context; + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + if (positiveResult && getValue().equals("custom")) { + showDialog(); + } + } + + private void showDialog() { + LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.vibrate_pattern_dialog, null); + this.VibratePatternEditText = (EditText)view.findViewById(R.id.editTextPattern); + + initializeDialog(view); + VibratePatternEditText.setText(TextSecurePreferences.getNotificationVibratePatternCustom(context)); + dialogInProgress = true; + } + + private void initializeDialog(View view) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setIcon(Dialogs.resolveIcon(context, R.attr.dialog_info_icon)); + builder.setTitle(R.string.preferences__pref_vibrate_custom_pattern_title); + builder.setView(view); + builder.setOnCancelListener(new DialogInterface.OnCancelListener() { + public void onCancel (DialogInterface dialog){ + dialogInProgress = false; + } + }); + builder.setPositiveButton(android.R.string.ok, new EmptyClickListener()); + builder.setNeutralButton(R.string.preferences__pref_vibrate_custom_pattern_test, new EmptyClickListener()); + builder.setNegativeButton(android.R.string.cancel, new EmptyClickListener()); + builder.setInverseBackgroundForced(true); + + AlertDialog dialog = builder.show(); + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new OkayListener(dialog)); + dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new TestListener(context)); + dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new CancelListener(dialog)); + } + + private class EmptyClickListener implements DialogInterface.OnClickListener { + @Override + public void onClick(DialogInterface dialog, int which) { } + } + + private class OkayListener implements View.OnClickListener { + private AlertDialog dialog; + public OkayListener( AlertDialog dialog) { this.dialog = dialog; } + + @Override + public void onClick(View view) { + final String VibratePattern = VibratePatternEditText.getText().toString(); + + try + { + MessageNotifier.parseVibratePattern(VibratePattern); + TextSecurePreferences.setNotificationVibratePatternCustom(context, VibratePattern); + Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_set, Toast.LENGTH_LONG).show(); + dialog.dismiss(); + dialogInProgress = false; + } + catch(NumberFormatException e) + { + Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_wrong, Toast.LENGTH_LONG).show(); + } + } + } + + private class TestListener implements View.OnClickListener { + private Context context; + public TestListener(Context context) { this.context = context; } + + @Override + public void onClick(View view) { + final String VibratePattern = VibratePatternEditText.getText().toString(); + + try + { + Vibrator vibrator = (Vibrator)this.context.getSystemService(Context.VIBRATOR_SERVICE); + vibrator.vibrate(MessageNotifier.parseVibratePattern(VibratePattern), -1); + } + catch(NumberFormatException e) + { + Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_wrong, Toast.LENGTH_LONG).show(); + } + } + } + + private class CancelListener implements View.OnClickListener { + private AlertDialog dialog; + public CancelListener(AlertDialog dialog) { this.dialog = dialog; } + + @Override + public void onClick(View view) { + dialog.dismiss(); + dialogInProgress = false; + } + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + super.onRestoreInstanceState(state); + if (dialogInProgress) { + showDialog(); + } + } + + @Override + protected View onCreateDialogView() { + dialogInProgress = false; + return super.onCreateDialogView(); + } +} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 31e1a5da4a9..f23fe3514d1 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -19,7 +19,8 @@ public class TextSecurePreferences { public static final String ENABLE_MANUAL_MMS_PREF = "pref_enable_manual_mms"; public static final String RINGTONE_PREF = "pref_key_ringtone"; - private static final String VIBRATE_PREF = "pref_key_vibrate"; + public static final String VIBRATE_PREF = "pref_vibrate"; + private static final String VIBRATE_PATTERN_PREF_CUSTOM = "pref_vibrate_pattern_custom"; private static final String NOTIFICATION_PREF = "pref_key_enable_notifications"; public static final String LED_COLOR_PREF = "pref_led_color"; public static final String LED_BLINK_PREF = "pref_led_blink"; @@ -243,8 +244,16 @@ public static String getNotificationRingtone(Context context) { return getStringPreference(context, RINGTONE_PREF, null); } - public static boolean isNotificationVibrateEnabled(Context context) { - return getBooleanPreference(context, VIBRATE_PREF, true); + public static String getNotificationVibrate(Context context) { + return getStringPreference(context, VIBRATE_PREF, "default"); + } + + public static String getNotificationVibratePatternCustom(Context context) { + return getStringPreference(context, VIBRATE_PATTERN_PREF_CUSTOM, "0,500,100,500"); + } + + public static void setNotificationVibratePatternCustom(Context context, String pattern) { + setStringPreference(context, VIBRATE_PATTERN_PREF_CUSTOM, pattern); } public static String getNotificationLedColor(Context context) { From dcb953d9589a240d8a6dda95c957a1bc4b510061 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Sat, 17 May 2014 12:07:55 +0200 Subject: [PATCH 02/10] fix variable names and alignment --- .../securesms/ApplicationPreferencesActivity.java | 2 +- .../securesms/notifications/MessageNotifier.java | 4 ++-- .../preferences/VibratePatternListPreference.java | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index cbecdb97b38..284affa85ff 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -123,7 +123,7 @@ protected void onCreate(Bundle icicle) { this.findPreference(TextSecurePreferences.LED_BLINK_PREF) .setOnPreferenceChangeListener(new ListSummaryListener()); this.findPreference(TextSecurePreferences.VIBRATE_PREF) - .setOnPreferenceChangeListener(new ListSummaryListener()); + .setOnPreferenceChangeListener(new ListSummaryListener()); this.findPreference(TextSecurePreferences.RINGTONE_PREF) .setOnPreferenceChangeListener(new RingtoneSummaryListener()); this.findPreference(UPDATE_DIRECTORY_PREF) diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 3376d67f8cb..29f3ae56a39 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -376,8 +376,8 @@ private static void setNotificationAlarms(Context context, } } - public static long[] parseVibratePattern(String VibratePattern) { - String[] vibratePatternCustomArrayString = VibratePattern.split(","); + public static long[] parseVibratePattern(String vibratePattern) { + String[] vibratePatternCustomArrayString = vibratePattern.split(","); long[] vibratePatternCustomArray = new long[vibratePatternCustomArrayString.length]; for (int i = 0; i < vibratePatternCustomArrayString.length; i++) { diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java index c93c694eef9..91e4f7483ea 100644 --- a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -43,7 +43,7 @@ public class VibratePatternListPreference extends ListPreference { private Context context; - private EditText VibratePatternEditText; + private EditText vibratePatternEditText; private boolean dialogInProgress; @@ -69,10 +69,10 @@ protected void onDialogClosed(boolean positiveResult) { private void showDialog() { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.vibrate_pattern_dialog, null); - this.VibratePatternEditText = (EditText)view.findViewById(R.id.editTextPattern); + this.vibratePatternEditText = (EditText)view.findViewById(R.id.editTextPattern); initializeDialog(view); - VibratePatternEditText.setText(TextSecurePreferences.getNotificationVibratePatternCustom(context)); + vibratePatternEditText.setText(TextSecurePreferences.getNotificationVibratePatternCustom(context)); dialogInProgress = true; } @@ -108,7 +108,7 @@ private class OkayListener implements View.OnClickListener { @Override public void onClick(View view) { - final String VibratePattern = VibratePatternEditText.getText().toString(); + final String VibratePattern = vibratePatternEditText.getText().toString(); try { @@ -131,7 +131,7 @@ private class TestListener implements View.OnClickListener { @Override public void onClick(View view) { - final String VibratePattern = VibratePatternEditText.getText().toString(); + final String VibratePattern = vibratePatternEditText.getText().toString(); try { From 392cd5e987079e70688f8407b5929bb8c1e9b300 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Sat, 17 May 2014 17:57:05 +0200 Subject: [PATCH 03/10] fix variable names --- .../preferences/VibratePatternListPreference.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java index 91e4f7483ea..46f42dea41f 100644 --- a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -108,12 +108,12 @@ private class OkayListener implements View.OnClickListener { @Override public void onClick(View view) { - final String VibratePattern = vibratePatternEditText.getText().toString(); + final String vibratePattern = vibratePatternEditText.getText().toString(); try { - MessageNotifier.parseVibratePattern(VibratePattern); - TextSecurePreferences.setNotificationVibratePatternCustom(context, VibratePattern); + MessageNotifier.parseVibratePattern(vibratePattern); + TextSecurePreferences.setNotificationVibratePatternCustom(context, vibratePattern); Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_set, Toast.LENGTH_LONG).show(); dialog.dismiss(); dialogInProgress = false; @@ -131,12 +131,12 @@ private class TestListener implements View.OnClickListener { @Override public void onClick(View view) { - final String VibratePattern = vibratePatternEditText.getText().toString(); + final String vibratePattern = vibratePatternEditText.getText().toString(); try { Vibrator vibrator = (Vibrator)this.context.getSystemService(Context.VIBRATOR_SERVICE); - vibrator.vibrate(MessageNotifier.parseVibratePattern(VibratePattern), -1); + vibrator.vibrate(MessageNotifier.parseVibratePattern(vibratePattern), -1); } catch(NumberFormatException e) { From 0da46b312fcde9ca2df8a499981c71d4c8ccd53f Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Thu, 12 Jun 2014 12:15:25 +0200 Subject: [PATCH 04/10] Fix lowercase/uppercase --- res/values/strings.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 20b8982e6f2..9dc951a70a9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -702,17 +702,17 @@ On For: Off For: Custom LED blink pattern set! - Vibrate Pattern - 2x Short - 2x Long - 3x Short - 3x Long + Vibrate pattern + 2x short + 2x long + 3x short + 3x long Disabled Test - Custom Vibrate pattern set! - Custom Vibrate Pattern - Wrong Format of Vibrate Pattern! - <Time Off>,<Time On>,... (in ms)\n\nExample: 0,500,100,500 + Custom vibrate pattern set! + Custom vibrate pattern + Wrong format of vibrate pattern! + <Time off>,<Time on>,... (in ms)\n\nExample: 0,500,100,500 Sound Change notification sound In-thread notifications From 6b4591c1d868ec3cc59bae2ae23794ab0c2a6810 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Thu, 12 Jun 2014 12:26:40 +0200 Subject: [PATCH 05/10] Fix xml formatting --- res/layout/vibrate_pattern_dialog.xml | 87 +++++++++++++-------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/res/layout/vibrate_pattern_dialog.xml b/res/layout/vibrate_pattern_dialog.xml index 5b6dc0f3acf..2d377f7e9da 100644 --- a/res/layout/vibrate_pattern_dialog.xml +++ b/res/layout/vibrate_pattern_dialog.xml @@ -1,51 +1,50 @@ - - + + android:layout_width="fill_parent"> - + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_width="fill_parent" + android:id="@+id/ScrollViewLinearLayout" + android:paddingLeft="5sp" + android:paddingRight="5sp" + android:paddingBottom="2sp" + android:paddingTop="2sp"> + + + + + + - - - - - - + From 7502fcfab2e3ce03372d16850f33bef0ff9e8903 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Thu, 12 Jun 2014 12:31:17 +0200 Subject: [PATCH 06/10] Fix formatting --- .../preferences/VibratePatternListPreference.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java index 46f42dea41f..174e8d04eee 100644 --- a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -110,16 +110,13 @@ private class OkayListener implements View.OnClickListener { public void onClick(View view) { final String vibratePattern = vibratePatternEditText.getText().toString(); - try - { + try { MessageNotifier.parseVibratePattern(vibratePattern); TextSecurePreferences.setNotificationVibratePatternCustom(context, vibratePattern); Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_set, Toast.LENGTH_LONG).show(); dialog.dismiss(); dialogInProgress = false; - } - catch(NumberFormatException e) - { + } catch (NumberFormatException e) { Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_wrong, Toast.LENGTH_LONG).show(); } } @@ -133,13 +130,10 @@ private class TestListener implements View.OnClickListener { public void onClick(View view) { final String vibratePattern = vibratePatternEditText.getText().toString(); - try - { + try { Vibrator vibrator = (Vibrator)this.context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(MessageNotifier.parseVibratePattern(vibratePattern), -1); - } - catch(NumberFormatException e) - { + } catch(NumberFormatException e) { Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_wrong, Toast.LENGTH_LONG).show(); } } From fa19b8c5a8be131224fb3aca4c37cc890cc3b4d9 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Thu, 12 Jun 2014 12:35:22 +0200 Subject: [PATCH 07/10] Fix indent --- .../securesms/preferences/VibratePatternListPreference.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java index 174e8d04eee..c7cfc238b3f 100644 --- a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -66,7 +66,7 @@ protected void onDialogClosed(boolean positiveResult) { } } - private void showDialog() { + private void showDialog() { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.vibrate_pattern_dialog, null); this.vibratePatternEditText = (EditText)view.findViewById(R.id.editTextPattern); From e7c81f1f0a9ea4ccc2691346a9d04669202506db Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Thu, 12 Jun 2014 16:44:54 +0200 Subject: [PATCH 08/10] Fix cancel behaviour and add the custom value to the summary --- .../preferences/VibratePatternListPreference.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java index c7cfc238b3f..6236d241f79 100644 --- a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -59,13 +59,26 @@ public VibratePatternListPreference(Context context, AttributeSet attrs) { @Override protected void onDialogClosed(boolean positiveResult) { + String previousSetting = getValue(); super.onDialogClosed(positiveResult); if (positiveResult && getValue().equals("custom")) { + setValue(previousSetting); + callChangeListener(previousSetting); + showDialog(); } } + @Override + public CharSequence getSummary() { + if (getValue().equals("custom")) { + return getEntry() + ": " + TextSecurePreferences.getNotificationVibratePatternCustom(context); + } else { + return super.getSummary(); + } + } + private void showDialog() { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.vibrate_pattern_dialog, null); @@ -113,6 +126,8 @@ public void onClick(View view) { try { MessageNotifier.parseVibratePattern(vibratePattern); TextSecurePreferences.setNotificationVibratePatternCustom(context, vibratePattern); + setValue("custom"); + callChangeListener("custom"); Toast.makeText(context, R.string.preferences__pref_vibrate_custom_pattern_set, Toast.LENGTH_LONG).show(); dialog.dismiss(); dialogInProgress = false; From e1575d84ec38f01c3e62475fecb4ad7e2afcbb27 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Sat, 21 Jun 2014 00:36:25 +0200 Subject: [PATCH 09/10] Add setting migration --- .../securesms/DatabaseUpgradeActivity.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index e6c712cada5..ed5dc92bdbb 100644 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -20,9 +20,11 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.ProgressBar; @@ -43,11 +45,13 @@ public class DatabaseUpgradeActivity extends Activity { public static final int MMS_BODY_VERSION = 46; public static final int TOFU_IDENTITIES_VERSION = 50; public static final int CURVE25519_VERSION = 63; + public static final int VIBRATE_PREF_STRING_VERSION = 72; private static final SortedSet UPGRADE_VERSIONS = new TreeSet() {{ add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION); add(TOFU_IDENTITIES_VERSION); add(CURVE25519_VERSION); + add(VIBRATE_PREF_STRING_VERSION); }}; private MasterSecret masterSecret; @@ -138,6 +142,17 @@ protected Void doInBackground(Integer... params) { } } + if (params[0] < VIBRATE_PREF_STRING_VERSION) { + final String key_boolean = "pref_key_vibrate"; + final String key_string = "pref_vibrate"; + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + if (preferences.contains(key_boolean) && !preferences.getBoolean(key_boolean, true)) { + preferences.edit().remove(key_boolean); + preferences.edit().putString(key_string, "disabled").commit(); + } + } + return null; } From 852b2175996078931771433492235d524ab76565 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Sun, 22 Jun 2014 20:04:12 +0200 Subject: [PATCH 10/10] migrateNotificationVibrate() --- .../securesms/DatabaseUpgradeActivity.java | 15 --------------- .../preferences/VibratePatternListPreference.java | 2 ++ .../securesms/util/TextSecurePreferences.java | 8 ++++++++ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index ed5dc92bdbb..e6c712cada5 100644 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -20,11 +20,9 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.ProgressBar; @@ -45,13 +43,11 @@ public class DatabaseUpgradeActivity extends Activity { public static final int MMS_BODY_VERSION = 46; public static final int TOFU_IDENTITIES_VERSION = 50; public static final int CURVE25519_VERSION = 63; - public static final int VIBRATE_PREF_STRING_VERSION = 72; private static final SortedSet UPGRADE_VERSIONS = new TreeSet() {{ add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION); add(TOFU_IDENTITIES_VERSION); add(CURVE25519_VERSION); - add(VIBRATE_PREF_STRING_VERSION); }}; private MasterSecret masterSecret; @@ -142,17 +138,6 @@ protected Void doInBackground(Integer... params) { } } - if (params[0] < VIBRATE_PREF_STRING_VERSION) { - final String key_boolean = "pref_key_vibrate"; - final String key_string = "pref_vibrate"; - - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - if (preferences.contains(key_boolean) && !preferences.getBoolean(key_boolean, true)) { - preferences.edit().remove(key_boolean); - preferences.edit().putString(key_string, "disabled").commit(); - } - } - return null; } diff --git a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java index 6236d241f79..f3bbbf55b64 100644 --- a/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/VibratePatternListPreference.java @@ -50,11 +50,13 @@ public class VibratePatternListPreference extends ListPreference { public VibratePatternListPreference(Context context) { super(context); this.context = context; + TextSecurePreferences.migrateNotificationVibrate(context); } public VibratePatternListPreference(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; + TextSecurePreferences.migrateNotificationVibrate(context); } @Override diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 3ab399b5df5..53a49974e7f 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -244,7 +244,15 @@ public static String getNotificationRingtone(Context context) { return getStringPreference(context, RINGTONE_PREF, null); } + public static void migrateNotificationVibrate(Context context) { + if (!getBooleanPreference(context, "pref_key_vibrate", true)) { + setStringPreference(context, VIBRATE_PREF, "disabled"); + PreferenceManager.getDefaultSharedPreferences(context).edit().remove("pref_key_vibrate").commit(); + } + } + public static String getNotificationVibrate(Context context) { + migrateNotificationVibrate(context); return getStringPreference(context, VIBRATE_PREF, "default"); }