Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BLEPrivacyPolicyNegotiator
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
idic
BLEPrivacyPolicyNegotiator
Commits
26e29607
Commit
26e29607
authored
Feb 24, 2017
by
idic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
感覺可以work 應該
parent
fb4c1d5a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
33 deletions
+85
-33
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
app/src/main/java/org/prlab/idic/privacypolicy/DeviceOperatorActivity.java
.../org/prlab/idic/privacypolicy/DeviceOperatorActivity.java
+63
-32
app/src/main/java/org/prlab/idic/privacypolicy/schedule/Schedulable.java
...va/org/prlab/idic/privacypolicy/schedule/Schedulable.java
+10
-0
app/src/main/res/drawable/ic_android_black_24dp.xml
app/src/main/res/drawable/ic_android_black_24dp.xml
+9
-0
app/src/main/res/layout/activity_device_operator.xml
app/src/main/res/layout/activity_device_operator.xml
+2
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
26e29607
...
...
@@ -44,6 +44,7 @@
android:exported=
"true"
/>
<activity
android:parentActivityName=
".MainActivity"
android:name=
".DeviceOperatorActivity"
/>
</application>
...
...
app/src/main/java/org/prlab/idic/privacypolicy/DeviceOperatorActivity.java
View file @
26e29607
...
...
@@ -14,6 +14,7 @@ import android.widget.*;
import
org.prlab.idic.privacypolicy.adapter.MessageRecyclerViewAdapter
;
import
org.prlab.idic.privacypolicy.ble.BLECustomScript
;
import
org.prlab.idic.privacypolicy.pojo.Message
;
import
org.prlab.idic.privacypolicy.schedule.Schedulable
;
import
org.prlab.idic.privacypolicy.storage.PrivacyPolicyStorageImpl
;
import
org.prlab.idic.privacypolicy.tool.BaseUtils
;
...
...
@@ -35,7 +36,7 @@ public class DeviceOperatorActivity extends AppCompatActivity {
private
TextView
mMessageBarTextView
;
private
EditText
mTemperatureEditText
;
private
Button
mTemperatureButton
;
private
Image
Button
mTemperatureButton
;
private
Switch
mAirPurifierSwitch
;
private
RecyclerView
.
Adapter
mMessageRecyclerViewAdapter
;
...
...
@@ -61,7 +62,7 @@ public class DeviceOperatorActivity extends AppCompatActivity {
private
void
initView
()
{
mMessageBarTextView
=
(
TextView
)
findViewById
(
R
.
id
.
text_operation_message_bar
);
mTemperatureEditText
=
(
EditText
)
findViewById
(
R
.
id
.
edit_operation_current_temperature
);
mTemperatureButton
=
(
Button
)
findViewById
(
R
.
id
.
button_operation_send_temperature
);
mTemperatureButton
=
(
Image
Button
)
findViewById
(
R
.
id
.
button_operation_send_temperature
);
mTemperatureButton
.
setOnClickListener
(
mTemperatureClickedListener
);
mAirPurifierSwitch
=
(
Switch
)
findViewById
(
R
.
id
.
switch_operation_air_purifier
);
...
...
@@ -113,6 +114,8 @@ public class DeviceOperatorActivity extends AppCompatActivity {
}
};
private
List
<
Schedulable
>
mPermissionSettingQueue
=
new
LinkedList
<>();
private
BLECustomScript
mBLECustomScript
=
new
BLECustomScript
()
{
int
expectedSuccessValue
=
0
;
...
...
@@ -176,8 +179,17 @@ public class DeviceOperatorActivity extends AppCompatActivity {
});
}
private
boolean
settingPermission
()
{
if
(
mPermissionSettingQueue
.
size
()
>
0
)
{
Log
.
i
(
TAG
,
"Continue to work."
);
mPermissionSettingQueue
.
remove
(
0
).
work
();
return
false
;
}
return
true
;
}
@Override
public
void
onDiscoverServiceCompleted
(
BluetoothGatt
gatt
)
{
public
void
onDiscoverServiceCompleted
(
final
BluetoothGatt
gatt
)
{
expectedSuccessValue
=
0
;
successValue
=
0
;
...
...
@@ -187,33 +199,44 @@ public class DeviceOperatorActivity extends AppCompatActivity {
layerUUIDs
.
add
(
String
.
valueOf
(
service
.
getUuid
()));
//Write service layer selection
int
selection
=
mPolicyStorage
.
get
(
layerUUIDs
);
if
(
selection
!=
-
1
)
{
BluetoothGattCharacteristic
characteristic
=
service
.
getCharacteristic
(
PRIVACY_POLICY_ACCEPT_UUID
);
if
(
characteristic
!=
null
)
{
characteristic
.
setValue
(
BaseUtils
.
int2Bytes
(
selection
));
Log
.
i
(
TAG
,
Arrays
.
toString
(
BaseUtils
.
int2Bytes
(
selection
)));
gatt
.
writeCharacteristic
(
characteristic
);
expectedSuccessValue
++;
addMessage
(
"Policy Setting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
" to "
+
selection
+
"."
);
}
if
(
selection
==
-
1
)
selection
=
0
;
final
BluetoothGattCharacteristic
characteristic
=
service
.
getCharacteristic
(
PRIVACY_POLICY_ACCEPT_UUID
);
if
(
characteristic
!=
null
)
{
final
int
finalSelection
=
selection
;
mPermissionSettingQueue
.
add
(
new
Schedulable
()
{
@Override
public
void
work
()
{
characteristic
.
setValue
(
BaseUtils
.
int2Bytes
(
finalSelection
));
Log
.
i
(
TAG
,
Arrays
.
toString
(
BaseUtils
.
int2Bytes
(
finalSelection
)));
gatt
.
writeCharacteristic
(
characteristic
);
expectedSuccessValue
++;
}
});
addMessage
(
"Policy Setting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
" to "
+
selection
+
"."
);
}
for
(
BluetoothGattCharacteristic
characteristic
:
service
.
getCharacteristics
())
{
layerUUIDs
.
add
(
String
.
valueOf
(
characteristic
.
getUuid
()));
for
(
BluetoothGattCharacteristic
characteristic
2
:
service
.
getCharacteristics
())
{
layerUUIDs
.
add
(
String
.
valueOf
(
characteristic
2
.
getUuid
()));
//Write characteristic layer selection
selection
=
mPolicyStorage
.
get
(
layerUUIDs
);
if
(
selection
!=
-
1
)
{
BluetoothGattDescriptor
descriptor
=
characteristic
.
getDescriptor
(
PRIVACY_POLICY_ACCEPT_UUID
);
if
(
descriptor
!=
null
)
{
descriptor
.
setValue
(
BaseUtils
.
int2Bytes
(
selection
));
Log
.
i
(
TAG
,
Arrays
.
toString
(
BaseUtils
.
int2Bytes
(
selection
)));
gatt
.
writeDescriptor
(
descriptor
);
expectedSuccessValue
++;
addMessage
(
"Policy Setting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
" to "
+
selection
+
"."
);
}
if
(
selection
==
-
1
)
selection
=
0
;
final
BluetoothGattDescriptor
descriptor
=
characteristic2
.
getDescriptor
(
PRIVACY_POLICY_ACCEPT_UUID
);
if
(
descriptor
!=
null
)
{
final
int
finalSelection1
=
selection
;
mPermissionSettingQueue
.
add
(
new
Schedulable
()
{
@Override
public
void
work
()
{
descriptor
.
setValue
(
BaseUtils
.
int2Bytes
(
finalSelection1
));
Log
.
i
(
TAG
,
Arrays
.
toString
(
BaseUtils
.
int2Bytes
(
finalSelection1
)));
gatt
.
writeDescriptor
(
descriptor
);
expectedSuccessValue
++;
}
});
addMessage
(
"Policy Setting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
" to "
+
selection
+
"."
);
}
layerUUIDs
.
remove
(
layerUUIDs
.
size
()
-
1
);
}
}
settingPermission
();
}
@Override
...
...
@@ -223,16 +246,14 @@ public class DeviceOperatorActivity extends AppCompatActivity {
List
<
String
>
layerUUIDs
=
new
LinkedList
<>();
layerUUIDs
.
add
(
characteristic
.
getService
().
getUuid
().
toString
());
addMessage
(
"Policy Setting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
(
status
==
GATT_SUCCESS
?
" success"
:
" failure"
)
+
" ."
);
requestServices
();
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
(
status
==
GATT_SUCCESS
?
" success"
:
" failure"
)
+
" ."
);
if
(
settingPermission
())
requestServices
();
}
else
if
(
TEMPERATURE_UUID
.
equals
(
characteristic
.
getUuid
()))
{
addMessage
(
"Temperature Setting"
,
"Set "
+
BaseUtils
.
bytesToInt
(
values
)
+
" to air conditioning."
);
addMessage
(
"Temperature Setting"
,
"Set "
+
BaseUtils
.
bytesToInt
(
values
)
+
" to the air conditioning."
);
requestTemperature
();
}
else
if
(
AIR_UUID
.
equals
(
characteristic
.
getUuid
()))
{
addMessage
(
"Air Purifier Setting"
,
"Turn "
+
(
BaseUtils
.
bytesToInt
(
values
)
==
1
?
" on"
:
" off"
)
+
"air purifier"
+
"."
);
addMessage
(
"Air Purifier Setting"
,
"Turn "
+
(
BaseUtils
.
bytesToInt
(
values
)
==
1
?
"on "
:
"off "
)
+
"the air purifier"
+
"."
);
requestAirPurifier
();
}
}
...
...
@@ -256,9 +277,10 @@ public class DeviceOperatorActivity extends AppCompatActivity {
List
<
String
>
layerUUIDs
=
new
LinkedList
<>();
layerUUIDs
.
add
(
descriptor
.
getCharacteristic
().
getService
().
getUuid
().
toString
());
layerUUIDs
.
add
(
descriptor
.
getCharacteristic
().
getUuid
().
toString
());
addMessage
(
"Policy
s
etting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
addMessage
(
"Policy
S
etting"
,
"Set "
+
BaseUtils
.
stringList2ArrayString
(
layerUUIDs
)
+
(
status
==
GATT_SUCCESS
?
" success"
:
" failure"
)
+
" ."
);
requestServices
();
if
(
settingPermission
())
requestServices
();
}
}
...
...
@@ -456,4 +478,13 @@ public class DeviceOperatorActivity extends AppCompatActivity {
});
}
@Override
public
void
onBackPressed
()
{
super
.
onBackPressed
();
if
(
mBluetoothGatt
!=
null
)
{
mBluetoothGatt
.
disconnect
();
mBluetoothGatt
.
close
();
}
}
}
app/src/main/java/org/prlab/idic/privacypolicy/schedule/Schedulable.java
0 → 100644
View file @
26e29607
package
org.prlab.idic.privacypolicy.schedule
;
/**
* Created by IDIC on 2017/2/24.
*/
public
interface
Schedulable
{
void
work
();
}
app/src/main/res/drawable/ic_android_black_24dp.xml
0 → 100644
View file @
26e29607
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"24dp"
android:height=
"24dp"
android:viewportWidth=
"24.0"
android:viewportHeight=
"24.0"
>
<path
android:fillColor=
"#FF000000"
android:pathData=
"M6,18c0,0.55 0.45,1 1,1h1v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L11,19h2v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L16,19h1c0.55,0 1,-0.45 1,-1L18,8L6,8v10zM3.5,8C2.67,8 2,8.67 2,9.5v7c0,0.83 0.67,1.5 1.5,1.5S5,17.33 5,16.5v-7C5,8.67 4.33,8 3.5,8zM20.5,8c-0.83,0 -1.5,0.67 -1.5,1.5v7c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5v-7c0,-0.83 -0.67,-1.5 -1.5,-1.5zM15.53,2.16l1.3,-1.3c0.2,-0.2 0.2,-0.51 0,-0.71 -0.2,-0.2 -0.51,-0.2 -0.71,0l-1.48,1.48C13.85,1.23 12.95,1 12,1c-0.96,0 -1.86,0.23 -2.66,0.63L7.85,0.15c-0.2,-0.2 -0.51,-0.2 -0.71,0 -0.2,0.2 -0.2,0.51 0,0.71l1.31,1.31C6.97,3.26 6,5.01 6,7h12c0,-1.99 -0.97,-3.75 -2.47,-4.84zM10,5L9,5L9,4h1v1zM15,5h-1L14,4h1v1z"
/>
</vector>
app/src/main/res/layout/activity_device_operator.xml
View file @
26e29607
...
...
@@ -28,7 +28,8 @@
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/item_size"
>
<Button
<ImageButton
android:src=
"@drawable/ic_android_black_24dp"
android:id=
"@+id/button_operation_send_temperature"
android:layout_alignParentEnd=
"true"
android:layout_width=
"@dimen/item_size"
...
...
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