1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

extract vibration pattern metadata out ouf MessagingController into

notificationsetting
This commit is contained in:
Jesse Vincent 2010-11-28 20:29:14 +00:00
parent b7f52a834f
commit 64667d03dc
3 changed files with 63 additions and 55 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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)
{