This example describes how to use Vibrator in OS. Class MorseCodeConverter provides the function of converting letters and numbers to Morse code:
For example,/* A */new long [] {DOT, GAP, DASH} correspond to Dot, Gap, and Dash respectively.
The time corresponding to DOT, GAP, and DASH is defined:
[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; with this conversion table, you can use vibrator to send the Morse code by means of vibration.
[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) allows the device to shake the phone in the specified mode. Repeat indicates the number of repeat times.-1 indicates that repeat is not repeated.
In addition, Vibrator provides public void vibrate (long milliseconds) to shake the phone at a given time.
Author: mapdigit