Morse code is a way in which one can encode characters and text using dots and dashes. The international Morse codes contain 26 letters of the alphabets and some non-English letters that are Arabic numerals as well as some punctuation. In Morse code, there is no difference between the upper and lower case letters. The transmission of the Morse Code is measured in dot durations. The Morse Code Converter App is an app that is used to convert the given statements to Morse Code. This is done by using Android Studio. The Languages that are used are Java and XML.
So in this article lets create a Morse Code Converter Android App using the Java language. This project also involves the conversion of the Morse Code into relevant Statements. It means both encoding and decoding can be done using this Android app.
Software Tools Required
The software tools required in this project are:
- ANDROID-STUDIO IDE (1.0.2)
- SDK having API level-21(minimum version)
- JAVA 7 and above
- An android smartphone – version 4.2.2(Jelly bean and above) (only for testing the software)
Step 1: Create a New Project
To create a new project in Android Studio please refer How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Create a Round Button
This step is optional (only if you want a black button with round corners). In the project tab, in the left-hand corner of the screen, click on the app folder. Then, click on the res folder. Then, right-click on the drawable folder and select New then select Drawable Resource file. Give this resource file a name. Remember one can use only lower case letters for the name of the resource file. Write the code below to create a resource file for black buttons with round corners. Use this resource file as background in the XML code of buttons to get black buttons with round corners.
In case one wants to use the default button or some other button then skip this optional step and don’t include the resource file in the background of the buttons.
Step 3: Working with activity_main.xml file
- Open the activity_main.xml file and start writing the xml code.
- Create 2 EditTexts in the xml file. One for writing the input and the other one for displaying the output. EditTexts are used because on clicking on the EditTexts the text can be selected and copied which will be very useful in sending the coded/uncoded message some other person using any messaging app.
- Make 3 Buttons: Encode, Decode and Clear.
- The Encode Button will take the input as text from the input EditText and then encode it into morse code and display it in the output EditText.
- The Decode Button will take the morse code as input from the input EditText and then decode it into alphabets and numbers and display it in the output EditText.
- The Clear Button will clear the input and output EditTexts.
- Give id’s to all the EditTexts and Buttons.
The complete xml code is given below:
Step 4: Working with MainActivity.java file
- Open the MainActivity.java file.
- Initialize the variables just under the MainActivity class (Syntax:- Edit Text etinput, etoutput;Button btnEncode, btnDecode, btnclear;)
- Assign the variables under the OnCreate method.
- Make an array and store all the alphabets and digits in it.
- Make another array and store the morse code of each alphahbets and digits in the indices corresponding to it’s alphabets and digits in the first array.
- Use the logic in the code below to complete the morse code converter app.
Below is the complete code for MainActivity.java file.
Output: Run on Emulator
Github link: Click here
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- How to Publish Your Android App on Amazon App Store for Free?
- Java Program to Convert English Text to Morse Code and Vice-Versa
- Android | Running your first Android app
- How to Add Audio Files to Android App in Android Studio?
- How to create a Facebook login using an Android App?
- How to create a Stopwatch App using Android Studio
- How to create a COVID-19 Tracker Android App
- How to create Swipe Navigation in an Android App
- How to create a Face Detection Android App using Machine Learning KIT on Firebase
- How to Create Static Shortcuts in Android App?
- How to Create a Quiz App In Android?
- How to Create a COVID-19 Tracker Android App to See Details of any City and State in India?
- How to Create a Basic Widget of an Android App?
- How to Create a Dynamic Widget of an Android App?
- How to Create a Dark Mode for a Custom Android App in Kotlin?
- Android | How to Create/Start a New Project in Android Studio?
- How to make a phone call from your Android App?
- Why Kotlin will replace Java for Android App Development
- App Development for Android in 2017: Challenges and Solutions
- Android | Creating a Calendar View app
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.