mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Fixed issue 2174
When selecting one of the five vibrate patterns or the number of repetitions, we should demonstrate to the user what the vibrate pattern feels like. (Thanks to achen.code) use the ListPreference instead of the EditTextPreference to set vibrate times.
This commit is contained in:
parent
41ebeb3498
commit
015666b657
@ -603,6 +603,18 @@
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="account_settings_vibrate_times_label">
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>8</item>
|
||||
<item>9</item>
|
||||
<item>10</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="account_settings_crypto_app_entries">
|
||||
<item>@string/account_settings_crypto_app_none</item>
|
||||
<item>APG</item>
|
||||
|
@ -266,13 +266,12 @@
|
||||
android:entryValues="@array/account_settings_vibrate_pattern_values"
|
||||
android:dialogTitle="@string/account_settings_vibrate_pattern_label" />
|
||||
|
||||
<EditTextPreference
|
||||
<ListPreference
|
||||
android:dependency="account_vibrate"
|
||||
android:key="account_vibrate_times"
|
||||
android:singleLine="true"
|
||||
android:inputType="number"
|
||||
android:title="@string/account_settings_vibrate_times"
|
||||
android:summary=""
|
||||
android:entries="@array/account_settings_vibrate_times_label"
|
||||
android:entryValues="@array/account_settings_vibrate_times_label"
|
||||
android:dialogTitle="@string/account_settings_vibrate_times" />
|
||||
|
||||
<CheckBoxPreference
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
@ -23,6 +24,7 @@ import com.fsck.k9.activity.ChooseIdentity;
|
||||
import com.fsck.k9.activity.ColorPickerDialog;
|
||||
import com.fsck.k9.activity.K9PreferenceActivity;
|
||||
import com.fsck.k9.activity.ManageIdentities;
|
||||
import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.crypto.Apg;
|
||||
import com.fsck.k9.mail.Store;
|
||||
import com.fsck.k9.service.MailService;
|
||||
@ -90,7 +92,7 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
private CheckBoxPreference mAccountNotifySync;
|
||||
private CheckBoxPreference mAccountVibrate;
|
||||
private ListPreference mAccountVibratePattern;
|
||||
private EditTextPreference mAccountVibrateTimes;
|
||||
private ListPreference mAccountVibrateTimes;
|
||||
private RingtonePreference mAccountRingtone;
|
||||
private ListPreference mDisplayMode;
|
||||
private ListPreference mSyncMode;
|
||||
@ -430,13 +432,14 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
int index = mAccountVibratePattern.findIndexOfValue(summary);
|
||||
mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntries()[index]);
|
||||
mAccountVibratePattern.setValue(summary);
|
||||
doVibrateTest(preference);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mAccountVibrateTimes = (EditTextPreference) findPreference(PREFERENCE_VIBRATE_TIMES);
|
||||
mAccountVibrateTimes = (ListPreference) findPreference(PREFERENCE_VIBRATE_TIMES);
|
||||
mAccountVibrateTimes.setValue(String.valueOf(mAccount.getVibrateTimes()));
|
||||
mAccountVibrateTimes.setSummary(String.valueOf(mAccount.getVibrateTimes()));
|
||||
mAccountVibrateTimes.setText(String.valueOf(mAccount.getVibrateTimes()));
|
||||
mAccountVibrateTimes.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
|
||||
{
|
||||
@Override
|
||||
@ -444,7 +447,8 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
{
|
||||
final String value = newValue.toString();
|
||||
mAccountVibrateTimes.setSummary(value);
|
||||
mAccountVibrateTimes.setText(value);
|
||||
mAccountVibrateTimes.setValue(value);
|
||||
doVibrateTest(preference);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@ -609,7 +613,7 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
mAccount.setMaximumAutoDownloadMessageSize(Integer.parseInt(mMessageSize.getValue()));
|
||||
mAccount.setVibrate(mAccountVibrate.isChecked());
|
||||
mAccount.setVibratePattern(Integer.parseInt(mAccountVibratePattern.getValue()));
|
||||
mAccount.setVibrateTimes(Integer.parseInt(mAccountVibrateTimes.getText()));
|
||||
mAccount.setVibrateTimes(Integer.parseInt(mAccountVibrateTimes.getValue()));
|
||||
mAccount.setGoToUnreadMessageSearch(mNotificationOpensUnread.isChecked());
|
||||
mAccount.setFolderTargetMode(Account.FolderMode.valueOf(mTargetMode.getValue()));
|
||||
mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue()));
|
||||
@ -778,4 +782,13 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void doVibrateTest(Preference preference)
|
||||
{
|
||||
// Do the vibration to show the user what it's like.
|
||||
Vibrator vibrate = (Vibrator)preference.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
long[] pattern = MessagingController.getVibratePattern(
|
||||
Integer.parseInt(mAccountVibratePattern.getValue()),
|
||||
Integer.parseInt(mAccountVibrateTimes.getValue()));
|
||||
vibrate.vibrate(pattern, -1);
|
||||
}
|
||||
}
|
||||
|
@ -4642,45 +4642,8 @@ public class MessagingController implements Runnable
|
||||
}
|
||||
if (account.isVibrate())
|
||||
{
|
||||
int times = account.getVibrateTimes();
|
||||
long[] pattern1 = new long[] {100,200};
|
||||
long[] pattern2 = new long[] {100,500};
|
||||
long[] pattern3 = new long[] {200,200};
|
||||
long[] pattern4 = new long[] {200,500};
|
||||
long[] pattern5 = new long[] {500,500};
|
||||
long[] src = null;
|
||||
|
||||
switch (account.getVibratePattern())
|
||||
{
|
||||
case 1:
|
||||
src = pattern1;
|
||||
break;
|
||||
case 2:
|
||||
src = pattern2;
|
||||
break;
|
||||
case 3:
|
||||
src = pattern3;
|
||||
break;
|
||||
case 4:
|
||||
src = pattern4;
|
||||
break;
|
||||
case 5:
|
||||
src = pattern5;
|
||||
break;
|
||||
default:
|
||||
notif.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (src != null)
|
||||
{
|
||||
long[] dest = new long[src.length * times];
|
||||
for (int n = 0; n < times; n++)
|
||||
{
|
||||
System.arraycopy(src, 0, dest, n * src.length, src.length);
|
||||
}
|
||||
notif.vibrate = dest;
|
||||
}
|
||||
long[] pattern = getVibratePattern(account.getVibratePattern(), account.getVibrateTimes());
|
||||
notif.vibrate = pattern;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4694,6 +4657,54 @@ public class MessagingController implements Runnable
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch a vibration pattern.
|
||||
*
|
||||
* @param vibratePattern Vibration pattern index to use.
|
||||
* @param vibrateTimes Number of times to do the vibration pattern.
|
||||
* @return Pattern multiplied by the number of times requested.
|
||||
*/
|
||||
public static long[] getVibratePattern(int vibratePattern, int vibrateTimes)
|
||||
{
|
||||
// These are "off, on" patterns, specified in milliseconds
|
||||
long[] pattern0 = new long[] {300,200}; // like the default pattern
|
||||
long[] pattern1 = new long[] {100,200};
|
||||
long[] pattern2 = new long[] {100,500};
|
||||
long[] pattern3 = new long[] {200,200};
|
||||
long[] pattern4 = new long[] {200,500};
|
||||
long[] pattern5 = new long[] {500,500};
|
||||
|
||||
long[] selectedPattern = pattern0; //default pattern
|
||||
|
||||
switch (vibratePattern)
|
||||
{
|
||||
case 1:
|
||||
selectedPattern = pattern1;
|
||||
break;
|
||||
case 2:
|
||||
selectedPattern = pattern2;
|
||||
break;
|
||||
case 3:
|
||||
selectedPattern = pattern3;
|
||||
break;
|
||||
case 4:
|
||||
selectedPattern = pattern4;
|
||||
break;
|
||||
case 5:
|
||||
selectedPattern = pattern5;
|
||||
break;
|
||||
}
|
||||
|
||||
long[] repeatedPattern = new long[selectedPattern.length * vibrateTimes];
|
||||
for (int n = 0; n < vibrateTimes; n++)
|
||||
{
|
||||
System.arraycopy(selectedPattern, 0, repeatedPattern, n * selectedPattern.length, selectedPattern.length);
|
||||
}
|
||||
// Do not wait before starting the vibration pattern.
|
||||
repeatedPattern[0] = 0;
|
||||
return repeatedPattern;
|
||||
}
|
||||
|
||||
/** Cancel a notification of new email messages */
|
||||
public void notifyAccountCancel(Context context, Account account)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user