Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
DDC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GOKA HARSHITH
DDC
Commits
bdd0ce76
Commit
bdd0ce76
authored
Jun 30, 2016
by
Harshith Goka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ArrayOutOfBound , Last resort
parent
72299da0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
300 additions
and
239 deletions
+300
-239
app/src/main/java/com/example/harshith/ddc/Constants.java
app/src/main/java/com/example/harshith/ddc/Constants.java
+7
-2
app/src/main/java/com/example/harshith/ddc/Gesture.java
app/src/main/java/com/example/harshith/ddc/Gesture.java
+4
-4
app/src/main/java/com/example/harshith/ddc/MainActivity.java
app/src/main/java/com/example/harshith/ddc/MainActivity.java
+1
-1
app/src/main/java/com/example/harshith/ddc/ProcessService.java
...rc/main/java/com/example/harshith/ddc/ProcessService.java
+0
-23
app/src/main/java/com/example/harshith/ddc/ProcessThread.java
...src/main/java/com/example/harshith/ddc/ProcessThread.java
+0
-40
app/src/main/java/com/example/harshith/ddc/ReceiveDataThread.java
...main/java/com/example/harshith/ddc/ReceiveDataThread.java
+144
-101
app/src/main/java/com/example/harshith/ddc/ReceiveService.java
...rc/main/java/com/example/harshith/ddc/ReceiveService.java
+140
-63
app/src/main/java/com/example/harshith/ddc/StaticGesture.java
...src/main/java/com/example/harshith/ddc/StaticGesture.java
+4
-5
No files found.
app/src/main/java/com/example/harshith/ddc/Constants.java
View file @
bdd0ce76
...
@@ -13,13 +13,18 @@ public class Constants {
...
@@ -13,13 +13,18 @@ public class Constants {
public
static
int
READ_STATUS_OK
=
0
;
public
static
int
READ_STATUS_OK
=
0
;
public
static
int
READ_STATUS_NOT_OK
=
1
;
public
static
int
READ_STATUS_NOT_OK
=
1
;
public
static
String
MUSIC_PLAYER
=
"Music Player"
;
public
static
String
PLAY_PAUSE
=
"Play/Pause"
;
public
static
String
PLAY_PAUSE
=
"Play/Pause"
;
public
static
String
OK_GOOGLE
=
"Ok Google"
;
public
static
String
OK_GOOGLE
=
"Ok Google"
;
public
static
String
OPEN_CAMERA
=
"Camera"
;
public
static
String
OPEN_CAMERA
=
"Camera"
;
public
static
String
GOOGLE_NOW
=
"GoogleApp"
;
public
static
String
GOOGLE_NOW
=
"GoogleApp"
;
public
static
String
CAMERA_CLICK
=
"CameraClick"
;
public
static
String
CAMERA_CLICK
=
"CameraClick"
;
public
static
String
VOLUME_UP
=
"VolumeUp"
;
public
static
String
VOLUME_CONTROL
=
"Volume Control"
;
public
static
String
VOLUME_DOWN
=
"VolumeDown"
;
public
static
String
END_CALL
=
"EndCall"
;
public
static
String
END_CALL
=
"EndCall"
;
public
static
String
HOME
=
"Home"
;
public
static
String
BACK
=
"Back"
;
public
static
int
MODE_NORMAL
=
0
;
public
static
int
MODE_VOLUME
=
255
;
}
}
app/src/main/java/com/example/harshith/ddc/Gesture.java
View file @
bdd0ce76
...
@@ -4,13 +4,13 @@ package com.example.harshith.ddc;
...
@@ -4,13 +4,13 @@ package com.example.harshith.ddc;
public
class
Gesture
{
public
class
Gesture
{
public
int
dataPoints
=
50
;
public
int
dataPoints
=
50
;
public
int
sensors
=
1
0
;
public
int
sensors
=
1
1
;
public
int
adcLevels
=
2
;
public
int
adcLevels
=
2
;
public
int
adcUpper
=
0
;
public
int
adcUpper
=
0
;
public
int
adcLower
=
100
;
public
int
adcLower
=
100
;
public
int
mpuLevels
=
3
;
public
int
mpuLevels
=
100
;
public
int
mpuUpper
=
1800
0
;
public
int
mpuUpper
=
5
0
;
public
int
mpuLower
=
-
1800
0
;
public
int
mpuLower
=
-
5
0
;
public
Gesture
(){}
public
Gesture
(){}
...
...
app/src/main/java/com/example/harshith/ddc/MainActivity.java
View file @
bdd0ce76
...
@@ -66,7 +66,7 @@ public class MainActivity extends AppCompatActivity {
...
@@ -66,7 +66,7 @@ public class MainActivity extends AppCompatActivity {
checkBTState
();
checkBTState
();
if
(
checkSelfPermission
(
android
.
Manifest
.
permission
.
CALL_PHONE
)
==
PackageManager
.
PERMISSION_DENIED
){
if
(
checkSelfPermission
(
android
.
Manifest
.
permission
.
CALL_PHONE
)
==
PackageManager
.
PERMISSION_DENIED
){
requestPermissions
(
new
String
[]{
android
.
Manifest
.
permission
.
CALL_PHONE
},
1
);
requestPermissions
(
new
String
[]{
android
.
Manifest
.
permission
.
CALL_PHONE
,
"android.permission.READ_EXTERNAL_STORAGE"
},
1
);
}
}
mPairedDevicesArrayAdapter
.
clear
();
mPairedDevicesArrayAdapter
.
clear
();
...
...
app/src/main/java/com/example/harshith/ddc/ProcessService.java
deleted
100644 → 0
View file @
72299da0
package
com.example.harshith.ddc
;
import
android.app.Service
;
import
android.content.Intent
;
import
android.os.IBinder
;
import
android.support.annotation.Nullable
;
/**
* Created by harshith on 18/6/16.
*/
public
class
ProcessService
extends
Service
{
@Override
public
void
onCreate
()
{
}
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
}
}
app/src/main/java/com/example/harshith/ddc/ProcessThread.java
deleted
100644 → 0
View file @
72299da0
package
com.example.harshith.ddc
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.os.Message
;
/**
* Created by harshith on 18/6/16.
*/
public
class
ProcessThread
extends
Thread
{
int
[]
liveReadings
;
Handler
handler
;
GlobalClass
globalClass
;
public
ProcessThread
(
GlobalClass
globalClass
)
{
liveReadings
=
null
;
this
.
globalClass
=
globalClass
;
}
@Override
public
void
run
()
{
Looper
.
prepare
();
handler
=
new
Handler
(){
@Override
public
void
handleMessage
(
Message
msg
)
{
liveReadings
=
(
int
[])
msg
.
obj
;
L
.
m
(
liveReadings
.
toString
());
}
};
globalClass
.
setProcessHandler
(
handler
);
Looper
.
loop
();
while
(
true
){
if
(
liveReadings
!=
null
){
}
}
}
}
app/src/main/java/com/example/harshith/ddc/ReceiveDataThread.java
View file @
bdd0ce76
...
@@ -4,6 +4,7 @@ import android.bluetooth.BluetoothSocket;
...
@@ -4,6 +4,7 @@ import android.bluetooth.BluetoothSocket;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.os.Looper
;
import
android.os.Message
;
import
android.provider.MediaStore
;
import
android.provider.MediaStore
;
import
android.util.Log
;
import
android.util.Log
;
...
@@ -15,6 +16,7 @@ import java.io.InputStream;
...
@@ -15,6 +16,7 @@ import java.io.InputStream;
*/
*/
public
class
ReceiveDataThread
extends
Thread
{
public
class
ReceiveDataThread
extends
Thread
{
int
mode
;
private
BluetoothSocket
bluetoothSocket
;
private
BluetoothSocket
bluetoothSocket
;
private
InputStream
inputStream
;
private
InputStream
inputStream
;
Handler
handler
;
Handler
handler
;
...
@@ -25,12 +27,12 @@ public class ReceiveDataThread extends Thread {
...
@@ -25,12 +27,12 @@ public class ReceiveDataThread extends Thread {
int
[]
readings
;
int
[]
readings
;
Gesture
[]
a
;
Gesture
[]
a
;
public
ReceiveDataThread
(
BluetoothSocket
bluetoothSocket
,
Handler
handler
,
GlobalClass
globalClass
)
{
public
ReceiveDataThread
(
BluetoothSocket
bluetoothSocket
,
Handler
handler
,
GlobalClass
globalClass
,
int
mode
)
{
this
.
bluetoothSocket
=
bluetoothSocket
;
this
.
bluetoothSocket
=
bluetoothSocket
;
this
.
handler
=
handler
;
this
.
handler
=
handler
;
this
.
globalClass
=
globalClass
;
this
.
globalClass
=
globalClass
;
stringBuilder
=
new
StringBuilder
();
stringBuilder
=
new
StringBuilder
();
this
.
mode
=
mode
;
a
=
new
Gesture
[
8
];
a
=
new
Gesture
[
8
];
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
a
[
i
]
=
new
StaticGesture
();
a
[
i
]
=
new
StaticGesture
();
...
@@ -38,36 +40,36 @@ public class ReceiveDataThread extends Thread {
...
@@ -38,36 +40,36 @@ public class ReceiveDataThread extends Thread {
int
[]
hand
;
int
q
=
0
;
int
[]
hand
;
int
q
=
0
;
q
=
0
;
hand
=
new
int
[]
{
0
,
1
,
1
,
0
,
8
,
8
,
8
,
8
,
8
,
8
};
q
=
0
;
hand
=
new
int
[]
{
0
,
0
,
1
,
1
,
0
,
8
,
8
,
8
,
8
,
8
,
8
};
//
neutral
//
Music Player
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
1
;
hand
=
new
int
[]
{
1
,
1
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
q
=
1
;
hand
=
new
int
[]
{
0
,
0
,
1
,
1
,
1
,
8
,
8
,
8
,
8
,
8
,
8
};
//
voice search
//
Volume
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
2
;
hand
=
new
int
[]
{
0
,
1
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
q
=
2
;
hand
=
new
int
[]
{
1
,
0
,
1
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
//
tap
//
OK Google
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
3
;
hand
=
new
int
[]
{
0
,
1
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
q
=
3
;
hand
=
new
int
[]
{
0
,
1
,
1
,
1
,
0
,
8
,
8
,
8
,
8
,
1
,
8
};
//
c
all
//
End C
all
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
4
;
hand
=
new
int
[]
{
0
,
0
,
1
,
1
,
8
,
8
,
8
,-
1
,
8
,
8
};
q
=
4
;
hand
=
new
int
[]
{
0
,
0
,
0
,
1
,
1
,
8
,
8
,
8
,-
1
,
8
,
8
};
// cam open
// cam open
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
5
;
hand
=
new
int
[]
{
0
,
0
,
0
,
1
,
8
,
8
,
8
,-
1
,
8
,
8
};
q
=
5
;
hand
=
new
int
[]
{
0
,
1
,
1
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
// cam click
// cam click
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
6
;
hand
=
new
int
[]
{
1
,
0
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
q
=
6
;
hand
=
new
int
[]
{
1
,
0
,
0
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
//
music open
//
Music Play
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
q
=
7
;
hand
=
new
int
[]
{
0
,
0
,
1
,
1
,
8
,
8
,
8
,
8
,
1
,
8
};
q
=
7
;
hand
=
new
int
[]
{
1
,
0
,
0
,
1
,
0
,
8
,
8
,
8
,
8
,
1
,
8
};
//
music play
//
Home
a
[
q
].
updateFrame
(
hand
);
a
[
q
].
updateFrame
(
hand
);
}
}
...
@@ -86,119 +88,160 @@ public class ReceiveDataThread extends Thread {
...
@@ -86,119 +88,160 @@ public class ReceiveDataThread extends Thread {
byte
[]
buffer
=
new
byte
[
64
];
byte
[]
buffer
=
new
byte
[
64
];
int
bytes
=
-
1
;
int
bytes
=
-
1
;
// ProcessThread processThread = new ProcessThread(globalClass);
// processThread.start();
//
// processHandler = globalClass.getProcessHandler();
Live
staticLive
=
new
Live
();
Live
staticLive
=
new
Live
();
int
no
=
50
;
int
no
=
50
;
//StaticLive.print();
//StaticLive.print();
int
count
=
0
;
int
count
=
0
;
int
gestActive
=
-
1
;
boolean
stay
=
true
;
int
gestActive
=
-
1
;
boolean
stay
=
true
;
if
(
mode
==
Constants
.
MODE_NORMAL
)
{
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
(
"~"
);
if
(
endOfLineIndex
>
0
)
{
int
startOfLineIndex
=
stringBuilder
.
indexOf
(
"#"
);
if
(
startOfLineIndex
>
endOfLineIndex
||
startOfLineIndex
==
-
1
)
{
startOfLineIndex
=
0
;
}
else
if
(
startOfLineIndex
==
0
)
{
startOfLineIndex
=
1
;
}
String
dataIn
=
stringBuilder
.
substring
(
startOfLineIndex
,
endOfLineIndex
);
while
(
true
)
{
String
[]
readingStrings
=
dataIn
.
split
(
"\\+"
);
bytes
=
inputStream
.
read
(
buffer
);
readings
=
new
int
[
readingStrings
.
length
];
readStatus
=
Constants
.
READ_STATUS_OK
;
for
(
int
i
=
0
;
i
!=
readingStrings
.
length
;
i
++)
{
String
readMessage
=
new
String
(
buffer
,
0
,
bytes
);
try
{
stringBuilder
.
append
(
readMessage
);
readings
[
i
]
=
Integer
.
valueOf
(
readingStrings
[
i
]);
int
endOfLineIndex
=
stringBuilder
.
indexOf
(
"~"
);
}
catch
(
NumberFormatException
e
)
{
if
(
endOfLineIndex
>
0
)
{
int
startOfLineIndex
=
stringBuilder
.
indexOf
(
"#"
);
if
(
startOfLineIndex
>
endOfLineIndex
||
startOfLineIndex
==
-
1
)
{
startOfLineIndex
=
0
;
}
else
if
(
startOfLineIndex
==
0
)
{
startOfLineIndex
=
1
;
}
String
dataIn
=
stringBuilder
.
substring
(
startOfLineIndex
,
endOfLineIndex
);
String
[]
readingStrings
=
dataIn
.
split
(
"\\+"
);
}
catch
(
NullPointerException
e
)
{
readings
=
new
int
[
readingStrings
.
length
];
for
(
int
i
=
0
;
i
!=
readingStrings
.
length
;
i
++)
{
try
{
readings
[
i
]
=
Integer
.
valueOf
(
readingStrings
[
i
]);
}
catch
(
NumberFormatException
e
)
{
}
}
}
catch
(
NullPointerException
e
)
{
String
testConvert
=
""
;
for
(
int
reading
:
readings
)
{
testConvert
+=
" "
+
reading
;
}
L
.
m
(
testConvert
);
stringBuilder
.
delete
(
0
,
endOfLineIndex
+
2
);
if
(
count
==
no
)
{
Log
.
d
(
"Gesture"
,
"Gesture "
+
gestActive
+
" is activated"
);
mode
=
Constants
.
MODE_NORMAL
;
if
(
gestActive
==
0
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
MUSIC_PLAYER
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
1
)
{
mode
=
Constants
.
MODE_VOLUME
;
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
VOLUME_CONTROL
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
2
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
OK_GOOGLE
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
3
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
PLAY_PAUSE
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
4
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
BACK
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
5
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
OPEN_CAMERA
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
6
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
CAMERA_CLICK
).
sendToTarget
();
Looper
.
loop
();
}
else
if
(
gestActive
==
7
)
{
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
Constants
.
HOME
).
sendToTarget
();
Looper
.
loop
();
}
count
=
0
;
gestActive
=
-
1
;
//if( str.equals("n") ) { stay = false; break; }
}
}
}
String
testConvert
=
""
;
for
(
int
reading
:
readings
)
{
testConvert
+=
" "
+
reading
;
}
L
.
m
(
testConvert
);
stringBuilder
.
delete
(
0
,
endOfLineIndex
+
2
);
if
(
count
==
no
){
if
(
count
<
no
)
{
Log
.
d
(
"Gesture"
,
"Gesture "
+
gestActive
+
" is activated"
);
if
(
readings
.
length
>=
11
)
{
if
(
gestActive
==
0
){
staticLive
.
update
(
readings
);
Looper
.
prepare
();
}
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
OPEN_CAMERA
).
sendToTarget
();
Looper
.
loop
();
}
}
else
if
(
gestActive
==
1
){
Looper
.
prepare
();
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
OK_GOOGLE
).
sendToTarget
();
if
(
a
[
i
].
isInFrame
(
staticLive
))
{
Looper
.
loop
();
if
(
gestActive
==
i
)
{
count
++;
break
;
}
else
{
gestActive
=
i
;
count
=
1
;
break
;
}
}
}
}
else
if
(
gestActive
==
2
){
}
Looper
.
prepare
();
}
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
GOOGLE_NOW
).
sendToTarget
();
}
Looper
.
loop
();
else
if
(
mode
==
Constants
.
MODE_VOLUME
){
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
(
"~"
);
if
(
endOfLineIndex
>
0
)
{
int
startOfLineIndex
=
stringBuilder
.
indexOf
(
"#"
);
if
(
startOfLineIndex
>
endOfLineIndex
||
startOfLineIndex
==
-
1
)
{
startOfLineIndex
=
0
;
}
else
if
(
startOfLineIndex
==
0
)
{
startOfLineIndex
=
1
;
}
}
else
if
(
gestActive
==
3
){
String
dataIn
=
stringBuilder
.
substring
(
startOfLineIndex
,
endOfLineIndex
);
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
PLAY_PAUSE
).
sendToTarget
();
String
[]
readingStrings
=
dataIn
.
split
(
"\\+"
);
Looper
.
loop
();
readings
=
new
int
[
readingStrings
.
length
];
for
(
int
i
=
0
;
i
!=
readingStrings
.
length
;
i
++)
{
try
{
readings
[
i
]
=
Integer
.
valueOf
(
readingStrings
[
i
]);
}
catch
(
NumberFormatException
e
)
{
}
catch
(
NullPointerException
e
)
{
}
}
}
else
if
(
gestActive
==
4
){
String
testConvert
=
""
;
Looper
.
prepare
();
for
(
int
reading
:
readings
)
{
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
CAMERA_CLICK
).
sendToTarget
();
testConvert
+=
" "
+
reading
;
Looper
.
loop
();
}
}
else
if
(
gestActive
==
5
){
L
.
m
(
testConvert
);
Looper
.
prepare
(
);
stringBuilder
.
delete
(
0
,
endOfLineIndex
+
2
);
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
VOLUME_UP
).
sendToTarget
();
if
(
readings
.
length
==
11
){
Looper
.
loop
(
);
staticLive
.
update
(
readings
);
}
}
else
if
(
gestActive
==
6
){
if
(!
a
[
1
].
isInFrame
(
staticLive
)){
mode
=
Constants
.
MODE_NORMAL
;
Looper
.
prepare
();
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
VOLUME_DOWN
).
sendToTarget
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
null
).
sendToTarget
();
Looper
.
loop
();
Looper
.
loop
();
}
}
else
if
(
gestActive
==
7
)
{
else
{
Looper
.
prepare
();
Looper
.
prepare
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
0
,
Constants
.
END_CALL
).
sendToTarget
();
handler
.
obtainMessage
(
Constants
.
READ_STATUS
,
readStatus
,
mode
,
readings
[
8
]
).
sendToTarget
();
Looper
.
loop
();
Looper
.
loop
();
}
}
count
=
0
;
gestActive
=
-
1
;
//if( str.equals("n") ) { stay = false; break; }
}
if
(
count
<
no
){
if
(
readings
.
length
==
10
)
{
staticLive
.
update
(
readings
);
}
}
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
if
(
a
[
i
].
isInFrame
(
staticLive
)){
if
(
gestActive
==
i
){
count
++;
break
;
}
else
{
gestActive
=
i
;
count
=
1
;
break
;
}
}
}
}
}
}
}
}
}
}
catch
(
IOException
e
){
catch
(
IOException
e
){
readStatus
=
Constants
.
READ_STATUS_NOT_OK
;
readStatus
=
Constants
.
READ_STATUS_NOT_OK
;
...
...
app/src/main/java/com/example/harshith/ddc/ReceiveService.java
View file @
bdd0ce76
...
@@ -9,6 +9,7 @@ import android.content.Context;
...
@@ -9,6 +9,7 @@ import android.content.Context;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ResolveInfo
;
import
android.content.pm.ResolveInfo
;
import
android.database.Cursor
;
import
android.media.AudioManager
;
import
android.media.AudioManager
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Handler
;
import
android.os.Handler
;
...
@@ -19,10 +20,13 @@ import android.provider.MediaStore;
...
@@ -19,10 +20,13 @@ import android.provider.MediaStore;
import
android.speech.RecognizerIntent
;
import
android.speech.RecognizerIntent
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.util.CircularArray
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.KeyEvent
;
import
android.view.KeyEvent
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.UUID
;
import
java.util.UUID
;
import
static
android
.
content
.
ContentValues
.
TAG
;
import
static
android
.
content
.
ContentValues
.
TAG
;
...
@@ -48,7 +52,7 @@ public class ReceiveService extends Service {
...
@@ -48,7 +52,7 @@ public class ReceiveService extends Service {
if
(
message
.
arg1
==
Constants
.
CONNECTION_STATUS_OK
){
if
(
message
.
arg1
==
Constants
.
CONNECTION_STATUS_OK
){
Toast
.
makeText
(
getApplicationContext
(),
"Connected"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getApplicationContext
(),
"Connected"
,
Toast
.
LENGTH_LONG
).
show
();
bluetoothSocket
=
(
BluetoothSocket
)
message
.
obj
;
bluetoothSocket
=
(
BluetoothSocket
)
message
.
obj
;
receiveDataThread
=
new
ReceiveDataThread
((
BluetoothSocket
)
message
.
obj
,
handler
,
globalClass
);
receiveDataThread
=
new
ReceiveDataThread
((
BluetoothSocket
)
message
.
obj
,
handler
,
globalClass
,
Constants
.
MODE_NORMAL
);
receiveDataThread
.
start
();
receiveDataThread
.
start
();
}
}
else
if
(
message
.
arg1
==
Constants
.
CONNECTION_STATUS_NOT_CONNECTED
){
else
if
(
message
.
arg1
==
Constants
.
CONNECTION_STATUS_NOT_CONNECTED
){
...
@@ -59,34 +63,51 @@ public class ReceiveService extends Service {
...
@@ -59,34 +63,51 @@ public class ReceiveService extends Service {
if
(
message
.
arg1
==
Constants
.
READ_STATUS_OK
)
{
if
(
message
.
arg1
==
Constants
.
READ_STATUS_OK
)
{
if
(((
String
)
message
.
obj
).
equals
(
Constants
.
OPEN_CAMERA
))
{
if
(((
String
)
message
.
obj
).
equals
(
Constants
.
OPEN_CAMERA
))
{
openCamera
();
openCamera
();
resumeReading
();
L
.
s
(
getBaseContext
(),
"Camera Open"
);
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
OK_GOOGLE
))
{
}
else
if
(
message
.
obj
.
equals
(
Constants
.
OK_GOOGLE
))
{
okGoogle
();
okGoogle
();
L
.
s
(
getBaseContext
(),
"Ok Google"
);
L
.
s
(
getBaseContext
(),
"Ok Google"
);
resumeReading
();
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
GOOGLE_NOW
))
{
}
else
if
(
message
.
obj
.
equals
(
Constants
.
GOOGLE_NOW
))
{
googleNow
();
googleNow
();
resumeReading
();
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
PLAY_PAUSE
))
{
}
else
if
(
message
.
obj
.
equals
(
Constants
.
PLAY_PAUSE
))
{
audioPlayPause
();
audioPlayPause
();
resumeReading
();
L
.
s
(
getBaseContext
(),
"Play/Pause"
);
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
CAMERA_CLICK
))
{
}
else
if
(
message
.
obj
.
equals
(
Constants
.
CAMERA_CLICK
))
{
CameraClick
();
cameraClick
();
resumeReading
();
L
.
s
(
getBaseContext
(),
"Picture Taken"
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
VOLUME_UP
))
{
resumeReading
(
message
.
arg2
);
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
){
else
if
(
message
.
obj
.
equals
(
Constants
.
END_CALL
))
{
L
.
s
(
getBaseContext
(),
"Domini Disconnected"
);
endCall
();
L
.
s
(
getBaseContext
(),
"Call Ended"
);
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
MUSIC_PLAYER
)){
openMusicPlayer
();
L
.
s
(
getBaseContext
(),
"Music Player"
);
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
HOME
)){
home
();
L
.
s
(
getBaseContext
(),
"Home"
);
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
BACK
)){
back
();
L
.
s
(
getBaseContext
(),
"Back"
);
resumeReading
(
message
.
arg2
);
}
else
if
(
message
.
obj
.
equals
(
Constants
.
VOLUME_CONTROL
)){
updateVolume
((
int
)
message
.
obj
);
}
}
}
}
else
if
(
message
.
arg1
==
Constants
.
READ_STATUS_NOT_OK
){
L
.
s
(
getBaseContext
(),
"Domini Disconnected"
);
}
}
}
}
}
};
};
...
@@ -115,6 +136,25 @@ public class ReceiveService extends Service {
...
@@ -115,6 +136,25 @@ public class ReceiveService extends Service {
}
}
public
void
updateVolume
(
int
roll
){
AudioManager
audioManager
=
(
AudioManager
)
getBaseContext
().
getSystemService
(
Context
.
AUDIO_SERVICE
);
int
maxVolume
=
audioManager
.
getStreamMaxVolume
(
AudioManager
.
STREAM_MUSIC
);
int
volume
=
((
roll
+
50
)/
100
)*
maxVolume
;
audioManager
.
setStreamVolume
(
AudioManager
.
STREAM_MUSIC
,
volume
,
AudioManager
.
FLAG_SHOW_UI
);
}
public
void
home
(){
inputKeyEvent
(
""
+
KeyEvent
.
KEYCODE_HOME
);
}
public
void
back
(){
inputKeyEvent
(
""
+
KeyEvent
.
KEYCODE_BACK
);
}
public
void
nowOnTap
(){
inputLongPressKeyEvent
(
""
+
KeyEvent
.
KEYCODE_HOME
);
}
public
void
openCamera
(){
public
void
openCamera
(){
Intent
i
=
new
Intent
(
android
.
provider
.
MediaStore
.
ACTION_IMAGE_CAPTURE
);
Intent
i
=
new
Intent
(
android
.
provider
.
MediaStore
.
ACTION_IMAGE_CAPTURE
);
try
{
try
{
...
@@ -131,6 +171,38 @@ public class ReceiveService extends Service {
...
@@ -131,6 +171,38 @@ public class ReceiveService extends Service {
}
catch
(
Exception
e
){
Log
.
i
(
TAG
,
"Unable to launch camera: "
+
e
);
}
}
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
)
{
public
void
dialPhoneNumber
(
String
phoneNumber
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_DIAL
);
Intent
intent
=
new
Intent
(
Intent
.
ACTION_DIAL
);
intent
.
setData
(
Uri
.
parse
(
"tel:"
+
phoneNumber
));
intent
.
setData
(
Uri
.
parse
(
"tel:"
+
phoneNumber
));
...
@@ -139,8 +211,8 @@ public class ReceiveService extends Service {
...
@@ -139,8 +211,8 @@ public class ReceiveService extends Service {
}
}
}
}
public
void
resumeReading
(){
public
void
resumeReading
(
int
mode
){
receiveDataThread
=
new
ReceiveDataThread
(
bluetoothSocket
,
handler
,
globalClass
);
receiveDataThread
=
new
ReceiveDataThread
(
bluetoothSocket
,
handler
,
globalClass
,
mode
);
receiveDataThread
.
start
();
receiveDataThread
.
start
();
}
}
...
@@ -156,6 +228,15 @@ public class ReceiveService extends Service {
...
@@ -156,6 +228,15 @@ public class ReceiveService extends Service {
startActivity
(
intent
);
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
(){
public
void
audioPlayPause
(){
AudioManager
audioManager
=
(
AudioManager
)
getBaseContext
().
getSystemService
(
Context
.
AUDIO_SERVICE
);
AudioManager
audioManager
=
(
AudioManager
)
getBaseContext
().
getSystemService
(
Context
.
AUDIO_SERVICE
);
KeyEvent
downEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_MEDIA_PLAY_PAUSE
);
KeyEvent
downEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_MEDIA_PLAY_PAUSE
);
...
@@ -164,65 +245,61 @@ public class ReceiveService extends Service {
...
@@ -164,65 +245,61 @@ public class ReceiveService extends Service {
audioManager
.
dispatchMediaKeyEvent
(
upEvent
);
audioManager
.
dispatchMediaKeyEvent
(
upEvent
);
}
}
public
void
CameraClick
(){
public
void
nextSong
(){
Thread
t
=
new
Thread
(
new
Runnable
()
{
AudioManager
audioManager
=
(
AudioManager
)
getBaseContext
().
getSystemService
(
Context
.
AUDIO_SERVICE
);
@Override
KeyEvent
downEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_MEDIA_NEXT
);
public
void
run
()
{
audioManager
.
dispatchMediaKeyEvent
(
downEvent
);
try
{
KeyEvent
upEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_UP
,
KeyEvent
.
KEYCODE_MEDIA_NEXT
);
Instrumentation
inst
=
new
Instrumentation
();
audioManager
.
dispatchMediaKeyEvent
(
upEvent
);
inst
.
sendKeyDownUpSync
(
KeyEvent
.
KEYCODE_CAMERA
);
}
}
public
void
previousSong
(){
catch
(
Exception
e
){
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
);
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
){
}
public
void
endCall
(){
}
inputKeyEvent
(
KeyEvent
.
KEYCODE_ENDCALL
+
""
);
});
t
.
start
();
}
}
public
void
VolumeDown
(){
Thread
t
=
new
Thread
(
new
Runnable
()
{
public
static
void
inputKeyEvent
(
final
String
keyCodeString
)
{
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
int
keyCode
=
Integer
.
parseInt
(
keyCodeString
);
try
{
try
{
Instrumentation
inst
=
new
Instrumentation
(
);
Process
processKeyEvent
=
Runtime
.
getRuntime
().
exec
(
"/system/xbin/su"
);
inst
.
sendKeyDownUpSync
(
KeyEvent
.
KEYCODE_VOLUME_DOWN
);
DataOutputStream
os
=
new
DataOutputStream
(
processKeyEvent
.
getOutputStream
()
);
}
os
.
writeBytes
(
"input keyevent "
+
keyCode
+
"\n"
);
catch
(
Exception
e
)
{
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
});
});
t
.
start
();
thread
.
start
();
}
}
public
void
EndCall
(){
Thread
t
=
new
Thread
(
new
Runnable
()
{
public
static
void
inputLongPressKeyEvent
(
final
String
keyCodeString
)
{
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
int
keyCode
=
Integer
.
parseInt
(
keyCodeString
);
try
{
try
{
Instrumentation
inst
=
new
Instrumentation
(
);
Process
processKeyEvent
=
Runtime
.
getRuntime
().
exec
(
"/system/xbin/su"
);
inst
.
sendKeyDownUpSync
(
KeyEvent
.
KEYCODE_ENDCALL
);
DataOutputStream
os
=
new
DataOutputStream
(
processKeyEvent
.
getOutputStream
()
);
}
os
.
writeBytes
(
"input keyevent --longpress "
+
keyCode
+
"\n"
);
catch
(
Exception
e
)
{
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
});
});
t
.
start
();
thread
.
start
();
}
}
}
}
app/src/main/java/com/example/harshith/ddc/StaticGesture.java
View file @
bdd0ce76
...
@@ -49,17 +49,16 @@ public class StaticGesture extends Gesture {
...
@@ -49,17 +49,16 @@ public class StaticGesture extends Gesture {
Frame
[]
f
=
new
Frame
[
sensors
];
Frame
[]
f
=
new
Frame
[
sensors
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
f
[
i
]
=
new
Frame
(
hand
[
i
],
false
,
adcUpper
,
adcLower
,
2
);
f
[
i
]
=
new
Frame
(
hand
[
i
],
false
,
adcUpper
,
adcLower
,
adcLevels
);
}
}
for
(
int
i
=
4
;
i
<
sensors
;
i
++)
{
for
(
int
i
=
5
;
i
<
sensors
;
i
++)
{
f
[
i
]
=
new
Frame
(
hand
[
i
],
true
,
mpuUpper
,
mpuLower
,
3
);
f
[
i
]
=
new
Frame
(
hand
[
i
],
true
,
mpuUpper
,
mpuLower
,
mpuLevels
);
}
}
for
(
int
i
=
0
;
i
<
sensors
;
i
++)
{
for
(
int
i
=
0
;
i
<
sensors
;
i
++)
{
f
[
i
].
pushLimits
(
data
[
i
]);
f
[
i
].
pushLimits
(
data
[
i
]);
}
}
this
.
updateFrame
(
data
);
this
.
updateFrame
(
data
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment