Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Vibrate Patterns to Settings #1169

Closed
wants to merge 11 commits into from

Conversation

agrajaghh
Copy link
Contributor

I added the ability to choose custom vibrate Patterns. This fixes issue #230 You can chose between:

  • default
  • 2x short
  • 2x long
  • 3x short
  • 3x long
  • custom (you can specify off-time, on-time)

Of course I'm open to different standard vibrate patters or other changes.

This is my first pull request and I'm quite new to Java and Android, so please be gentle ;)

@@ -0,0 +1,151 @@
/**
* Copyright (C) 2011 Whisper Systems

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2014? :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe, fixed...

@agrajaghh
Copy link
Contributor Author

I tested it on my Nexus 4 and on a Android 2.3 emulator (couldn't test the vibrate, just the dialogs).

What do you think?

@moxie0
Copy link
Contributor

moxie0 commented Mar 21, 2014

instead of having a checkbox to enable/disable vibrations, and then a separate preference for the vibration pattern, let's just have one preference where one of the options is "do not vibrate" or whatever

@moxie0
Copy link
Contributor

moxie0 commented Mar 21, 2014

Also, the preference description should display the configured value rather than describing what the preference is.

@agrajaghh
Copy link
Contributor Author

@moxie0 Okay, you are right, thats better! I fixed it.
I'm still not that happy with one other thing: I can't prevent the dialog where you enter the custom pattern from closing. So when you enter a wrong pattern oder click on the "Test" Button the dialog gets closed, and I open it again. It would be better if it wouldn't close... Do you have an advice how I can do that?

edit: done now

builder.setVibrate(new long[]{0,300,200,300,200,300});
} else if (vibratePattern.equals("3x_long")) {
builder.setVibrate(new long[]{0,750,400,750,400,750});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have the stored preference be the eventual value that's passed to setVibrate so that you don't have to do this rule matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I changed the behaviour, can you check if its okay?

@agrajaghh
Copy link
Contributor Author

I squashed the commits into one and I think I fixed your points

@@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be aligned like the lines above it.

@agrajaghh
Copy link
Contributor Author

I fixed the variable names and alignment

<item>@string/preferences__pref_disabled</item>
</string-array>

<string-array name="pref_vibrate_values" translatable="false">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default/custom/disabled are all translatable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this are the vaules, they are never displayed. The pref_vibrate_entries above are displayed. Should I really remove the translatable=false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no you're totally right, sorry I mixed the entries with values when I was speed reading :)

@mcginty
Copy link
Contributor

mcginty commented Jun 12, 2014

If I have a normal pattern set, choose custom and then hit "Cancel" in the Custom Vibrate Pattern dialog, my setting still shows up as "custom" when it should probably not be set.

@mcginty
Copy link
Contributor

mcginty commented Jun 12, 2014

May be a good idea to also in the summary show the pattern they have set instead of just "Custom." Perhaps something like "Custom: 0,500,100,500"

}
}

private void showDialog() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse-indent :)

@agrajaghh
Copy link
Contributor Author

@mcginty I fixed the "Cancel" or back-button behaviour and added the custom value to the summary like this "Custom: 0,500,100,500"

Sorry for the formatting, lower/uppercase and indent mistakes...

@moxie0
Copy link
Contributor

moxie0 commented Jun 13, 2014

also how are you going to migrate people's existing vibrate preference to this?

@agrajaghh
Copy link
Contributor Author

@moxie0 The default pattern will be set regardless of the current setting. You are right, thats not good...
Can you give me a hint where I can insert a migration during update?

@agrajaghh
Copy link
Contributor Author

Should I put it in the DatabaseUpgradeActivity to prevent a loss of the setting when vibrate is currently disabled?

public static boolean isNotificationVibrateEnabled(Context context) {
return getBooleanPreference(context, VIBRATE_PREF, true);
public static String getNotificationVibrate(Context context) {
return getStringPreference(context, VIBRATE_PREF, "default");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just change this line to be backward compatible?

getStringPreference(context, VIBRATE_PREF, getBooleanPreference(context, VIBRATE_PREF, true) ? "default" : "disabled");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I thought of a check there too, but I thought its more clean when we don't check every time a notification arrives, and just once during update. But perhaps you're right and this is easier...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, but the problem is that the setting will be displayed wrong nevertheless. getNotificationVibrate is not called when you open the settings and the summary is displayed. I think the real migration is the better way....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 06/20/2014 03:41 PM, agrajaghh wrote:

I tried it, but the problem is that the setting will be displayed wrong
nevertheless. getNotificationVibrate is not called when you open the
settings and the summary is displayed. I think the real migration is the
better way....

You can't be guaranteed that activity runs first. Migrations should be
avoided whenever possible.

http://www.thoughtcrime.org

@agrajaghh
Copy link
Contributor Author

The existing preference is now migrated in DatabaseUpgradeActivity

@@ -243,8 +244,24 @@ 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 void migrateNotificationVibrate(Context context) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the migration here. Is this better?

@claenn
Copy link

claenn commented Jul 1, 2014

love your vibration feature, thanks a lot.

@pejakm
Copy link

pejakm commented Dec 6, 2014

@agrajaghh Can we have a rebase, please?

@agrajaghh
Copy link
Contributor Author

@pejakm I'm waiting for #1635 to be in

@pejakm
Copy link

pejakm commented Dec 6, 2014

@agrajaghh Ah, I see what you mean. I've applied the patch and compiled successfully, and it looks great! Thank you for this!

@moxie0
Copy link
Contributor

moxie0 commented Dec 11, 2014

Thanks @agrajaghh, but I think we're going to skip this for now. It's a lot of code and includes a preference migration, and we're not sure that it's something the majority of users will find useful. We want to focus on customization for the core settings first.

@moxie0 moxie0 closed this Dec 11, 2014
@pejakm
Copy link

pejakm commented Dec 12, 2014

@agrajaghh Could you please rebase it anyway, for people who want this in their own build?

@agrajaghh
Copy link
Contributor Author

@pejakm done at https://github.com/agrajaghh/TextSecure/tree/VibratePattern

But I won't keep it up to date, sry...

edit: not tested btw...

@pejakm
Copy link

pejakm commented Dec 12, 2014

Thank you very much! :)

@pejakm
Copy link

pejakm commented Dec 12, 2014

@agrajaghh Tested and works, thank you once again.

@claenn
Copy link

claenn commented Dec 12, 2014

Thanks for the rebase. It's very useful. I've had to use an automation tool
(automagic, tasker) before.

Mladen Pejaković notifications@github.com schrieb am Fr., 12. Dez. 2014
14:24:

@agrajaghh https://github.com/agrajaghh Tested and works, thank you
once again.


Reply to this email directly or view it on GitHub
#1169 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants