I call it “Finnish On The Go”, essentially a soundboard app that plays a sound every time you click a button. The buttons are programmed to play the sound corresponding to the spoken Finnish words of the phrase you click on. As part of my course for Android development, the goal was to make an app that might help you if you were traveling to a foreign country, in this case Finland. Here is the app I made if you want to test it out:

http://www.mediafire.com/file/bwbqqtgki0bwlmq/FinishOnTheGo.apk

And here are the files:

AndroidManifest.xml

[CODE]
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.alaskalinuxuser.finnishonthego”>

<application
android:allowBackup=”true”
android:icon=”@drawable/icon_finland”
android:label=”@string/app_name”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

</manifest>
[/CODE]

MainActivity.java

[CODE]
/* Copyright 2017 AlaskaLinuxUser
*
*Licensed under the Apache License, Version 2.0 (the “License”);
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an “AS IS” BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License. */

package com.alaskalinuxuser.finnishonthego;

import android.content.Context;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

public void playClip0 (View view) {
playSoundClip(R.raw.hello_fi);
}

public void playClip1 (View view) {
playSoundClip(R.raw.goodbye_fin);
}

public void playClip2 (View view) {
playSoundClip(R.raw.howtosay_fin);
}

public void playClip3 (View view) {
playSoundClip(R.raw.nounderstand_fin);
}

public void playClip4 (View view) {
playSoundClip(R.raw.thanks2_fin);
}

public void playClip5 (View view) {
playSoundClip(R.raw.sorry_fin);
}

public void playClip6 (View view) {
playSoundClip(R.raw.mynameis_fin);
}

public void playClip7 (View view) {
playSoundClip(R.raw.whatyourname_fin);
}

public void playSoundClip(int handle){

Context appContext = getApplicationContext();
MediaPlayer mp = MediaPlayer.create(appContext , handle);
mp.start();

}

}
[/CODE]

activity_main.xml

[CODE]
<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:id=”@+id/activity_main”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.alaskalinuxuser.finnishonthego.MainActivity”>

<GridLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_centerVertical=”true”
android:layout_centerHorizontal=”true”
android:columnCount=”2″
android:rowCount=”4″>

<Button
android:text=”Hello”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”0″
android:layout_row=”0″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”0″
android:onClick=”playClip0″
android:id=”@+id/button” />

<Button
android:text=”Goodbye”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”1″
android:layout_row=”0″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”1″
android:onClick=”playClip1″
android:id=”@+id/button1″ />

<Button
android:text=”How do I say …”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”0″
android:layout_row=”1″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”2″
android:onClick=”playClip2″
android:id=”@+id/button2″ />

<Button
android:text=”I don’t understand.”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”1″
android:layout_row=”1″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”3″
android:onClick=”playClip3″
android:id=”@+id/button3″ />

<Button
android:text=”Thanks!”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”0″
android:layout_row=”2″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”4″
android:onClick=”playClip4″
android:id=”@+id/button4″ />

<Button
android:text=”I’m sorry.”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”1″
android:layout_row=”2″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”5″
android:onClick=”playClip5″
android:id=”@+id/button5″ />

<Button
android:text=”My name is …”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”0″
android:layout_row=”3″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”6″
android:onClick=”playClip6″
android:id=”@+id/button6″ />

<Button
android:text=”What is your name?”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”1″
android:layout_row=”3″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”7″
android:onClick=”playClip7″
android:id=”@+id/button7″ />

</GridLayout>
</RelativeLayout>
[/CODE]

So that is how I did it. However, after completing the project, the instructor showed us a much better way to do that, with slight modification, as we see here:

First, I had to change the activity_main.xml, and edit the onclick function to be the same for every button. I also needed to change the id to be the same name as the name of the audio file in the “raw” folder. Here’s an exerpt:

[CODE]
<Button
android:text=”I don’t understand.”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”1″
android:layout_row=”1″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”3″
android:onClick=”playClip”
android:id=”@+id/understand” />

<Button
android:text=”Thanks!”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_column=”0″
android:layout_row=”2″
android:layout_rowWeight=”1″
android:layout_columnWeight=”1″
android:layout_gravity=”fill”
android:tag=”4″
android:onClick=”playClip”
android:id=”@+id/thanks” />
[/CODE]

Then, I completely redid the MainActivity.java in accordance with what the course taught:

[CODE]
/* Copyright 2017 AlaskaLinuxUser
*
*Licensed under the Apache License, Version 2.0 (the “License”);
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an “AS IS” BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License. */

package com.alaskalinuxuser.finnishonthego;

import android.content.Context;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

public void playClip (View myView) {

int theId = myView.getId();
String theButton = “”;

theButton = myView.getResources().getResourceEntryName(theId);

int resId = getResources().getIdentifier(theButton, “raw”, “com.alaskalinuxuser.finnishonthego”);

MediaPlayer mp = MediaPlayer.create(this, resId);
mp.start();
}

}
[/CODE]

Once I ran that, it worked identical to what I had made, however, as you can see, Rob’s version has way more expandability, as well as a cleaner code. Pretty neat! Here is the download for 2.0, if you want to compare the apps:

http://www.mediafire.com/file/z8eq18zw2xwxnwm/FinnishOnTheGo_2_0.apk

Linux – keep it simple.

 

19 Replies to “Android: making a soundboard app!”

    1. All the code is right here, you can copy in paste it, but if you want the files themselves, you can view them on my github, I can put them up there tomorrow if you’d like.

    1. I used Android Studio to make that one. I have released apps on fdroid before, I don’t think this one is quite polished enough for release yet. Perhaps with more features it could be ready for that.

  1. Thank you, I ask this because I am a French Librist blogger, and that I like to discover new software or application for me and my blog As you can see, I am into sharing software.

Leave a Reply to wilfried00 Cancel reply

Your email address will not be published. Required fields are marked *