Commit a928799d authored by Harshith Goka's avatar Harshith Goka

Add functionalities

parent f313b577
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -3,7 +3,7 @@
package="com.example.harshith.ddc">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:name=".GlobalClass"
android:allowBackup="true"
......
......@@ -12,5 +12,10 @@ public class Constants {
public static int READ_STATUS = 18;
public static int READ_STATUS_OK = 0;
public static int READ_STATUS_NOT_OK = 1;
public static String PLAY_PAUSE = "Play/Pause";
public static String OK_GOOGLE = "Ok Google";
public static String OPEN_CAMERA = "Camera";
public static String GOOGLE_NOW = "GoogleApp";
}
......@@ -3,6 +3,7 @@ package com.example.harshith.ddc;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
......@@ -15,6 +16,7 @@ import android.widget.TextView;
import android.widget.Toast;
import java.util.Set;
import java.util.jar.Manifest;
/**
* Created by harshith on 17/6/16.
......@@ -63,6 +65,10 @@ public class MainActivity extends AppCompatActivity {
checkBTState();
if(checkSelfPermission(android.Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_DENIED){
requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},1);
}
mPairedDevicesArrayAdapter.clear();
textConnectionStatus.setText(" ");
......
package com.example.harshith.ddc;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.util.Log;
import java.io.IOException;
......@@ -36,15 +38,15 @@ public class ReceiveDataThread extends Thread {
int[]hand; int q=0;
q=0; hand = new int [] {0,0,0,0,8,8,8,8,8,8};
q=0; hand = new int [] {0,1,1,0,8,8,8,8,8,8};
// neutral
a[q].updateFrame(hand);
q=1; hand = new int [] {1,1,0,0,8,8,8,8,1,8};
q=1; hand = new int [] {1,1,1,1,8,8,8,8,1,8};
// voice search
a[q].updateFrame(hand);
q=2; hand = new int [] {1,0,1,1,8,8,8,8,1,8};
q=2; hand = new int [] {0,1,1,1,8,8,8,8,1,8};
// tap
a[q].updateFrame(hand);
......@@ -130,6 +132,27 @@ public class ReceiveDataThread extends Thread {
if(count == no){
Log.d("Gesture","Gesture " + gestActive + " is activated");
if(gestActive == 0){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.OPEN_CAMERA).sendToTarget();
Looper.loop();
}
else if(gestActive == 1){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.OK_GOOGLE).sendToTarget();
Looper.loop();
}
else if(gestActive == 2){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.GOOGLE_NOW).sendToTarget();
Looper.loop();
}
else if(gestActive == 3){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,Constants.PLAY_PAUSE).sendToTarget();
Looper.loop();
}
count = 0;
gestActive = -1;
//if( str.equals("n") ) { stay = false; break; }
......@@ -151,34 +174,7 @@ public class ReceiveDataThread extends Thread {
}
}
}
// int[] flex = new int[5];
// for (int i = 0; i != 5; i++) {
// try {
// flex[i] = readings[i];
// }
// catch (ArrayIndexOutOfBoundsException e) {
//
// }
// }
//
// int[] mpu = new int[6];
// for (int i = 0; i != 6; i++) {
// try {
// mpu[i] = readings[5 + i];
// }
// catch (ArrayIndexOutOfBoundsException e) {
//
// }
// }
}
// if(processHandler != null) {
// processHandler.obtainMessage(1, readings).sendToTarget();
// }
// else {
// processHandler = globalClass.getProcessHandler();
// }
}
......
package com.example.harshith.ddc;
import android.Manifest;
import android.app.Service;
import android.bluetooth.BluetoothSocket;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.speech.RecognizerIntent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
import java.util.UUID;
import static android.content.ContentValues.TAG;
/**
* Created by harshith on 17/6/16.
*/
......@@ -18,6 +33,7 @@ import java.util.UUID;
public class ReceiveService extends Service {
ConnectThread connectThread;
ReceiveDataThread receiveDataThread;
BluetoothSocket bluetoothSocket;
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
public Handler handler;
GlobalClass globalClass;
......@@ -30,6 +46,7 @@ public class ReceiveService extends Service {
if(message.what == Constants.CONNECTION_STATUS) {
if(message.arg1 == Constants.CONNECTION_STATUS_OK){
Toast.makeText(getApplicationContext(),"Connected",Toast.LENGTH_LONG).show();
bluetoothSocket = (BluetoothSocket) message.obj;
receiveDataThread = new ReceiveDataThread((BluetoothSocket) message.obj,handler,globalClass);
receiveDataThread.start();
}
......@@ -38,7 +55,23 @@ public class ReceiveService extends Service {
}
}
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();
}
}
}
};
......@@ -66,5 +99,54 @@ public class ReceiveService extends Service {
public void onDestroy(){
}
public void openCamera(){
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
PackageManager pm = getBaseContext().getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Intent intent = new Intent();
intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name));
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (Exception e){ Log.i(TAG, "Unable to launch camera: " + e); }
}
public void dialPhoneNumber(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
public void resumeReading(){
receiveDataThread = new ReceiveDataThread(bluetoothSocket,handler,globalClass);
receiveDataThread.start();
}
public void googleNow(){
Intent intent = new Intent(Intent.ACTION_ASSIST);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
public void okGoogle(){
Intent intent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
public void audioPlayPause(){
AudioManager audioManager = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
KeyEvent downEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
audioManager.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
audioManager.dispatchMediaKeyEvent(upEvent);
}
}
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