Commit 27b23b3c authored by Harshith Goka's avatar Harshith Goka

Add more functionalities and inits mpu values

parent c4602190
......@@ -14,7 +14,7 @@ class DynamicQueue{
public int latestElement = 0;
public int foremostElement = 0;
public int[] threshold;
public double alterFactor = -1;
public double alterFactor = -0.5;
public DynamicQueue(DynamicGesture []gest,int[] threshold){
gesture = gest.clone();
......@@ -130,10 +130,10 @@ class DynamicQueue{
int[][] gestarraytemp = validSensorArrayComp(i);
x.arrayInput(gestarraytemp, arraytemp);
dtwGap[slotNo][i].add( Math.max( 0.0, ((double)(x.sdtwDistance() + dtwGap[slotNo][i].size()*alterFactor)) ) );
dtwGap[slotNo][i].add( Math.max( 0.0, (x.sdtwDistance() + dtwGap[slotNo][i].size()*alterFactor)) );
}
for (int i=0; i<noOfGestures; i++) {
if((int)dtwGap[slotNo][i].get(dtwGap[slotNo][i].size()-1) >=threshold[i]) shortlist[slotNo][i] = false;
if((new Double((double)dtwGap[slotNo][i].get(dtwGap[slotNo][i].size()-1))).intValue() >=threshold[i]) shortlist[slotNo][i] = false;
}
}
......@@ -153,7 +153,7 @@ class DynamicQueue{
public int proceedExecution(){
int no;
// no = Math.max((latestElement - 20)%noOfSlots,foremostElement);
no = Math.max((latestElement - 20),foremostElement);
for (int i=foremostElement; i!=latestElement; i=(i+1)%noOfSlots) {
if(getShortlistCount(i)==0) foremostElement = (foremostElement+1)%noOfSlots;
else if(getShortlistCount(i)==1) {
......@@ -185,8 +185,9 @@ class DynamicQueue{
System.out.print('\n');
System.out.println("DTW Status:");
for (int i=0; i<noOfGestures; i++) {
System.out.print("Gesture " + i + " : ");
for (int j=0; j<noOfSlots; j++) {
System.out.print(dtwGap[j][i] + " ");
System.out.print(j + " - " + dtwGap[j][i] + " ");
}
System.out.print('\n');
}
......
......@@ -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;
......@@ -87,6 +88,9 @@ public class MainActivity extends AppCompatActivity {
}
private void checkBTState() {
// if(checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") == PackageManager.PERMISSION_DENIED){
// requestPermissions(new String[]{"android.permission.READ_EXTERNAL_STORAGE"},1);
// }e
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter == null) {
Toast.makeText(this,"This device doesn't support bluetooth.",Toast.LENGTH_SHORT).show();
......
......@@ -49,8 +49,10 @@ public class ReceiveDataThread extends Thread {
threshold = new int[noOfGestures];
// initialising the 11 gestures
// initialising the 11 gestures
indx=0;
array = readingsGenerate(new int[] {14,13,18,15,12},new int[] {76,84,88,81,82});
array = readingsGenerate(new int[] {14,13,18,15,12,0,0,0,0,35,0},new int[] {76,84,88,81,82,0,0,0,0,35,0});
a[indx] = new DynamicGesture(array.length);
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
......@@ -59,7 +61,9 @@ public class ReceiveDataThread extends Thread {
indx=1;
array = readingsGenerate(new int[]{2},new int[]{3});
array = readingsGenerate(new int[]{28,77,77,76,94,0,0,0,0,0,0},new int[]{28,77,77,76,94,201,0,0,0,0,0});
setValue(array,0,5,201);
lineDraw(array, 0, 0, 51, 5, false); lineDraw(array, 50, -50, 101, 5, true); lineDraw(array, 150, 50, 51, 5, false);
a[indx] = new DynamicGesture(array.length);
cons = new int[] {1,1,1,1,1,1,0,0,1,1,0};
......@@ -68,7 +72,7 @@ public class ReceiveDataThread extends Thread {
threshold[indx] = 40;
indx=2;
array = readingsGenerate(new int [] {14,13,18,15,12},new int [] {23,75,90,13,8});
array = readingsGenerate(new int [] {14,13,18,15,12,0,0,0,0,0,0},new int [] {23,75,90,13,8,0,0,0,0,0,0});
a[indx] = new DynamicGesture(array.length);
......@@ -78,7 +82,7 @@ public class ReceiveDataThread extends Thread {
threshold[indx] = 40;
indx=3;
array = readingsGenerate(new int [] {14,13,18,15,12},new int [] {2,11,2,10,1});
array = readingsGenerate(new int [] {14,13,18,15,12,0,0,0,0,0,0},new int [] {52,11,2,10,1,0,0,0,0,0,0});
a[indx] = new DynamicGesture(array.length);
......@@ -88,7 +92,7 @@ public class ReceiveDataThread extends Thread {
threshold[indx] = 40;
indx=4;
array = readingsGenerate(new int[]{2},new int[]{3});
array = readingsGenerate(new int[]{14,13,18,15,12,0,0,0,0,35,0},new int[]{47,5,5,5,93,0,0,0,0,35,0});
a[indx] = new DynamicGesture(array.length);
......@@ -99,7 +103,7 @@ public class ReceiveDataThread extends Thread {
indx=5;
array = readingsGenerate(new int [] {14,13,18,15,12} ,new int [] {47,5,5,5,93});
array = readingsGenerate(new int [] {47,5,5,5,93,0,0,0,-35,0,0} ,new int [] {71,3,14,89,81,0,0,0,-35,0,0});
a[indx] = new DynamicGesture(array.length);
......@@ -110,8 +114,9 @@ public class ReceiveDataThread extends Thread {
indx=6;
array = readingsGenerate(new int[]{2},new int[]{3});
array = readingsGenerate(new int[]{47,5,5,5,93,0,0,0,-35,0,0},new int[]{47,5,5,5,93,201,0,0,-35,0,0});//LD
setValue(array,0,5,201);
lineDraw(array, 0, 0, 51, 5, false); lineDraw(array, 50, -50, 101, 5, true); lineDraw(array, 150, 50, 51, 5, false);
a[indx] = new DynamicGesture(array.length);
......@@ -122,7 +127,9 @@ public class ReceiveDataThread extends Thread {
indx=7;
array = readingsGenerate(new int[]{2},new int[]{3});
array = readingsGenerate(new int[]{47,5,5,5,93,0,0,0,0,35,0},new int[]{47,5,5,5,93,201,0,0,0,35,0});
setValue(array,0,5,201);
lineDraw(array, 0, 0, 51, 5, false); lineDraw(array, 50, -50, 101, 5, true); lineDraw(array, 150, 50, 51, 5, false);
a[indx] = new DynamicGesture(array.length);
......@@ -133,7 +140,7 @@ public class ReceiveDataThread extends Thread {
indx=8;
array = readingsGenerate(new int [] {14,13,18,15,12},new int [] {47,81,21,15,8});
array = readingsGenerate(new int [] {14,13,18,15,12,0,0,0,0,35,0},new int [] {47,81,21,15,8,0,0,0,0,35,0});
a[indx] = new DynamicGesture(array.length);
......@@ -144,7 +151,7 @@ public class ReceiveDataThread extends Thread {
indx=9;
array = readingsGenerate(new int [] {76,84,88,81,82},new int [] {14,5,80,60,75});
array = readingsGenerate(new int [] {76,84,88,81,82,0,0,0,0,35,0},new int [] {14,5,80,60,75,0,0,0,0,35,0});
a[indx] = new DynamicGesture(array.length);
......@@ -155,7 +162,7 @@ public class ReceiveDataThread extends Thread {
indx=10;
array = readingsGenerate(new int [] {14,5,80,60,75},new int [] {28,77,77,76,94});
array = readingsGenerate(new int [] {14,5,80,60,75,0,0,0,0,35,0},new int [] {28,77,77,76,94,0,0,0,0,35,0});
a[indx] = new DynamicGesture(array.length);
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
......@@ -165,7 +172,7 @@ public class ReceiveDataThread extends Thread {
indx=11;
array = readingsGenerate(new int [] {14,5,80,60,75},new int [] {76,84,88,81,82});
array = readingsGenerate(new int [] {14,5,80,60,75,0,0,0,0,35,0},new int [] {76,84,88,81,82,0,0,0,0,35,0});
a[indx] = new DynamicGesture(array.length);
......@@ -174,7 +181,8 @@ public class ReceiveDataThread extends Thread {
// a[indx].printData();
threshold[indx] = 40;
threshold = new int[]{0,0,0,0,0,0,0,0,0,0,0,0};
threshold = new int[]{40,40,40,40,40,40,40,40,40,40,40,40};
DynamicQueue q = new DynamicQueue(a,threshold);
Live dynamiclive = new Live();
......@@ -198,7 +206,7 @@ public class ReceiveDataThread extends Thread {
i = q.proceedExecution();
if (i != -1) {
Looper.prepare();
handler.sendMessageDelayed(handler.obtainMessage(Constants.READ_STATUS, readStatus, i, null), 10000);
// handler.sendMessageDelayed(handler.obtainMessage(Constants.READ_STATUS, readStatus, i, null), 10000);
L.m("Gesture " + i + " is executed");
q.gestureStatusPrint();
Looper.loop();
......@@ -269,30 +277,21 @@ public class ReceiveDataThread extends Thread {
}
}
public static int[][] readingsGenerate(int[] low,int[] high){
public int[][] readingsGenerate(int[] low,int[] high){
int size=0;
for(int i=0;i<5;i++){
for(int i=0;i<low.length;i++){
int diff=high[i]-low[i];
if(diff>size){
size=diff;
}
}
//now size = maximum difference between low and high values
int [] [] array=new int[size][11];
float size2=size-1;
for(int i=0;i<size;i++){
array[i][0]=low[0]+(int)((high[0]-low[0])*(i/size2));
array[i][1]=low[1]+(int)((high[1]-low[1])*(i/size2));
array[i][2]=low[2]+(int)((high[2]-low[2])*(i/size2));
array[i][3]=low[3]+(int)((high[3]-low[3])*(i/size2));
array[i][4]=low[4]+(int)((high[4]-low[4])*(i/size2));
array[i][5]=0;
array[i][6]=0;
array[i][7]=0;
array[i][8]=0;
array[i][9]=0;
array[i][10]=0;
int [] [] array=new int[size+1][low.length];
float size2=size;
for(int i=0;i<size+1;i++){
for (int j=0;j<low.length ; j++) {
array[i][j]=low[j]+(int)((high[j]-low[j])*(i/size2));
}
}
return array;
}
......
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Handler;
......@@ -21,6 +22,8 @@ import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;
import static android.content.ContentValues.TAG;
......@@ -59,11 +62,13 @@ public class ReceiveService extends Service {
Toast.makeText(getBaseContext(),"Gesture " + message.arg2 + " is executed",Toast.LENGTH_SHORT).show();
switch(message.arg2) {
case 0:
home();
break;
case 1:
back();
break;
case 2:
break;
case 3:
......@@ -75,9 +80,10 @@ public class ReceiveService extends Service {
audioPlayPause();
break;
case 6:
nextSong();
break;
case 7:
previousSong();
break;
case 8:
okGoogle();
......@@ -86,9 +92,10 @@ public class ReceiveService extends Service {
openCamera();
break;
case 10:
cameraClick();
break;
case 11:
gallery();
break;
default:
break;
......@@ -127,6 +134,29 @@ public class ReceiveService extends Service {
}
public void back(){
Thread t= new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
}
catch (Exception e){
}
}
});
t.start();
}
public void home(){
inputKeyEvent("" + KeyEvent.KEYCODE_HOME);
}
public void nowOnTap(){
inputLongPressKeyEvent("" + KeyEvent.KEYCODE_HOME);
}
public void openCamera(){
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
......@@ -143,6 +173,38 @@ public class ReceiveService extends Service {
} catch (Exception e){ Log.i(TAG, "Unable to launch camera: " + e); }
}
public void cameraClick(){
inputKeyEvent("" + KeyEvent.KEYCODE_CAMERA);
}
public void gallery(){
if(checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") == PackageManager.PERMISSION_DENIED){
L.s(getBaseContext(),"Please grant Permission to read storage data");
}
else {
// Get last taken photo
String[] projection = new String[]{
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.MIME_TYPE
};
final Cursor cursor = getContentResolver()
.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
// Open in Gallery
if (cursor.moveToFirst()) {
String imageLocation = cursor.getString(1);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + imageLocation), "image/*");
startActivity(intent);
}
}
}
public void dialPhoneNumber(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
......@@ -168,6 +230,15 @@ public class ReceiveService extends Service {
startActivity(intent);
}
public void openMusicPlayer(){
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.android.music", "com.android.music.MusicBrowserActivity");
intent.setComponent(comp);
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);
......@@ -176,57 +247,57 @@ public class ReceiveService extends Service {
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 nextSong(){
AudioManager audioManager = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
KeyEvent downEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT);
audioManager.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_MEDIA_NEXT);
audioManager.dispatchMediaKeyEvent(upEvent);
}
public void VolumeUp(){
Thread t= new Thread(new Runnable() {
public void previousSong(){
AudioManager audioManager = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
KeyEvent downEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
audioManager.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_MEDIA_PREVIOUS);
audioManager.dispatchMediaKeyEvent(upEvent);
}
public static void inputKeyEvent(final String keyCodeString) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
int keyCode = Integer.parseInt(keyCodeString);
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_UP);
}
catch (Exception e){
Process processKeyEvent = Runtime.getRuntime().exec("/system/xbin/su");
DataOutputStream os = new DataOutputStream(processKeyEvent.getOutputStream());
os.writeBytes("input keyevent " + keyCode + "\n");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
t.start();
thread.start();
}
public void VolumeDown(){
Thread t= new Thread(new Runnable() {
public static void inputLongPressKeyEvent(final String keyCodeString) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
int keyCode = Integer.parseInt(keyCodeString);
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);
}
catch (Exception e){
Process processKeyEvent = Runtime.getRuntime().exec("/system/xbin/su");
DataOutputStream os = new DataOutputStream(processKeyEvent.getOutputStream());
os.writeBytes("input keyevent --longpress " + keyCode + "\n");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
t.start();
}
thread.start();
public void openMusicPlayer(){
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.android.music", "com.android.music.MusicBrowserActivity");
intent.setComponent(comp);
startActivity(intent);
}
}
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