当前位置:操作系统 > 安卓/Android >>

Android ApiDemos示例解析(89):OS->Morse Code

本例介绍了OS中的Vibrator (震动)的用法,类MorseCodeConverter 提供了将字母数字到 Morse code 转换:

 \

比如:/* A */ new long[] { DOT, GAP, DASH }  分别对应Dot , Gap, Dash

DOT,GAP ,DASH 对应的时间定义为:


[java] 
private static final long SPEED_BASE = 100; 
static final long DOT = SPEED_BASE; 
static final long DASH = SPEED_BASE * 3; 
static final long GAP = SPEED_BASE; 
static final long LETTER_GAP = SPEED_BASE * 3; 
static final long WORD_GAP = SPEED_BASE * 7; 

private static final long SPEED_BASE = 100;
static final long DOT = SPEED_BASE;
static final long DASH = SPEED_BASE * 3;
static final long GAP = SPEED_BASE;
static final long LETTER_GAP = SPEED_BASE * 3;
static final long WORD_GAP = SPEED_BASE * 7;有了这个转换表,就可以使用vibrator 利用震动发送Morse code.


[java] 
long[] pattern = MorseCodeConverter.pattern(text); 
  
// Start the vibration  
Vibrator vibrator 
 = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); 
vibrator.vibrate(pattern, -1); 

long[] pattern = MorseCodeConverter.pattern(text);
 
// Start the vibration
Vibrator vibrator
 = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(pattern, -1);
public void vibrate(long[] pattern, int repeat) 可以让设备以指定的模式来震动手机。repeat 为重复的次数,-1表示不重复。

此外Vibrator 还提供了public void vibrate(long milliseconds) 可以使手机震动给定时间。

 \
作者:mapdigit
 

 

 

 

 

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,