Hak cipta dan penggunaan kembali:
Lisensi ini mengizinkan setiap orang untuk menggubah, memperbaiki, dan membuat ciptaan turunan bukan untuk kepentingan komersial, selama anda mencantumkan nama penulis dan melisensikan ciptaan turunan dengan syarat yang serupa dengan ciptaan asli.
Copyright and reuse:
This license lets you remix, tweak, and build upon work
non-commercially, as long as you credit the origin creator
and license it on your new creations under the identical
terms.
LAMPIRAN
Bagian A : Pengkodean……….48
1. Pengkodean home page……….48
2. Pengkodean back page………..50
3. Pengkodean drawer pair………53
4. Pengkodean MainActivity……….54
5. Pengkodean ListDeivce……….61
6. Pengkodean ListAdapter………...65
7. Pengkodean Manifest………67
Bagian B : User Acceptance Test………...68
1. Hasil UAT Olivia Olita Olga………68
2. Hasil UAT Theodorus Alvin Darmadi……….72
3. Hasil UAT Michael Isaac……….76
4. Hasil UAT Wanaldi………..80
Bagian A :
1. Pengkodean Home Page
<?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"
tools:context="com.example.budi.micer_final.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_Root">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/headerMain"
android:background="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Micer"
android:textSize="30sp"
android:id="@+id/textHeader"
android:textColor="#FFFF"
android:textStyle="bold"
android:gravity="center"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/buttonList"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:contentDescription="@string/app_name"
android:paddingTop="5dp"
android:scaleType="center"
android:src="@drawable/back"
android:text="List"
android:textStyle="bold"
style="@style/Widget.AppCompat.Button" />
</RelativeLayout>
<ImageButton
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/Bluetooth"
android:scaleType="fitCenter"
android:background="@android:drawable/presence_invisible"
android:id="@+id/Bluetooth1"
android:layout_marginTop="49dp"
android:layout_below="@+id/headerMain"
android:layout_alignLeft="@+id/application"
android:layout_alignStart="@+id/application" />
<ImageButton
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/button"
android:scaleType="fitCenter"
android:background="@android:drawable/screen_background_light_tr ansparent"
android:id="@+id/application"
android:layout_below="@+id/Bluetooth1"
android:layout_centerHorizontal="true"
android:layout_marginTop="27dp" />
</RelativeLayout>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/activity_back"
android:visibility="gone"
/>
</RelativeLayout>
2. Pengkodean Back Page
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/backHeader"
android:layout_height="60dp"
android:background="@color/colorPrimary">
<ImageButton
android:id="@+id/buttonBack"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:background="@color/colorPrimary"
android:contentDescription="@string/app_name"
android:paddingTop="10dp"
android:scaleType="fitCenter"
android:src="@drawable/back"
android:text="Back" />
<TextView
android:id="@+id/textureView"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Micer"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
<Button
android:id="@+id/buttonSearch"
android:layout_below="@+id/backHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search" />
<RelativeLayout
android:id="@+id/backPairedHeader"
android:layout_below="@+id/buttonSearch"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/textureView1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="left"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Paired Device"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ListView
android:id="@+id/listviewpaired"
android:layout_below="@+id/backPairedHeader"
android:layout_width="match_parent"
android:layout_height="195dp"
/>
<RelativeLayout
android:id="@+id/backDicsHeader”
android:layout_below="@+id/listviewpaired"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/textureView2"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="left"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Opened Device"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ListView
android:id="@+id/listviewdevice"
android:layout_below="@+id/backDicsHeader"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/loading"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
3. Pengkodean Drawer Pair
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/kiriBluetooth"
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="6dp"
android:src="@drawable/Bluetooth" />
<TextView
android:id="@+id/nama"
android:layout_width="250dp"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textSize="16sp"
android:textColor="@android:color/darker_gray"
android:textStyle="bold" />
<TextView
android:id="@+id/alamat"
android:layout_width="250dp"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textSize="16sp"
android:textColor="@android:color/darker_gray"
android:textStyle="bold" />
<Button
android:layout_width="80dp"
android:layout_height="50dp"
android:text="Test"
android:id="@+id/testPaired"/>
</LinearLayout>
4. Pengkodean MainActivity
package com.example.budi.micer_final;
import android.app.Activity;
import android.app.ProgressDialog;
import android.Bluetooth.BluetoothAdapter;
import android.Bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Process;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
public class MainActivity extends Activity { AudioPipeStream recorder;
int multiplier = 1;
boolean playAudio = true;
private ImageButton play;
private ImageButton mActieBtnAndPaired;
private Button mPairedBtn;
private ImageButton mBackBtn;
private Button mScanBtn;
private ProgressDialog mProgressdlg;
private ArrayList<BluetoothDevice> mDeviceList = new ArrayList<BluetoothDevice>();
private BluetoothAdapter mBluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActieBtnAndPaired = (ImageButton) findViewById(R.id.Bluetooth1);
mPairedBtn = (Button) findViewById(R.id.buttonList);
mScanBtn = (Button) findViewById(R.id.buttonSearch);
mBackBtn = (ImageButton) findViewById(R.id.buttonBack);
play = (ImageButton) findViewById(R.id.application);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mPairedBtn.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
Set<BluetoothDevice> pairedDevice = mBluetoothAdapter.getBondedDevices();
if(pairedDevice == null || pairedDevice.size() == 0){
showToast("No Paired Device Found");
}else{
ArrayList<BluetoothDevice> list = new ArrayList<BluetoothDevice>();
list.addAll(pairedDevice);
Intent intent = new Intent(MainActivity.this, ListDevice.class);
intent.putParcelableArrayListExtra("device.list", list);
startActivity(intent);
} } });
play.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { if(playAudio){
MainActivity.this.recorder = MainActivity.this.new AudioPipeStream();
}else{
MainActivity.this.recorder.stahp();
MainActivity.this.recorder.interrupt();
try{
MainActivity.this.recorder.join();
} catch (InterruptedException e) { e.printStackTrace();
}finally {
playAudio = false;
} } } });
mScanBtn.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
mBluetoothAdapter.startDiscovery();
} });
mActieBtnAndPaired.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
if(mBluetoothAdapter.isEnabled()){
mBluetoothAdapter.disable();
}else{
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, 1000);
} }
});
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver, filter);
}
public void onPause(){
if(mBluetoothAdapter!= null){
if(mBluetoothAdapter.isDiscovering()){
mBluetoothAdapter.cancelDiscovery();
} }
super.onPause();
}
public void onDestroy(){
unregisterReceiver(mReceiver);
super.onDestroy();
}
public void showToast(String message){
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
public final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override
public void onReceive(Context context, Intent intent) { String action = intent.getAction();
if(BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
final int state =
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if(state == BluetoothAdapter.STATE_ON){
showToast("Enable");
} }else
if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
mDeviceList = new ArrayList<BluetoothDevice>();
}else if
(mBluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
Intent newIntent = new Intent(MainActivity.this,ListDevice.class);
newIntent.putParcelableArrayListExtra("device.list", mDeviceList);
startActivity(newIntent);
}else if(BluetoothDevice.ACTION_FOUND.equals(action)){
BluetoothDevice device = (BluetoothDevice)
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mDeviceList.add(device);
showToast("Found Device" + device.getName());
} } };
public class AudioPipeStream extends Thread{
private Boolean running = false;
public int[] rates = new int[] {44100, 22050, 16000, 11025, 800};
private AudioPipeStream(){
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_URGEN T_AUDIO);
start();
}
public void run(){
running = true;
int hz = 0;
int n = 0;
short[] buf;
for(int rate : rates){
n = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
if(n > 0){
hz = rate;
break;
} }
buf = new short[n];
n *= MainActivity.this.multiplier;
if(hz == 0){
throw new UnsupportedOperationException("No suported sample rate found");
}else{
showToast("SAMPLE RATE IS " + hz);
}
AudioRecord rec = null;
AudioTrack trk = null;
try{
rec = new AudioRecord(MediaRecorder.AudioSource.MIC, hz, AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, n);
trk = new AudioTrack(AudioManager.STREAM_MUSIC, hz, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, n, AudioTrack.MODE_STREAM);
trk.play();
showToast("Start D");
while(running){
n = rec.read(buf,0,buf.length);
trk.write(buf,0,buf.length);
}
}catch (Throwable t){
t.printStackTrace();
}finally { rec.stop();
rec.release();
trk.stop();
trk.release();
} }
public void stahp(){
running = false;
} } }
5. Pengkodean ListDevice
package com.example.budi.micer_final;
import android.app.Activity;
import android.Bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList
public class ListDevice extends Activity { private Toast showToast;
private ListView mListView;
private ListAdapater mListAdapter;
private ArrayList<BluetoothDevice> mDeviceList;
public void onCreate (Bundle saveInstanceState){
super.onCreate(saveInstanceState);
mDeviceList =
getIntent().getExtras().getParcelableArrayList("device.list");
mListView = (ListView) findViewById(R.id.listviewdevice);
mListAdapter = new ListAdapater(this);
mListAdapter.setData(mDeviceList);
mListAdapter.setListener(new
ListAdapater.OnPairButtonClickListener(){
@Override
public void OnPairButtonClick(int position){
BluetoothDevice device = mDeviceList.get(position);
if(device.getBondState() == BluetoothDevice.BOND_BONDED){
unpairDevice(device);
}else{
showToast("Pairinnnggg...");
pairDevice(device);
} } });
mListView.setAdapter(mListAdapter);
registerReceiver(mPairRecevier, new
IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
}
private void unpairDevice (BluetoothDevice device){
try {
Method method = device.getClass().getMethod("remoeBond", (Class[]) null);
method.invoke(device, (Object[]) null);
} catch (NoSuchMethodException e) { e.printStackTrace();
} catch (InvocationTargetException e) { e.printStackTrace();
} catch (IllegalAccessException e) { e.printStackTrace();
} }
private void pairDevice (BluetoothDevice device){
try {
Method method = device.getClass().getMethod("createBond", (Class[]) null);
method.invoke(device, (Object[]) null);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) { e.printStackTrace();
} catch (IllegalAccessException e) { e.printStackTrace();
} }
private final BroadcastReceiver mPairRecevier = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) { String action = intent.getAction();
if(BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)){
final int state =
intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
final int prevState =
intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
if(state == BluetoothDevice.BOND_BONDED && prevState ==
BluetoothDevice.BOND_BONDING);
showToast("Paired");
}else {
showToast("Unpaired");
}
mListAdapter.notifyDataSetChanged();
} };
}
6. Pengkodean ListAdapter
package com.example.budi.micer_final;
import android.Bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
public class ListAdapater extends BaseAdapter { private LayoutInflater minflater;
private List<BluetoothDevice> mData;
private OnPairButtonClickListener mListener;
public ListAdapater(Context context) { minflater = LayoutInflater.from(context);
}
public void setData(List<BluetoothDevice> data) { mData = data;
}
public void setListener(OnPairButtonClickListener listener) { mListener = listener;
}
public int getCount() {
return (mData == null) ? 0 : mData.size();
}
public Object getItem(int position) { return null;
}
public long getItemId(int position) { return position;
}
public View getView(final int position, View convertView, ViewGroup parent){
ViewHolder holder;
if(convertView == null){
convertView = minflater.inflate(R.layout.activity_back, null);
holder = new ViewHolder();
holder.root = (LinearLayout) convertView.findViewById(R.id.root);
holder.nameTV = (TextView) convertView.findViewById(R.id.nama);
holder.addressTV = (TextView) convertView.findViewById(R.id.alamat);
holder.pairButton = (TextView) convertView.findViewById(R.id.testPaired);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
BluetoothDevice device = mData.get(position);
holder.nameTV.setText(device.getName());
holder.addressTV.setText(device.getAddress());
holder.pairButton.setText((device.getBondState() ==
BluetoothDevice.BOND_BONDED) ? "Unpiar" : "Pair");
holder.pairButton.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { if(mListener != null){
mListener.OnPairButtonClick(position);
} }
});
return convertView;
}
static class ViewHolder{
LinearLayout root TextView nameTV;
TextView addressTV;
TextView pairButton;
}
public interface OnPairButtonClickListener{
public abstract void OnPairButtonClick (int position);
} }
7. Pengkodean Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.budi.micer_final">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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