Commit 72299da0 authored by Harshith Goka's avatar Harshith Goka

Debug crash, add more functionalities

parent a928799d
......@@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.INJECT_EVENTS"/>
<application
android:name=".GlobalClass"
android:allowBackup="true"
......
......@@ -17,5 +17,9 @@ public class Constants {
public static String OK_GOOGLE = "Ok Google";
public static String OPEN_CAMERA = "Camera";
public static String GOOGLE_NOW = "GoogleApp";
public static String CAMERA_CLICK = "CameraClick";
public static String VOLUME_UP="VolumeUp";
public static String VOLUME_DOWN="VolumeDown";
public static String END_CALL="EndCall";
}
......@@ -22,8 +22,14 @@ public class Frame{
}
if(index == 8){
upperBound = lrBound;
lowerBound = upBound;
if(isMpu) {
upperBound = lrBound;
lowerBound = upBound;
}
else{
upperBound = upBound;
lowerBound = lrBound;
}
}
}
......
......@@ -98,6 +98,7 @@ public class ReceiveDataThread extends Thread {
while(true) {
bytes = inputStream.read(buffer);
readStatus = Constants.READ_STATUS_OK;
String readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage);
int endOfLineIndex = stringBuilder.indexOf("~");
......@@ -134,25 +135,45 @@ public class ReceiveDataThread extends Thread {
Log.d("Gesture","Gesture " + gestActive + " is activated");
if(gestActive == 0){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.OPEN_CAMERA).sendToTarget();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.OPEN_CAMERA).sendToTarget();
Looper.loop();
}
else if(gestActive == 1){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.OK_GOOGLE).sendToTarget();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.OK_GOOGLE).sendToTarget();
Looper.loop();
}
else if(gestActive == 2){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.GOOGLE_NOW).sendToTarget();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.GOOGLE_NOW).sendToTarget();
Looper.loop();
}
else if(gestActive == 3){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.PLAY_PAUSE).sendToTarget();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.PLAY_PAUSE).sendToTarget();
Looper.loop();
}
else if(gestActive == 4){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.CAMERA_CLICK).sendToTarget();
Looper.loop();
}
else if(gestActive == 5){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.VOLUME_UP).sendToTarget();
Looper.loop();
}
else if(gestActive == 6){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.VOLUME_DOWN).sendToTarget();
Looper.loop();
}
else if(gestActive == 7){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,Constants.END_CALL).sendToTarget();
Looper.loop();
}
count = 0;
gestActive = -1;
//if( str.equals("n") ) { stay = false; break; }
......@@ -181,6 +202,9 @@ public class ReceiveDataThread extends Thread {
}
catch (IOException e){
readStatus = Constants.READ_STATUS_NOT_OK;
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,readStatus,0,null);
Looper.loop();
}
}
......
package com.example.harshith.ddc;
import android.Manifest;
import android.app.Instrumentation;
import android.app.Service;
import android.bluetooth.BluetoothSocket;
import android.content.ComponentName;
......@@ -50,27 +51,41 @@ public class ReceiveService extends Service {
receiveDataThread = new ReceiveDataThread((BluetoothSocket) message.obj,handler,globalClass);
receiveDataThread.start();
}
else if((int) message.obj == Constants.CONNECTION_STATUS_NOT_CONNECTED){
else if(message.arg1 == Constants.CONNECTION_STATUS_NOT_CONNECTED){
Toast.makeText(getApplicationContext(),"Couldn't Connect to Dextera Domini, Check whether it is switched on",Toast.LENGTH_SHORT).show();
}
}
else if (message.what == Constants.READ_STATUS) {
if(((String)message.obj).equals(Constants.OPEN_CAMERA)){
openCamera();
resumeReading();
}
else if(message.obj.equals(Constants.OK_GOOGLE)){
okGoogle();
L.s(getBaseContext(),"Ok Google");
resumeReading();
}
else if (message.obj.equals(Constants.GOOGLE_NOW)){
googleNow();
resumeReading();
}
else if(message.obj.equals(Constants.PLAY_PAUSE)){
audioPlayPause();
resumeReading();
if (message.arg1 == Constants.READ_STATUS_OK) {
if (((String) message.obj).equals(Constants.OPEN_CAMERA)) {
openCamera();
resumeReading();
} else if (message.obj.equals(Constants.OK_GOOGLE)) {
okGoogle();
L.s(getBaseContext(), "Ok Google");
resumeReading();
} else if (message.obj.equals(Constants.GOOGLE_NOW)) {
googleNow();
resumeReading();
} else if (message.obj.equals(Constants.PLAY_PAUSE)) {
audioPlayPause();
resumeReading();
} else if (message.obj.equals(Constants.CAMERA_CLICK)) {
CameraClick();
resumeReading();
} else if (message.obj.equals(Constants.VOLUME_UP)) {
VolumeUp();
resumeReading();
} else if (message.obj.equals(Constants.VOLUME_DOWN)) {
VolumeDown();
resumeReading();
} else if (message.obj.equals(Constants.END_CALL)) {
EndCall();
resumeReading();
}
else if(message.arg1 == Constants.READ_STATUS_NOT_OK){
L.s(getBaseContext(),"Domini Disconnected");
}
}
}
}
......@@ -148,5 +163,66 @@ public class ReceiveService extends Service {
KeyEvent upEvent = new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
audioManager.dispatchMediaKeyEvent(upEvent);
}
public void CameraClick(){
Thread t= new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_CAMERA);
}
catch (Exception e){
}
}
});
t.start();
}
public void VolumeUp(){
Thread t= new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_UP);
}
catch (Exception e){
}
}
});
t.start();
}
public void VolumeDown(){
Thread t= new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);
}
catch (Exception e){
}
}
});
t.start();
}
public void EndCall(){
Thread t= new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENDCALL);
}
catch (Exception e){
}
}
});
t.start();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment