setting a string into long[] for vibrate function
i am doing a application to do custom vibrations based on the characters in a text file but am facing problem dealing with passing in a custom vibration through a method
private void classifier(char c)
{
String s = null;
if (c == 'L')
{
s = "{0, dot, long_gap, long_gap, sh开发者_StackOverflow社区ort_gap, dot, medium_gap}";
}
vibratePattern(s);
}
private void vibratePattern(String s)
{
Vibrator vibrator;
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern101 = s;
vibrator.vibrate(pattern101, -1);
}
what am i trying to get here is that when the classifier method detects a char "L" passed in when using the classifier method it will pass in the pattern to the vibratePattern method to process and proceed with the vibration
i know that my code here is wrong as i am using a string in the classifier method while the vibrate method takes in a long[]
i tried using parseLong to convert the string to long but the long[] does not accept it..
If a method needs a long[]
as argument, give it a long[]
, not a String :
private void classifier(char c)
{
long[] s = null;
if (c == 'L')
{
s = new long[] {0, dot, long_gap, long_gap, short_gap, dot, medium_gap};
}
vibratePattern(s);
}
private void vibratePattern(long[] s)
{
Vibrator vibrator;
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(s, -1);
}
精彩评论