diff --git a/src/com/fsck/k9/NotificationSetting.java b/src/com/fsck/k9/NotificationSetting.java index 6c5640e2a..ff9a6c7a0 100644 --- a/src/com/fsck/k9/NotificationSetting.java +++ b/src/com/fsck/k9/NotificationSetting.java @@ -112,4 +112,62 @@ public class NotificationSetting mVibrateTimes = times; } + + + /* + * 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 long[] getVibration() + { + return getVibration(mVibratePattern, mVibrateTimes); + } + + public static long[] getVibration(int pattern, int times) + { + // 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 (pattern) + { + 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 * times]; + for (int n = 0; n < times; n++) + { + System.arraycopy(selectedPattern, 0, repeatedPattern, n * selectedPattern.length, selectedPattern.length); + } + // Do not wait before starting the vibration pattern. + repeatedPattern[0] = 0; + return repeatedPattern; + } + + + } diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index 44a43af9f..e10a5bcda 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -21,6 +21,7 @@ import java.util.List; import com.fsck.k9.Account; import com.fsck.k9.Account.FolderMode; import com.fsck.k9.K9; +import com.fsck.k9.NotificationSetting; import com.fsck.k9.Preferences; import com.fsck.k9.R; import com.fsck.k9.mail.Folder; @@ -29,7 +30,6 @@ 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; @@ -946,9 +946,8 @@ public class AccountSettings extends K9PreferenceActivity { // 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); + vibrate.vibrate(NotificationSetting.getVibration( + Integer.parseInt(mAccountVibratePattern.getValue()), + Integer.parseInt(mAccountVibrateTimes.getValue())), -1); } } diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index e0d39ebb2..d5df17efb 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -4741,8 +4741,7 @@ public class MessagingController implements Runnable } if (setting.shouldVibrate()) { - long[] pattern = getVibratePattern(setting.getVibratePattern(), setting.getVibrateTimes()); - notification.vibrate = pattern; + notification.vibrate = setting.getVibration(); } } @@ -4755,54 +4754,6 @@ public class MessagingController implements Runnable } } - /* - * 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) {