Android ApiDemos example (89): OS-& gt; Morse Code

Source: Internet
Author: User

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
 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.