Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4713e0d965 | ||
|
|
f6876b5b1d | ||
|
|
146d36f246 | ||
|
|
2cb4a2f1d3 | ||
|
|
988b1c75a8 | ||
|
|
7a9e03ed4d | ||
|
|
4b1fd007d3 | ||
|
|
887e6de3e4 | ||
|
|
5417b4e739 | ||
|
|
7e72dfd19a | ||
|
|
23223480e5 | ||
|
|
e3e2a87b5e | ||
|
|
4cea4391eb | ||
|
|
63150ed8f6 | ||
|
|
d986fcdf4d | ||
|
|
ea57dd01e5 | ||
|
|
6f1f112d98 | ||
|
|
549c4f109e | ||
|
|
d63841dd27 | ||
|
|
4913f9236b | ||
|
|
8f6e376231 | ||
|
|
9ff121e82a | ||
|
|
ccf87dbef0 | ||
|
|
b510811b18 | ||
|
|
c1619e67ec | ||
|
|
1c22a3386b | ||
|
|
b83b6568ca | ||
|
|
4a90b36f6a | ||
|
|
fd90b14bdc | ||
|
|
91fdef99c3 | ||
|
|
63264fcf9b | ||
|
|
2758ef180d | ||
|
|
3d2b48706d | ||
|
|
e52ce4cd30 | ||
|
|
bbb477fc77 | ||
|
|
4478006109 | ||
|
|
d117484143 | ||
|
|
f7d8389668 | ||
|
|
4282c53372 | ||
|
|
35e2a1158d | ||
|
|
66e86e66b3 | ||
|
|
4c4a355ff5 | ||
|
|
07011b2053 | ||
|
|
fdcdaf53c9 | ||
|
|
55a1c24753 | ||
|
|
ca88fbfb07 | ||
|
|
3497d7b8ea | ||
|
|
e8e763210b | ||
|
|
b6ea652e46 | ||
|
|
a30a47f67a | ||
|
|
914f5c033b | ||
|
|
f64b8ea860 | ||
|
|
2445431393 | ||
|
|
a6e10d09c3 | ||
|
|
7972a335c3 | ||
|
|
e99203c7e4 | ||
|
|
ee311b0ba5 | ||
|
|
fb64c46c95 | ||
|
|
c7557519e8 | ||
|
|
01c1ac3f5e | ||
|
|
b473034703 | ||
|
|
bf78ecc794 | ||
|
|
6d9a77a990 | ||
|
|
ec68d375c7 | ||
|
|
e8524f719f | ||
|
|
f04c517c80 | ||
|
|
b6d7958389 | ||
|
|
04d2e4b432 | ||
|
|
abd346946a | ||
|
|
17edf90086 | ||
|
|
879e1c6ef3 | ||
|
|
d7d806fb5c | ||
|
|
910af92989 | ||
|
|
9f36411511 | ||
|
|
eb893a7f21 | ||
|
|
8788a89e48 | ||
|
|
bb10620883 | ||
|
|
3e29054f82 | ||
|
|
9d5f0a3cef | ||
|
|
695b1f2481 | ||
|
|
d7357b0b0f | ||
|
|
e272338cc6 | ||
|
|
3dd84220a3 | ||
|
|
4bc2781ee7 | ||
|
|
62bfbbb064 | ||
|
|
31d167a93f | ||
|
|
500610fb98 | ||
|
|
5ca7295c30 | ||
|
|
e2027a457a | ||
|
|
6c31b67b14 | ||
|
|
04fe674cf6 | ||
|
|
17b3b8fafc | ||
|
|
0d38c8bbe0 | ||
|
|
f7ff8a38e1 | ||
|
|
b7677bdcce | ||
|
|
1ff4a15818 | ||
|
|
bd42507521 | ||
|
|
fe924f6fe9 | ||
|
|
dfe8594f06 | ||
|
|
553d14b05f | ||
|
|
b38ca31df5 | ||
|
|
6e566c664d | ||
|
|
8c4b75232e | ||
|
|
4521bc7d4e | ||
|
|
eaecf63724 | ||
|
|
ec62b91449 | ||
|
|
223cca442d | ||
|
|
f3613f8eb0 | ||
|
|
8b193aa89c | ||
|
|
58ec35aae5 | ||
|
|
c61c5ba14c | ||
|
|
d75cf137ba | ||
|
|
5e3d268815 | ||
|
|
3bcf90277f | ||
|
|
81a205a8db | ||
|
|
97a3344e81 | ||
|
|
cd47b33449 | ||
|
|
2ba25a9e65 | ||
|
|
d2606b72cd | ||
|
|
584495ef61 | ||
|
|
9b28aeef8b | ||
|
|
b6bf31589a | ||
|
|
67238bd2f0 | ||
|
|
5f278a6ba0 | ||
|
|
a21f90acb5 | ||
|
|
5f8ed5765a | ||
|
|
605f85d215 | ||
|
|
21f4a7fd5c | ||
|
|
2219164869 | ||
|
|
a8646ef61d | ||
|
|
f641de9893 | ||
|
|
bca8b44ad6 | ||
|
|
c34dfa4af4 | ||
|
|
38644cee28 | ||
|
|
47898e84ea | ||
|
|
ac74b52aed | ||
|
|
3f76813e80 | ||
|
|
1b8dc5de5f | ||
|
|
3c8c0f14f2 | ||
|
|
6e73c74b60 | ||
|
|
9ead47bdf7 | ||
|
|
e4828a9720 | ||
|
|
4f971e8a1b | ||
|
|
34fbc1d005 | ||
|
|
b72049defc | ||
|
|
54f3cc84c4 | ||
|
|
7884358564 | ||
|
|
f24c9f99dc | ||
|
|
64b97c650d | ||
|
|
9daf4c4747 | ||
|
|
94f7936c4a | ||
|
|
02f7b642cf | ||
|
|
8d10bf05af | ||
|
|
8c0cee9589 | ||
|
|
6b23bd6733 | ||
|
|
1a60c88f35 | ||
|
|
3312d99177 | ||
|
|
ea01806915 | ||
|
|
36173f2fcb | ||
|
|
4c66fe906e | ||
|
|
60cfa150b5 | ||
|
|
bd2231b075 | ||
|
|
158f5f2e04 | ||
|
|
f1315dc742 | ||
|
|
28aa0c3e4b | ||
|
|
6b9dbca7ab | ||
|
|
291e0c41af | ||
|
|
c9eedd5d87 | ||
|
|
2470321e15 | ||
|
|
d85a199117 | ||
|
|
b047cde4ea | ||
|
|
9a1796f2eb | ||
|
|
7e8a6b121e | ||
|
|
810c7488c4 | ||
|
|
8af24695fd | ||
|
|
533a9bf54d | ||
|
|
8653e4853b | ||
|
|
c464a9d71f | ||
|
|
26e4851c0d | ||
|
|
11f0ee25bf | ||
|
|
a76cafc6e2 | ||
|
|
bd2920e6d9 | ||
|
|
5caf33b45d | ||
|
|
6a74d070eb | ||
|
|
eba02ade08 | ||
|
|
394effea36 | ||
|
|
4d51f1890a | ||
|
|
a8b2c3bf7d | ||
|
|
d1c6abaa91 | ||
|
|
587ed5803e | ||
|
|
49d272be1e | ||
|
|
d9e54c7780 | ||
|
|
170dbbc7e8 | ||
|
|
3fc1dd1a26 | ||
|
|
0acb52099c | ||
|
|
b6015a3f2e | ||
|
|
ae1e767fa6 | ||
|
|
6e12e71133 | ||
|
|
e4e3faea06 | ||
|
|
7c42250e13 | ||
|
|
ebb0724b28 | ||
|
|
a7ae0c6588 | ||
|
|
e5433bf2ec | ||
|
|
fd8ffd4f7d | ||
|
|
f49455712a | ||
|
|
132f64114e | ||
|
|
27e9b3e0d1 | ||
|
|
a6c6dfc6ba | ||
|
|
6a7875cc61 | ||
|
|
6f80caa1c6 | ||
|
|
a9646cbf28 | ||
|
|
52edfa32df | ||
|
|
ca81e6a7bd | ||
|
|
49e4c20ab6 | ||
|
|
ab98b4d1db | ||
|
|
6b32301894 | ||
|
|
d9cdfab828 | ||
|
|
62a8723344 | ||
|
|
2b69938ad5 | ||
|
|
c42f65bd3a | ||
|
|
ad0d9962b5 | ||
|
|
58f24953f3 | ||
|
|
3d212456e6 | ||
|
|
fff0a28310 | ||
|
|
48da91cb40 | ||
|
|
98df050f42 | ||
|
|
93cb72ac2f | ||
|
|
713228c06e | ||
|
|
c868d45896 | ||
|
|
4abce042eb | ||
|
|
62034e1b10 | ||
|
|
135f4594be | ||
|
|
900aaf3c8c | ||
|
|
5baa40ed59 | ||
|
|
759e8076c3 | ||
|
|
17b9f19dc2 | ||
|
|
374a5c4263 | ||
|
|
2fd79140cb | ||
|
|
a0910e620f | ||
|
|
475c1719d7 | ||
|
|
baa39c7a77 | ||
|
|
e11cc09da2 |
@@ -3,16 +3,16 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 36
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.jens.automation2"
|
applicationId "com.jens.automation2"
|
||||||
minSdkVersion 16
|
minSdkVersion 19
|
||||||
compileSdkVersion 31
|
compileSdkVersion 36
|
||||||
buildToolsVersion '29.0.2'
|
buildToolsVersion '36.0.0'
|
||||||
useLibrary 'org.apache.http.legacy'
|
useLibrary 'org.apache.http.legacy'
|
||||||
versionCode 121
|
versionCode 149
|
||||||
versionName "1.7.6"
|
versionName "1.8.8"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -36,9 +36,15 @@ android {
|
|||||||
{
|
{
|
||||||
dimension "version"
|
dimension "version"
|
||||||
versionNameSuffix "-googlePlay"
|
versionNameSuffix "-googlePlay"
|
||||||
targetSdkVersion 30
|
targetSdkVersion 36
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
targetSdkVersion is kept at 28 for as long as possible.
|
||||||
|
If raised wifi cannot be switched on or off anymore without root permissions.
|
||||||
|
In the Google version I'm forced to raise the value regularly.
|
||||||
|
*/
|
||||||
|
|
||||||
fdroidFlavor
|
fdroidFlavor
|
||||||
{
|
{
|
||||||
dimension "version"
|
dimension "version"
|
||||||
@@ -57,24 +63,25 @@ android {
|
|||||||
checkReleaseBuilds false
|
checkReleaseBuilds false
|
||||||
}
|
}
|
||||||
namespace 'com.jens.automation2'
|
namespace 'com.jens.automation2'
|
||||||
|
buildToolsVersion '36.0.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.jetbrains:annotations:15.0'
|
implementation 'org.jetbrains:annotations:26.1.0'
|
||||||
googlePlayFlavorImplementation 'com.google.firebase:firebase-appindexing:20.0.0'
|
googlePlayFlavorImplementation 'com.google.firebase:firebase-appindexing:20.0.0'
|
||||||
googlePlayFlavorImplementation 'com.google.android.gms:play-services-location:18.0.0'
|
googlePlayFlavorImplementation 'com.google.android.gms:play-services-location:20.0.0'
|
||||||
|
|
||||||
apkFlavorImplementation 'com.google.firebase:firebase-appindexing:20.0.0'
|
apkFlavorImplementation 'com.google.firebase:firebase-appindexing:20.0.0'
|
||||||
apkFlavorImplementation 'com.google.android.gms:play-services-location:18.0.0'
|
apkFlavorImplementation 'com.google.android.gms:play-services-location:20.0.0'
|
||||||
|
|
||||||
implementation 'com.linkedin.dexmaker:dexmaker:2.25.0'
|
implementation 'com.linkedin.dexmaker:dexmaker:2.28.6'
|
||||||
implementation 'org.apache.commons:commons-lang3:3.0'
|
implementation 'org.apache.commons:commons-lang3:3.20.0'
|
||||||
|
|
||||||
//implementation "androidx.security:security-crypto:1.0.0"
|
//implementation "androidx.security:security-crypto:1.0.0"
|
||||||
//implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
|
//implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
implementation 'androidx.appcompat:appcompat:1.4.2'
|
||||||
implementation 'com.google.android.material:material:1.6.1'
|
implementation 'com.google.android.material:material:1.6.1'
|
||||||
testImplementation 'junit:junit:4'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:anyDensity="true"
|
android:anyDensity="true"
|
||||||
@@ -50,7 +52,6 @@
|
|||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||||
<!-- <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />-->
|
|
||||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.NFC" />
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
@@ -66,6 +67,21 @@
|
|||||||
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||||
|
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||||
|
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
|
<uses-permission android:name="android.hardware.sensor.proximity"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_CALL_LOG" />
|
||||||
|
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" tools:ignore="ProtectedPermissions" />
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
<!--android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />-->
|
||||||
|
<uses-permission android:name="com.termux.permission.RUN_COMMAND" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
|
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
|
||||||
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.telephony"
|
android:name="android.hardware.telephony"
|
||||||
@@ -83,7 +99,7 @@
|
|||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:allowClearUserData="true"
|
android:allowClearUserData="true"
|
||||||
android:icon="@drawable/gears"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:networkSecurityConfig="@xml/network_security_config">
|
android:networkSecurityConfig="@xml/network_security_config">
|
||||||
@@ -98,20 +114,11 @@
|
|||||||
android:name="google_analytics_ssaid_collection_enabled"
|
android:name="google_analytics_ssaid_collection_enabled"
|
||||||
android:value="false" />
|
android:value="false" />
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".ActivityMainScreen"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
<activity
|
|
||||||
android:name=".ActivityManagePoi"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
<activity
|
|
||||||
android:name=".ActivitySettings"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".AutomationService"
|
android:name=".AutomationService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/app_name" />
|
android:label="@string/app_name"
|
||||||
|
android:foregroundServiceType="specialUse" />
|
||||||
|
|
||||||
<receiver android:name=".receivers.StartupIntentReceiver" android:enabled="true" android:exported="true">
|
<receiver android:name=".receivers.StartupIntentReceiver" android:enabled="true" android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -126,6 +133,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:name=".receivers.PackageReplacedReceiver"
|
<receiver android:name=".receivers.PackageReplacedReceiver"
|
||||||
|
android:exported="true"
|
||||||
android:enabled="true">
|
android:enabled="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
@@ -134,9 +142,11 @@
|
|||||||
<receiver android:name=".receivers.DateTimeListener" />
|
<receiver android:name=".receivers.DateTimeListener" />
|
||||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||||
<receiver android:name=".receivers.TimeZoneListener" />
|
<receiver android:name=".receivers.TimeZoneListener" />
|
||||||
|
<receiver android:name=".receivers.CalendarReceiver" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".DeviceAdmin"
|
android:name=".DeviceAdmin"
|
||||||
|
android:exported="true"
|
||||||
android:description="@string/app_name"
|
android:description="@string/app_name"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||||
@@ -148,6 +158,9 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<activity android:name=".ActivityMainScreen" android:label="@string/app_name" />
|
||||||
|
<activity android:name=".ActivityManagePoi" android:label="@string/app_name" />
|
||||||
|
<activity android:name=".ActivitySettings" android:label="@string/app_name" />
|
||||||
<activity android:name=".ActivityManageRule" />
|
<activity android:name=".ActivityManageRule" />
|
||||||
<activity android:name=".ActivityManageActionTriggerUrl" />
|
<activity android:name=".ActivityManageActionTriggerUrl" />
|
||||||
<activity android:name=".ActivityDisplayLongMessage" />
|
<activity android:name=".ActivityDisplayLongMessage" />
|
||||||
@@ -171,8 +184,16 @@
|
|||||||
<activity android:name=".ActivityManageTriggerTethering" />
|
<activity android:name=".ActivityManageTriggerTethering" />
|
||||||
<activity android:name=".ActivityManageActionWakeLock" />
|
<activity android:name=".ActivityManageActionWakeLock" />
|
||||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||||
|
<activity android:name=".ActivityManageActionMakePhoneCall" />
|
||||||
|
<activity android:name=".ActivityManageActionSetVariable" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCheckVariable" />
|
||||||
|
<activity android:name=".ActivityManageActionCopyToClipboard" />
|
||||||
|
<activity android:name=".ActivityManageActionLocationService" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCharging" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ActivityMainTabLayout"
|
android:name=".ActivityMainTabLayout"
|
||||||
|
android:exported="true"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -197,7 +218,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.nfc.action.TECH_DISCOVERED"
|
android:name="android.nfc.action.TECH_DISCOVERED"
|
||||||
@@ -210,17 +230,20 @@
|
|||||||
<activity android:name=".ActivityManageActionStartActivity" />
|
<activity android:name=".ActivityManageActionStartActivity" />
|
||||||
<activity android:name=".ActivityManageTriggerNfc" />
|
<activity android:name=".ActivityManageTriggerNfc" />
|
||||||
<activity android:name=".ActivityManageActionSpeakText" />
|
<activity android:name=".ActivityManageActionSpeakText" />
|
||||||
<activity android:name=".ActivityManageActionPlaySound" />
|
|
||||||
<activity android:name=".ActivityManageTriggerBluetooth" />
|
<activity android:name=".ActivityManageTriggerBluetooth" />
|
||||||
<activity android:name=".ActivityMainProfiles" />
|
<activity android:name=".ActivityMainProfiles" />
|
||||||
<activity android:name=".ActivityManageProfile" />
|
<activity android:name=".ActivityManageProfile" />
|
||||||
<activity android:name=".ActivityManageTriggerWifi" />
|
<activity android:name=".ActivityManageTriggerWifi" />
|
||||||
<activity android:name=".ActivityVolumeTest" />
|
<activity android:name=".ActivityVolumeTest" />
|
||||||
<activity android:name=".ActivityPermissions"></activity>
|
<activity android:name=".ActivityPermissions" />
|
||||||
<activity android:name=".ActivityManageTriggerNotification" />
|
<activity android:name=".ActivityManageTriggerNotification" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||||
|
<activity android:name=".ActivityManageTriggerProximity" />
|
||||||
|
<activity android:name=".ActivityManageActionSetSystemSetting" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".receivers.NotificationListener"
|
android:name=".receivers.NotificationListener"
|
||||||
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -229,7 +252,6 @@
|
|||||||
|
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<activity android:name=".ActivityPermissions" />
|
|
||||||
|
|
||||||
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
||||||
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
||||||
@@ -252,6 +274,17 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<service android:name=".MyAccessibilityService"
|
||||||
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.accessibilityservice"
|
||||||
|
android:resource="@xml/config_accessibility_service" />
|
||||||
|
</service>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -18,7 +18,7 @@ public class MyGoogleApiClient
|
|||||||
public com.google.android.gms.appindexing.Action getIndexApiAction()
|
public com.google.android.gms.appindexing.Action getIndexApiAction()
|
||||||
{
|
{
|
||||||
Thing object = new Thing.Builder()
|
Thing object = new Thing.Builder()
|
||||||
.setName("ActivityMainScreen Page") // TODO: Define a title for the content shown.
|
.setName("ActivityMainScreen Page")
|
||||||
// TODO: Make sure this auto-generated URL is correct.
|
// TODO: Make sure this auto-generated URL is correct.
|
||||||
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
|
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ import android.os.Looper;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.android.gms.location.DetectedActivity;
|
import com.google.android.gms.location.DetectedActivity;
|
||||||
import com.jens.automation2.receivers.ActivityDetectionReceiver;
|
import com.jens.automation2.receivers.ActivityDetectionReceiver;
|
||||||
import com.jens.automation2.receivers.BroadcastListener;
|
import com.jens.automation2.receivers.BroadcastListener;
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -107,7 +110,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
}
|
}
|
||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readFromFile()
|
public static void readFromFile()
|
||||||
@@ -347,7 +350,16 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
||||||
{
|
{
|
||||||
if(oneTrigger.getTimeFrame().repetition > 0)
|
if(oneTrigger.getTimeFrame().repetition > 0)
|
||||||
return true;
|
{
|
||||||
|
if(this.getLastExecution() != null)
|
||||||
|
{
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
if (this.getLastExecution().getTimeInMillis() + oneTrigger.getTimeFrame().getRepetition() * 1000 <= now.getTimeInMillis())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||||
{
|
{
|
||||||
@@ -364,23 +376,28 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
if(hasNotAppliedSinceLastExecution())
|
if(hasNotAppliedSinceLastExecution())
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" has not flipped since its last execution.", 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" does not apply.", 4);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean applies(Context context)
|
public boolean applies(Context context)
|
||||||
{
|
{
|
||||||
if(AutomationService.getInstance() == null)
|
if(AutomationService.getInstance() == null)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule \"" + getName() + "\" cannot apply.", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +409,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule %1$s generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule \"%1$s\" generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,7 +484,9 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
AutomationService service = AutomationService.getInstance();
|
AutomationService service = AutomationService.getInstance();
|
||||||
service.speak(messages[0], false);
|
service.speak(messages[0], false);
|
||||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
|
||||||
|
if(Settings.showToasts)
|
||||||
|
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
super.onProgressUpdate(messages);
|
super.onProgressUpdate(messages);
|
||||||
}
|
}
|
||||||
@@ -495,8 +514,6 @@ public class Rule implements Comparable<Rule>
|
|||||||
protected boolean activateInternally(AutomationService automationService)
|
protected boolean activateInternally(AutomationService automationService)
|
||||||
{
|
{
|
||||||
boolean isActuallyToggleable = isActuallyToggable();
|
boolean isActuallyToggleable = isActuallyToggable();
|
||||||
|
|
||||||
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
|
||||||
boolean doToggle = ruleToggle && isActuallyToggleable;
|
boolean doToggle = ruleToggle && isActuallyToggleable;
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
@@ -510,11 +527,35 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(Settings.startNewThreadForRuleActivation)
|
if(Settings.startNewThreadForRuleActivation)
|
||||||
publishProgress(message);
|
publishProgress(message);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Make a note of Rule/CalendarEvent executed combinations
|
||||||
|
*/
|
||||||
|
if(Rule.this.hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent))
|
||||||
|
{
|
||||||
|
for(CalendarReceiver.CalendarEvent event : CalendarReceiver.getApplyingCalendarEvents(Rule.this))
|
||||||
|
{
|
||||||
|
if(!CalendarReceiver.hasEventBeenUsedInRule(Rule.this, event))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Record only the first calendar event that matched because the rule may
|
||||||
|
be executed once for every matching event.
|
||||||
|
*/
|
||||||
|
Miscellaneous.logEvent("i", "Rule", "Executing this rule run for calender event: " + event, 5);
|
||||||
|
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(Rule.this, event));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Run actions one after another
|
||||||
|
*/
|
||||||
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Rule.this.getActionSet().get(i).run(automationService, doToggle);
|
Miscellaneous.logEvent("i", "RuleExecution", "Running action " + Rule.this.getActionSet().get(i).toStringShort() + " of rule " + Rule.this.getName(), 5);
|
||||||
|
Rule.this.getActionSet().get(i).run(automationService, doToggle);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -551,10 +592,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
public void activate(AutomationService automationService, boolean force)
|
public void activate(AutomationService automationService, boolean force)
|
||||||
{
|
{
|
||||||
ActivateRuleTask task = new ActivateRuleTask();
|
ActivateRuleTask task = new ActivateRuleTask();
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
|
||||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
|
|
||||||
else
|
|
||||||
task.execute(automationService, force);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Rule> findRuleCandidates(Trigger.Trigger_Enum triggerType)
|
public static ArrayList<Rule> findRuleCandidates(Trigger.Trigger_Enum triggerType)
|
||||||
@@ -769,4 +807,71 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj)
|
||||||
|
{
|
||||||
|
return this.getName().equals(((Rule)obj).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTriggerOfType(Trigger.Trigger_Enum queryType)
|
||||||
|
{
|
||||||
|
for(Trigger t : getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(queryType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasActionOfType(Action.Action_Enum queryType)
|
||||||
|
{
|
||||||
|
for(Action a : getActionSet())
|
||||||
|
{
|
||||||
|
if(a.getAction().equals(queryType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountOfTriggersForType(Trigger.Trigger_Enum type)
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Trigger t : getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(type))
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountOfActionsForType(Action.Action_Enum type)
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Action a : getActionSet())
|
||||||
|
{
|
||||||
|
if(a.getAction().equals(type))
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getAmountOfActivatedRules()
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Rule r : Rule.getRuleCollection())
|
||||||
|
{
|
||||||
|
if(r.isRuleActive())
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:anyDensity="true"
|
android:anyDensity="true"
|
||||||
@@ -50,7 +52,6 @@
|
|||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||||
<!-- <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />-->
|
|
||||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.NFC" />
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
@@ -64,6 +65,21 @@
|
|||||||
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||||
|
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||||
|
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
|
<uses-permission android:name="android.hardware.sensor.proximity"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_CALL_LOG" />
|
||||||
|
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" tools:ignore="ProtectedPermissions" />
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
<!--android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />-->
|
||||||
|
<uses-permission android:name="com.termux.permission.RUN_COMMAND" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
|
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
|
||||||
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.telephony"
|
android:name="android.hardware.telephony"
|
||||||
@@ -81,7 +97,7 @@
|
|||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:allowClearUserData="true"
|
android:allowClearUserData="true"
|
||||||
android:icon="@drawable/gears"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:networkSecurityConfig="@xml/network_security_config">
|
android:networkSecurityConfig="@xml/network_security_config">
|
||||||
@@ -96,20 +112,11 @@
|
|||||||
android:name="google_analytics_ssaid_collection_enabled"
|
android:name="google_analytics_ssaid_collection_enabled"
|
||||||
android:value="false" />
|
android:value="false" />
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".ActivityMainScreen"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
<activity
|
|
||||||
android:name=".ActivityManagePoi"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
<activity
|
|
||||||
android:name=".ActivitySettings"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".AutomationService"
|
android:name=".AutomationService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/app_name" />
|
android:label="@string/app_name"
|
||||||
|
android:foregroundServiceType="specialUse" />
|
||||||
|
|
||||||
<receiver android:name=".receivers.StartupIntentReceiver" android:enabled="true" android:exported="true">
|
<receiver android:name=".receivers.StartupIntentReceiver" android:enabled="true" android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -124,6 +131,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:name=".receivers.PackageReplacedReceiver"
|
<receiver android:name=".receivers.PackageReplacedReceiver"
|
||||||
|
android:exported="true"
|
||||||
android:enabled="true">
|
android:enabled="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
@@ -132,9 +140,11 @@
|
|||||||
<receiver android:name=".receivers.DateTimeListener" />
|
<receiver android:name=".receivers.DateTimeListener" />
|
||||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||||
<receiver android:name=".receivers.TimeZoneListener" />
|
<receiver android:name=".receivers.TimeZoneListener" />
|
||||||
|
<receiver android:name=".receivers.CalendarReceiver" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".DeviceAdmin"
|
android:name=".DeviceAdmin"
|
||||||
|
android:exported="true"
|
||||||
android:description="@string/app_name"
|
android:description="@string/app_name"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||||
@@ -146,6 +156,9 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<activity android:name=".ActivityMainScreen" android:label="@string/app_name" />
|
||||||
|
<activity android:name=".ActivityManagePoi" android:label="@string/app_name" />
|
||||||
|
<activity android:name=".ActivitySettings" android:label="@string/app_name" />
|
||||||
<activity android:name=".ActivityManageRule" />
|
<activity android:name=".ActivityManageRule" />
|
||||||
<activity android:name=".ActivityManageActionTriggerUrl" />
|
<activity android:name=".ActivityManageActionTriggerUrl" />
|
||||||
<activity android:name=".ActivityDisplayLongMessage" />
|
<activity android:name=".ActivityDisplayLongMessage" />
|
||||||
@@ -169,8 +182,16 @@
|
|||||||
<activity android:name=".ActivityManageTriggerTethering" />
|
<activity android:name=".ActivityManageTriggerTethering" />
|
||||||
<activity android:name=".ActivityManageActionWakeLock" />
|
<activity android:name=".ActivityManageActionWakeLock" />
|
||||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||||
|
<activity android:name=".ActivityManageActionMakePhoneCall" />
|
||||||
|
<activity android:name=".ActivityManageActionSetVariable" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCheckVariable" />
|
||||||
|
<activity android:name=".ActivityManageActionCopyToClipboard" />
|
||||||
|
<activity android:name=".ActivityManageActionLocationService" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCharging" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ActivityMainTabLayout"
|
android:name=".ActivityMainTabLayout"
|
||||||
|
android:exported="true"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -195,7 +216,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.nfc.action.TECH_DISCOVERED"
|
android:name="android.nfc.action.TECH_DISCOVERED"
|
||||||
@@ -208,17 +228,20 @@
|
|||||||
<activity android:name=".ActivityManageActionStartActivity" />
|
<activity android:name=".ActivityManageActionStartActivity" />
|
||||||
<activity android:name=".ActivityManageTriggerNfc" />
|
<activity android:name=".ActivityManageTriggerNfc" />
|
||||||
<activity android:name=".ActivityManageActionSpeakText" />
|
<activity android:name=".ActivityManageActionSpeakText" />
|
||||||
<activity android:name=".ActivityManageActionPlaySound" />
|
|
||||||
<activity android:name=".ActivityManageTriggerBluetooth" />
|
<activity android:name=".ActivityManageTriggerBluetooth" />
|
||||||
<activity android:name=".ActivityMainProfiles" />
|
<activity android:name=".ActivityMainProfiles" />
|
||||||
<activity android:name=".ActivityManageProfile" />
|
<activity android:name=".ActivityManageProfile" />
|
||||||
<activity android:name=".ActivityManageTriggerWifi" />
|
<activity android:name=".ActivityManageTriggerWifi" />
|
||||||
<activity android:name=".ActivityVolumeTest" />
|
<activity android:name=".ActivityVolumeTest" />
|
||||||
<activity android:name=".ActivityPermissions"></activity>
|
<activity android:name=".ActivityPermissions" />
|
||||||
<activity android:name=".ActivityManageTriggerNotification" />
|
<activity android:name=".ActivityManageTriggerNotification" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||||
|
<activity android:name=".ActivityManageTriggerProximity" />
|
||||||
|
<activity android:name=".ActivityManageActionSetSystemSetting" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".receivers.NotificationListener"
|
android:name=".receivers.NotificationListener"
|
||||||
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -227,7 +250,6 @@
|
|||||||
|
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<activity android:name=".ActivityPermissions" />
|
|
||||||
|
|
||||||
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
||||||
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
||||||
@@ -238,6 +260,17 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<service android:name=".MyAccessibilityService"
|
||||||
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.accessibilityservice"
|
||||||
|
android:resource="@xml/config_accessibility_service" />
|
||||||
|
</service>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -10,7 +10,10 @@ import android.os.Looper;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import com.jens.automation2.receivers.BroadcastListener;
|
import com.jens.automation2.receivers.BroadcastListener;
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -104,7 +107,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
}
|
}
|
||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readFromFile()
|
public static void readFromFile()
|
||||||
@@ -344,7 +347,16 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
||||||
{
|
{
|
||||||
if(oneTrigger.getTimeFrame().repetition > 0)
|
if(oneTrigger.getTimeFrame().repetition > 0)
|
||||||
return true;
|
{
|
||||||
|
if(this.getLastExecution() != null)
|
||||||
|
{
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
if (this.getLastExecution().getTimeInMillis() + oneTrigger.getTimeFrame().getRepetition() * 1000 <= now.getTimeInMillis())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||||
{
|
{
|
||||||
@@ -361,23 +373,28 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
if(hasNotAppliedSinceLastExecution())
|
if(hasNotAppliedSinceLastExecution())
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" has not flipped since its last execution.", 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" does not apply.", 4);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean applies(Context context)
|
public boolean applies(Context context)
|
||||||
{
|
{
|
||||||
if(AutomationService.getInstance() == null)
|
if(AutomationService.getInstance() == null)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule \"" + getName() + "\" cannot apply.", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +406,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule %1$s generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule \"%1$s\" generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +457,9 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
AutomationService service = AutomationService.getInstance();
|
AutomationService service = AutomationService.getInstance();
|
||||||
service.speak(messages[0], false);
|
service.speak(messages[0], false);
|
||||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
|
||||||
|
if(Settings.showToasts)
|
||||||
|
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
super.onProgressUpdate(messages);
|
super.onProgressUpdate(messages);
|
||||||
}
|
}
|
||||||
@@ -468,8 +487,6 @@ public class Rule implements Comparable<Rule>
|
|||||||
protected boolean activateInternally(AutomationService automationService)
|
protected boolean activateInternally(AutomationService automationService)
|
||||||
{
|
{
|
||||||
boolean isActuallyToggleable = isActuallyToggable();
|
boolean isActuallyToggleable = isActuallyToggable();
|
||||||
|
|
||||||
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
|
||||||
boolean doToggle = ruleToggle && isActuallyToggleable;
|
boolean doToggle = ruleToggle && isActuallyToggleable;
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
@@ -483,10 +500,34 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(Settings.startNewThreadForRuleActivation)
|
if(Settings.startNewThreadForRuleActivation)
|
||||||
publishProgress(message);
|
publishProgress(message);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Make a note of Rule/CalendarEvent executed combinations
|
||||||
|
*/
|
||||||
|
if(Rule.this.hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent))
|
||||||
|
{
|
||||||
|
for(CalendarReceiver.CalendarEvent event : CalendarReceiver.getApplyingCalendarEvents(Rule.this))
|
||||||
|
{
|
||||||
|
if(!CalendarReceiver.hasEventBeenUsedInRule(Rule.this, event))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Record only the first calendar event that matched because the rule may
|
||||||
|
be executed once for every matching event.
|
||||||
|
*/
|
||||||
|
Miscellaneous.logEvent("i", "Rule", "Executing this rule run for calender event: " + event, 5);
|
||||||
|
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(Rule.this, event));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Run actions one after another
|
||||||
|
*/
|
||||||
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "RuleExecution", "Running action " + Rule.this.getActionSet().get(i).toStringShort() + " of rule " + Rule.this.getName(), 5);
|
||||||
Rule.this.getActionSet().get(i).run(automationService, doToggle);
|
Rule.this.getActionSet().get(i).run(automationService, doToggle);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
@@ -524,10 +565,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
public void activate(AutomationService automationService, boolean force)
|
public void activate(AutomationService automationService, boolean force)
|
||||||
{
|
{
|
||||||
ActivateRuleTask task = new ActivateRuleTask();
|
ActivateRuleTask task = new ActivateRuleTask();
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
|
||||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
|
|
||||||
else
|
|
||||||
task.execute(automationService, force);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Rule> findRuleCandidates(Trigger.Trigger_Enum triggerType)
|
public static ArrayList<Rule> findRuleCandidates(Trigger.Trigger_Enum triggerType)
|
||||||
@@ -742,4 +780,71 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj)
|
||||||
|
{
|
||||||
|
return this.getName().equals(((Rule)obj).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTriggerOfType(Trigger.Trigger_Enum queryType)
|
||||||
|
{
|
||||||
|
for(Trigger t : getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(queryType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasActionOfType(Action.Action_Enum queryType)
|
||||||
|
{
|
||||||
|
for(Action a : getActionSet())
|
||||||
|
{
|
||||||
|
if(a.getAction().equals(queryType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountOfTriggersForType(Trigger.Trigger_Enum type)
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Trigger t : getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(type))
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountOfActionsForType(Action.Action_Enum type)
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Action a : getActionSet())
|
||||||
|
{
|
||||||
|
if(a.getAction().equals(type))
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getAmountOfActivatedRules()
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Rule r : Rule.getRuleCollection())
|
||||||
|
{
|
||||||
|
if(r.isRuleActive())
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:anyDensity="true"
|
android:anyDensity="true"
|
||||||
@@ -49,7 +51,6 @@
|
|||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||||
<!-- <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />-->
|
|
||||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.NFC" />
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
@@ -64,11 +65,23 @@
|
|||||||
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
|
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
|
||||||
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
|
<uses-permission android:name="android.hardware.sensor.proximity"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" tools:ignore="ProtectedPermissions" />
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
<!--android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />-->
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
<uses-permission android:name="com.termux.permission.RUN_COMMAND" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
|
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
|
||||||
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:allowClearUserData="true"
|
android:allowClearUserData="true"
|
||||||
android:icon="@drawable/gears"
|
android:icon="@drawable/crane"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:networkSecurityConfig="@xml/network_security_config">
|
android:networkSecurityConfig="@xml/network_security_config">
|
||||||
@@ -83,22 +96,19 @@
|
|||||||
android:name="google_analytics_ssaid_collection_enabled"
|
android:name="google_analytics_ssaid_collection_enabled"
|
||||||
android:value="false" />
|
android:value="false" />
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".ActivityMainScreen"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
<activity
|
|
||||||
android:name=".ActivityManagePoi"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
<activity
|
|
||||||
android:name=".ActivitySettings"
|
|
||||||
android:label="@string/app_name"></activity>
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".AutomationService"
|
android:name=".AutomationService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/app_name" />
|
android:label="@string/app_name"
|
||||||
|
android:foregroundServiceType="specialUse" >
|
||||||
|
<property
|
||||||
|
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||||
|
android:value="Automating things on the device" />
|
||||||
|
</service>
|
||||||
|
|
||||||
<receiver android:name=".receivers.StartupIntentReceiver" android:enabled="true" android:exported="true">
|
<receiver android:name=".receivers.StartupIntentReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<!--<action android:name="android.intent.action.SCREEN_ON" />-->
|
<!--<action android:name="android.intent.action.SCREEN_ON" />-->
|
||||||
<!--<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />-->
|
<!--<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />-->
|
||||||
@@ -111,6 +121,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:name=".receivers.PackageReplacedReceiver"
|
<receiver android:name=".receivers.PackageReplacedReceiver"
|
||||||
|
android:exported="true"
|
||||||
android:enabled="true">
|
android:enabled="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
@@ -119,9 +130,11 @@
|
|||||||
<receiver android:name=".receivers.DateTimeListener" />
|
<receiver android:name=".receivers.DateTimeListener" />
|
||||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||||
<receiver android:name=".receivers.TimeZoneListener" />
|
<receiver android:name=".receivers.TimeZoneListener" />
|
||||||
|
<receiver android:name=".receivers.CalendarReceiver" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".DeviceAdmin"
|
android:name=".DeviceAdmin"
|
||||||
|
android:exported="true"
|
||||||
android:description="@string/app_name"
|
android:description="@string/app_name"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||||
@@ -133,6 +146,9 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<activity android:name=".ActivityMainScreen" android:label="@string/app_name" />
|
||||||
|
<activity android:name=".ActivityManagePoi" android:label="@string/app_name" />
|
||||||
|
<activity android:name=".ActivitySettings" android:label="@string/app_name" />
|
||||||
<activity android:name=".ActivityManageRule" />
|
<activity android:name=".ActivityManageRule" />
|
||||||
<activity android:name=".ActivityManageActionTriggerUrl" />
|
<activity android:name=".ActivityManageActionTriggerUrl" />
|
||||||
<activity android:name=".ActivityDisplayLongMessage" />
|
<activity android:name=".ActivityDisplayLongMessage" />
|
||||||
@@ -156,8 +172,15 @@
|
|||||||
<activity android:name=".ActivityManageTriggerTethering" />
|
<activity android:name=".ActivityManageTriggerTethering" />
|
||||||
<activity android:name=".ActivityManageActionWakeLock" />
|
<activity android:name=".ActivityManageActionWakeLock" />
|
||||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||||
|
<activity android:name=".ActivityManageActionSetVariable" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCheckVariable" />
|
||||||
|
<activity android:name=".ActivityManageActionCopyToClipboard" />
|
||||||
|
<activity android:name=".ActivityManageActionLocationService" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCharging" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ActivityMainTabLayout"
|
android:name=".ActivityMainTabLayout"
|
||||||
|
android:exported="true"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -182,7 +205,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.nfc.action.TECH_DISCOVERED"
|
android:name="android.nfc.action.TECH_DISCOVERED"
|
||||||
@@ -195,17 +217,20 @@
|
|||||||
<activity android:name=".ActivityManageActionStartActivity" />
|
<activity android:name=".ActivityManageActionStartActivity" />
|
||||||
<activity android:name=".ActivityManageTriggerNfc" />
|
<activity android:name=".ActivityManageTriggerNfc" />
|
||||||
<activity android:name=".ActivityManageActionSpeakText" />
|
<activity android:name=".ActivityManageActionSpeakText" />
|
||||||
<activity android:name=".ActivityManageActionPlaySound" />
|
|
||||||
<activity android:name=".ActivityManageTriggerBluetooth" />
|
<activity android:name=".ActivityManageTriggerBluetooth" />
|
||||||
<activity android:name=".ActivityMainProfiles" />
|
<activity android:name=".ActivityMainProfiles" />
|
||||||
<activity android:name=".ActivityManageProfile" />
|
<activity android:name=".ActivityManageProfile" />
|
||||||
<activity android:name=".ActivityManageTriggerWifi" />
|
<activity android:name=".ActivityManageTriggerWifi" />
|
||||||
<activity android:name=".ActivityVolumeTest" />
|
<activity android:name=".ActivityVolumeTest" />
|
||||||
<activity android:name=".ActivityPermissions"></activity>
|
<activity android:name=".ActivityPermissions" />
|
||||||
<activity android:name=".ActivityManageTriggerNotification" />
|
<activity android:name=".ActivityManageTriggerNotification" />
|
||||||
|
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||||
|
<activity android:name=".ActivityManageTriggerProximity" />
|
||||||
|
<activity android:name=".ActivityManageActionSetSystemSetting" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".receivers.NotificationListener"
|
android:name=".receivers.NotificationListener"
|
||||||
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -214,8 +239,6 @@
|
|||||||
|
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<activity android:name=".ActivityPermissions" />
|
|
||||||
|
|
||||||
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
||||||
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ import android.os.Looper;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.android.gms.location.DetectedActivity;
|
import com.google.android.gms.location.DetectedActivity;
|
||||||
import com.jens.automation2.receivers.ActivityDetectionReceiver;
|
import com.jens.automation2.receivers.ActivityDetectionReceiver;
|
||||||
import com.jens.automation2.receivers.BroadcastListener;
|
import com.jens.automation2.receivers.BroadcastListener;
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -107,7 +110,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
}
|
}
|
||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readFromFile()
|
public static void readFromFile()
|
||||||
@@ -347,7 +350,16 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
||||||
{
|
{
|
||||||
if(oneTrigger.getTimeFrame().repetition > 0)
|
if(oneTrigger.getTimeFrame().repetition > 0)
|
||||||
return true;
|
{
|
||||||
|
if(this.getLastExecution() != null)
|
||||||
|
{
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
if (this.getLastExecution().getTimeInMillis() + oneTrigger.getTimeFrame().getRepetition() * 1000 <= now.getTimeInMillis())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||||
{
|
{
|
||||||
@@ -364,23 +376,28 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
if(hasNotAppliedSinceLastExecution())
|
if(hasNotAppliedSinceLastExecution())
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" has not flipped since its last execution.", 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" does not apply.", 4);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean applies(Context context)
|
public boolean applies(Context context)
|
||||||
{
|
{
|
||||||
if(AutomationService.getInstance() == null)
|
if(AutomationService.getInstance() == null)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule \"" + getName() + "\" cannot apply.", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +409,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule %1$s generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule \"%1$s\" generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,7 +484,9 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
AutomationService service = AutomationService.getInstance();
|
AutomationService service = AutomationService.getInstance();
|
||||||
service.speak(messages[0], false);
|
service.speak(messages[0], false);
|
||||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
|
||||||
|
if(Settings.showToasts)
|
||||||
|
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
super.onProgressUpdate(messages);
|
super.onProgressUpdate(messages);
|
||||||
}
|
}
|
||||||
@@ -495,8 +514,6 @@ public class Rule implements Comparable<Rule>
|
|||||||
protected boolean activateInternally(AutomationService automationService)
|
protected boolean activateInternally(AutomationService automationService)
|
||||||
{
|
{
|
||||||
boolean isActuallyToggleable = isActuallyToggable();
|
boolean isActuallyToggleable = isActuallyToggable();
|
||||||
|
|
||||||
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
|
||||||
boolean doToggle = ruleToggle && isActuallyToggleable;
|
boolean doToggle = ruleToggle && isActuallyToggleable;
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
@@ -510,10 +527,34 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(Settings.startNewThreadForRuleActivation)
|
if(Settings.startNewThreadForRuleActivation)
|
||||||
publishProgress(message);
|
publishProgress(message);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Make a note of Rule/CalendarEvent executed combinations
|
||||||
|
*/
|
||||||
|
if(Rule.this.hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent))
|
||||||
|
{
|
||||||
|
for(CalendarReceiver.CalendarEvent event : CalendarReceiver.getApplyingCalendarEvents(Rule.this))
|
||||||
|
{
|
||||||
|
if(!CalendarReceiver.hasEventBeenUsedInRule(Rule.this, event))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Record only the first calendar event that matched because the rule may
|
||||||
|
be executed once for every matching event.
|
||||||
|
*/
|
||||||
|
Miscellaneous.logEvent("i", "Rule", "Executing this rule run for calender event: " + event, 5);
|
||||||
|
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(Rule.this, event));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Run actions one after another
|
||||||
|
*/
|
||||||
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "RuleExecution", "Running action " + Rule.this.getActionSet().get(i).toStringShort() + " of rule " + Rule.this.getName(), 5);
|
||||||
Rule.this.getActionSet().get(i).run(automationService, doToggle);
|
Rule.this.getActionSet().get(i).run(automationService, doToggle);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
@@ -551,10 +592,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
public void activate(AutomationService automationService, boolean force)
|
public void activate(AutomationService automationService, boolean force)
|
||||||
{
|
{
|
||||||
ActivateRuleTask task = new ActivateRuleTask();
|
ActivateRuleTask task = new ActivateRuleTask();
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
|
||||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
|
|
||||||
else
|
|
||||||
task.execute(automationService, force);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Rule> findRuleCandidates(Trigger.Trigger_Enum triggerType)
|
public static ArrayList<Rule> findRuleCandidates(Trigger.Trigger_Enum triggerType)
|
||||||
@@ -769,4 +807,71 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj)
|
||||||
|
{
|
||||||
|
return this.getName().equals(((Rule)obj).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTriggerOfType(Trigger.Trigger_Enum queryType)
|
||||||
|
{
|
||||||
|
for(Trigger t : getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(queryType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasActionOfType(Action.Action_Enum queryType)
|
||||||
|
{
|
||||||
|
for(Action a : getActionSet())
|
||||||
|
{
|
||||||
|
if(a.getAction().equals(queryType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountOfTriggersForType(Trigger.Trigger_Enum type)
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Trigger t : getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(type))
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountOfActionsForType(Action.Action_Enum type)
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Action a : getActionSet())
|
||||||
|
{
|
||||||
|
if(a.getAction().equals(type))
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getAmountOfActivatedRules()
|
||||||
|
{
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
for(Rule r : Rule.getRuleCollection())
|
||||||
|
{
|
||||||
|
if(r.isRuleActive())
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -6,13 +6,13 @@ import android.os.Build;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class Action
|
public class Action
|
||||||
@@ -21,7 +21,10 @@ public class Action
|
|||||||
|
|
||||||
public static final String actionParameter2Split = "ap2split";
|
public static final String actionParameter2Split = "ap2split";
|
||||||
public static final String intentPairSeparator = "intPairSplit";
|
public static final String intentPairSeparator = "intPairSplit";
|
||||||
|
public static final String actionParameters2SeparatorInner = "a2splitInner";
|
||||||
|
public static final String actionParameters2SeparatorOuter = "a2splitOuter";
|
||||||
public static final String vibrateSeparator = ",";
|
public static final String vibrateSeparator = ",";
|
||||||
|
public static final String httpErrorDefaultText = "HTTP_ERROR";
|
||||||
|
|
||||||
public enum Action_Enum
|
public enum Action_Enum
|
||||||
{
|
{
|
||||||
@@ -31,13 +34,9 @@ public class Action
|
|||||||
setWifiTethering,
|
setWifiTethering,
|
||||||
setBluetoothTethering,
|
setBluetoothTethering,
|
||||||
setDisplayRotation,
|
setDisplayRotation,
|
||||||
turnWifiOn,turnWifiOff,
|
|
||||||
turnBluetoothOn,turnBluetoothOff,
|
|
||||||
triggerUrl,
|
triggerUrl,
|
||||||
changeSoundProfile,
|
changeSoundProfile,
|
||||||
turnUsbTetheringOn,turnUsbTetheringOff,
|
turnUsbTetheringOn,turnUsbTetheringOff,
|
||||||
turnWifiTetheringOn,turnWifiTetheringOff,
|
|
||||||
enableScreenRotation,disableScreenRotation,
|
|
||||||
startOtherActivity,
|
startOtherActivity,
|
||||||
waitBeforeNextAction,
|
waitBeforeNextAction,
|
||||||
turnScreenOnOrOff,
|
turnScreenOnOrOff,
|
||||||
@@ -54,7 +53,14 @@ public class Action
|
|||||||
sendBroadcast,
|
sendBroadcast,
|
||||||
runExecutable,
|
runExecutable,
|
||||||
wakelock,
|
wakelock,
|
||||||
sendTextMessage;
|
setVariable,
|
||||||
|
startPhoneCall,
|
||||||
|
stopPhoneCall,
|
||||||
|
copyToClipboard,
|
||||||
|
setLocationService,
|
||||||
|
sendTextMessage,
|
||||||
|
takeScreenshot,
|
||||||
|
setSystemSetting;
|
||||||
|
|
||||||
public String getFullName(Context context)
|
public String getFullName(Context context)
|
||||||
{
|
{
|
||||||
@@ -72,14 +78,6 @@ public class Action
|
|||||||
return context.getResources().getString(R.string.actionSetUsbTethering);
|
return context.getResources().getString(R.string.actionSetUsbTethering);
|
||||||
case setDisplayRotation:
|
case setDisplayRotation:
|
||||||
return context.getResources().getString(R.string.actionSetDisplayRotation);
|
return context.getResources().getString(R.string.actionSetDisplayRotation);
|
||||||
case turnWifiOn:
|
|
||||||
return context.getResources().getString(R.string.actionTurnWifiOn);
|
|
||||||
case turnWifiOff:
|
|
||||||
return context.getResources().getString(R.string.actionTurnWifiOff);
|
|
||||||
case turnBluetoothOn:
|
|
||||||
return context.getResources().getString(R.string.actionTurnBluetoothOn);
|
|
||||||
case turnBluetoothOff:
|
|
||||||
return context.getResources().getString(R.string.actionTurnBluetoothOff);
|
|
||||||
case triggerUrl:
|
case triggerUrl:
|
||||||
return context.getResources().getString(R.string.actionTriggerUrl);
|
return context.getResources().getString(R.string.actionTriggerUrl);
|
||||||
case changeSoundProfile:
|
case changeSoundProfile:
|
||||||
@@ -88,14 +86,6 @@ public class Action
|
|||||||
return context.getResources().getString(R.string.actionTurnUsbTetheringOn);
|
return context.getResources().getString(R.string.actionTurnUsbTetheringOn);
|
||||||
case turnUsbTetheringOff:
|
case turnUsbTetheringOff:
|
||||||
return context.getResources().getString(R.string.actionTurnUsbTetheringOff);
|
return context.getResources().getString(R.string.actionTurnUsbTetheringOff);
|
||||||
case turnWifiTetheringOn:
|
|
||||||
return context.getResources().getString(R.string.actionTurnWifiTetheringOn);
|
|
||||||
case turnWifiTetheringOff:
|
|
||||||
return context.getResources().getString(R.string.actionTurnWifiTetheringOff);
|
|
||||||
case enableScreenRotation:
|
|
||||||
return context.getResources().getString(R.string.actionEnableScreenRotation);
|
|
||||||
case disableScreenRotation:
|
|
||||||
return context.getResources().getString(R.string.actionDisableScreenRotation);
|
|
||||||
case startOtherActivity:
|
case startOtherActivity:
|
||||||
return context.getResources().getString(R.string.startOtherActivity);
|
return context.getResources().getString(R.string.startOtherActivity);
|
||||||
case waitBeforeNextAction:
|
case waitBeforeNextAction:
|
||||||
@@ -130,6 +120,20 @@ public class Action
|
|||||||
return context.getResources().getString(R.string.runExecutable);
|
return context.getResources().getString(R.string.runExecutable);
|
||||||
case wakelock:
|
case wakelock:
|
||||||
return context.getResources().getString(R.string.keepDeviceAwake);
|
return context.getResources().getString(R.string.keepDeviceAwake);
|
||||||
|
case setVariable:
|
||||||
|
return context.getResources().getString(R.string.setVariable);
|
||||||
|
case startPhoneCall:
|
||||||
|
return context.getResources().getString(R.string.startPhoneCall);
|
||||||
|
case stopPhoneCall:
|
||||||
|
return context.getResources().getString(R.string.endPhoneCall);
|
||||||
|
case copyToClipboard:
|
||||||
|
return context.getResources().getString(R.string.copyTextToClipboard);
|
||||||
|
case takeScreenshot:
|
||||||
|
return context.getResources().getString(R.string.takeScreenshot);
|
||||||
|
case setLocationService:
|
||||||
|
return context.getResources().getString(R.string.setLocationServiceCapital);
|
||||||
|
case setSystemSetting:
|
||||||
|
return context.getResources().getString(R.string.setSystemSettingCapital);
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
@@ -279,22 +283,79 @@ public class Action
|
|||||||
case wakelock:
|
case wakelock:
|
||||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.keepDeviceAwake) + " (" + String.valueOf(getParameter1()) + ")");
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.keepDeviceAwake) + " (" + String.valueOf(getParameter1()) + ")");
|
||||||
break;
|
break;
|
||||||
|
case setVariable:
|
||||||
|
String[] variableParams = getParameter2().split(actionParameter2Split);
|
||||||
|
String addition;
|
||||||
|
if (variableParams.length >= 2)
|
||||||
|
addition = " (key: " + variableParams[0] + ", value: " + variableParams[1] + ")";
|
||||||
|
else
|
||||||
|
addition = " (delete key: " + variableParams[0] + ")";
|
||||||
|
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.setVariable) + addition);
|
||||||
|
break;
|
||||||
|
case startPhoneCall:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.startPhoneCall));
|
||||||
|
break;
|
||||||
|
case stopPhoneCall:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.endPhoneCall));
|
||||||
|
break;
|
||||||
|
case copyToClipboard:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.copyTextToClipboard));
|
||||||
|
break;
|
||||||
|
case takeScreenshot:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.takeScreenshot));
|
||||||
|
break;
|
||||||
|
case setLocationService:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.setLocationService) + ": " );
|
||||||
|
switch(Integer.parseInt(getParameter2()))
|
||||||
|
{
|
||||||
|
case android.provider.Settings.Secure.LOCATION_MODE_OFF:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.off));
|
||||||
|
break;
|
||||||
|
case android.provider.Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.LOCATION_MODE_SENSOR_ONLY));
|
||||||
|
break;
|
||||||
|
case android.provider.Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.LOCATION_MODE_BATTERY_SAVING));
|
||||||
|
break;
|
||||||
|
case android.provider.Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.LOCATION_MODE_HIGH_ACCURACY));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
returnString.append(action.toString());
|
returnString.append(action.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getAction().equals(Action_Enum.triggerUrl))
|
if (this.getAction().equals(Action_Enum.triggerUrl))
|
||||||
{
|
{
|
||||||
String[] components = parameter2.split(";");
|
String[] components;
|
||||||
|
if(parameter2.contains(Action.actionParameter2Split))
|
||||||
|
components = parameter2.split(Action.actionParameter2Split);
|
||||||
|
else
|
||||||
|
components = parameter2.split(";");
|
||||||
|
|
||||||
if (components.length >= 3)
|
if (components.length >= 3)
|
||||||
{
|
{
|
||||||
|
returnString.append(" (");
|
||||||
|
if(components.length >= 4)
|
||||||
|
returnString.append(components[3]);
|
||||||
|
else
|
||||||
|
returnString.append(ActivityManageActionTriggerUrl.methodGet);
|
||||||
|
returnString.append(")");
|
||||||
|
|
||||||
returnString.append(": " + components[2]);
|
returnString.append(": " + components[2]);
|
||||||
|
|
||||||
if (parameter1)
|
if (parameter1)
|
||||||
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingAuthentication) + ".");
|
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingAuthentication) + ".");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
returnString.append(" (");
|
||||||
|
returnString.append(ActivityManageActionTriggerUrl.methodGet);;
|
||||||
|
returnString.append(")");
|
||||||
returnString.append(": " + components[0]);
|
returnString.append(": " + components[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (this.getAction().equals(Action_Enum.startOtherActivity))
|
else if (this.getAction().equals(Action_Enum.startOtherActivity))
|
||||||
{
|
{
|
||||||
@@ -337,24 +398,24 @@ public class Action
|
|||||||
if (parts.length > 4 && !StringUtils.isBlank(parts[4]))
|
if (parts.length > 4 && !StringUtils.isBlank(parts[4]))
|
||||||
returnString.append(", " + Miscellaneous.getAnyContext().getResources().getString(R.string.ifString) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.text) + " " + Trigger.getMatchString(parts[3]) + " " + parts[4]);
|
returnString.append(", " + Miscellaneous.getAnyContext().getResources().getString(R.string.ifString) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.text) + " " + Trigger.getMatchString(parts[3]) + " " + parts[4]);
|
||||||
|
|
||||||
if(parts.length >= 6)
|
if (parts.length >= 6)
|
||||||
{
|
{
|
||||||
if(!parts[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
|
if (!parts[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
|
||||||
{
|
{
|
||||||
returnString.append(" " + String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.withButton), parts[5]));
|
returnString.append(" " + String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.withButton), parts[5]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(this.getAction().equals(Action_Enum.setWifi))
|
else if (this.getAction().equals(Action_Enum.setWifi))
|
||||||
{
|
{
|
||||||
if(!StringUtils.isEmpty(this.parameter2))
|
if (!StringUtils.isEmpty(this.parameter2))
|
||||||
{
|
{
|
||||||
boolean useRoot = Boolean.parseBoolean(this.parameter2);
|
boolean useRoot = Boolean.parseBoolean(this.parameter2);
|
||||||
if(useRoot)
|
if (useRoot)
|
||||||
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingRoot));
|
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingRoot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(this.getAction().equals(Action_Enum.controlMediaPlayback))
|
else if (this.getAction().equals(Action_Enum.controlMediaPlayback))
|
||||||
{
|
{
|
||||||
returnString.append(": ");
|
returnString.append(": ");
|
||||||
|
|
||||||
@@ -382,10 +443,12 @@ public class Action
|
|||||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.unknown));
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.unknown));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(this.getAction().equals(Action_Enum.sendBroadcast))
|
else if (this.getAction().equals(Action_Enum.sendBroadcast))
|
||||||
{
|
{
|
||||||
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/"));
|
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/"));
|
||||||
}
|
}
|
||||||
|
else if(this.getAction().equals(Action_Enum.setVariable) || this.getAction().equals(Action_Enum.copyToClipboard) || this.getAction().equals(Action_Enum.setLocationService))
|
||||||
|
; // it's completed further above already
|
||||||
else if (parameter2 != null && parameter2.length() > 0)
|
else if (parameter2 != null && parameter2.length() > 0)
|
||||||
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
|
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
|
||||||
}
|
}
|
||||||
@@ -414,25 +477,9 @@ public class Action
|
|||||||
for(Action_Enum action : Action_Enum.values())
|
for(Action_Enum action : Action_Enum.values())
|
||||||
{
|
{
|
||||||
if( // exclusion for deprecated types
|
if( // exclusion for deprecated types
|
||||||
!action.toString().equals("turnWifiOn")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnWifiOff")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnBluetoothOn")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnBluetoothOff")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnUsbTetheringOn")
|
!action.toString().equals("turnUsbTetheringOn")
|
||||||
&&
|
&&
|
||||||
!action.toString().equals("turnUsbTetheringOff")
|
!action.toString().equals("turnUsbTetheringOff")
|
||||||
&&
|
|
||||||
!action.toString().equals("turnWifiTetheringOn")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnWifiTetheringOff")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("enableScreenRotation")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("disableScreenRotation")
|
|
||||||
) // exclusion for deprecated types
|
) // exclusion for deprecated types
|
||||||
actionTypesList.add(action.toString());
|
actionTypesList.add(action.toString());
|
||||||
}
|
}
|
||||||
@@ -446,27 +493,11 @@ public class Action
|
|||||||
for(Action_Enum action : Action_Enum.values())
|
for(Action_Enum action : Action_Enum.values())
|
||||||
{
|
{
|
||||||
if( // exclusion for deprecated types
|
if( // exclusion for deprecated types
|
||||||
!action.toString().equals("turnWifiOn")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnWifiOff")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnBluetoothOn")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnBluetoothOff")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnUsbTetheringOn")
|
!action.toString().equals("turnUsbTetheringOn")
|
||||||
&&
|
&&
|
||||||
!action.toString().equals("turnUsbTetheringOff")
|
!action.toString().equals("turnUsbTetheringOff")
|
||||||
&&
|
|
||||||
!action.toString().equals("turnWifiTetheringOn")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("turnWifiTetheringOff")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("enableScreenRotation")
|
|
||||||
&&
|
|
||||||
!action.toString().equals("disableScreenRotation")
|
|
||||||
) // exclusion for deprecated types
|
) // exclusion for deprecated types
|
||||||
actionTypesList.add(action.getFullName(context));
|
actionTypesList.add(action.getFullName(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (String[])actionTypesList.toArray(new String[actionTypesList.size()]);
|
return (String[])actionTypesList.toArray(new String[actionTypesList.size()]);
|
||||||
@@ -493,7 +524,7 @@ public class Action
|
|||||||
triggerUrl(context);
|
triggerUrl(context);
|
||||||
break;
|
break;
|
||||||
case setBluetooth:
|
case setBluetooth:
|
||||||
Actions.setBluetooth(context, getParameter1(), toggleActionIfPossible);
|
boolean result = Actions.setBluetooth(context, getParameter1(), toggleActionIfPossible);
|
||||||
break;
|
break;
|
||||||
case setUsbTethering:
|
case setUsbTethering:
|
||||||
Actions.setUsbTethering(context, getParameter1(), toggleActionIfPossible);
|
Actions.setUsbTethering(context, getParameter1(), toggleActionIfPossible);
|
||||||
@@ -590,6 +621,28 @@ public class Action
|
|||||||
else
|
else
|
||||||
Actions.wakeLockStop();
|
Actions.wakeLockStop();
|
||||||
break;
|
break;
|
||||||
|
case setVariable:
|
||||||
|
Actions.setVariable(this.getParameter2());
|
||||||
|
break;
|
||||||
|
case startPhoneCall:
|
||||||
|
Actions.startPhoneCall(context, this.getParameter2());
|
||||||
|
break;
|
||||||
|
case stopPhoneCall:
|
||||||
|
Actions.endPhoneCall(context);
|
||||||
|
break;
|
||||||
|
case copyToClipboard:
|
||||||
|
Actions.copyToClipboard(context, Miscellaneous.replaceVariablesInText(this.getParameter2(), context));
|
||||||
|
break;
|
||||||
|
case takeScreenshot:
|
||||||
|
Actions.takeScreenshot();
|
||||||
|
break;
|
||||||
|
case setLocationService:
|
||||||
|
Actions.setLocationService(Integer.parseInt(this.getParameter2()), AutomationService.getInstance());
|
||||||
|
break;
|
||||||
|
case setSystemSetting:
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||||
|
Actions.setSystemSetting(this.getParameter2(), AutomationService.getInstance());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||||
break;
|
break;
|
||||||
@@ -603,34 +656,55 @@ public class Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void triggerUrl(Context context)
|
private void triggerUrl(Context context)
|
||||||
{
|
{
|
||||||
|
//TODO: Check if data needs to be escaped
|
||||||
String username = null;
|
String username = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
|
String method = ActivityManageActionTriggerUrl.methodGet;
|
||||||
String url;
|
String url;
|
||||||
|
String params = null;
|
||||||
|
|
||||||
String[] components = getParameter2().split(";");
|
String[] components;
|
||||||
|
if(getParameter2().contains(Action.actionParameter2Split))
|
||||||
|
components = getParameter2().split(Action.actionParameter2Split, -1);
|
||||||
|
else
|
||||||
|
components = getParameter2().split(";", -1);
|
||||||
|
|
||||||
if(components.length >= 3)
|
if(components.length >= 3)
|
||||||
{
|
{
|
||||||
username = components[0];
|
username = components[0];
|
||||||
password = components[1];
|
password = components[1];
|
||||||
url = components[2];
|
url = components[2];
|
||||||
|
|
||||||
|
if(components.length >= 4)
|
||||||
|
method = components[3];
|
||||||
|
|
||||||
|
if(components.length >= 5)
|
||||||
|
{
|
||||||
|
params = components[4];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else // compatibility for very old versions which haven't upgraded, yet.
|
||||||
url = components[0];
|
url = components[0];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
url = Miscellaneous.replaceVariablesInText(url, context);
|
url = Miscellaneous.replaceVariablesInText(url, context);
|
||||||
|
// if(!StringUtils.isEmpty(params))
|
||||||
|
// params = URLEncoder.encode(Miscellaneous.replaceVariablesInText(params, context), "UTF-8");
|
||||||
|
|
||||||
Actions myAction = new Actions();
|
Actions myAction = new Actions();
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", "HTTP", "Attempting download of " + url, 4); //getResources().getString("attemptingDownloadOf");
|
Miscellaneous.logEvent("i", "HTTP", "Attempting download of " + url, 4); //getResources().getString("attemptingDownloadOf");
|
||||||
|
|
||||||
|
/*
|
||||||
|
Theoretically credentials could be saved, but authentication has been turned off afterwards.
|
||||||
|
The following if clause is there to force username and password to be null.
|
||||||
|
*/
|
||||||
if(this.getParameter1()) // use authentication
|
if(this.getParameter1()) // use authentication
|
||||||
new DownloadTask().execute(url, username, password);
|
new DownloadTask().execute(url, username, password, method, params);
|
||||||
else
|
else
|
||||||
new DownloadTask().execute(url, null, null);
|
new DownloadTask().execute(url, null, null, method, params);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -645,32 +719,60 @@ public class Action
|
|||||||
{
|
{
|
||||||
Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler);
|
Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler);
|
||||||
|
|
||||||
int attempts=1;
|
int attempts = 1;
|
||||||
String urlString=parameters[0];
|
String urlString=parameters[0];
|
||||||
|
|
||||||
String urlUsername = null;
|
String urlUsername = null;
|
||||||
String urlPassword = null;
|
String urlPassword = null;
|
||||||
|
String method = ActivityManageActionTriggerUrl.methodGet;
|
||||||
|
Map<String,String> httpParams = new HashMap<>();
|
||||||
|
|
||||||
if(parameters.length >= 3)
|
if(parameters.length >= 3)
|
||||||
{
|
{
|
||||||
urlUsername=parameters[1];
|
urlUsername = parameters[1];
|
||||||
urlPassword=parameters[2];
|
urlPassword = parameters[2];
|
||||||
|
|
||||||
|
if(parameters.length >= 4)
|
||||||
|
method = parameters[3];
|
||||||
|
|
||||||
|
if(parameters.length >= 5 && parameters[4] != null)
|
||||||
|
{
|
||||||
|
// has params
|
||||||
|
String[] paramPairs = parameters[4].split(Action.actionParameters2SeparatorOuter);
|
||||||
|
String value = "";
|
||||||
|
for(String pair : paramPairs)
|
||||||
|
{
|
||||||
|
String[] pieces = pair.split(Action.actionParameters2SeparatorInner);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
value = Miscellaneous.replaceVariablesInText(pieces[1], Miscellaneous.getAnyContext());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
value = "error";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pieces.length == 2)
|
||||||
|
httpParams.put(pieces[0], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String response = "httpError";
|
String response = httpErrorDefaultText;
|
||||||
HttpGet post;
|
|
||||||
|
if(Settings.httpAttempts < 1)
|
||||||
if(Settings.httpAttempts < 1)
|
|
||||||
Miscellaneous.logEvent("w", "HTTP Request", Miscellaneous.getAnyContext().getResources().getString(R.string.cantDownloadTooFewRequestsInSettings), 3);
|
Miscellaneous.logEvent("w", "HTTP Request", Miscellaneous.getAnyContext().getResources().getString(R.string.cantDownloadTooFewRequestsInSettings), 3);
|
||||||
|
|
||||||
while(attempts <= Settings.httpAttempts && response.equals("httpError"))
|
while(attempts <= Settings.httpAttempts && response.equals(httpErrorDefaultText))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "HTTP Request", "Attempt " + String.valueOf(attempts++) + " of " + String.valueOf(Settings.httpAttempts), 3);
|
Miscellaneous.logEvent("i", "HTTP Request", "Attempt " + String.valueOf(attempts++) + " of " + String.valueOf(Settings.httpAttempts), 3);
|
||||||
|
|
||||||
// Either thorough checking or no encryption
|
// Either thorough checking or no encryption
|
||||||
if(!Settings.httpAcceptAllCertificates || !urlString.toLowerCase(Locale.getDefault()).contains("https"))
|
// if(!Settings.httpAcceptAllCertificates || !urlString.toLowerCase(Locale.getDefault()).contains("https"))
|
||||||
response = Miscellaneous.downloadURL(urlString, urlUsername, urlPassword);
|
response = Miscellaneous.downloadURL(urlString, urlUsername, urlPassword, method, httpParams);
|
||||||
else
|
// else
|
||||||
response = Miscellaneous.downloadURLwithoutCertificateChecking(urlString, urlUsername, urlPassword);
|
// response = Miscellaneous.downloadUrlWithoutCertificateChecking(urlString, urlUsername, urlPassword, method, httpParams);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
@@ -39,8 +40,11 @@ public class ActivityControlCenter extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_control_center);
|
setContentView(R.layout.activity_control_center);
|
||||||
|
|
||||||
|
|
||||||
bVolumeTest = (Button) findViewById(R.id.bVolumeTest);
|
bVolumeTest = (Button) findViewById(R.id.bVolumeTest);
|
||||||
bVolumeTest.setOnClickListener(new View.OnClickListener()
|
bVolumeTest.setOnClickListener(new View.OnClickListener()
|
||||||
{
|
{
|
||||||
@@ -96,8 +100,17 @@ public class ActivityControlCenter extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
AlertDialog dialog = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.importChooseFolderNotice), ActivityControlCenter.this);
|
||||||
startActivityForResult(intent, requestCodeImport);
|
dialog.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialogInterface)
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||||
|
startActivityForResult(intent, requestCodeImport);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialog.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -384,6 +397,7 @@ public class ActivityControlCenter extends Activity
|
|||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
|
||||||
String folder = Miscellaneous.getWriteableFolder();
|
String folder = Miscellaneous.getWriteableFolder();
|
||||||
if (folder != null && folder.length() > 0)
|
if (folder != null && folder.length() > 0)
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class ActivityDisplayLongMessage extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_display_long_message);
|
setContentView(R.layout.activity_display_long_message);
|
||||||
|
|
||||||
tvMessageTitle = (TextView)findViewById(R.id.tvMessageTitle);
|
tvMessageTitle = (TextView)findViewById(R.id.tvMessageTitle);
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ public class ActivityHelp extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(layout.help_text);
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
setContentView(layout.activity_help_text);
|
||||||
|
|
||||||
TextView tvHelpTextEnergySaving = (TextView) findViewById(R.id.tvHelpTextEnergySaving);
|
TextView tvHelpTextEnergySaving = (TextView) findViewById(R.id.tvHelpTextEnergySaving);
|
||||||
tvHelpTextEnergySaving.setMovementMethod(LinkMovementMethod.getInstance());
|
tvHelpTextEnergySaving.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public class ActivityMainPoi extends ActivityGeneric
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.main_poi_layout);
|
setContentView(R.layout.main_poi_layout);
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -107,6 +109,13 @@ public class ActivityMainPoi extends ActivityGeneric
|
|||||||
this.storeServiceReferenceInVariable();
|
this.storeServiceReferenceInVariable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
}
|
||||||
|
|
||||||
private void buttonAddPoi()
|
private void buttonAddPoi()
|
||||||
{
|
{
|
||||||
poiToEdit = null;
|
poiToEdit = null;
|
||||||
@@ -190,8 +199,27 @@ public class ActivityMainPoi extends ActivityGeneric
|
|||||||
startActivityForResult(manageSpecificPoiIntent, 2000);
|
startActivityForResult(manageSpecificPoiIntent, 2000);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if(pointOfInterest.delete(Miscellaneous.getAnyContext()))
|
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(ActivityMainPoi.this);
|
||||||
updateListView();
|
deleteDialog.setMessage(getResources().getString(R.string.areYouSure));
|
||||||
|
deleteDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
if(pointOfInterest.delete(Miscellaneous.getAnyContext()))
|
||||||
|
updateListView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deleteDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteDialog.show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public class ActivityMainProfiles extends ActivityGeneric
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.main_profile_layout);
|
setContentView(R.layout.main_profile_layout);
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -154,6 +156,13 @@ public class ActivityMainProfiles extends ActivityGeneric
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
}
|
||||||
|
|
||||||
private AlertDialog getProfileDialog(final Profile profile)
|
private AlertDialog getProfileDialog(final Profile profile)
|
||||||
{
|
{
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||||
@@ -187,10 +196,29 @@ public class ActivityMainProfiles extends ActivityGeneric
|
|||||||
Rule user = profile.isInUseByRules();
|
Rule user = profile.isInUseByRules();
|
||||||
if(user == null)
|
if(user == null)
|
||||||
{
|
{
|
||||||
if (profile.delete(ActivityMainProfiles.this))
|
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(ActivityMainProfiles.this);
|
||||||
updateListView();
|
deleteDialog.setMessage(getResources().getString(R.string.areYouSure));
|
||||||
else
|
deleteDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||||
Toast.makeText(ActivityMainProfiles.this, getResources().getString(R.string.profileCouldNotBeDeleted), Toast.LENGTH_LONG).show();
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
if (profile.delete(ActivityMainProfiles.this))
|
||||||
|
updateListView();
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityMainProfiles.this, getResources().getString(R.string.profileCouldNotBeDeleted), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deleteDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteDialog.show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Toast.makeText(ActivityMainProfiles.this, String.format(getResources().getString(R.string.ruleXIsUsingProfileY), user.getName(), profile.getName()), Toast.LENGTH_LONG).show();
|
Toast.makeText(ActivityMainProfiles.this, String.format(getResources().getString(R.string.ruleXIsUsingProfileY), user.getName(), profile.getName()), Toast.LENGTH_LONG).show();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import android.widget.ListView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.jens.automation2.AutomationService.serviceCommands;
|
import com.jens.automation2.AutomationService.serviceCommands;
|
||||||
import com.jens.automation2.receivers.DateTimeListener;
|
import com.jens.automation2.receivers.DateTimeListener;
|
||||||
|
|
||||||
@@ -46,7 +47,9 @@ public class ActivityMainRules extends ActivityGeneric
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.main_rule_layout);
|
setContentView(R.layout.main_rule_layout);
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -152,6 +155,13 @@ public class ActivityMainRules extends ActivityGeneric
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
@@ -187,7 +197,14 @@ public class ActivityMainRules extends ActivityGeneric
|
|||||||
{
|
{
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||||
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithRule));
|
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithRule));
|
||||||
alertDialogBuilder.setItems(new String[]{ getResources().getString(R.string.runManually), getResources().getString(R.string.edit), getResources().getString(R.string.deleteCapital), getResources().getString(R.string.clone) }, new DialogInterface.OnClickListener()
|
|
||||||
|
String toggleEnabled;
|
||||||
|
if(ruleThisIsAbout.isRuleActive())
|
||||||
|
toggleEnabled = getResources().getString(R.string.disable);
|
||||||
|
else
|
||||||
|
toggleEnabled = getResources().getString(R.string.enable);
|
||||||
|
|
||||||
|
alertDialogBuilder.setItems(new String[]{ getResources().getString(R.string.runManually), getResources().getString(R.string.edit), getResources().getString(R.string.deleteCapital), toggleEnabled, getResources().getString(R.string.clone) }, new DialogInterface.OnClickListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which)
|
public void onClick(DialogInterface dialog, int which)
|
||||||
@@ -213,13 +230,45 @@ public class ActivityMainRules extends ActivityGeneric
|
|||||||
startActivityForResult(manageSpecificRuleIntent, requestCodeChangeRule);
|
startActivityForResult(manageSpecificRuleIntent, requestCodeChangeRule);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(ruleThisIsAbout.delete())
|
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(ActivityMainRules.this);
|
||||||
|
deleteDialog.setMessage(getResources().getString(R.string.areYouSure));
|
||||||
|
deleteDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
if(ruleThisIsAbout.delete())
|
||||||
|
{
|
||||||
|
ruleToEdit = null; //clear cache
|
||||||
|
updateListView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deleteDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteDialog.show();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ruleToEdit = ruleThisIsAbout;
|
||||||
|
if(ruleToEdit.isRuleActive())
|
||||||
|
ruleToEdit.setRuleActive(false);
|
||||||
|
else
|
||||||
|
ruleToEdit.setRuleActive(true);
|
||||||
|
|
||||||
|
if(ruleToEdit.change(ActivityMainRules.this))
|
||||||
{
|
{
|
||||||
ruleToEdit = null; //clear cache
|
ruleToEdit = null; //clear cache
|
||||||
updateListView();
|
updateListView();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 4:
|
||||||
ruleToEdit = ruleThisIsAbout;
|
ruleToEdit = ruleThisIsAbout;
|
||||||
if(ruleToEdit.cloneRule(ActivityMainRules.this))
|
if(ruleToEdit.cloneRule(ActivityMainRules.this))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,9 +6,13 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -31,6 +35,7 @@ import com.jens.automation2.location.LocationProvider;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public class ActivityMainScreen extends ActivityGeneric
|
public class ActivityMainScreen extends ActivityGeneric
|
||||||
@@ -42,7 +47,7 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
|
|
||||||
ToggleButton toggleService, tbLockSound;
|
ToggleButton toggleService, tbLockSound;
|
||||||
Button bShowHelp, bPrivacy, bAddSoundLockTIme, bDonate, bControlCenter;
|
Button bShowHelp, bPrivacy, bAddSoundLockTIme, bDonate, bControlCenter;
|
||||||
TextView tvActivePoi, tvClosestPoi, tvLastRule, tvLastProfile, tvMainScreenNotePermissions, tvMainScreenNoteFeaturesFromOtherFlavor, tvMainScreenNoteLocationImpossibleBlameGoogle, tvMainScreenNoteNews, tvLockSoundDuration;
|
TextView tvActivePoi, tvClosestPoi, tvLastRule, tvLastProfile, tvMainScreenNotePermissions, tvMainScreenNoteFeaturesFromOtherFlavor, tvMainScreenNoteLocationImpossibleBlameGoogle, tvMainScreenNoteNews, tvLockSoundDuration, tvContactNotice;
|
||||||
|
|
||||||
ListView lvRuleHistory;
|
ListView lvRuleHistory;
|
||||||
ArrayAdapter<Rule> ruleHistoryListViewAdapter;
|
ArrayAdapter<Rule> ruleHistoryListViewAdapter;
|
||||||
@@ -51,6 +56,8 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.main_overview_layout);
|
setContentView(R.layout.main_overview_layout);
|
||||||
|
|
||||||
activityMainScreenInstance = this;
|
activityMainScreenInstance = this;
|
||||||
@@ -78,10 +85,14 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
tbLockSound = (ToggleButton) findViewById(R.id.tbLockSound);
|
tbLockSound = (ToggleButton) findViewById(R.id.tbLockSound);
|
||||||
toggleService = (ToggleButton) findViewById(R.id.tbArmMastListener);
|
toggleService = (ToggleButton) findViewById(R.id.tbArmMastListener);
|
||||||
bDonate = (Button)findViewById(R.id.bDonate);
|
bDonate = (Button)findViewById(R.id.bDonate);
|
||||||
|
tvContactNotice = (TextView) findViewById(R.id.tvContactNotice);
|
||||||
|
|
||||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))
|
if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))
|
||||||
bDonate.setVisibility(View.VISIBLE);
|
bDonate.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
// Make links clickable
|
||||||
|
tvContactNotice.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
toggleService.setChecked(AutomationService.isMyServiceRunning(this));
|
toggleService.setChecked(AutomationService.isMyServiceRunning(this));
|
||||||
toggleService.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
toggleService.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||||
{
|
{
|
||||||
@@ -117,9 +128,9 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
String privacyPolicyUrl = "https://server47.de/donate";
|
String donationUrl = "https://server47.de/donate";
|
||||||
|
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(privacyPolicyUrl));
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(donationUrl));
|
||||||
startActivity(browserIntent);
|
startActivity(browserIntent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -270,9 +281,14 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
activityMainScreenInstance.tvMainScreenNotePermissions.setVisibility(View.GONE);
|
activityMainScreenInstance.tvMainScreenNotePermissions.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Miscellaneous.restrictedFeaturesConfigured())
|
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_fdroid) && Miscellaneous.restrictedFeaturesConfiguredFdroid())
|
||||||
{
|
{
|
||||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setText(R.string.settingsReferringToRestrictedFeatures);
|
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setText(R.string.settingsReferringToRestrictedFeaturesInFdroid);
|
||||||
|
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay) && Miscellaneous.restrictedFeaturesConfiguredGoogle())
|
||||||
|
{
|
||||||
|
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setText(R.string.settingsReferringToRestrictedFeaturesInGoogle);
|
||||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setVisibility(View.VISIBLE);
|
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -283,14 +299,6 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
|
|
||||||
if(Miscellaneous.googleToBlameForLocation(true))
|
if(Miscellaneous.googleToBlameForLocation(true))
|
||||||
{
|
{
|
||||||
// Intent intent = new Intent(AutomationService.this, ActivityDisplayLongMessage.class);
|
|
||||||
// intent.putExtra("longMessage", getResources().getString(R.string.locationEngineDisabledLong));
|
|
||||||
// PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0);
|
|
||||||
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
|
|
||||||
// Miscellaneous.createDismissableNotificationWithDelay(2200, getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi);
|
|
||||||
// else
|
|
||||||
// Miscellaneous.createDismissableNotification(getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi);
|
|
||||||
|
|
||||||
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setText(R.string.locationEngineDisabledShort);
|
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setText(R.string.locationEngineDisabledShort);
|
||||||
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setVisibility(View.VISIBLE);
|
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setVisibility(View.VISIBLE);
|
||||||
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setOnClickListener(new OnClickListener()
|
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setOnClickListener(new OnClickListener()
|
||||||
@@ -315,8 +323,7 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
uiUpdateRunning = true;
|
uiUpdateRunning = true;
|
||||||
activityMainScreenInstance.toggleService.setChecked(true);
|
activityMainScreenInstance.toggleService.setChecked(true);
|
||||||
uiUpdateRunning = false;
|
uiUpdateRunning = false;
|
||||||
// if(activityMainScreenInstance.hasWindowFocus())
|
|
||||||
// {
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PointOfInterest activePoi = PointOfInterest.getActivePoi();
|
PointOfInterest activePoi = PointOfInterest.getActivePoi();
|
||||||
@@ -433,7 +440,7 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
else
|
else
|
||||||
activityMainScreenInstance.checkForNews();
|
activityMainScreenInstance.checkForNews();
|
||||||
|
|
||||||
if(BuildConfig.FLAVOR.equals("apkFlavor") && Settings.automaticUpdateCheck)
|
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk) && Settings.automaticUpdateCheck)
|
||||||
{
|
{
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
if (Settings.lastUpdateCheck == Settings.default_lastUpdateCheck || now.getTimeInMillis() >= Settings.lastUpdateCheck + (long)(Settings.updateCheckFrequencyDays * 24 * 60 * 60 * 1000))
|
if (Settings.lastUpdateCheck == Settings.default_lastUpdateCheck || now.getTimeInMillis() >= Settings.lastUpdateCheck + (long)(Settings.updateCheckFrequencyDays * 24 * 60 * 60 * 1000))
|
||||||
@@ -525,15 +532,30 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
{
|
{
|
||||||
if (Rule.getRuleCollection().size() > 0)
|
if (Rule.getRuleCollection().size() > 0)
|
||||||
{
|
{
|
||||||
|
if(Rule.getAmountOfActivatedRules() == 0)
|
||||||
|
{
|
||||||
|
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStartNoActivatedRules), Toast.LENGTH_LONG).show();
|
||||||
|
activityMainScreenInstance.toggleService.setChecked(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 34 && !ActivityPermissions.havePermission(Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE, context))
|
||||||
|
{
|
||||||
|
Toast.makeText(context, context.getResources().getString(R.string.permissionForegroundServiceTypeSpecialUseRequired), Toast.LENGTH_LONG).show();
|
||||||
|
activityMainScreenInstance.toggleService.setChecked(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!AutomationService.isMyServiceRunning(context))
|
if (!AutomationService.isMyServiceRunning(context))
|
||||||
{
|
{
|
||||||
// if(myServiceIntent == null) //do we need that line?????
|
|
||||||
myServiceIntent = new Intent(context, AutomationService.class);
|
myServiceIntent = new Intent(context, AutomationService.class);
|
||||||
myServiceIntent.putExtra("startAtBoot", startAtBoot);
|
myServiceIntent.putExtra("startAtBoot", startAtBoot);
|
||||||
context.startService(myServiceIntent);
|
context.startService(myServiceIntent);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
Miscellaneous.logEvent("w", "Service", context.getResources().getString(R.string.logServiceAlreadyRunning), 3);
|
Miscellaneous.logEvent("w", "Service", context.getResources().getString(R.string.logServiceAlreadyRunning), 3);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStart), Toast.LENGTH_LONG).show();
|
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStart), Toast.LENGTH_LONG).show();
|
||||||
activityMainScreenInstance.toggleService.setChecked(false);
|
activityMainScreenInstance.toggleService.setChecked(false);
|
||||||
@@ -570,6 +592,7 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
toggleService.setChecked(AutomationService.isMyServiceRunning(this));
|
toggleService.setChecked(AutomationService.isMyServiceRunning(this));
|
||||||
ActivityMainScreen.updateMainScreen();
|
ActivityMainScreen.updateMainScreen();
|
||||||
|
|
||||||
@@ -580,7 +603,7 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
Miscellaneous.messageBox(getResources().getString(R.string.app_name), getResources().getString(R.string.android9RecordAudioNotice) + " " + getResources().getString(R.string.messageNotShownAgain), ActivityMainScreen.this).show();
|
Miscellaneous.messageBox(getResources().getString(R.string.app_name), getResources().getString(R.string.android9RecordAudioNotice) + " " + getResources().getString(R.string.messageNotShownAgain), ActivityMainScreen.this).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= 29 && !Settings.noticeAndroid10WifiShown && Rule.isAnyRuleUsing(Action.Action_Enum.setWifi))
|
if(Miscellaneous.getTargetSDK(ActivityMainScreen.this) >= 29 && !Settings.noticeAndroid10WifiShown && Rule.isAnyRuleUsing(Action.Action_Enum.setWifi))
|
||||||
{
|
{
|
||||||
Settings.noticeAndroid10WifiShown = true;
|
Settings.noticeAndroid10WifiShown = true;
|
||||||
Settings.writeSettings(ActivityMainScreen.this);
|
Settings.writeSettings(ActivityMainScreen.this);
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ package com.jens.automation2;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.TabActivity;
|
import android.app.TabActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.nfc.NfcAdapter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
|
|
||||||
import com.jens.automation2.receivers.NfcReceiver;
|
import com.jens.automation2.receivers.NfcReceiver;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public class ActivityMainTabLayout extends TabActivity
|
public class ActivityMainTabLayout extends TabActivity
|
||||||
@@ -17,8 +23,9 @@ public class ActivityMainTabLayout extends TabActivity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Settings.readFromPersistentStorage(ActivityMainTabLayout.this);
|
Settings.readFromPersistentStorage(ActivityMainTabLayout.this);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
|
||||||
if(Settings.tabsPlacement == 1)
|
if(Settings.tabsPlacement == 1)
|
||||||
setContentView(R.layout.main_tab_layout_tabs_at_bottom);
|
setContentView(R.layout.main_tab_layout_tabs_at_bottom);
|
||||||
@@ -55,21 +62,24 @@ public class ActivityMainTabLayout extends TabActivity
|
|||||||
tabHost.setCurrentTab(Settings.startScreen);
|
tabHost.setCurrentTab(Settings.startScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
// Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onResume().", 5);
|
// Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onResume().", 5);
|
||||||
NfcReceiver.checkIntentForNFC(this, getIntent());
|
if(!(getIntent().getAction() == null || getIntent().getAction().isEmpty()) && getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED))
|
||||||
// NfcReceiver.checkIntentForNFC(this, new Intent(this.getApplicationContext(), this.getClass()));
|
{
|
||||||
|
NfcReceiver.checkIntentForNFC(this, getIntent());
|
||||||
|
moveTaskToBack(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent)
|
protected void onNewIntent(Intent intent)
|
||||||
{
|
{
|
||||||
// Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onNewIntent().", 5);
|
// Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onNewIntent().", 5);
|
||||||
// setIntent(intent);
|
|
||||||
NfcReceiver.checkIntentForNFC(this, intent);
|
NfcReceiver.checkIntentForNFC(this, intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,8 @@ public class ActivityManageActionBrightnessSetting extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
setContentView(R.layout.activity_manage_action_brightness_settings);
|
setContentView(R.layout.activity_manage_action_brightness_settings);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
chkAutoBrightness = (CheckBox)findViewById(R.id.chkAutoBrightness);
|
chkAutoBrightness = (CheckBox)findViewById(R.id.chkAutoBrightness);
|
||||||
|
|||||||
@@ -259,6 +259,8 @@ public class ActivityManageActionCloseNotification extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_close_notification);
|
setContentView(R.layout.activity_manage_action_close_notification);
|
||||||
|
|
||||||
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public class ActivityManageActionControlMedia extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_control_media);
|
setContentView(R.layout.activity_manage_action_control_media);
|
||||||
|
|
||||||
rbMediaPlayPause = (RadioButton)findViewById(R.id.rbMediaPlayPause);
|
rbMediaPlayPause = (RadioButton)findViewById(R.id.rbMediaPlayPause);
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class ActivityManageActionCopyToClipboard extends Activity
|
||||||
|
{
|
||||||
|
private Button bSaveCopyToClipboard;
|
||||||
|
private EditText etCopyToClipboard;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
this.setContentView(R.layout.activity_manage_action_copy_to_clipboard);
|
||||||
|
|
||||||
|
bSaveCopyToClipboard = (Button) findViewById(R.id.bSaveCopyToClipboard);
|
||||||
|
etCopyToClipboard = (EditText)findViewById(R.id.etCopyToClipboard);
|
||||||
|
|
||||||
|
bSaveCopyToClipboard.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
if(StringUtils.isEmpty(etCopyToClipboard.getText().toString()))
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionCopyToClipboard.this, getResources().getString(R.string.enterText), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, etCopyToClipboard.getText().toString());
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
String text = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2);
|
||||||
|
etCopyToClipboard.setText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@ public class ActivityManageActionCreateNotification extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_create_notification);
|
setContentView(R.layout.activity_manage_action_create_notification);
|
||||||
|
|
||||||
etNotificationTitle = (EditText) findViewById(R.id.etNotificationTitle);
|
etNotificationTitle = (EditText) findViewById(R.id.etNotificationTitle);
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class ActivityManageActionLocationService extends Activity
|
||||||
|
{
|
||||||
|
RadioButton rbActionLocationServiceOff, rbActionLocationServiceSensorsOnly, rbActionLocationServiceBatterySaving, rbActionLocationServiceHighAccuracy;
|
||||||
|
Button bActionSetLocationServiceSave;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
setContentView(R.layout.activity_manage_action_location_service);
|
||||||
|
|
||||||
|
rbActionLocationServiceOff = (RadioButton) findViewById(R.id.rbActionLocationServiceOff);
|
||||||
|
rbActionLocationServiceSensorsOnly = (RadioButton)findViewById(R.id.rbActionLocationServiceSensorsOnly);
|
||||||
|
rbActionLocationServiceBatterySaving = (RadioButton)findViewById(R.id.rbActionLocationServiceBatterySaving);
|
||||||
|
rbActionLocationServiceHighAccuracy = (RadioButton)findViewById(R.id.rbActionLocationServiceHighAccuracy);
|
||||||
|
bActionSetLocationServiceSave = (Button) findViewById(R.id.bActionSetLocationServiceSave);
|
||||||
|
|
||||||
|
Intent input = getIntent();
|
||||||
|
|
||||||
|
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
String[] params = input.getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
|
||||||
|
int desiredState = Integer.parseInt(params[0]);
|
||||||
|
|
||||||
|
switch(desiredState)
|
||||||
|
{
|
||||||
|
case Settings.Secure.LOCATION_MODE_OFF:
|
||||||
|
rbActionLocationServiceOff.setChecked(true);
|
||||||
|
break;
|
||||||
|
case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
|
||||||
|
rbActionLocationServiceSensorsOnly.setChecked(true);
|
||||||
|
break;
|
||||||
|
case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
|
||||||
|
rbActionLocationServiceBatterySaving.setChecked(true);
|
||||||
|
break;
|
||||||
|
case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
|
||||||
|
rbActionLocationServiceHighAccuracy.setChecked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bActionSetLocationServiceSave.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
if(rbActionLocationServiceOff.isChecked())
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_OFF));
|
||||||
|
else if(rbActionLocationServiceSensorsOnly.isChecked())
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_SENSORS_ONLY));
|
||||||
|
else if(rbActionLocationServiceBatterySaving.isChecked())
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_BATTERY_SAVING));
|
||||||
|
else
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY));
|
||||||
|
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class ActivityManageActionMakePhoneCall extends Activity
|
||||||
|
{
|
||||||
|
EditText etTargetPhoneNumber;
|
||||||
|
Button bActionMakePhoneCallSave;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
setContentView(R.layout.activity_manage_action_make_phone_call);
|
||||||
|
|
||||||
|
etTargetPhoneNumber = (EditText)findViewById(R.id.etTargetPhoneNumber);
|
||||||
|
bActionMakePhoneCallSave = (Button) findViewById(R.id.bActionMakePhoneCallSave);
|
||||||
|
|
||||||
|
Intent input = getIntent();
|
||||||
|
/*if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
|
||||||
|
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||||
|
*/
|
||||||
|
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
|
etTargetPhoneNumber.setText(input.getStringExtra(ActivityManageRule.intentNameActionParameter2));
|
||||||
|
|
||||||
|
bActionMakePhoneCallSave.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
if(!StringUtils.isEmpty(etTargetPhoneNumber.getText()))
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter1, false);
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, etTargetPhoneNumber.getText().toString());
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityManageActionMakePhoneCall.this, getResources().getText(R.string.enterPhoneNumber), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,8 @@ public class ActivityManageActionPlaySound extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_play_sound);
|
setContentView(R.layout.activity_manage_action_play_sound);
|
||||||
|
|
||||||
chkPlaySoundAlwaysPlay = (CheckBox)findViewById(R.id.chkPlaySoundAlwaysPlay);
|
chkPlaySoundAlwaysPlay = (CheckBox)findViewById(R.id.chkPlaySoundAlwaysPlay);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ public class ActivityManageActionRunExecutable extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_run_executable);
|
setContentView(R.layout.activity_manage_action_run_executable);
|
||||||
|
|
||||||
chkRunExecAsRoot = (CheckBox)findViewById(R.id.chkRunExecAsRoot);
|
chkRunExecAsRoot = (CheckBox)findViewById(R.id.chkRunExecAsRoot);
|
||||||
@@ -57,6 +59,15 @@ public class ActivityManageActionRunExecutable extends Activity
|
|||||||
saveExecSettings();
|
saveExecSettings();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
String[] parts = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
|
||||||
|
etRunExecutablePath.setText(parts[0]);
|
||||||
|
|
||||||
|
if(parts.length > 1)
|
||||||
|
etRunExecutableParameters.setText(parts[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveExecSettings()
|
void saveExecSettings()
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ public class ActivityManageActionSendBroadcast extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_send_broadcast);
|
setContentView(R.layout.activity_manage_action_send_broadcast);
|
||||||
|
|
||||||
etBroadcastToSend = (EditText)findViewById(R.id.etBroadcastToSend);
|
etBroadcastToSend = (EditText)findViewById(R.id.etBroadcastToSend);
|
||||||
@@ -225,7 +227,7 @@ public class ActivityManageActionSendBroadcast extends Activity
|
|||||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||||
{
|
{
|
||||||
if(supportedIntentTypes[arg2].equals("int") || supportedIntentTypes[arg2].equals("long") || supportedIntentTypes[arg2].equals("short"))
|
if(supportedIntentTypes[arg2].equals("int") || supportedIntentTypes[arg2].equals("long") || supportedIntentTypes[arg2].equals("short"))
|
||||||
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER);
|
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||||
else if(supportedIntentTypes[arg2].equals("double") || supportedIntentTypes[arg2].equals("float"))
|
else if(supportedIntentTypes[arg2].equals("double") || supportedIntentTypes[arg2].equals("float"))
|
||||||
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||||
else
|
else
|
||||||
@@ -235,8 +237,6 @@ public class ActivityManageActionSendBroadcast extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> arg0)
|
public void onNothingSelected(AdapterView<?> arg0)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,26 +9,37 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.jens.automation2.Action.Action_Enum;
|
import com.jens.automation2.Action.Action_Enum;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
public class ActivityManageActionSendTextMessage extends Activity
|
public class ActivityManageActionSendTextMessage extends Activity
|
||||||
{
|
{
|
||||||
Button bSaveSendTextMessage, bImportNumberFromContacts;
|
Button bSaveSendTextMessage, bImportNumberFromContacts, bMmsAttachment;
|
||||||
EditText etPhoneNumber, etSendTextMessage;
|
EditText etPhoneNumber, etSendTextMessage;
|
||||||
|
RadioButton rbMessageTypeSms, rbMessageTypeMms;
|
||||||
|
TextView tvSendMmsFileAttachment;
|
||||||
|
|
||||||
protected final static int requestCodeForContactsPermissions = 9876;
|
protected final static int requestCodeForContactsPermissions = 9876;
|
||||||
protected final static int requestCodeGetContact = 3235;
|
protected final static int requestCodeGetContact = 3235;
|
||||||
|
protected final static int requestCodeGetMMSattachment = 3236;
|
||||||
// private String existingUrl = "";
|
|
||||||
|
public static final String messageTypeSms = "sms";
|
||||||
|
public static final String messageTypeMms = "mms";
|
||||||
|
|
||||||
public static boolean edit = false;
|
public static boolean edit = false;
|
||||||
public static Action resultingAction = null;
|
public static Action resultingAction = null;
|
||||||
@@ -37,12 +48,18 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
this.setContentView(R.layout.activity_manage_action_send_textmessage);
|
this.setContentView(R.layout.activity_manage_action_send_textmessage);
|
||||||
|
|
||||||
etSendTextMessage = (EditText)findViewById(R.id.etSendTextMessage);
|
etSendTextMessage = (EditText)findViewById(R.id.etSendTextMessage);
|
||||||
etPhoneNumber = (EditText)findViewById(R.id.etPhoneNumber);
|
etPhoneNumber = (EditText)findViewById(R.id.etPhoneNumber);
|
||||||
bSaveSendTextMessage = (Button)findViewById(R.id.bSaveSendTextMessage);
|
bSaveSendTextMessage = (Button)findViewById(R.id.bSaveSendTextMessage);
|
||||||
bImportNumberFromContacts = (Button)findViewById(R.id.bImportNumberFromContacts);
|
bImportNumberFromContacts = (Button)findViewById(R.id.bImportNumberFromContacts);
|
||||||
|
rbMessageTypeSms = (RadioButton)findViewById(R.id.rbMessageTypeSms);
|
||||||
|
rbMessageTypeMms = (RadioButton) findViewById(R.id.rbMessageTypeMms);
|
||||||
|
bMmsAttachment = (Button)findViewById(R.id.bMmsAttachment);
|
||||||
|
tvSendMmsFileAttachment = (TextView)findViewById(R.id.tvSendMmsFileAttachment);
|
||||||
|
|
||||||
bSaveSendTextMessage.setOnClickListener(new OnClickListener()
|
bSaveSendTextMessage.setOnClickListener(new OnClickListener()
|
||||||
{
|
{
|
||||||
@@ -51,13 +68,29 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
{
|
{
|
||||||
if(etSendTextMessage.getText().toString().length() > 0 && etPhoneNumber.getText().toString().length() > 0)
|
if(etSendTextMessage.getText().toString().length() > 0 && etPhoneNumber.getText().toString().length() > 0)
|
||||||
{
|
{
|
||||||
if(resultingAction == null)
|
if(rbMessageTypeMms.isChecked() && StringUtils.isEmpty(tvSendMmsFileAttachment.getText().toString()))
|
||||||
|
Toast.makeText(getBaseContext(), getResources().getString(R.string.chooseFile), Toast.LENGTH_LONG).show();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
resultingAction = new Action();
|
if (resultingAction == null)
|
||||||
resultingAction.setAction(Action_Enum.sendTextMessage);
|
{
|
||||||
resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString());
|
resultingAction = new Action();
|
||||||
|
resultingAction.setAction(Action_Enum.sendTextMessage);
|
||||||
|
String messageType = null;
|
||||||
|
String path = "";
|
||||||
|
|
||||||
|
if(rbMessageTypeSms.isChecked())
|
||||||
|
messageType = messageTypeSms;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageType = messageTypeMms;
|
||||||
|
path = Actions.smsSeparator + tvSendMmsFileAttachment.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString() + Actions.smsSeparator + messageType + path);
|
||||||
|
}
|
||||||
|
backToRuleManager();
|
||||||
}
|
}
|
||||||
backToRuleManager();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Toast.makeText(getBaseContext(), getResources().getString(R.string.enterPhoneNumberAndText), Toast.LENGTH_LONG).show();
|
Toast.makeText(getBaseContext(), getResources().getString(R.string.enterPhoneNumberAndText), Toast.LENGTH_LONG).show();
|
||||||
@@ -78,6 +111,28 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RadioButton.OnCheckedChangeListener checkedChangedListener = new RadioButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b)
|
||||||
|
{
|
||||||
|
bMmsAttachment.setEnabled(rbMessageTypeMms.isChecked());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
rbMessageTypeSms.setOnCheckedChangeListener(checkedChangedListener);
|
||||||
|
rbMessageTypeMms.setOnCheckedChangeListener(checkedChangedListener);
|
||||||
|
|
||||||
|
bMmsAttachment.setOnClickListener(new OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
Intent chooseFileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
chooseFileIntent.setType("*/*");
|
||||||
|
chooseFileIntent = Intent.createChooser(chooseFileIntent, getResources().getString(R.string.chooseFile));
|
||||||
|
startActivityForResult(chooseFileIntent, requestCodeGetMMSattachment);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ActivityManageActionSendTextMessage.edit = getIntent().getBooleanExtra("edit", false);
|
ActivityManageActionSendTextMessage.edit = getIntent().getBooleanExtra("edit", false);
|
||||||
if(edit)
|
if(edit)
|
||||||
{
|
{
|
||||||
@@ -144,10 +199,10 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
{
|
{
|
||||||
if(requestCode == requestCodeGetContact)
|
if(resultCode == Activity.RESULT_OK)
|
||||||
{
|
{
|
||||||
if(resultCode == Activity.RESULT_OK)
|
if(requestCode == requestCodeGetContact)
|
||||||
{
|
{
|
||||||
String phoneNo = null;
|
String phoneNo = null;
|
||||||
String name = null;
|
String name = null;
|
||||||
|
|
||||||
@@ -165,6 +220,12 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
etPhoneNumber.setText(phoneNo);
|
etPhoneNumber.setText(phoneNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (requestCode == requestCodeGetMMSattachment)
|
||||||
|
{
|
||||||
|
Uri fileUri = data.getData();
|
||||||
|
String filePath = fileUri.getPath();
|
||||||
|
tvSendMmsFileAttachment.setText(filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//super.onActivityResult(requestCode, resultCode, data);
|
//super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class ActivityManageActionSetSystemSetting extends Activity
|
||||||
|
{
|
||||||
|
Spinner spinnerSettingTarget, spinnerSettingDataType;
|
||||||
|
EditText etSettingName, etSettingValue;
|
||||||
|
Button bSaveSetSystemSetting;
|
||||||
|
TextView tvSetSystemSettingExamples, tvSetSystemSettingNoticeWriteSecureSettings;
|
||||||
|
|
||||||
|
ArrayAdapter<String> settingTargetSpinnerAdapter, settingDataTypeSpinnerAdapter;
|
||||||
|
protected final static String[] targets = { "Global", "System", "Secure" };
|
||||||
|
protected final static String[] dataTypes = { "String", "Long", "Int", "Float" };
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
this.setContentView(R.layout.activity_manage_action_set_system_setting);
|
||||||
|
|
||||||
|
spinnerSettingTarget = (Spinner) findViewById(R.id.spinnerSettingTarget);
|
||||||
|
spinnerSettingDataType = (Spinner) findViewById(R.id.spinnerSettingDataType);
|
||||||
|
etSettingName = (EditText)findViewById(R.id.etSettingName);
|
||||||
|
etSettingValue = (EditText)findViewById(R.id.etSettingValue);
|
||||||
|
bSaveSetSystemSetting = (Button)findViewById(R.id.bSaveSetSystemSetting);
|
||||||
|
tvSetSystemSettingExamples = (TextView)findViewById(R.id.tvSetSystemSettingExamples);
|
||||||
|
tvSetSystemSettingNoticeWriteSecureSettings = (TextView)findViewById(R.id.tvSetSystemSettingNoticeWriteSecureSettings);
|
||||||
|
|
||||||
|
settingTargetSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, targets);
|
||||||
|
spinnerSettingTarget.setAdapter(settingTargetSpinnerAdapter);
|
||||||
|
settingTargetSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
settingDataTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, dataTypes);
|
||||||
|
spinnerSettingDataType.setAdapter(settingDataTypeSpinnerAdapter);
|
||||||
|
settingDataTypeSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
tvSetSystemSettingExamples.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
|
if(ActivityPermissions.havePermission(Manifest.permission.WRITE_SECURE_SETTINGS, ActivityManageActionSetSystemSetting.this))
|
||||||
|
tvSetSystemSettingNoticeWriteSecureSettings.setVisibility(View.GONE);
|
||||||
|
else
|
||||||
|
tvSetSystemSettingNoticeWriteSecureSettings.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
// Make links clickable
|
||||||
|
tvSetSystemSettingNoticeWriteSecureSettings.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
|
spinnerSettingDataType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
|
||||||
|
{
|
||||||
|
if(dataTypes[i].equalsIgnoreCase("String"))
|
||||||
|
etSettingValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
else if(dataTypes[i].equalsIgnoreCase("Float"))
|
||||||
|
etSettingValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||||
|
else
|
||||||
|
etSettingValue.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> adapterView)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bSaveSetSystemSetting.setOnClickListener(new OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
if(etSettingName.getText().toString().isEmpty())
|
||||||
|
{
|
||||||
|
Toast.makeText(getBaseContext(), getResources().getString(R.string.enterAname), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(etSettingValue.getText().toString().isEmpty())
|
||||||
|
{
|
||||||
|
Toast.makeText(getBaseContext(), getResources().getString(R.string.enterAvalue), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String selectedDataType = dataTypes[spinnerSettingDataType.getSelectedItemPosition()];
|
||||||
|
if(
|
||||||
|
selectedDataType.equalsIgnoreCase("Int")
|
||||||
|
||
|
||||||
|
selectedDataType.equalsIgnoreCase("Long")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if(!Miscellaneous.isNumeric(etSettingValue.getText().toString()) || Miscellaneous.isNonDecimalNumber(etSettingValue.getText().toString()))
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionSetSystemSetting.this, getResources().getString(R.string.enter_a_number), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(selectedDataType.equalsIgnoreCase("Float"))
|
||||||
|
{
|
||||||
|
if(!Miscellaneous.isNumeric(etSettingValue.getText().toString()))
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionSetSystemSetting.this, getResources().getString(R.string.enter_a_number), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent returnIntent = new Intent();
|
||||||
|
|
||||||
|
String param2Data = targets[spinnerSettingTarget.getSelectedItemPosition()] + Action.actionParameter2Split + dataTypes[spinnerSettingDataType.getSelectedItemPosition()] + Action.actionParameter2Split + etSettingName.getText().toString() + Action.actionParameter2Split + etSettingValue.getText().toString();
|
||||||
|
|
||||||
|
returnIntent.putExtra(ActivityManageRule.intentNameActionParameter1, false);
|
||||||
|
returnIntent.putExtra(ActivityManageRule.intentNameActionParameter2, param2Data);
|
||||||
|
|
||||||
|
setResult(RESULT_OK, returnIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
// dataType, setting name, setting value
|
||||||
|
String[] components = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split, -1);
|
||||||
|
|
||||||
|
if(components.length == 4)
|
||||||
|
{
|
||||||
|
int positionTarget = Miscellaneous.arraySearchIndexOf(targets, components[0], false, true);
|
||||||
|
int positionDataType = Miscellaneous.arraySearchIndexOf(dataTypes, components[1], false, true);
|
||||||
|
|
||||||
|
if(positionDataType >= 0)
|
||||||
|
{
|
||||||
|
spinnerSettingTarget.setSelection(positionTarget);
|
||||||
|
spinnerSettingDataType.setSelection(positionDataType);
|
||||||
|
etSettingName.setText(components[2]);
|
||||||
|
etSettingValue.setText(components[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int position = Miscellaneous.arraySearchIndexOf(dataTypes, components[0], false, true);
|
||||||
|
|
||||||
|
if (position >= 0)
|
||||||
|
{
|
||||||
|
spinnerSettingDataType.setSelection(position);
|
||||||
|
etSettingName.setText(components[1]);
|
||||||
|
etSettingValue.setText(components[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateListView()
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "ListView", "Attempting to update spinnerSettingDataType", 4);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(spinnerSettingDataType.getAdapter() == null)
|
||||||
|
spinnerSettingDataType.setAdapter(settingDataTypeSpinnerAdapter);
|
||||||
|
|
||||||
|
settingDataTypeSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
catch(NullPointerException e)
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
//import static com.jens.automation2.ActivityManageActionTriggerUrl.edit;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.jens.automation2.Action.Action_Enum;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class ActivityManageActionSetVariable extends Activity
|
||||||
|
{
|
||||||
|
private Button bSaveVariable;
|
||||||
|
private EditText etVariableSetKey, etVariableSetValue;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
this.setContentView(R.layout.activity_manage_action_set_variable);
|
||||||
|
|
||||||
|
etVariableSetKey = (EditText)findViewById(R.id.etVariableSetKey);
|
||||||
|
etVariableSetValue = (EditText)findViewById(R.id.etVariableSetValue);
|
||||||
|
bSaveVariable = (Button)findViewById(R.id.bSaveVariable);
|
||||||
|
bSaveVariable.setOnClickListener(new OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
if(StringUtils.isEmpty(etVariableSetKey.getText().toString()))
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionSetVariable.this, getResources().getString(R.string.enterVariableKey), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
|
||||||
|
if(StringUtils.isEmpty(etVariableSetValue.getText().toString()))
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, etVariableSetKey.getText().toString());
|
||||||
|
else
|
||||||
|
response.putExtra(ActivityManageRule.intentNameActionParameter2, etVariableSetKey.getText().toString() + Action.actionParameter2Split + etVariableSetValue.getText().toString());
|
||||||
|
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
String[] input = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
|
||||||
|
etVariableSetKey.setText(input[0]);
|
||||||
|
if(input.length > 1)
|
||||||
|
etVariableSetValue.setText(input[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@ public class ActivityManageActionSpeakText extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
this.setContentView(R.layout.activity_manage_action_speak_text);
|
this.setContentView(R.layout.activity_manage_action_speak_text);
|
||||||
|
|
||||||
etSpeakText = (EditText)findViewById(R.id.etTextToSpeak);
|
etSpeakText = (EditText)findViewById(R.id.etTextToSpeak);
|
||||||
@@ -31,7 +33,7 @@ public class ActivityManageActionSpeakText extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
if(etSpeakText.getText().toString().length()>0)
|
if(!etSpeakText.getText().toString().isEmpty())
|
||||||
{
|
{
|
||||||
if(resultingAction == null)
|
if(resultingAction == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.widget.CompoundButton;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -48,16 +49,19 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ListView lvIntentPairs;
|
ListView lvIntentPairs;
|
||||||
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath;
|
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath, etClassName;
|
||||||
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity, showStartProgramExamples;
|
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity, showStartProgramExamples;
|
||||||
Spinner spinnerParameterType;
|
Spinner spinnerParameterType;
|
||||||
boolean edit = false;
|
RadioGroup rgAppStartupType;
|
||||||
|
// boolean edit = false;
|
||||||
ProgressDialog progressDialog = null;
|
ProgressDialog progressDialog = null;
|
||||||
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast;
|
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast, rbStartAppByService, rbStartAppByForegroundService;
|
||||||
|
|
||||||
final String urlShowExamples = "https://server47.de/automation/examples_startProgram.html";
|
final String urlShowExamples = "https://server47.de/automation/examples.html";
|
||||||
final static String startByActivityString = "0";
|
public final static String startByActivityString = "0";
|
||||||
final static String startByBroadcastString = "1";
|
public final static String startByBroadcastString = "1";
|
||||||
|
public final static String startByServiceString = "2";
|
||||||
|
public final static String startByForegroundServiceString = "3";
|
||||||
|
|
||||||
final static int requestCodeForRequestQueryAllPackagesPermission = 4711;
|
final static int requestCodeForRequestQueryAllPackagesPermission = 4711;
|
||||||
|
|
||||||
@@ -65,11 +69,14 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_start_activity);
|
setContentView(R.layout.activity_manage_action_start_activity);
|
||||||
|
|
||||||
lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs);
|
lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs);
|
||||||
etParameterName = (EditText)findViewById(R.id.etParameterName);
|
etParameterName = (EditText)findViewById(R.id.etParameterName);
|
||||||
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
||||||
|
etClassName = (EditText)findViewById(R.id.etClassName);
|
||||||
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
||||||
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
|
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
|
||||||
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
|
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
|
||||||
@@ -81,13 +88,15 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
showStartProgramExamples = (Button)findViewById(R.id.showStartProgramExamples);
|
showStartProgramExamples = (Button)findViewById(R.id.showStartProgramExamples);
|
||||||
rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity);
|
rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity);
|
||||||
rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast);
|
rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast);
|
||||||
|
rbStartAppByService = (RadioButton)findViewById(R.id.rbStartAppByService);
|
||||||
|
rbStartAppByForegroundService = (RadioButton)findViewById(R.id.rbStartAppByForegroundService);
|
||||||
|
rgAppStartupType = (RadioGroup)findViewById(R.id.rgAppStartupType);
|
||||||
|
|
||||||
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
|
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
|
||||||
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
|
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
|
||||||
intentTypeSpinnerAdapter.notifyDataSetChanged();
|
intentTypeSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
|
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
|
||||||
|
|
||||||
bSelectApp.setOnClickListener(new OnClickListener()
|
bSelectApp.setOnClickListener(new OnClickListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -223,22 +232,32 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
|
|
||||||
String parameter2 = "";
|
String parameter2 = "";
|
||||||
|
|
||||||
if (rbStartAppSelectByActivity.isChecked())
|
/*
|
||||||
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
|
0 = packageName
|
||||||
else {
|
1 = className
|
||||||
if (etPackageName.getText().toString() != null && etPackageName.getText().toString().length() > 0)
|
2 = activityName/actionName
|
||||||
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
|
3 = startType
|
||||||
else
|
4 = parameters
|
||||||
parameter2 += Actions.dummyPackageString + ";" + etActivityOrActionPath.getText().toString();
|
*/
|
||||||
}
|
|
||||||
|
parameter2 += etPackageName.getText().toString()
|
||||||
|
+ Action.actionParameter2Split
|
||||||
|
+ etClassName.getText().toString()
|
||||||
|
+ Action.actionParameter2Split
|
||||||
|
+ etActivityOrActionPath.getText().toString()
|
||||||
|
+ Action.actionParameter2Split;
|
||||||
|
|
||||||
if (rbStartAppByActivity.isChecked())
|
if (rbStartAppByActivity.isChecked())
|
||||||
parameter2 += ";" + startByActivityString;
|
parameter2 += startByActivityString;
|
||||||
|
else if(rbStartAppByService.isChecked())
|
||||||
|
parameter2 += startByServiceString;
|
||||||
|
else if(rbStartAppByForegroundService.isChecked())
|
||||||
|
parameter2 += startByForegroundServiceString;
|
||||||
else
|
else
|
||||||
parameter2 += ";" + startByBroadcastString;
|
parameter2 += startByBroadcastString;
|
||||||
|
|
||||||
for (String s : intentPairList)
|
for (String s : intentPairList)
|
||||||
parameter2 += ";" + s;
|
parameter2 += Action.actionParameter2Split + s;
|
||||||
|
|
||||||
returnData.putExtra(ActivityManageRule.intentNameActionParameter2, parameter2);
|
returnData.putExtra(ActivityManageRule.intentNameActionParameter2, parameter2);
|
||||||
|
|
||||||
@@ -264,7 +283,7 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||||
{
|
{
|
||||||
if(supportedIntentTypes[arg2].equals("int") || supportedIntentTypes[arg2].equals("long") || supportedIntentTypes[arg2].equals("short"))
|
if(supportedIntentTypes[arg2].equals("int") || supportedIntentTypes[arg2].equals("long") || supportedIntentTypes[arg2].equals("short"))
|
||||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER);
|
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||||
else if(supportedIntentTypes[arg2].equals("double") || supportedIntentTypes[arg2].equals("float"))
|
else if(supportedIntentTypes[arg2].equals("double") || supportedIntentTypes[arg2].equals("float"))
|
||||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||||
else
|
else
|
||||||
@@ -274,8 +293,6 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> arg0)
|
public void onNothingSelected(AdapterView<?> arg0)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -285,7 +302,9 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||||
{
|
{
|
||||||
if(isChecked)
|
if(isChecked)
|
||||||
|
{
|
||||||
bSelectApp.setEnabled(isChecked);
|
bSelectApp.setEnabled(isChecked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -591,34 +610,36 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
rbStartAppSelectByActivity.setChecked(!selectionByAction);
|
rbStartAppSelectByActivity.setChecked(!selectionByAction);
|
||||||
rbStartAppSelectByAction.setChecked(selectionByAction);
|
rbStartAppSelectByAction.setChecked(selectionByAction);
|
||||||
|
|
||||||
String[] params = input.getStringExtra(ActivityManageRule.intentNameActionParameter2).split(";");
|
/*
|
||||||
|
0 = packageName
|
||||||
|
1 = className
|
||||||
|
2 = activityName/actionName
|
||||||
|
3 = startType
|
||||||
|
4 = parameters
|
||||||
|
*/
|
||||||
|
|
||||||
rbStartAppByActivity.setChecked(params[2].equals(startByActivityString));
|
try
|
||||||
rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString));
|
|
||||||
|
|
||||||
int startIndex = -1;
|
|
||||||
|
|
||||||
if(!selectionByAction)
|
|
||||||
{
|
{
|
||||||
|
String[] params;
|
||||||
|
String partsString = input.getStringExtra(ActivityManageRule.intentNameActionParameter2);
|
||||||
|
|
||||||
|
if(partsString.contains(Action.actionParameter2Split))
|
||||||
|
params = partsString.split(Action.actionParameter2Split, -1);
|
||||||
|
else
|
||||||
|
params = partsString.split(";", -1);
|
||||||
|
|
||||||
etPackageName.setText(params[0]);
|
etPackageName.setText(params[0]);
|
||||||
etActivityOrActionPath.setText(params[1]);
|
etClassName.setText(params[1]);
|
||||||
}
|
etActivityOrActionPath.setText(params[2]);
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!params[0].contains(Actions.dummyPackageString))
|
|
||||||
etPackageName.setText(params[0]);
|
|
||||||
|
|
||||||
etActivityOrActionPath.setText(params[1]);
|
rbStartAppByActivity.setChecked(params[3].equals(startByActivityString));
|
||||||
}
|
rbStartAppByBroadcast.setChecked(params[3].equals(startByBroadcastString));
|
||||||
|
rbStartAppByService.setChecked(params[3].equals(startByServiceString));
|
||||||
|
rbStartAppByForegroundService.setChecked(params[3].equals(startByForegroundServiceString));
|
||||||
|
|
||||||
if (params.length >= 3)
|
|
||||||
startIndex = 3;
|
|
||||||
|
|
||||||
if(startIndex > -1 && params.length > startIndex)
|
|
||||||
{
|
|
||||||
intentPairList.clear();
|
intentPairList.clear();
|
||||||
|
|
||||||
for(int i=startIndex; i<params.length; i++)
|
for(int i=4; i<params.length; i++)
|
||||||
{
|
{
|
||||||
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
||||||
lvIntentPairs.setVisibility(View.VISIBLE);
|
lvIntentPairs.setVisibility(View.VISIBLE);
|
||||||
@@ -628,6 +649,10 @@ public class ActivityManageActionStartActivity extends Activity
|
|||||||
|
|
||||||
updateIntentPairList();
|
updateIntentPairList();
|
||||||
}
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.errorLoadingValues), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIntentPairList()
|
private void updateIntentPairList()
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -13,32 +17,43 @@ import android.widget.CompoundButton;
|
|||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.RadioButton;
|
||||||
import android.widget.TableLayout;
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.jens.automation2.Action.Action_Enum;
|
import com.jens.automation2.Action.Action_Enum;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ActivityManageActionTriggerUrl extends Activity
|
public class ActivityManageActionTriggerUrl extends Activity
|
||||||
{
|
{
|
||||||
Button bSaveTriggerUrl;
|
Button bSaveTriggerUrl, bAddHttpParam;
|
||||||
EditText etTriggerUrl, etTriggerUrlUsername, etTriggerUrlPassword;
|
EditText etTriggerUrl, etTriggerUrlUsername, etTriggerUrlPassword, etParameterName, etParameterValue;
|
||||||
ListView lvTriggerUrlPostParameters;
|
ListView lvTriggerUrlPostParameters;
|
||||||
CheckBox chkTriggerUrlUseAuthentication;
|
CheckBox chkTriggerUrlUseAuthentication;
|
||||||
|
RadioButton rbTriggerUrlMethodGet, rbTriggerUrlMethodPost;
|
||||||
TableLayout tlTriggerUrlAuthentication;
|
TableLayout tlTriggerUrlAuthentication;
|
||||||
|
TextView tvHttpParameterExplanation;
|
||||||
|
ArrayAdapter<String> httpParametersAdapter;
|
||||||
|
|
||||||
|
private ArrayList<String> httpParamsList = new ArrayList<>();
|
||||||
ArrayAdapter<Map<String,String>> lvTriggerUrlPostParametersAdapter;
|
ArrayAdapter<Map<String,String>> lvTriggerUrlPostParametersAdapter;
|
||||||
|
|
||||||
// private String existingUrl = "";
|
public static final String methodGet = "GET";
|
||||||
|
public static final String methodPost = "POST";
|
||||||
public static boolean edit = false;
|
|
||||||
public static Action resultingAction = null;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
this.setContentView(R.layout.activity_manage_action_trigger_url);
|
this.setContentView(R.layout.activity_manage_action_trigger_url);
|
||||||
|
|
||||||
etTriggerUrl = (EditText)findViewById(R.id.etTriggerUrl);
|
etTriggerUrl = (EditText)findViewById(R.id.etTriggerUrl);
|
||||||
@@ -48,6 +63,35 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
lvTriggerUrlPostParameters = (ListView)findViewById(R.id.lvTriggerUrlPostParameters);
|
lvTriggerUrlPostParameters = (ListView)findViewById(R.id.lvTriggerUrlPostParameters);
|
||||||
tlTriggerUrlAuthentication = (TableLayout)findViewById(R.id.tlTriggerUrlAuthentication);
|
tlTriggerUrlAuthentication = (TableLayout)findViewById(R.id.tlTriggerUrlAuthentication);
|
||||||
bSaveTriggerUrl = (Button)findViewById(R.id.bSaveSpeakText);
|
bSaveTriggerUrl = (Button)findViewById(R.id.bSaveSpeakText);
|
||||||
|
rbTriggerUrlMethodGet = (RadioButton) findViewById(R.id.rbTriggerUrlMethodGet);
|
||||||
|
rbTriggerUrlMethodPost = (RadioButton) findViewById(R.id.rbTriggerUrlMethodPost);
|
||||||
|
etTriggerUrl = (EditText) findViewById(R.id.etTriggerUrl);
|
||||||
|
etParameterName = (EditText) findViewById(R.id.etParameterName);
|
||||||
|
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
||||||
|
bAddHttpParam = (Button)findViewById(R.id.bAddHttpParam);
|
||||||
|
tvHttpParameterExplanation = (TextView)findViewById(R.id.tvHttpParameterExplanation);
|
||||||
|
|
||||||
|
etParameterName.setEnabled(false);
|
||||||
|
etParameterValue.setEnabled(false);
|
||||||
|
bAddHttpParam.setEnabled(false);
|
||||||
|
|
||||||
|
rbTriggerUrlMethodPost.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
etParameterName.setEnabled(checked);
|
||||||
|
etParameterValue.setEnabled(checked);
|
||||||
|
bAddHttpParam.setEnabled(checked);
|
||||||
|
if(checked)
|
||||||
|
lvTriggerUrlPostParameters.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tvHttpParameterExplanation.setText(String.format(getResources().getString(R.string.httpParametersExplanation), Miscellaneous.httpMainData, Miscellaneous.doNoEncodingString));
|
||||||
|
|
||||||
|
httpParametersAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, httpParamsList);
|
||||||
|
|
||||||
bSaveTriggerUrl.setOnClickListener(new OnClickListener()
|
bSaveTriggerUrl.setOnClickListener(new OnClickListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -55,44 +99,64 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
{
|
{
|
||||||
if(etTriggerUrl.getText().toString().length() > 0)
|
if(etTriggerUrl.getText().toString().length() > 0)
|
||||||
{
|
{
|
||||||
if(resultingAction == null)
|
Intent returnIntent = new Intent();
|
||||||
{
|
|
||||||
resultingAction = new Action();
|
returnIntent.putExtra(ActivityManageRule.intentNameActionParameter1, chkTriggerUrlUseAuthentication.isChecked());
|
||||||
resultingAction.setAction(Action_Enum.triggerUrl);
|
|
||||||
resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked());
|
String username = etTriggerUrlUsername.getText().toString();
|
||||||
|
String password = etTriggerUrlPassword.getText().toString();
|
||||||
String username = etTriggerUrlUsername.getText().toString();
|
|
||||||
String password = etTriggerUrlPassword.getText().toString();
|
if(username == null)
|
||||||
|
username = "";
|
||||||
if(username == null)
|
|
||||||
username = "";
|
if(password == null)
|
||||||
|
password = "";
|
||||||
if(password == null)
|
|
||||||
password = "";
|
String method = methodGet;
|
||||||
|
if(rbTriggerUrlMethodPost.isChecked())
|
||||||
ActivityManageActionTriggerUrl.resultingAction.setParameter2(
|
method = methodPost;
|
||||||
username + ";" +
|
|
||||||
password + ";" +
|
String httpParams = "";
|
||||||
etTriggerUrl.getText().toString().trim()
|
for (String s : httpParamsList)
|
||||||
);
|
httpParams += Action.actionParameters2SeparatorOuter + s;
|
||||||
}
|
if(httpParams.length() > 0)
|
||||||
backToRuleManager();
|
httpParams = httpParams.substring(Action.actionParameters2SeparatorOuter.length());
|
||||||
|
|
||||||
|
returnIntent.putExtra(ActivityManageRule.intentNameActionParameter2,
|
||||||
|
username + Action.actionParameter2Split +
|
||||||
|
password + Action.actionParameter2Split +
|
||||||
|
etTriggerUrl.getText().toString().trim() + Action.actionParameter2Split +
|
||||||
|
method + Action.actionParameter2Split +
|
||||||
|
httpParams
|
||||||
|
);
|
||||||
|
|
||||||
|
setResult(RESULT_OK, returnIntent);
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Toast.makeText(getBaseContext(), getResources().getString(R.string.urlTooShort), Toast.LENGTH_LONG).show();
|
Toast.makeText(getBaseContext(), getResources().getString(R.string.urlTooShort), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
chkTriggerUrlUseAuthentication.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
chkTriggerUrlUseAuthentication.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||||
{
|
{
|
||||||
if(isChecked)
|
if(isChecked)
|
||||||
|
{
|
||||||
tlTriggerUrlAuthentication.setVisibility(View.VISIBLE);
|
tlTriggerUrlAuthentication.setVisibility(View.VISIBLE);
|
||||||
|
rbTriggerUrlMethodGet.setChecked(false);
|
||||||
|
rbTriggerUrlMethodPost.setChecked(true);
|
||||||
|
rbTriggerUrlMethodGet.setEnabled(false);
|
||||||
|
rbTriggerUrlMethodPost.setEnabled(false);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
tlTriggerUrlAuthentication.setVisibility(View.GONE);
|
tlTriggerUrlAuthentication.setVisibility(View.GONE);
|
||||||
|
rbTriggerUrlMethodGet.setEnabled(true);
|
||||||
|
rbTriggerUrlMethodPost.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
etTriggerUrlUsername.setEnabled(isChecked);
|
etTriggerUrlUsername.setEnabled(isChecked);
|
||||||
etTriggerUrlPassword.setEnabled(isChecked);
|
etTriggerUrlPassword.setEnabled(isChecked);
|
||||||
@@ -109,52 +173,86 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
});
|
});
|
||||||
updateListView();
|
updateListView();
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
ActivityManageActionTriggerUrl.edit = getIntent().getBooleanExtra("edit", false);
|
|
||||||
if(edit)
|
|
||||||
{
|
{
|
||||||
// username,password,URL
|
// username,password,URL,etc.
|
||||||
String[] components = ActivityManageActionTriggerUrl.resultingAction.getParameter2().split(";");
|
String[] components;
|
||||||
|
|
||||||
|
if(getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).contains(Action.actionParameter2Split))
|
||||||
|
components = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split, -1);
|
||||||
|
else
|
||||||
|
components = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(";", -1);
|
||||||
|
|
||||||
if(components.length >= 3)
|
if(components.length >= 3)
|
||||||
{
|
{
|
||||||
etTriggerUrl.setText(components[2]);
|
etTriggerUrl.setText(components[2]);
|
||||||
chkTriggerUrlUseAuthentication.setChecked(ActivityManageActionTriggerUrl.resultingAction.getParameter1());
|
chkTriggerUrlUseAuthentication.setChecked(getIntent().getBooleanExtra(ActivityManageRule.intentNameActionParameter1, false));
|
||||||
etTriggerUrlUsername.setText(components[0]);
|
etTriggerUrlUsername.setText(components[0]);
|
||||||
etTriggerUrlPassword.setText(components[1]);
|
etTriggerUrlPassword.setText(components[1]);
|
||||||
|
|
||||||
|
if(components.length >= 4)
|
||||||
|
{
|
||||||
|
switch(components[3])
|
||||||
|
{
|
||||||
|
case methodPost:
|
||||||
|
rbTriggerUrlMethodPost.setChecked(true);
|
||||||
|
break;
|
||||||
|
case methodGet:
|
||||||
|
default:
|
||||||
|
rbTriggerUrlMethodGet.setChecked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(components.length >= 5)
|
||||||
|
{
|
||||||
|
if(!StringUtils.isEmpty(components[4]) && components[4].contains(Action.actionParameters2SeparatorInner))
|
||||||
|
{
|
||||||
|
String httpParams[] = components[4].split(Action.actionParameters2SeparatorOuter);
|
||||||
|
for (String paramPair : httpParams)
|
||||||
|
httpParamsList.add(paramPair);
|
||||||
|
|
||||||
|
updateHttpParamsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
etTriggerUrl.setText(components[0]);
|
etTriggerUrl.setText(components[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
bAddHttpParam.setOnClickListener(new OnClickListener()
|
||||||
private void backToRuleManager()
|
|
||||||
{
|
|
||||||
if(edit && resultingAction != null)
|
|
||||||
{
|
{
|
||||||
String username = etTriggerUrlUsername.getText().toString();
|
@Override
|
||||||
String password = etTriggerUrlPassword.getText().toString();
|
public void onClick(View view)
|
||||||
|
{
|
||||||
if(username == null)
|
if(StringUtils.isEmpty(etParameterName.getText()) || StringUtils.isEmpty(etParameterValue.getText()))
|
||||||
username = "";
|
{
|
||||||
|
Toast.makeText(ActivityManageActionTriggerUrl.this, getResources().getString(R.string.enterValidDataIntoParametersFields), Toast.LENGTH_SHORT).show();
|
||||||
if(password == null)
|
return;
|
||||||
password = "";
|
}
|
||||||
|
|
||||||
ActivityManageActionTriggerUrl.resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked());
|
httpParamsList.add(etParameterName.getText() + Action.actionParameters2SeparatorInner + etParameterValue.getText());
|
||||||
|
|
||||||
ActivityManageActionTriggerUrl.resultingAction.setParameter2(
|
updateHttpParamsList();
|
||||||
username + ";" +
|
etParameterName.setText("");
|
||||||
password + ";" +
|
etParameterValue.setText("");
|
||||||
etTriggerUrl.getText().toString()
|
|
||||||
);
|
if(lvTriggerUrlPostParameters.getVisibility() != View.VISIBLE)
|
||||||
}
|
lvTriggerUrlPostParameters.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
setResult(RESULT_OK);
|
});
|
||||||
|
|
||||||
this.finish();
|
lvTriggerUrlPostParameters.setOnItemLongClickListener(new OnItemLongClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||||
|
{
|
||||||
|
getHttpParamsDialog(arg2).show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateListView()
|
private void updateListView()
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "ListView", "Attempting to update lvTriggerUrlPostParameters", 4);
|
Miscellaneous.logEvent("i", "ListView", "Attempting to update lvTriggerUrlPostParameters", 4);
|
||||||
@@ -162,10 +260,36 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
{
|
{
|
||||||
if(lvTriggerUrlPostParameters.getAdapter() == null)
|
if(lvTriggerUrlPostParameters.getAdapter() == null)
|
||||||
lvTriggerUrlPostParameters.setAdapter(lvTriggerUrlPostParametersAdapter);
|
lvTriggerUrlPostParameters.setAdapter(lvTriggerUrlPostParametersAdapter);
|
||||||
|
|
||||||
lvTriggerUrlPostParametersAdapter.notifyDataSetChanged();
|
lvTriggerUrlPostParametersAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
catch(NullPointerException e)
|
catch(NullPointerException e)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateHttpParamsList()
|
||||||
|
{
|
||||||
|
if(lvTriggerUrlPostParameters.getAdapter() == null)
|
||||||
|
lvTriggerUrlPostParameters.setAdapter(httpParametersAdapter);
|
||||||
|
|
||||||
|
httpParametersAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AlertDialog getHttpParamsDialog(final int itemPosition)
|
||||||
|
{
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityManageActionTriggerUrl.this);
|
||||||
|
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithIntentPair));
|
||||||
|
alertDialogBuilder.setItems(new String[]{getResources().getString(R.string.delete)}, new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which)
|
||||||
|
{
|
||||||
|
// Only 1 choice at the moment, no need to check
|
||||||
|
ActivityManageActionTriggerUrl.this.httpParamsList.remove(itemPosition);
|
||||||
|
updateHttpParamsList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
|
return alertDialog;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package com.jens.automation2;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -22,11 +25,14 @@ public class ActivityManageActionVibrate extends Activity
|
|||||||
{
|
{
|
||||||
TextView etVibratePattern;
|
TextView etVibratePattern;
|
||||||
Button bTestVibratePattern, bSaveVibratePattern;
|
Button bTestVibratePattern, bSaveVibratePattern;
|
||||||
|
ProgressDialog pdPleaseWait = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_vibrate);
|
setContentView(R.layout.activity_manage_action_vibrate);
|
||||||
|
|
||||||
etVibratePattern = (EditText)findViewById(R.id.etVibratePattern);
|
etVibratePattern = (EditText)findViewById(R.id.etVibratePattern);
|
||||||
@@ -58,7 +64,20 @@ public class ActivityManageActionVibrate extends Activity
|
|||||||
if (ActivityPermissions.havePermission(Manifest.permission.VIBRATE, ActivityManageActionVibrate.this))
|
if (ActivityPermissions.havePermission(Manifest.permission.VIBRATE, ActivityManageActionVibrate.this))
|
||||||
{
|
{
|
||||||
String pattern = etVibratePattern.getText().toString();
|
String pattern = etVibratePattern.getText().toString();
|
||||||
Actions.vibrate(false, pattern);
|
|
||||||
|
String[] patternArray = pattern.split(",");
|
||||||
|
long sum = 0;
|
||||||
|
for(String element : patternArray)
|
||||||
|
sum += Long.parseLong(element);
|
||||||
|
|
||||||
|
if(sum <= 2000)
|
||||||
|
Actions.vibrate(false, pattern);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pdPleaseWait = ProgressDialog.show(ActivityManageActionVibrate.this, null, getResources().getString(R.string.pleaseWait));
|
||||||
|
VibrateTask vt = new VibrateTask();
|
||||||
|
vt.execute(pattern);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,4 +101,22 @@ public class ActivityManageActionVibrate extends Activity
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VibrateTask extends AsyncTask<String, Void, Void>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(String... strings)
|
||||||
|
{
|
||||||
|
String pattern = (String)strings[0];
|
||||||
|
Actions.vibrate(false, pattern);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void unused)
|
||||||
|
{
|
||||||
|
pdPleaseWait.dismiss();
|
||||||
|
super.onPostExecute(unused);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,8 @@ public class ActivityManageActionWakeLock extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_wakelock);
|
setContentView(R.layout.activity_manage_action_wakelock);
|
||||||
|
|
||||||
rbWakeLockActivate = (RadioButton)findViewById(R.id.rbWakeLockActivate);
|
rbWakeLockActivate = (RadioButton)findViewById(R.id.rbWakeLockActivate);
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class ActivityManageActionWifi extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_action_wifi);
|
setContentView(R.layout.activity_manage_action_wifi);
|
||||||
|
|
||||||
chkWifiRunAsRoot = (CheckBox)findViewById(R.id.chkWifiRunAsRoot);
|
chkWifiRunAsRoot = (CheckBox)findViewById(R.id.chkWifiRunAsRoot);
|
||||||
@@ -34,14 +36,14 @@ public class ActivityManageActionWifi extends Activity
|
|||||||
|
|
||||||
Intent input = getIntent();
|
Intent input = getIntent();
|
||||||
if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
|
if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
|
||||||
|
{
|
||||||
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||||
|
rbActionWifiOff.setChecked(!input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||||
|
}
|
||||||
|
|
||||||
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
chkWifiRunAsRoot.setChecked(Boolean.parseBoolean(input.getStringExtra(ActivityManageRule.intentNameActionParameter2)));
|
chkWifiRunAsRoot.setChecked(Boolean.parseBoolean(input.getStringExtra(ActivityManageRule.intentNameActionParameter2)));
|
||||||
|
|
||||||
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
|
||||||
// Miscellaneous.messageBox(getResources().getString(R.string.app_name), getResources().getString(R.string.android10WifiToggleNotice), ActivityManageActionWifi.this).show();
|
|
||||||
|
|
||||||
if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q)
|
if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q)
|
||||||
tvWifiExplanation1.setVisibility(View.VISIBLE);
|
tvWifiExplanation1.setVisibility(View.VISIBLE);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
@@ -7,6 +8,7 @@ import android.content.ActivityNotFoundException;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.location.Criteria;
|
import android.location.Criteria;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
@@ -23,6 +25,9 @@ import android.widget.EditText;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.PermissionChecker;
|
||||||
|
|
||||||
import com.jens.automation2.receivers.ConnectivityReceiver;
|
import com.jens.automation2.receivers.ConnectivityReceiver;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -40,6 +45,7 @@ public class ActivityManagePoi extends Activity
|
|||||||
EditText guiPoiName, guiPoiLatitude, guiPoiLongitude, guiPoiRadius;
|
EditText guiPoiName, guiPoiLatitude, guiPoiLongitude, guiPoiRadius;
|
||||||
Calendar locationSearchStart = null;
|
Calendar locationSearchStart = null;
|
||||||
Timer timer = null;
|
Timer timer = null;
|
||||||
|
int requestCodeGetLocationPermission = 1293;
|
||||||
|
|
||||||
final static int defaultRadius = 250;
|
final static int defaultRadius = 250;
|
||||||
final static int searchTimeout = 120;
|
final static int searchTimeout = 120;
|
||||||
@@ -59,6 +65,8 @@ public class ActivityManagePoi extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
this.setContentView(R.layout.activity_manage_specific_poi);
|
this.setContentView(R.layout.activity_manage_specific_poi);
|
||||||
|
|
||||||
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
@@ -76,7 +84,15 @@ public class ActivityManagePoi extends Activity
|
|||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
getNotificationDialog(getResources().getString(R.string.positioningWindowNotice)).show();
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
{
|
||||||
|
if (ActivityPermissions.havePermission(Manifest.permission.ACCESS_FINE_LOCATION, ActivityManagePoi.this))
|
||||||
|
getNotificationDialog(getResources().getString(R.string.positioningWindowNotice)).show();
|
||||||
|
else
|
||||||
|
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestCodeGetLocationPermission);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
getNotificationDialog(getResources().getString(R.string.positioningWindowNotice)).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -110,7 +126,20 @@ public class ActivityManagePoi extends Activity
|
|||||||
//else
|
//else
|
||||||
// new Poi to be created
|
// new Poi to be created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
||||||
|
{
|
||||||
|
if(requestCode == requestCodeGetLocationPermission)
|
||||||
|
{
|
||||||
|
if(permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION) && grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||||
|
getNotificationDialog(getResources().getString(R.string.positioningWindowNotice)).show();
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityManagePoi.this, getResources().getString(R.string.locationPermissionRequired), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
}
|
||||||
|
|
||||||
private void createPoi()
|
private void createPoi()
|
||||||
{
|
{
|
||||||
myLocationManager.removeUpdates(myLocationListenerGps);
|
myLocationManager.removeUpdates(myLocationListenerGps);
|
||||||
@@ -313,20 +342,20 @@ public class ActivityManagePoi extends Activity
|
|||||||
public void onClick(DialogInterface dialog, int which)
|
public void onClick(DialogInterface dialog, int which)
|
||||||
{
|
{
|
||||||
progressDialog = ProgressDialog.show(ActivityManagePoi.this, "", getResources().getString(R.string.gettingPosition), true, true);
|
progressDialog = ProgressDialog.show(ActivityManagePoi.this, "", getResources().getString(R.string.gettingPosition), true, true);
|
||||||
if(Build.VERSION.SDK_INT >= 31)
|
// if(Build.VERSION.SDK_INT >= 31)
|
||||||
{
|
// {
|
||||||
AlertDialog dia = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.locationNotWorkingOn12), ActivityManagePoi.this);
|
// AlertDialog dia = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.locationNotWorkingOn12), ActivityManagePoi.this);
|
||||||
dia.setOnDismissListener(new DialogInterface.OnDismissListener()
|
// dia.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||||
{
|
// {
|
||||||
@Override
|
// @Override
|
||||||
public void onDismiss(DialogInterface dialogInterface)
|
// public void onDismiss(DialogInterface dialogInterface)
|
||||||
{
|
// {
|
||||||
getLocation();
|
// getLocation();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
dia.show();
|
// dia.show();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
getLocation();
|
getLocation();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -410,22 +439,16 @@ public class ActivityManagePoi extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider)
|
public void onProviderDisabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider)
|
public void onProviderEnabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,22 +476,16 @@ public class ActivityManagePoi extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider)
|
public void onProviderDisabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider)
|
public void onProviderEnabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -28,8 +27,6 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class ActivityManageProfile extends Activity
|
public class ActivityManageProfile extends Activity
|
||||||
{
|
{
|
||||||
private static ProgressDialog progressDialog;
|
private static ProgressDialog progressDialog;
|
||||||
@@ -37,47 +34,48 @@ public class ActivityManageProfile extends Activity
|
|||||||
final static int intentCodeRingtonePickerCallsRingtone = 9011;
|
final static int intentCodeRingtonePickerCallsRingtone = 9011;
|
||||||
final static int intentCodeRingtonePickerNotificationsFile = 9020;
|
final static int intentCodeRingtonePickerNotificationsFile = 9020;
|
||||||
final static int intentCodeRingtonePickerNotificationsRingtone = 9021;
|
final static int intentCodeRingtonePickerNotificationsRingtone = 9021;
|
||||||
|
final static String android14Hint = " (>= Android 14)";
|
||||||
|
|
||||||
CheckBox checkBoxChangeSoundMode, checkBoxChangeVolumeMusicVideoGameMedia, checkBoxChangeVolumeNotifications, checkBoxChangeVolumeAlarms, checkBoxChangeIncomingCallsRingtone, checkBoxChangeNotificationRingtone, checkBoxChangeAudibleSelection, checkBoxChangeScreenLockUnlockSound, checkBoxChangeHapticFeedback, checkBoxChangeVibrateWhenRinging, checkBoxVibrateWhenRinging, checkBoxAudibleSelection, checkBoxScreenLockUnlockSound, checkBoxHapticFeedback, checkBoxChangeDnd;
|
CheckBox checkBoxChangeSoundMode, checkBoxChangeVolumeMusicVideoGameMedia, checkBoxChangeVolumeNotifications, checkBoxChangeVolumeRingtone, checkBoxChangeVolumeAlarms, checkBoxChangeIncomingCallsRingtone, checkBoxChangeNotificationRingtone, checkBoxChangeAudibleSelection, checkBoxChangeScreenLockUnlockSound, checkBoxChangeHapticFeedback, checkBoxChangeVibrateWhenRinging, checkBoxVibrateWhenRinging, checkBoxAudibleSelection, checkBoxScreenLockUnlockSound, checkBoxHapticFeedback, checkBoxChangeDnd;
|
||||||
Spinner spinnerSoundMode, spinnerDndMode;
|
Spinner spinnerSoundMode, spinnerDndMode;
|
||||||
SeekBar seekBarVolumeMusic, seekBarVolumeNotifications, seekBarVolumeAlarms;
|
SeekBar seekBarVolumeMusic, seekBarVolumeNotifications, seekBarVolumeAlarms, seekBarVolumeRingtones;
|
||||||
Button bChangeSoundIncomingCalls, bChangeSoundNotifications, bSaveProfile;
|
Button bChangeSoundIncomingCalls, bChangeSoundNotifications, bSaveProfile;
|
||||||
TextView tvIncomingCallsRingtone, tvNotificationsRingtone;
|
TextView tvIncomingCallsRingtone, tvNotificationsRingtone, tvRingtoneVolume, tvNotificationsVolume;
|
||||||
EditText etName;
|
EditText etName;
|
||||||
|
|
||||||
boolean guiUpdate = false;
|
boolean guiUpdate = false;
|
||||||
|
|
||||||
File incomingCallsRingtone = null, notificationsRingtone = null;
|
String incomingCallsRingtone = null, notificationsRingtone = null;
|
||||||
|
|
||||||
ArrayAdapter<String> soundModeAdapter;
|
ArrayAdapter<String> soundModeAdapter;
|
||||||
ArrayAdapter<String> dndModeAdapter;
|
ArrayAdapter<String> dndModeAdapter;
|
||||||
|
|
||||||
public void setIncomingCallsRingtone(File incomingCallsRingtone)
|
public void setIncomingCallsRingtone(String incomingCallsRingtone)
|
||||||
{
|
{
|
||||||
this.incomingCallsRingtone = incomingCallsRingtone;
|
this.incomingCallsRingtone = incomingCallsRingtone;
|
||||||
|
|
||||||
if(incomingCallsRingtone != null)
|
if(incomingCallsRingtone != null)
|
||||||
tvIncomingCallsRingtone.setText(this.incomingCallsRingtone.getAbsolutePath());
|
tvIncomingCallsRingtone.setText(this.incomingCallsRingtone);
|
||||||
else
|
else
|
||||||
tvIncomingCallsRingtone.setText(getResources().getString(R.string.none));
|
tvIncomingCallsRingtone.setText(getResources().getString(R.string.none));
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getIncomingCallsRingtone()
|
public String getIncomingCallsRingtone()
|
||||||
{
|
{
|
||||||
return incomingCallsRingtone;
|
return incomingCallsRingtone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotificationsRingtone(File notificationsRingtone)
|
public void setNotificationsRingtone(String notificationsRingtone)
|
||||||
{
|
{
|
||||||
this.notificationsRingtone = notificationsRingtone;
|
this.notificationsRingtone = notificationsRingtone;
|
||||||
|
|
||||||
if(this.notificationsRingtone != null)
|
if(this.notificationsRingtone != null)
|
||||||
tvNotificationsRingtone.setText(this.notificationsRingtone.getAbsolutePath());
|
tvNotificationsRingtone.setText(this.notificationsRingtone);
|
||||||
else
|
else
|
||||||
tvNotificationsRingtone.setText(getResources().getString(R.string.none));
|
tvNotificationsRingtone.setText(getResources().getString(R.string.none));
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getNotificationsRingtone()
|
public String getNotificationsRingtone()
|
||||||
{
|
{
|
||||||
return notificationsRingtone;
|
return notificationsRingtone;
|
||||||
}
|
}
|
||||||
@@ -86,12 +84,15 @@ public class ActivityManageProfile extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
this.setContentView(R.layout.activity_manage_specific_profile);
|
this.setContentView(R.layout.activity_manage_specific_profile);
|
||||||
|
|
||||||
checkBoxChangeSoundMode = (CheckBox)findViewById(R.id.checkBoxChangeSoundMode);
|
checkBoxChangeSoundMode = (CheckBox)findViewById(R.id.checkBoxChangeSoundMode);
|
||||||
checkBoxChangeDnd = (CheckBox)findViewById(R.id.checkBoxChangeDnd);
|
checkBoxChangeDnd = (CheckBox)findViewById(R.id.checkBoxChangeDnd);
|
||||||
checkBoxChangeVolumeMusicVideoGameMedia = (CheckBox)findViewById(R.id.checkBoxChangeVolumeMusicVideoGameMedia);
|
checkBoxChangeVolumeMusicVideoGameMedia = (CheckBox)findViewById(R.id.checkBoxChangeVolumeMusicVideoGameMedia);
|
||||||
checkBoxChangeVolumeNotifications = (CheckBox)findViewById(R.id.checkBoxChangeVolumeNotifications);
|
checkBoxChangeVolumeNotifications = (CheckBox)findViewById(R.id.checkBoxChangeVolumeNotifications);
|
||||||
|
checkBoxChangeVolumeRingtone = (CheckBox)findViewById(R.id.checkBoxChangeVolumeRingtones);
|
||||||
checkBoxChangeVolumeAlarms = (CheckBox)findViewById(R.id.checkBoxChangeVolumeAlarms);
|
checkBoxChangeVolumeAlarms = (CheckBox)findViewById(R.id.checkBoxChangeVolumeAlarms);
|
||||||
checkBoxChangeIncomingCallsRingtone = (CheckBox)findViewById(R.id.checkBoxChangeIncomingCallsRingtone);
|
checkBoxChangeIncomingCallsRingtone = (CheckBox)findViewById(R.id.checkBoxChangeIncomingCallsRingtone);
|
||||||
checkBoxChangeNotificationRingtone = (CheckBox)findViewById(R.id.checkBoxChangeNotificationRingtone);
|
checkBoxChangeNotificationRingtone = (CheckBox)findViewById(R.id.checkBoxChangeNotificationRingtone);
|
||||||
@@ -107,11 +108,14 @@ public class ActivityManageProfile extends Activity
|
|||||||
spinnerDndMode = (Spinner)findViewById(R.id.spinnerDndMode);
|
spinnerDndMode = (Spinner)findViewById(R.id.spinnerDndMode);
|
||||||
seekBarVolumeMusic = (SeekBar)findViewById(R.id.seekBarVolumeMusic);
|
seekBarVolumeMusic = (SeekBar)findViewById(R.id.seekBarVolumeMusic);
|
||||||
seekBarVolumeNotifications = (SeekBar)findViewById(R.id.seekBarVolumeNotifications);
|
seekBarVolumeNotifications = (SeekBar)findViewById(R.id.seekBarVolumeNotifications);
|
||||||
|
seekBarVolumeRingtones = (SeekBar)findViewById(R.id.seekBarVolumeRingtones);
|
||||||
seekBarVolumeAlarms = (SeekBar)findViewById(R.id.seekBarVolumeAlarms);
|
seekBarVolumeAlarms = (SeekBar)findViewById(R.id.seekBarVolumeAlarms);
|
||||||
bChangeSoundIncomingCalls = (Button)findViewById(R.id.bChangeSoundIncomingCalls);
|
bChangeSoundIncomingCalls = (Button)findViewById(R.id.bChangeSoundIncomingCalls);
|
||||||
bChangeSoundNotifications = (Button)findViewById(R.id.bChangeSoundNotifications);
|
bChangeSoundNotifications = (Button)findViewById(R.id.bChangeSoundNotifications);
|
||||||
tvIncomingCallsRingtone = (TextView)findViewById(R.id.tvIncomingCallsRingtone);
|
tvIncomingCallsRingtone = (TextView)findViewById(R.id.tvIncomingCallsRingtone);
|
||||||
tvNotificationsRingtone = (TextView)findViewById(R.id.tvNotificationsRingtone);
|
tvNotificationsRingtone = (TextView)findViewById(R.id.tvNotificationsRingtone);
|
||||||
|
tvRingtoneVolume = (TextView)findViewById(R.id.tvRingtoneVolume);
|
||||||
|
tvNotificationsVolume = (TextView)findViewById(R.id.tvNotificationsVolume);
|
||||||
bSaveProfile = (Button)findViewById(R.id.bSaveProfile);
|
bSaveProfile = (Button)findViewById(R.id.bSaveProfile);
|
||||||
etName = (EditText)findViewById(R.id.etName);
|
etName = (EditText)findViewById(R.id.etName);
|
||||||
|
|
||||||
@@ -123,6 +127,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
spinnerDndMode.setEnabled(false);
|
spinnerDndMode.setEnabled(false);
|
||||||
seekBarVolumeMusic.setEnabled(false);
|
seekBarVolumeMusic.setEnabled(false);
|
||||||
seekBarVolumeNotifications.setEnabled(false);
|
seekBarVolumeNotifications.setEnabled(false);
|
||||||
|
seekBarVolumeRingtones.setEnabled(false);
|
||||||
seekBarVolumeAlarms.setEnabled(false);
|
seekBarVolumeAlarms.setEnabled(false);
|
||||||
bChangeSoundIncomingCalls.setEnabled(false);
|
bChangeSoundIncomingCalls.setEnabled(false);
|
||||||
bChangeSoundNotifications.setEnabled(false);
|
bChangeSoundNotifications.setEnabled(false);
|
||||||
@@ -136,11 +141,36 @@ public class ActivityManageProfile extends Activity
|
|||||||
checkBoxChangeDnd.setEnabled(false);
|
checkBoxChangeDnd.setEnabled(false);
|
||||||
spinnerDndMode.setEnabled(false);
|
spinnerDndMode.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT >= 34)
|
||||||
|
{
|
||||||
|
checkBoxChangeVolumeRingtone.setEnabled(true);
|
||||||
|
|
||||||
|
checkBoxChangeVolumeRingtone.setVisibility(View.VISIBLE);
|
||||||
|
tvRingtoneVolume.setVisibility(View.VISIBLE);
|
||||||
|
seekBarVolumeRingtones.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
tvNotificationsVolume.setText(getResources().getString(R.string.volumeNotifications));
|
||||||
|
tvRingtoneVolume.setText(getResources().getString(R.string.volumeRingtone));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
checkBoxChangeVolumeRingtone.setEnabled(false);
|
||||||
|
tvRingtoneVolume.setEnabled(false);
|
||||||
|
seekBarVolumeRingtones.setEnabled(false);
|
||||||
|
|
||||||
|
checkBoxChangeVolumeRingtone.setVisibility(View.GONE);
|
||||||
|
tvRingtoneVolume.setVisibility(View.GONE);
|
||||||
|
seekBarVolumeRingtones.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
tvNotificationsVolume.setText(getResources().getString(R.string.volumeRingtone) + " + " + getResources().getString(R.string.volumeNotifications));
|
||||||
|
}
|
||||||
|
|
||||||
// Scale SeekBars to the system's maximum volume values
|
// Scale SeekBars to the system's maximum volume values
|
||||||
AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE);
|
||||||
seekBarVolumeMusic.setMax(am.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
|
seekBarVolumeMusic.setMax(am.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
|
||||||
seekBarVolumeNotifications.setMax(am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION));
|
seekBarVolumeNotifications.setMax(am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION));
|
||||||
|
seekBarVolumeRingtones.setMax(am.getStreamMaxVolume(AudioManager.STREAM_RING));
|
||||||
seekBarVolumeAlarms.setMax(am.getStreamMaxVolume(AudioManager.STREAM_ALARM));
|
seekBarVolumeAlarms.setMax(am.getStreamMaxVolume(AudioManager.STREAM_ALARM));
|
||||||
|
|
||||||
soundModeAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, new String[]
|
soundModeAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, new String[]
|
||||||
@@ -200,6 +230,14 @@ public class ActivityManageProfile extends Activity
|
|||||||
seekBarVolumeNotifications.setEnabled(isChecked);
|
seekBarVolumeNotifications.setEnabled(isChecked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
checkBoxChangeVolumeRingtone.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||||
|
{
|
||||||
|
seekBarVolumeRingtones.setEnabled(isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
checkBoxChangeVolumeAlarms.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
checkBoxChangeVolumeAlarms.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -284,26 +322,26 @@ public class ActivityManageProfile extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
// Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
fileIntent.setType("audio/*");
|
// fileIntent.setType("audio/*");
|
||||||
startActivityForResult(Intent.createChooser(fileIntent, "Select a ringtone"), intentCodeRingtonePickerCallsFile);
|
// startActivityForResult(Intent.createChooser(fileIntent, "Select a ringtone"), intentCodeRingtonePickerCallsFile);
|
||||||
}
|
// }
|
||||||
catch(ActivityNotFoundException e)
|
// catch(ActivityNotFoundException e)
|
||||||
{
|
// {
|
||||||
// Use media browser instead
|
// Use media browser instead
|
||||||
Intent fileSelectionIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
Intent fileSelectionIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||||
|
|
||||||
if(ActivityMainProfiles.profileToEdit != null)
|
if(ActivityMainProfiles.profileToEdit != null)
|
||||||
{
|
{
|
||||||
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.incomingCallsRingtone.getAbsolutePath());
|
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.incomingCallsRingtone);
|
||||||
if(ActivityMainProfiles.profileToEdit.changeIncomingCallsRingtone)
|
if(ActivityMainProfiles.profileToEdit.changeIncomingCallsRingtone)
|
||||||
fileSelectionIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currenturi);
|
fileSelectionIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currenturi);
|
||||||
}
|
}
|
||||||
|
|
||||||
startActivityForResult(fileSelectionIntent, intentCodeRingtonePickerCallsRingtone);
|
startActivityForResult(fileSelectionIntent, intentCodeRingtonePickerCallsRingtone);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bChangeSoundNotifications.setOnClickListener(new OnClickListener()
|
bChangeSoundNotifications.setOnClickListener(new OnClickListener()
|
||||||
@@ -324,7 +362,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
|
|
||||||
if(ActivityMainProfiles.profileToEdit != null)
|
if(ActivityMainProfiles.profileToEdit != null)
|
||||||
{
|
{
|
||||||
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.notificationRingtone.getAbsolutePath());
|
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.notificationRingtone);
|
||||||
if(ActivityMainProfiles.profileToEdit.changeNotificationRingtone)
|
if(ActivityMainProfiles.profileToEdit.changeNotificationRingtone)
|
||||||
fileSelectionIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currenturi);
|
fileSelectionIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currenturi);
|
||||||
}
|
}
|
||||||
@@ -335,7 +373,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
});
|
});
|
||||||
|
|
||||||
if(ActivityMainProfiles.profileToEdit != null)
|
if(ActivityMainProfiles.profileToEdit != null)
|
||||||
editProfile(ActivityMainProfiles.profileToEdit);
|
loadValuesIntoGui(ActivityMainProfiles.profileToEdit);
|
||||||
//else
|
//else
|
||||||
// new Profile to be created
|
// new Profile to be created
|
||||||
|
|
||||||
@@ -368,7 +406,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editProfile(Profile profileToEdit)
|
public void loadValuesIntoGui(Profile profileToEdit)
|
||||||
{
|
{
|
||||||
guiUpdate = true;
|
guiUpdate = true;
|
||||||
|
|
||||||
@@ -377,6 +415,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
checkBoxChangeDnd.setChecked(ActivityMainProfiles.profileToEdit.getChangeDndMode());
|
checkBoxChangeDnd.setChecked(ActivityMainProfiles.profileToEdit.getChangeDndMode());
|
||||||
checkBoxChangeVolumeMusicVideoGameMedia.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeMusicVideoGameMedia());
|
checkBoxChangeVolumeMusicVideoGameMedia.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeMusicVideoGameMedia());
|
||||||
checkBoxChangeVolumeNotifications.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeNotifications());
|
checkBoxChangeVolumeNotifications.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeNotifications());
|
||||||
|
checkBoxChangeVolumeRingtone.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeRingtones());
|
||||||
checkBoxChangeVolumeAlarms.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeAlarms());
|
checkBoxChangeVolumeAlarms.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeAlarms());
|
||||||
checkBoxChangeIncomingCallsRingtone.setChecked(ActivityMainProfiles.profileToEdit.getChangeIncomingCallsRingtone());
|
checkBoxChangeIncomingCallsRingtone.setChecked(ActivityMainProfiles.profileToEdit.getChangeIncomingCallsRingtone());
|
||||||
checkBoxChangeNotificationRingtone.setChecked(ActivityMainProfiles.profileToEdit.getChangeNotificationRingtone());
|
checkBoxChangeNotificationRingtone.setChecked(ActivityMainProfiles.profileToEdit.getChangeNotificationRingtone());
|
||||||
@@ -389,6 +428,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
spinnerDndMode.setSelection(ActivityMainProfiles.profileToEdit.getDndMode()-1);
|
spinnerDndMode.setSelection(ActivityMainProfiles.profileToEdit.getDndMode()-1);
|
||||||
seekBarVolumeMusic.setProgress(ActivityMainProfiles.profileToEdit.getVolumeMusic());
|
seekBarVolumeMusic.setProgress(ActivityMainProfiles.profileToEdit.getVolumeMusic());
|
||||||
seekBarVolumeNotifications.setProgress(ActivityMainProfiles.profileToEdit.getVolumeNotifications());
|
seekBarVolumeNotifications.setProgress(ActivityMainProfiles.profileToEdit.getVolumeNotifications());
|
||||||
|
seekBarVolumeRingtones.setProgress(ActivityMainProfiles.profileToEdit.getVolumeRingtones());
|
||||||
seekBarVolumeAlarms.setProgress(ActivityMainProfiles.profileToEdit.getVolumeAlarms());
|
seekBarVolumeAlarms.setProgress(ActivityMainProfiles.profileToEdit.getVolumeAlarms());
|
||||||
checkBoxAudibleSelection.setChecked(ActivityMainProfiles.profileToEdit.audibleSelection);
|
checkBoxAudibleSelection.setChecked(ActivityMainProfiles.profileToEdit.audibleSelection);
|
||||||
checkBoxScreenLockUnlockSound.setChecked(ActivityMainProfiles.profileToEdit.screenLockUnlockSound);
|
checkBoxScreenLockUnlockSound.setChecked(ActivityMainProfiles.profileToEdit.screenLockUnlockSound);
|
||||||
@@ -413,6 +453,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
ActivityMainProfiles.profileToEdit.setChangeDndMode(checkBoxChangeDnd.isChecked());
|
ActivityMainProfiles.profileToEdit.setChangeDndMode(checkBoxChangeDnd.isChecked());
|
||||||
ActivityMainProfiles.profileToEdit.setChangeVolumeMusicVideoGameMedia(checkBoxChangeVolumeMusicVideoGameMedia.isChecked());
|
ActivityMainProfiles.profileToEdit.setChangeVolumeMusicVideoGameMedia(checkBoxChangeVolumeMusicVideoGameMedia.isChecked());
|
||||||
ActivityMainProfiles.profileToEdit.setChangeVolumeNotifications(checkBoxChangeVolumeNotifications.isChecked());
|
ActivityMainProfiles.profileToEdit.setChangeVolumeNotifications(checkBoxChangeVolumeNotifications.isChecked());
|
||||||
|
ActivityMainProfiles.profileToEdit.setChangeVolumeRingtones(checkBoxChangeVolumeRingtone.isChecked());
|
||||||
ActivityMainProfiles.profileToEdit.setChangeVolumeAlarms(checkBoxChangeVolumeAlarms.isChecked());
|
ActivityMainProfiles.profileToEdit.setChangeVolumeAlarms(checkBoxChangeVolumeAlarms.isChecked());
|
||||||
ActivityMainProfiles.profileToEdit.setChangeIncomingCallsRingtone(checkBoxChangeIncomingCallsRingtone.isChecked());
|
ActivityMainProfiles.profileToEdit.setChangeIncomingCallsRingtone(checkBoxChangeIncomingCallsRingtone.isChecked());
|
||||||
ActivityMainProfiles.profileToEdit.setChangeNotificationRingtone(checkBoxChangeNotificationRingtone.isChecked());
|
ActivityMainProfiles.profileToEdit.setChangeNotificationRingtone(checkBoxChangeNotificationRingtone.isChecked());
|
||||||
@@ -429,6 +470,7 @@ public class ActivityManageProfile extends Activity
|
|||||||
ActivityMainProfiles.profileToEdit.setDndMode(spinnerDndMode.getSelectedItemPosition()+1);
|
ActivityMainProfiles.profileToEdit.setDndMode(spinnerDndMode.getSelectedItemPosition()+1);
|
||||||
ActivityMainProfiles.profileToEdit.setVolumeMusic(seekBarVolumeMusic.getProgress());
|
ActivityMainProfiles.profileToEdit.setVolumeMusic(seekBarVolumeMusic.getProgress());
|
||||||
ActivityMainProfiles.profileToEdit.setVolumeNotifications(seekBarVolumeNotifications.getProgress());
|
ActivityMainProfiles.profileToEdit.setVolumeNotifications(seekBarVolumeNotifications.getProgress());
|
||||||
|
ActivityMainProfiles.profileToEdit.setVolumeRingtones(seekBarVolumeRingtones.getProgress());
|
||||||
ActivityMainProfiles.profileToEdit.setVolumeAlarms(seekBarVolumeAlarms.getProgress());
|
ActivityMainProfiles.profileToEdit.setVolumeAlarms(seekBarVolumeAlarms.getProgress());
|
||||||
ActivityMainProfiles.profileToEdit.setIncomingCallsRingtone(incomingCallsRingtone);
|
ActivityMainProfiles.profileToEdit.setIncomingCallsRingtone(incomingCallsRingtone);
|
||||||
ActivityMainProfiles.profileToEdit.setNotificationRingtone(notificationsRingtone);
|
ActivityMainProfiles.profileToEdit.setNotificationRingtone(notificationsRingtone);
|
||||||
@@ -495,15 +537,20 @@ public class ActivityManageProfile extends Activity
|
|||||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, uri);
|
// if(Build.VERSION.SDK_INT < 26)
|
||||||
setIncomingCallsRingtone(new File(ringTonePath));
|
// {
|
||||||
|
// String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, uri);
|
||||||
|
// setIncomingCallsRingtone(ringTonePath);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
setIncomingCallsRingtone(uri.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case intentCodeRingtonePickerCallsFile:
|
case intentCodeRingtonePickerCallsFile:
|
||||||
{
|
{
|
||||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
||||||
setIncomingCallsRingtone(new File(ringTonePath));
|
setIncomingCallsRingtone(ringTonePath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case intentCodeRingtonePickerNotificationsRingtone: // notifications
|
case intentCodeRingtonePickerNotificationsRingtone: // notifications
|
||||||
@@ -511,15 +558,20 @@ public class ActivityManageProfile extends Activity
|
|||||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
// if(Build.VERSION.SDK_INT < 26)
|
||||||
setNotificationsRingtone(new File(ringTonePath));
|
// {
|
||||||
|
// String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, uri);
|
||||||
|
// setNotificationsRingtone(ringTonePath);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
setNotificationsRingtone(uri.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case intentCodeRingtonePickerNotificationsFile:
|
case intentCodeRingtonePickerNotificationsFile:
|
||||||
{
|
{
|
||||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
||||||
setNotificationsRingtone(new File(ringTonePath));
|
setNotificationsRingtone(ringTonePath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -133,6 +133,24 @@ public class ActivityManageRule extends Activity
|
|||||||
final static int requestCodeActionWakeLockEdit = 820;
|
final static int requestCodeActionWakeLockEdit = 820;
|
||||||
final static int requestCodeTriggerSubSystemStateAdd = 821;
|
final static int requestCodeTriggerSubSystemStateAdd = 821;
|
||||||
final static int requestCodeTriggerSubSystemStateEdit = 822;
|
final static int requestCodeTriggerSubSystemStateEdit = 822;
|
||||||
|
final static int requestCodeActionMakePhoneCallAdd = 823;
|
||||||
|
final static int requestCodeActionMakePhoneCallEdit = 824;
|
||||||
|
final static int requestCodeActionSetVariableAdd = 825;
|
||||||
|
final static int requestCodeActionSetVariableEdit = 826;
|
||||||
|
final static int requestCodeTriggerCheckVariableAdd = 827;
|
||||||
|
final static int requestCodeTriggerCheckVariableEdit = 828;
|
||||||
|
final static int requestCodeActionCopyTextToClipboardAdd = 829;
|
||||||
|
final static int requestCodeActionCopyTextToClipboardEdit = 830;
|
||||||
|
final static int requestCodeActionSetLocationServiceAdd = 831;
|
||||||
|
final static int requestCodeActionSetLocationServiceEdit = 832;
|
||||||
|
final static int requestCodeTriggerCalendarEventAdd = 833;
|
||||||
|
final static int requestCodeTriggerCalendarEventEdit = 834;
|
||||||
|
final static int requestCodeTriggerChargingAdd = 835;
|
||||||
|
final static int requestCodeTriggerChargingEdit = 836;
|
||||||
|
final static int requestCodeTriggerProximityAdd = 837;
|
||||||
|
final static int requestCodeTriggerProximityEdit = 838;
|
||||||
|
final static int requestCodeActionSetSystemSettingAdd = 839;
|
||||||
|
final static int requestCodeActionSetSystemSettingEdit = 840;
|
||||||
|
|
||||||
public static ActivityManageRule getInstance()
|
public static ActivityManageRule getInstance()
|
||||||
{
|
{
|
||||||
@@ -146,6 +164,8 @@ public class ActivityManageRule extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_specific_rule);
|
setContentView(R.layout.activity_manage_specific_rule);
|
||||||
|
|
||||||
context = this;
|
context = this;
|
||||||
@@ -330,6 +350,30 @@ public class ActivityManageRule extends Activity
|
|||||||
subSystemStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
subSystemStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
startActivityForResult(subSystemStateEditor, requestCodeTriggerSubSystemStateEdit);
|
startActivityForResult(subSystemStateEditor, requestCodeTriggerSubSystemStateEdit);
|
||||||
break;
|
break;
|
||||||
|
case checkVariable:
|
||||||
|
Intent variableStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCheckVariable.class);
|
||||||
|
variableStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
|
variableStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
|
startActivityForResult(variableStateEditor, requestCodeTriggerCheckVariableEdit);
|
||||||
|
break;
|
||||||
|
case calendarEvent:
|
||||||
|
Intent calendarStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCalendar.class);
|
||||||
|
calendarStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
|
calendarStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
|
startActivityForResult(calendarStateEditor, requestCodeTriggerCalendarEventEdit);
|
||||||
|
break;
|
||||||
|
case charging:
|
||||||
|
Intent chargingStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCharging.class);
|
||||||
|
chargingStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
|
chargingStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
|
startActivityForResult(chargingStateEditor, requestCodeTriggerChargingEdit);
|
||||||
|
break;
|
||||||
|
case proximity:
|
||||||
|
Intent proximityEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerProximity.class);
|
||||||
|
proximityEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
|
proximityEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
|
startActivityForResult(proximityEditor, requestCodeTriggerProximityEdit);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -371,9 +415,8 @@ public class ActivityManageRule extends Activity
|
|||||||
break;
|
break;
|
||||||
case triggerUrl:
|
case triggerUrl:
|
||||||
Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityManageActionTriggerUrl.class);
|
Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityManageActionTriggerUrl.class);
|
||||||
ActivityManageActionTriggerUrl.resultingAction = a;
|
activityEditTriggerUrlIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
ActivityManageActionTriggerUrl.resultingAction.setParentRule(ruleToEdit);
|
activityEditTriggerUrlIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
activityEditTriggerUrlIntent.putExtra("edit", true);
|
|
||||||
startActivityForResult(activityEditTriggerUrlIntent, requestCodeActionTriggerUrlEdit);
|
startActivityForResult(activityEditTriggerUrlIntent, requestCodeActionTriggerUrlEdit);
|
||||||
break;
|
break;
|
||||||
case speakText:
|
case speakText:
|
||||||
@@ -416,6 +459,17 @@ public class ActivityManageRule extends Activity
|
|||||||
activityEditRunExecutableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
activityEditRunExecutableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
startActivityForResult(activityEditRunExecutableIntent, requestCodeActionRunExecutableEdit);
|
startActivityForResult(activityEditRunExecutableIntent, requestCodeActionRunExecutableEdit);
|
||||||
break;
|
break;
|
||||||
|
case startPhoneCall:
|
||||||
|
Intent activityEditMakePhoneCallIntent = new Intent(ActivityManageRule.this, ActivityManageActionMakePhoneCall.class);
|
||||||
|
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
|
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
|
startActivityForResult(activityEditMakePhoneCallIntent, requestCodeActionMakePhoneCallEdit);
|
||||||
|
break;
|
||||||
|
case setVariable:
|
||||||
|
Intent activityEditSetVariableIntent = new Intent(ActivityManageRule.this, ActivityManageActionSetVariable.class);
|
||||||
|
activityEditSetVariableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
|
startActivityForResult(activityEditSetVariableIntent, requestCodeActionSetVariableEdit);
|
||||||
|
break;
|
||||||
case setWifi:
|
case setWifi:
|
||||||
Intent activityEditSetWifiIntent = new Intent(ActivityManageRule.this, ActivityManageActionWifi.class);
|
Intent activityEditSetWifiIntent = new Intent(ActivityManageRule.this, ActivityManageActionWifi.class);
|
||||||
activityEditSetWifiIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
activityEditSetWifiIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
@@ -446,6 +500,24 @@ public class ActivityManageRule extends Activity
|
|||||||
actionPlaySoundIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
actionPlaySoundIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundEdit);
|
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundEdit);
|
||||||
break;
|
break;
|
||||||
|
case copyToClipboard:
|
||||||
|
Intent actionCopyToClipboardIntent = new Intent(context, ActivityManageActionCopyToClipboard.class);
|
||||||
|
actionCopyToClipboardIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
|
actionCopyToClipboardIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
|
startActivityForResult(actionCopyToClipboardIntent, requestCodeActionCopyTextToClipboardEdit);
|
||||||
|
break;
|
||||||
|
case setLocationService:
|
||||||
|
Intent actionSetLocationServiceIntent = new Intent(context, ActivityManageActionLocationService.class);
|
||||||
|
// actionSetLocationServiceIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
|
actionSetLocationServiceIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
|
startActivityForResult(actionSetLocationServiceIntent, requestCodeActionSetLocationServiceEdit);
|
||||||
|
break;
|
||||||
|
case setSystemSetting:
|
||||||
|
Intent actionSetSystemSettingIntent = new Intent(context, ActivityManageActionSetSystemSetting.class);
|
||||||
|
// actionSetSystemSettingIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
|
actionSetSystemSettingIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
|
startActivityForResult(actionSetSystemSettingIntent, requestCodeActionSetSystemSettingEdit);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Miscellaneous.logEvent("w", "Edit action", "Editing of action type " + a.getAction().toString() + " not implemented, yet.", 4);
|
Miscellaneous.logEvent("w", "Edit action", "Editing of action type " + a.getAction().toString() + " not implemented, yet.", 4);
|
||||||
break;
|
break;
|
||||||
@@ -486,7 +558,7 @@ public class ActivityManageRule extends Activity
|
|||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
// Open help popup
|
// Open help popup
|
||||||
Miscellaneous.messageBox(getResources().getString(R.string.whatsThis), getResources().getString(R.string.helpTextToggable), ActivityManageRule.this).show();
|
Miscellaneous.messageBox(getResources().getString(R.string.whatsThis), getResources().getString(R.string.helpTextToggleable), ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -567,7 +639,7 @@ public class ActivityManageRule extends Activity
|
|||||||
items.add(new Item(typesLong[i].toString(), R.drawable.megaphone));
|
items.add(new Item(typesLong[i].toString(), R.drawable.megaphone));
|
||||||
else if(types[i].toString().equals(Trigger_Enum.phoneCall.toString()))
|
else if(types[i].toString().equals(Trigger_Enum.phoneCall.toString()))
|
||||||
{
|
{
|
||||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
|
if(ActivityPermissions.isPermissionDeclaredInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
||||||
}
|
}
|
||||||
else if(types[i].toString().equals(Trigger_Enum.nfcTag.toString()))
|
else if(types[i].toString().equals(Trigger_Enum.nfcTag.toString()))
|
||||||
@@ -596,6 +668,13 @@ public class ActivityManageRule extends Activity
|
|||||||
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
||||||
else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString()))
|
else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString()))
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate));
|
items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate));
|
||||||
|
else if(types[i].toString().equals(Trigger_Enum.checkVariable.toString()))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.variable));
|
||||||
|
else if(types[i].toString().equals(Trigger_Enum.calendarEvent.toString()))
|
||||||
|
{
|
||||||
|
if(ActivityPermissions.isPermissionDeclaredInManifest(ActivityManageRule.this, Manifest.permission.READ_CALENDAR))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.calendar));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||||
}
|
}
|
||||||
@@ -604,15 +683,15 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
public View getView(int position, View convertView, ViewGroup parent)
|
public View getView(int position, View convertView, ViewGroup parent)
|
||||||
{
|
{
|
||||||
//User super class to create the View
|
// User super class to create the View
|
||||||
View v = super.getView(position, convertView, parent);
|
View v = super.getView(position, convertView, parent);
|
||||||
|
|
||||||
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
||||||
|
|
||||||
//Put the image on the TextView
|
// Put the image on the TextView
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
||||||
|
|
||||||
//Add margin between image and text (support various screen densities)
|
// Add margin between image and text (support various screen densities)
|
||||||
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
||||||
tv.setCompoundDrawablePadding(dp5);
|
tv.setCompoundDrawablePadding(dp5);
|
||||||
|
|
||||||
@@ -656,7 +735,21 @@ public class ActivityManageRule extends Activity
|
|||||||
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeAdd);
|
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeAdd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(triggerType == Trigger_Enum.charging || triggerType == Trigger_Enum.musicPlaying)
|
else if(triggerType == Trigger_Enum.charging)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerType(Trigger_Enum.charging);
|
||||||
|
Intent triggerChargingIntent = new Intent(myContext, ActivityManageTriggerCharging.class);
|
||||||
|
startActivityForResult(triggerChargingIntent, requestCodeTriggerChargingAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(triggerType == Trigger_Enum.proximity)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerType(Trigger_Enum.proximity);
|
||||||
|
Intent triggerProximityIntent = new Intent(myContext, ActivityManageTriggerProximity.class);
|
||||||
|
startActivityForResult(triggerProximityIntent, requestCodeTriggerProximityAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(triggerType == Trigger_Enum.musicPlaying)
|
||||||
booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
||||||
else if(triggerType == Trigger_Enum.usb_host_connection)
|
else if(triggerType == Trigger_Enum.usb_host_connection)
|
||||||
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
||||||
@@ -814,6 +907,20 @@ public class ActivityManageRule extends Activity
|
|||||||
startActivityForResult(subSystemStateTriggerEditor, requestCodeTriggerSubSystemStateAdd);
|
startActivityForResult(subSystemStateTriggerEditor, requestCodeTriggerSubSystemStateAdd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if(triggerType == Trigger_Enum.checkVariable)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerType(Trigger_Enum.checkVariable);
|
||||||
|
Intent variableTriggerEditor = new Intent(myContext, ActivityManageTriggerCheckVariable.class);
|
||||||
|
startActivityForResult(variableTriggerEditor, requestCodeTriggerCheckVariableAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(triggerType == Trigger_Enum.calendarEvent)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerType(Trigger_Enum.calendarEvent);
|
||||||
|
Intent calendarTriggerEditor = new Intent(myContext, ActivityManageTriggerCalendar.class);
|
||||||
|
startActivityForResult(calendarTriggerEditor, requestCodeTriggerCalendarEventAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
getTriggerParameterDialog(context, booleanChoices).show();
|
getTriggerParameterDialog(context, booleanChoices).show();
|
||||||
|
|
||||||
@@ -1055,7 +1162,7 @@ public class ActivityManageRule extends Activity
|
|||||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
||||||
|
|
||||||
alertDialog.setTitle(myContext.getResources().getString(R.string.phoneNumber));
|
alertDialog.setTitle(myContext.getResources().getString(R.string.phoneNumber));
|
||||||
alertDialog.setMessage(myContext.getResources().getString(R.string.enterPhoneNumber));
|
alertDialog.setMessage(myContext.getResources().getString(R.string.enterPhoneNumberBlankForAny));
|
||||||
|
|
||||||
// Set an EditText view to get user input
|
// Set an EditText view to get user input
|
||||||
final EditText input = new EditText(this);
|
final EditText input = new EditText(this);
|
||||||
@@ -1316,9 +1423,11 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
//add TriggerUrl
|
newAction.setParentRule(ruleToEdit);
|
||||||
ActivityManageActionTriggerUrl.resultingAction.setParentRule(ruleToEdit);
|
newAction.setAction(Action_Enum.triggerUrl);
|
||||||
ruleToEdit.getActionSet().add(ActivityManageActionTriggerUrl.resultingAction);
|
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||||
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1326,7 +1435,14 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
//edit TriggerUrl
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter1))
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter2))
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
|
||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1383,6 +1499,54 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerChargingAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||||
|
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||||
|
newTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerProximityAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||||
|
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||||
|
newTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerChargingEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
Trigger chargingStateTrigger = new Trigger();
|
||||||
|
chargingStateTrigger.setTriggerType(Trigger_Enum.charging);
|
||||||
|
chargingStateTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
chargingStateTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
chargingStateTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().set(editIndex, chargingStateTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerProximityEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
Trigger proximityTrigger = new Trigger();
|
||||||
|
proximityTrigger.setTriggerType(Trigger_Enum.proximity);
|
||||||
|
proximityTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
proximityTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
proximityTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().set(editIndex, proximityTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeActionStartActivityAdd)
|
else if(requestCode == requestCodeActionStartActivityAdd)
|
||||||
{
|
{
|
||||||
// manage start of other activity
|
// manage start of other activity
|
||||||
@@ -1582,6 +1746,27 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeActionMakePhoneCallAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newAction.setParentRule(ruleToEdit);
|
||||||
|
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionSetVariableAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newAction.setParentRule(ruleToEdit);
|
||||||
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeActionWakeLockAdd)
|
else if(requestCode == requestCodeActionWakeLockAdd)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
@@ -1692,6 +1877,35 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeActionMakePhoneCallEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter1) && data.hasExtra(intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionSetVariableEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeActionSetWifiEdit)
|
else if(requestCode == requestCodeActionSetWifiEdit)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
@@ -1886,6 +2100,28 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerCheckVariableAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
newTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerCalendarEventAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
newTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeTriggerTetheringEdit)
|
else if(requestCode == requestCodeTriggerTetheringEdit)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
@@ -1912,6 +2148,109 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerCheckVariableEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
Trigger editedTrigger = new Trigger();
|
||||||
|
editedTrigger.setTriggerType(Trigger_Enum.checkVariable);
|
||||||
|
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
editedTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerCalendarEventEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
Trigger editedTrigger = new Trigger();
|
||||||
|
editedTrigger.setTriggerType(Trigger_Enum.calendarEvent);
|
||||||
|
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
editedTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionCopyTextToClipboardAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newAction.setParentRule(ruleToEdit);
|
||||||
|
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionCopyTextToClipboardEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionSetLocationServiceAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newAction.setParentRule(ruleToEdit);
|
||||||
|
// newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionSetLocationServiceEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
// ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionSetSystemSettingAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newAction.setParentRule(ruleToEdit);
|
||||||
|
// newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(requestCode == requestCodeActionSetSystemSettingEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
// ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
|
||||||
|
if(data.hasExtra(intentNameActionParameter2))
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AlertDialog getActionTypeDialog()
|
protected AlertDialog getActionTypeDialog()
|
||||||
@@ -1971,12 +2310,35 @@ public class ActivityManageRule extends Activity
|
|||||||
items.add(new Item(typesLong[i].toString(), R.drawable.coffee));
|
items.add(new Item(typesLong[i].toString(), R.drawable.coffee));
|
||||||
else if(types[i].toString().equals(Action_Enum.runExecutable.toString()))
|
else if(types[i].toString().equals(Action_Enum.runExecutable.toString()))
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.script));
|
items.add(new Item(typesLong[i].toString(), R.drawable.script));
|
||||||
|
else if(types[i].toString().equals(Action_Enum.startPhoneCall.toString()))
|
||||||
|
{
|
||||||
|
if(ActivityPermissions.isPermissionDeclaredInManifest(ActivityManageRule.this, Manifest.permission.CALL_PHONE))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
||||||
|
}
|
||||||
|
else if(types[i].toString().equals(Action_Enum.stopPhoneCall.toString()))
|
||||||
|
{
|
||||||
|
if(ActivityPermissions.isPermissionDeclaredInManifest(ActivityManageRule.this, Manifest.permission.ANSWER_PHONE_CALLS))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
||||||
|
}
|
||||||
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||||
{
|
{
|
||||||
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
if(ActivityPermissions.isPermissionDeclaredInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
||||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.message));
|
items.add(new Item(typesLong[i].toString(), R.drawable.message));
|
||||||
}
|
}
|
||||||
|
else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString()))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.clipboard));
|
||||||
|
else if(types[i].toString().equals(Action_Enum.setVariable.toString()))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.variable));
|
||||||
|
else if(types[i].toString().equals(Action_Enum.setLocationService.toString()))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.compass_small));
|
||||||
|
else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||||
|
{
|
||||||
|
if(ActivityPermissions.isServiceAvailable(Miscellaneous.getAnyContext(), "MyAccessibilityService"))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.copier));
|
||||||
|
}
|
||||||
|
else if(types[i].toString().equals(Action_Enum.setSystemSetting.toString()))
|
||||||
|
{ items.add(new Item(typesLong[i].toString(), R.drawable.gears_small));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||||
}
|
}
|
||||||
@@ -2009,28 +2371,28 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
newAction = new Action();
|
newAction = new Action();
|
||||||
|
|
||||||
if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.triggerUrl.toString()))
|
CharSequence[] actionTypes = Action.getActionTypesAsArray();
|
||||||
|
if(actionTypes[which].toString().equals(Action_Enum.triggerUrl.toString()))
|
||||||
{
|
{
|
||||||
//launch other activity to enter a url and parameters;
|
//launch other activity to enter a url and parameters;
|
||||||
newAction.setAction(Action_Enum.triggerUrl);
|
newAction.setAction(Action_Enum.triggerUrl);
|
||||||
ActivityManageActionTriggerUrl.resultingAction = null;
|
|
||||||
Intent editTriggerIntent = new Intent(context, ActivityManageActionTriggerUrl.class);
|
Intent editTriggerIntent = new Intent(context, ActivityManageActionTriggerUrl.class);
|
||||||
startActivityForResult(editTriggerIntent, requestCodeActionTriggerUrlAdd);
|
startActivityForResult(editTriggerIntent, requestCodeActionTriggerUrlAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifi.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setWifi.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setWifi);
|
newAction.setAction(Action_Enum.setWifi);
|
||||||
Intent editSetWifiIntent = new Intent(context, ActivityManageActionWifi.class);
|
Intent editSetWifiIntent = new Intent(context, ActivityManageActionWifi.class);
|
||||||
startActivityForResult(editSetWifiIntent, requestCodeActionSetWifiAdd);
|
startActivityForResult(editSetWifiIntent, requestCodeActionSetWifiAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setBluetooth.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setBluetooth.toString()))
|
||||||
{
|
{
|
||||||
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
||||||
Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();;
|
Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();;
|
||||||
newAction.setAction(Action_Enum.setBluetooth);
|
newAction.setAction(Action_Enum.setBluetooth);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setUsbTethering.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setUsbTethering.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setUsbTethering);
|
newAction.setAction(Action_Enum.setUsbTethering);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
@@ -2038,12 +2400,12 @@ public class ActivityManageRule extends Activity
|
|||||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1)
|
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1)
|
||||||
Miscellaneous.messageBox(context.getResources().getString(R.string.warning), context.getResources().getString(R.string.usbTetheringFailForAboveGingerbread), context).show();
|
Miscellaneous.messageBox(context.getResources().getString(R.string.warning), context.getResources().getString(R.string.usbTetheringFailForAboveGingerbread), context).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifiTethering.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setWifiTethering.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setWifiTethering);
|
newAction.setAction(Action_Enum.setWifiTethering);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setBluetoothTethering.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setBluetoothTethering.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setBluetoothTethering);
|
newAction.setAction(Action_Enum.setBluetoothTethering);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
@@ -2054,12 +2416,12 @@ public class ActivityManageRule extends Activity
|
|||||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O)
|
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O)
|
||||||
Miscellaneous.messageBox(context.getResources().getString(R.string.notice), context.getResources().getString(R.string.btTetheringNotice), context).show();
|
Miscellaneous.messageBox(context.getResources().getString(R.string.notice), context.getResources().getString(R.string.btTetheringNotice), context).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setDisplayRotation.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setDisplayRotation.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setDisplayRotation);
|
newAction.setAction(Action_Enum.setDisplayRotation);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.changeSoundProfile.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.changeSoundProfile.toString()))
|
||||||
{
|
{
|
||||||
if(Profile.getProfileCollection().size() > 0)
|
if(Profile.getProfileCollection().size() > 0)
|
||||||
{
|
{
|
||||||
@@ -2069,23 +2431,23 @@ public class ActivityManageRule extends Activity
|
|||||||
else
|
else
|
||||||
Toast.makeText(context, getResources().getString(R.string.noProfilesCreateOneFirst), Toast.LENGTH_LONG).show();
|
Toast.makeText(context, getResources().getString(R.string.noProfilesCreateOneFirst), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.startOtherActivity.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.startOtherActivity.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.startOtherActivity);
|
newAction.setAction(Action_Enum.startOtherActivity);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class);
|
||||||
startActivityForResult(intent, requestCodeActionStartActivityAdd);
|
startActivityForResult(intent, requestCodeActionStartActivityAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.waitBeforeNextAction.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.waitBeforeNextAction.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.waitBeforeNextAction);
|
newAction.setAction(Action_Enum.waitBeforeNextAction);
|
||||||
getActionWaitBeforeNextActionDialog(ActivityManageRule.this).show();
|
getActionWaitBeforeNextActionDialog(ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.turnScreenOnOrOff.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.turnScreenOnOrOff.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.turnScreenOnOrOff);
|
newAction.setAction(Action_Enum.turnScreenOnOrOff);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setAirplaneMode.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setAirplaneMode.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setAirplaneMode);
|
newAction.setAction(Action_Enum.setAirplaneMode);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
@@ -2094,13 +2456,13 @@ public class ActivityManageRule extends Activity
|
|||||||
Miscellaneous.messageBox(getResources().getString(R.string.airplaneMode), getResources().getString(R.string.rootExplanation), ActivityManageRule.this).show();
|
Miscellaneous.messageBox(getResources().getString(R.string.airplaneMode), getResources().getString(R.string.rootExplanation), ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setDataConnection.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setDataConnection.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setDataConnection);
|
newAction.setAction(Action_Enum.setDataConnection);
|
||||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||||
Miscellaneous.messageBox(getResources().getString(R.string.actionDataConnection), getResources().getString(R.string.rootExplanation), ActivityManageRule.this).show();
|
Miscellaneous.messageBox(getResources().getString(R.string.actionDataConnection), getResources().getString(R.string.rootExplanation), ActivityManageRule.this).show();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.speakText.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.speakText.toString()))
|
||||||
{
|
{
|
||||||
//launch other activity to enter a url and parameters;
|
//launch other activity to enter a url and parameters;
|
||||||
newAction.setAction(Action_Enum.speakText);
|
newAction.setAction(Action_Enum.speakText);
|
||||||
@@ -2108,9 +2470,9 @@ public class ActivityManageRule extends Activity
|
|||||||
Intent editTriggerIntent = new Intent(context, ActivityManageActionSpeakText.class);
|
Intent editTriggerIntent = new Intent(context, ActivityManageActionSpeakText.class);
|
||||||
startActivityForResult(editTriggerIntent, requestCodeActionSpeakTextAdd);
|
startActivityForResult(editTriggerIntent, requestCodeActionSpeakTextAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendTextMessage.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||||
{
|
{
|
||||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
if(ActivityPermissions.isPermissionDeclaredInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
||||||
{
|
{
|
||||||
//launch other activity to enter parameters;
|
//launch other activity to enter parameters;
|
||||||
newAction.setAction(Action_Enum.sendTextMessage);
|
newAction.setAction(Action_Enum.sendTextMessage);
|
||||||
@@ -2119,66 +2481,108 @@ public class ActivityManageRule extends Activity
|
|||||||
startActivityForResult(editTriggerIntent, requestCodeActionSendTextMessageAdd);
|
startActivityForResult(editTriggerIntent, requestCodeActionSendTextMessageAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.playMusic.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.playMusic.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.playMusic);
|
newAction.setAction(Action_Enum.playMusic);
|
||||||
ruleToEdit.getActionSet().add(newAction);
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
refreshActionList();
|
refreshActionList();
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.vibrate.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.vibrate.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.vibrate);
|
newAction.setAction(Action_Enum.vibrate);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
||||||
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendBroadcast.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.sendBroadcast.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.sendBroadcast);
|
newAction.setAction(Action_Enum.sendBroadcast);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSendBroadcast.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSendBroadcast.class);
|
||||||
startActivityForResult(intent, requestCodeActionSendBroadcastAdd);
|
startActivityForResult(intent, requestCodeActionSendBroadcastAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.runExecutable.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.runExecutable.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.runExecutable);
|
newAction.setAction(Action_Enum.runExecutable);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
|
||||||
startActivityForResult(intent, requestCodeActionRunExecutableAdd);
|
startActivityForResult(intent, requestCodeActionRunExecutableAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.wakelock.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.startPhoneCall.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.startPhoneCall);
|
||||||
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionMakePhoneCall.class);
|
||||||
|
startActivityForResult(intent, requestCodeActionMakePhoneCallAdd);
|
||||||
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.setVariable.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.setVariable);
|
||||||
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSetVariable.class);
|
||||||
|
startActivityForResult(intent, requestCodeActionSetVariableAdd);
|
||||||
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.stopPhoneCall.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.stopPhoneCall);
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
refreshActionList();
|
||||||
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.wakelock.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.wakelock);
|
newAction.setAction(Action_Enum.wakelock);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionWakeLock.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionWakeLock.class);
|
||||||
startActivityForResult(intent, requestCodeActionWakeLockAdd);
|
startActivityForResult(intent, requestCodeActionWakeLockAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.controlMediaPlayback.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.controlMediaPlayback.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.controlMediaPlayback);
|
newAction.setAction(Action_Enum.controlMediaPlayback);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionControlMedia.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionControlMedia.class);
|
||||||
startActivityForResult(intent, requestCodeActionControlMediaAdd);
|
startActivityForResult(intent, requestCodeActionControlMediaAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.createNotification.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.createNotification.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.createNotification);
|
newAction.setAction(Action_Enum.createNotification);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCreateNotification.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCreateNotification.class);
|
||||||
startActivityForResult(intent, requestCodeActionCreateNotificationAdd);
|
startActivityForResult(intent, requestCodeActionCreateNotificationAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.closeNotification.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.closeNotification.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.closeNotification);
|
newAction.setAction(Action_Enum.closeNotification);
|
||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCloseNotification.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCloseNotification.class);
|
||||||
startActivityForResult(intent, requestCodeActionCloseNotificationAdd);
|
startActivityForResult(intent, requestCodeActionCloseNotificationAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setScreenBrightness.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.setScreenBrightness.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setScreenBrightness);
|
newAction.setAction(Action_Enum.setScreenBrightness);
|
||||||
Intent actionScreenBrightnessIntent = new Intent(context, ActivityManageActionBrightnessSetting.class);
|
Intent actionScreenBrightnessIntent = new Intent(context, ActivityManageActionBrightnessSetting.class);
|
||||||
startActivityForResult(actionScreenBrightnessIntent, requestCodeActionScreenBrightnessAdd);
|
startActivityForResult(actionScreenBrightnessIntent, requestCodeActionScreenBrightnessAdd);
|
||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.playSound.toString()))
|
else if(actionTypes[which].toString().equals(Action_Enum.playSound.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.playSound);
|
newAction.setAction(Action_Enum.playSound);
|
||||||
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
||||||
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundAdd);
|
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundAdd);
|
||||||
}
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.copyToClipboard.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.copyToClipboard);
|
||||||
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCopyToClipboard.class);
|
||||||
|
startActivityForResult(intent, requestCodeActionCopyTextToClipboardAdd);
|
||||||
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.takeScreenshot);
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
refreshActionList();
|
||||||
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.setLocationService.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.setLocationService);
|
||||||
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionLocationService.class);
|
||||||
|
startActivityForResult(intent, requestCodeActionSetLocationServiceAdd);
|
||||||
|
}
|
||||||
|
else if(actionTypes[which].toString().equals(Action_Enum.setSystemSetting.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.setSystemSetting);
|
||||||
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSetSystemSetting.class);
|
||||||
|
startActivityForResult(intent, requestCodeActionSetSystemSettingAdd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -16,22 +18,27 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.jens.automation2.receivers.BluetoothReceiver;
|
import com.jens.automation2.receivers.BluetoothReceiver;
|
||||||
|
|
||||||
public class ActivityManageTriggerBluetooth extends Activity
|
public class ActivityManageTriggerBluetooth extends Activity
|
||||||
{
|
{
|
||||||
|
final static int requestPermissionCodeBluetoothConnect = 4711;
|
||||||
protected static Trigger editedBluetoothTrigger;
|
protected static Trigger editedBluetoothTrigger;
|
||||||
RadioButton radioAnyBluetoothDevice, radioNoDevice, radioDeviceFromList, radioBluetoothConnected, radioBluetoothDisconnected, radioBluetoothInRange, radioBluetoothOutRange;
|
RadioButton radioAnyBluetoothDevice, radioNoDevice, radioDeviceFromList, radioBluetoothConnected, radioBluetoothDisconnected, radioBluetoothInRange, radioBluetoothOutRange;
|
||||||
Button bSaveBluetoothTrigger;
|
Button bSaveBluetoothTrigger;
|
||||||
Spinner spinnerBluetoothDevices;
|
Spinner spinnerBluetoothDevices;
|
||||||
TextView tvBluetoothNotPresentNotice;
|
TextView tvBluetoothNotPresentNotice;
|
||||||
|
|
||||||
ArrayAdapter<String> bluetoothDevicesSpinnerAdapter;
|
ArrayAdapter<String> bluetoothDevicesSpinnerAdapter = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_bluetooth);
|
setContentView(R.layout.activity_manage_trigger_bluetooth);
|
||||||
|
|
||||||
radioAnyBluetoothDevice = (RadioButton)findViewById(R.id.radioAnyBluetoothDevice);
|
radioAnyBluetoothDevice = (RadioButton)findViewById(R.id.radioAnyBluetoothDevice);
|
||||||
@@ -44,8 +51,6 @@ public class ActivityManageTriggerBluetooth extends Activity
|
|||||||
bSaveBluetoothTrigger = (Button)findViewById(R.id.bSaveBluetoothTrigger);
|
bSaveBluetoothTrigger = (Button)findViewById(R.id.bSaveBluetoothTrigger);
|
||||||
spinnerBluetoothDevices = (Spinner)findViewById(R.id.spinnerBluetoothDevices);
|
spinnerBluetoothDevices = (Spinner)findViewById(R.id.spinnerBluetoothDevices);
|
||||||
tvBluetoothNotPresentNotice = (TextView)findViewById(R.id.tvBluetoothNotPresentNotice);
|
tvBluetoothNotPresentNotice = (TextView)findViewById(R.id.tvBluetoothNotPresentNotice);
|
||||||
|
|
||||||
bluetoothDevicesSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, BluetoothReceiver.getAllPairedBluetoothDevicesStrings());
|
|
||||||
|
|
||||||
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
||||||
tvBluetoothNotPresentNotice.setVisibility(View.VISIBLE);
|
tvBluetoothNotPresentNotice.setVisibility(View.VISIBLE);
|
||||||
@@ -73,17 +78,37 @@ public class ActivityManageTriggerBluetooth extends Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
refreshBluetoothDeviceSpinner();
|
if(Miscellaneous.getTargetSDK(ActivityManageTriggerBluetooth.this) >= 31 && !ActivityPermissions.havePermission(Manifest.permission.BLUETOOTH_CONNECT, ActivityManageTriggerBluetooth.this))
|
||||||
spinnerBluetoothDevices.setEnabled(false);
|
requestPermissions(new String[] {Manifest.permission.BLUETOOTH_CONNECT }, requestPermissionCodeBluetoothConnect);
|
||||||
|
else
|
||||||
|
refreshBluetoothDeviceSpinner();
|
||||||
|
|
||||||
|
spinnerBluetoothDevices.setEnabled(false);
|
||||||
|
|
||||||
if(editedBluetoothTrigger.getBluetoothDeviceAddress() != null && editedBluetoothTrigger.getBluetoothDeviceAddress().length() > 0)
|
if(editedBluetoothTrigger.getBluetoothDeviceAddress() != null && editedBluetoothTrigger.getBluetoothDeviceAddress().length() > 0)
|
||||||
loadVariableIntoGui();
|
loadVariableIntoGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void refreshBluetoothDeviceSpinner()
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
||||||
|
{
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
||||||
|
if(requestCode == requestPermissionCodeBluetoothConnect)
|
||||||
|
{
|
||||||
|
if(permissions[0].equals(Manifest.permission.BLUETOOTH_CONNECT) && grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||||
|
refreshBluetoothDeviceSpinner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void refreshBluetoothDeviceSpinner()
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "Spinner", "Attempting to update spinnerBluetoothDevices", 4);
|
Miscellaneous.logEvent("i", "Spinner", "Attempting to update spinnerBluetoothDevices", 4);
|
||||||
|
|
||||||
|
if(bluetoothDevicesSpinnerAdapter == null)
|
||||||
|
bluetoothDevicesSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, BluetoothReceiver.getAllPairedBluetoothDevicesStrings());
|
||||||
|
|
||||||
if(spinnerBluetoothDevices.getAdapter() == null)
|
if(spinnerBluetoothDevices.getAdapter() == null)
|
||||||
{
|
{
|
||||||
spinnerBluetoothDevices.setAdapter(bluetoothDevicesSpinnerAdapter);
|
spinnerBluetoothDevices.setAdapter(bluetoothDevicesSpinnerAdapter);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ public class ActivityManageTriggerBroadcast extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_broadcasts);
|
setContentView(R.layout.activity_manage_trigger_broadcasts);
|
||||||
|
|
||||||
bBroadcastShowSuggestions = findViewById(R.id.bBroadcastShowSuggestions);
|
bBroadcastShowSuggestions = findViewById(R.id.bBroadcastShowSuggestions);
|
||||||
|
|||||||
@@ -0,0 +1,405 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.CalendarContract;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActivityManageTriggerCalendar extends Activity
|
||||||
|
{
|
||||||
|
CheckBox chkCalendarEventActive, chkCalendarAvailabilityBusy, chkCalendarAvailabilityFree, chkCalendarAvailabilityTentative, chkCalendarAvailabilityOutOfOffice, chkCalendarAvailabilityWorkingElsewhere, chkCalendarAllDayEvent, chkCalendarEvaluateAllDayEvent, chkCalendarEvaluateReoccurring, chkCalendarReoccurring;
|
||||||
|
Spinner spinnerCalendarTitleDirection, spinnerCalendarLocationDirection, spinnerCalendarDescriptionDirection;
|
||||||
|
EditText etCalendarTitle, etCalendarLocation, etCalendarDescription;
|
||||||
|
LinearLayout llCalendarSelection;
|
||||||
|
Button bSaveTriggerCalendar;
|
||||||
|
List<CheckBox> checkboxesCalendars = new ArrayList<>();
|
||||||
|
final static String separator = ",";
|
||||||
|
TextView tvMissingCalendarHint;
|
||||||
|
|
||||||
|
private static String[] directions;
|
||||||
|
ArrayAdapter<String> directionSpinnerAdapter;
|
||||||
|
public static int requestCodePermissionReadCalendar = 815;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
setContentView(R.layout.activity_manage_trigger_calendar);
|
||||||
|
|
||||||
|
chkCalendarEventActive = (CheckBox) findViewById(R.id.chkCalendarEventActive);
|
||||||
|
spinnerCalendarTitleDirection = (Spinner)findViewById(R.id.spinnerCalendarTitleDirection);
|
||||||
|
spinnerCalendarLocationDirection = (Spinner)findViewById(R.id.spinnerCalendarLocationDirection);
|
||||||
|
spinnerCalendarDescriptionDirection = (Spinner)findViewById(R.id.spinnerCalendarDescriptionDirection);
|
||||||
|
chkCalendarAllDayEvent = (CheckBox)findViewById(R.id.chkCalendarAllDayEvent);
|
||||||
|
chkCalendarAvailabilityBusy = (CheckBox)findViewById(R.id.chkCalendarAvailabilityBusy);
|
||||||
|
chkCalendarAvailabilityFree = (CheckBox)findViewById(R.id.chkCalendarAvailabilityFree);
|
||||||
|
chkCalendarAvailabilityTentative = (CheckBox)findViewById(R.id.chkCalendarAvailabilityTentative);
|
||||||
|
chkCalendarAvailabilityOutOfOffice = (CheckBox)findViewById(R.id.chkCalendarAvailabilityOutOfOffice);
|
||||||
|
chkCalendarAvailabilityWorkingElsewhere = (CheckBox)findViewById(R.id.chkCalendarAvailabilityWorkingElsewhere);
|
||||||
|
chkCalendarEvaluateAllDayEvent = (CheckBox)findViewById(R.id.chkCalendarEvaluateAllDayEvent);
|
||||||
|
chkCalendarEvaluateReoccurring = (CheckBox)findViewById(R.id.chkCalendarEvaluateReoccurring);
|
||||||
|
chkCalendarReoccurring = (CheckBox)findViewById(R.id.chkCalendarReoccurring);
|
||||||
|
|
||||||
|
tvMissingCalendarHint = (TextView) findViewById(R.id.tvMissingCalendarHint);
|
||||||
|
|
||||||
|
llCalendarSelection = (LinearLayout)findViewById(R.id.llCalendarSelection);
|
||||||
|
|
||||||
|
etCalendarTitle = (EditText)findViewById(R.id.etCalendarTitle);
|
||||||
|
etCalendarLocation = (EditText)findViewById(R.id.etCalendarLocation);
|
||||||
|
etCalendarDescription = (EditText)findViewById(R.id.etCalendarDescription);
|
||||||
|
|
||||||
|
bSaveTriggerCalendar = (Button)findViewById(R.id.bSaveTriggerCalendar);
|
||||||
|
|
||||||
|
directions = new String[] {
|
||||||
|
getResources().getString(R.string.directionStringEquals),
|
||||||
|
getResources().getString(R.string.directionStringContains),
|
||||||
|
getResources().getString(R.string.directionStringDoesNotContain),
|
||||||
|
getResources().getString(R.string.directionStringStartsWith),
|
||||||
|
getResources().getString(R.string.directionStringEndsWith),
|
||||||
|
getResources().getString(R.string.directionStringNotEquals)
|
||||||
|
};
|
||||||
|
directionSpinnerAdapter = new ArrayAdapter<>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageTriggerCalendar.directions);
|
||||||
|
spinnerCalendarTitleDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
spinnerCalendarLocationDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
spinnerCalendarDescriptionDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
directionSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
chkCalendarEvaluateAllDayEvent.setChecked(false);
|
||||||
|
chkCalendarAllDayEvent.setEnabled(false);
|
||||||
|
chkCalendarEvaluateAllDayEvent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
chkCalendarAllDayEvent.setEnabled(checked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chkCalendarEvaluateReoccurring.setChecked(false);
|
||||||
|
chkCalendarReoccurring.setEnabled(false);
|
||||||
|
chkCalendarEvaluateReoccurring.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
chkCalendarReoccurring.setEnabled(checked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
{
|
||||||
|
if(ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, ActivityManageTriggerCalendar.this) || ActivityPermissions.havePermission(Manifest.permission.WRITE_CALENDAR, ActivityManageTriggerCalendar.this))
|
||||||
|
populateCalenderCheckboxes();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityManageTriggerCalendar.this);
|
||||||
|
builder.setTitle(getResources().getString(R.string.info));
|
||||||
|
builder.setMessage(getResources().getString(R.string.permissionCalendarRequired));
|
||||||
|
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
ActivityManageTriggerCalendar.this.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
|
{
|
||||||
|
requestPermissions(new String[]{ Manifest.permission.READ_CALENDAR } , requestCodePermissionReadCalendar);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
populateCalenderCheckboxes();
|
||||||
|
|
||||||
|
chkCalendarEventActive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
if(checked)
|
||||||
|
chkCalendarEventActive.setText(R.string.eventIsCurrentlyHappening);
|
||||||
|
else
|
||||||
|
chkCalendarEventActive.setText(R.string.eventIsCurrentlyNotHappening);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chkCalendarAllDayEvent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
if(checked)
|
||||||
|
chkCalendarAllDayEvent.setText(getResources().getString(R.string.allDayEventTrue));
|
||||||
|
else
|
||||||
|
chkCalendarAllDayEvent.setText(getResources().getString(R.string.allDayEventFalse));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chkCalendarReoccurring.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
if(checked)
|
||||||
|
chkCalendarReoccurring.setText(R.string.reoccurringTrue);
|
||||||
|
else
|
||||||
|
chkCalendarReoccurring.setText(R.string.reoccurringFalse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bSaveTriggerCalendar.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
String titleDir = Trigger.getMatchCode(spinnerCalendarTitleDirection.getSelectedItem().toString());
|
||||||
|
String title = etCalendarTitle.getText().toString();
|
||||||
|
String descriptionDir = Trigger.getMatchCode(spinnerCalendarDescriptionDirection.getSelectedItem().toString());
|
||||||
|
String description = etCalendarDescription.getText().toString();
|
||||||
|
String locationDir = Trigger.getMatchCode(spinnerCalendarLocationDirection.getSelectedItem().toString());
|
||||||
|
String location = etCalendarLocation.getText().toString();
|
||||||
|
|
||||||
|
List<String> availabilityList = new ArrayList<>();
|
||||||
|
if(chkCalendarAvailabilityBusy.isChecked())
|
||||||
|
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_BUSY));
|
||||||
|
|
||||||
|
if(chkCalendarAvailabilityFree.isChecked())
|
||||||
|
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_FREE));
|
||||||
|
|
||||||
|
if(chkCalendarAvailabilityTentative.isChecked())
|
||||||
|
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_TENTATIVE));
|
||||||
|
|
||||||
|
if(chkCalendarAvailabilityOutOfOffice.isChecked())
|
||||||
|
availabilityList.add(String.valueOf(CalendarReceiver.AVAILABILITY_OUT_OF_OFFICE));
|
||||||
|
|
||||||
|
if(chkCalendarAvailabilityWorkingElsewhere.isChecked())
|
||||||
|
availabilityList.add(String.valueOf(CalendarReceiver.AVAILABILITY_WORKING_ELSEWHERE));
|
||||||
|
|
||||||
|
List<CalendarReceiver.AndroidCalendar> selectedCalendarsList = new ArrayList<>();
|
||||||
|
for(CheckBox calCheckbox : checkboxesCalendars)
|
||||||
|
{
|
||||||
|
if(calCheckbox.isChecked())
|
||||||
|
selectedCalendarsList.add((CalendarReceiver.AndroidCalendar) calCheckbox.getTag());
|
||||||
|
}
|
||||||
|
List<String> selectedCalendarsIdArray = new ArrayList<>();
|
||||||
|
for(CalendarReceiver.AndroidCalendar cal : selectedCalendarsList)
|
||||||
|
selectedCalendarsIdArray.add(String.valueOf(cal.calendarId));
|
||||||
|
|
||||||
|
String returnString =
|
||||||
|
titleDir + Trigger.triggerParameter2Split + title + Trigger.triggerParameter2Split +
|
||||||
|
descriptionDir + Trigger.triggerParameter2Split + description + Trigger.triggerParameter2Split +
|
||||||
|
locationDir + Trigger.triggerParameter2Split + location + Trigger.triggerParameter2Split +
|
||||||
|
String.valueOf(chkCalendarEvaluateAllDayEvent.isChecked()) + Trigger.triggerParameter2Split +
|
||||||
|
String.valueOf(chkCalendarAllDayEvent.isChecked()) + Trigger.triggerParameter2Split +
|
||||||
|
String.valueOf(chkCalendarEvaluateReoccurring.isChecked()) + Trigger.triggerParameter2Split +
|
||||||
|
String.valueOf(chkCalendarReoccurring.isChecked()) + Trigger.triggerParameter2Split +
|
||||||
|
Miscellaneous.explode(separator, availabilityList.toArray(new String[availabilityList.size()])) + Trigger.triggerParameter2Split +
|
||||||
|
Miscellaneous.explode(separator, selectedCalendarsIdArray.toArray(new String[selectedCalendarsIdArray.size()]));
|
||||||
|
|
||||||
|
Intent data = new Intent();
|
||||||
|
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkCalendarEventActive.isChecked());
|
||||||
|
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, returnString);
|
||||||
|
ActivityManageTriggerCalendar.this.setResult(RESULT_OK, data);
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Intent inputIntent = getIntent();
|
||||||
|
if(inputIntent.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||||
|
loadValuesIntoGui(inputIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateCalenderCheckboxes()
|
||||||
|
{
|
||||||
|
List<CalendarReceiver.AndroidCalendar> calList = CalendarReceiver.readCalendars(ActivityManageTriggerCalendar.this);
|
||||||
|
|
||||||
|
if(calList != null)
|
||||||
|
{
|
||||||
|
if(calList.size() > 0)
|
||||||
|
{
|
||||||
|
for (CalendarReceiver.AndroidCalendar cal : calList)
|
||||||
|
{
|
||||||
|
CheckBox oneCalCheckbox = new CheckBox(ActivityManageTriggerCalendar.this);
|
||||||
|
oneCalCheckbox.setText(cal.toString());
|
||||||
|
oneCalCheckbox.setTag(cal);
|
||||||
|
llCalendarSelection.addView(oneCalCheckbox);
|
||||||
|
checkboxesCalendars.add(oneCalCheckbox);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.noCalendarsOnYourDevice), ActivityManageTriggerCalendar.this).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.errorReadingCalendars), ActivityManageTriggerCalendar.this).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadValuesIntoGui(Intent data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (data.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||||
|
chkCalendarEventActive.setChecked(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||||
|
|
||||||
|
if (data.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||||
|
{
|
||||||
|
String input[] = data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split, -1);
|
||||||
|
/*
|
||||||
|
0 = titleDir
|
||||||
|
1 = title
|
||||||
|
2 = descriptionDir
|
||||||
|
3 = description
|
||||||
|
4 = locationDir
|
||||||
|
5 = location
|
||||||
|
6 = evaluate all day event
|
||||||
|
7 = all day event
|
||||||
|
8 = evaluate reoccurring
|
||||||
|
9 = reoccurring
|
||||||
|
10 = availability list
|
||||||
|
11 = calendars list
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (int i = 0; i < directions.length; i++)
|
||||||
|
{
|
||||||
|
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[0]))
|
||||||
|
spinnerCalendarTitleDirection.setSelection(i);
|
||||||
|
|
||||||
|
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[2]))
|
||||||
|
spinnerCalendarDescriptionDirection.setSelection(i);
|
||||||
|
|
||||||
|
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[4]))
|
||||||
|
spinnerCalendarLocationDirection.setSelection(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
etCalendarTitle.setText(input[1]);
|
||||||
|
etCalendarDescription.setText(input[3]);
|
||||||
|
etCalendarLocation.setText(input[5]);
|
||||||
|
|
||||||
|
chkCalendarEvaluateAllDayEvent.setChecked(Boolean.parseBoolean(input[6]));
|
||||||
|
chkCalendarAllDayEvent.setChecked(Boolean.parseBoolean(input[7]));
|
||||||
|
|
||||||
|
chkCalendarEvaluateReoccurring.setChecked(Boolean.parseBoolean(input[8]));
|
||||||
|
chkCalendarReoccurring.setChecked(Boolean.parseBoolean(input[9]));
|
||||||
|
|
||||||
|
String[] availabilities = null;
|
||||||
|
if (!StringUtils.isEmpty(input[10]))
|
||||||
|
availabilities = input[10].split(separator);
|
||||||
|
|
||||||
|
if (availabilities != null)
|
||||||
|
{
|
||||||
|
for (String avail : availabilities)
|
||||||
|
{
|
||||||
|
if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_BUSY)
|
||||||
|
chkCalendarAvailabilityBusy.setChecked(true);
|
||||||
|
else if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_FREE)
|
||||||
|
chkCalendarAvailabilityFree.setChecked(true);
|
||||||
|
else if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_TENTATIVE)
|
||||||
|
chkCalendarAvailabilityTentative.setChecked(true);
|
||||||
|
else if (Integer.parseInt(avail) == CalendarReceiver.AVAILABILITY_OUT_OF_OFFICE)
|
||||||
|
chkCalendarAvailabilityOutOfOffice.setChecked(true);
|
||||||
|
else if (Integer.parseInt(avail) == CalendarReceiver.AVAILABILITY_WORKING_ELSEWHERE)
|
||||||
|
chkCalendarAvailabilityWorkingElsewhere.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] calendars = null;
|
||||||
|
if (!StringUtils.isEmpty(input[11]))
|
||||||
|
calendars = input[11].split(separator);
|
||||||
|
|
||||||
|
if (calendars != null)
|
||||||
|
{
|
||||||
|
List<String> usedCalendarIDs = new ArrayList<>();
|
||||||
|
List<String> unusedCalendarIDs = new ArrayList<>();
|
||||||
|
for (CheckBox checkbox : checkboxesCalendars)
|
||||||
|
{
|
||||||
|
int id = ((CalendarReceiver.AndroidCalendar) checkbox.getTag()).calendarId;
|
||||||
|
for (String calId : calendars)
|
||||||
|
{
|
||||||
|
if (calId.equals(String.valueOf(id)))
|
||||||
|
{
|
||||||
|
usedCalendarIDs.add(String.valueOf(id));
|
||||||
|
checkbox.setChecked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String calId : calendars)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.arraySearch((ArrayList<String>) usedCalendarIDs, calId, false, true))
|
||||||
|
unusedCalendarIDs.add(calId);
|
||||||
|
}
|
||||||
|
if (unusedCalendarIDs.size() > 0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
A calendar has been configured that has been deleted since. We cannot resolve it.
|
||||||
|
It will be removed with the next save, but we should inform this user
|
||||||
|
of these circumstances.
|
||||||
|
*/
|
||||||
|
|
||||||
|
tvMissingCalendarHint.setText(String.format(getResources().getString(R.string.calendarsMissingHint), Miscellaneous.explode(", ", (ArrayList<String>) unusedCalendarIDs)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", "ActivityManagerTriggerCalender", "Error loading values into GUI: " + Log.getStackTraceString(e), 1);
|
||||||
|
Toast.makeText(ActivityManageTriggerCalendar.this, getResources().getString(R.string.errorLoadingValues), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
||||||
|
{
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
||||||
|
if(requestCode == requestCodePermissionReadCalendar)
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
permissions[0].equals(Manifest.permission.READ_CALENDAR)
|
||||||
|
||
|
||||||
|
permissions[0].equals(Manifest.permission.WRITE_CALENDAR)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||||
|
populateCalenderCheckboxes();
|
||||||
|
else
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.BatteryManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.jens.automation2.receivers.BatteryReceiver;
|
||||||
|
|
||||||
|
public class ActivityManageTriggerCharging extends Activity
|
||||||
|
{
|
||||||
|
RadioButton rbChargingOn, rbChargingOff, rbChargingTypeAny, rbChargingTypeAc, rbChargingTypeUsb, rbChargingTypeWireless;
|
||||||
|
Button bTriggerChargingSave;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
setContentView(R.layout.activity_manage_trigger_charging);
|
||||||
|
|
||||||
|
rbChargingOn = (RadioButton) findViewById(R.id.rbChargingOn);
|
||||||
|
rbChargingOff = (RadioButton) findViewById(R.id.rbChargingOff);
|
||||||
|
rbChargingTypeAny = (RadioButton) findViewById(R.id.rbChargingTypeAny);
|
||||||
|
rbChargingTypeAc = (RadioButton) findViewById(R.id.rbChargingTypeAc);
|
||||||
|
rbChargingTypeUsb = (RadioButton) findViewById(R.id.rbChargingTypeUsb);
|
||||||
|
rbChargingTypeWireless = (RadioButton) findViewById(R.id.rbChargingTypeWireless);
|
||||||
|
|
||||||
|
bTriggerChargingSave = (Button) findViewById(R.id.bTriggerChargingSave);
|
||||||
|
|
||||||
|
Intent input = getIntent();
|
||||||
|
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||||
|
{
|
||||||
|
|
||||||
|
rbChargingOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||||
|
rbChargingOff.setChecked(!input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||||
|
|
||||||
|
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||||
|
{
|
||||||
|
|
||||||
|
String[] params2 = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||||
|
int chargingType = Integer.parseInt(params2[0]);
|
||||||
|
|
||||||
|
rbChargingTypeAny.setChecked(chargingType == 0);
|
||||||
|
rbChargingTypeAc.setChecked(chargingType == BatteryManager.BATTERY_PLUGGED_AC);
|
||||||
|
rbChargingTypeUsb.setChecked(chargingType == BatteryManager.BATTERY_PLUGGED_USB);
|
||||||
|
rbChargingTypeWireless.setChecked(chargingType == BatteryManager.BATTERY_PLUGGED_WIRELESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bTriggerChargingSave.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbChargingOn.isChecked());
|
||||||
|
|
||||||
|
String param2 = "";
|
||||||
|
|
||||||
|
if(rbChargingTypeAny.isChecked())
|
||||||
|
param2 = String.valueOf(BatteryReceiver.batteryChargingTypeAny);
|
||||||
|
else if(rbChargingTypeAc.isChecked())
|
||||||
|
param2 = String.valueOf(BatteryReceiver.batteryChargingTypeAc);
|
||||||
|
else if(rbChargingTypeUsb.isChecked())
|
||||||
|
param2 = String.valueOf(BatteryReceiver.batteryChargingTypeUsb);
|
||||||
|
else if(rbChargingTypeWireless.isChecked())
|
||||||
|
param2 = String.valueOf(BatteryReceiver.batteryChargingTypeWireless);
|
||||||
|
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, param2);
|
||||||
|
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class ActivityManageTriggerCheckVariable extends Activity
|
||||||
|
{
|
||||||
|
EditText etVariableKeyTrigger, etVariableValueTrigger;
|
||||||
|
CheckBox chkTriggerVariableDirection;
|
||||||
|
Button bTriggerVariableSave;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
|
setContentView(R.layout.activity_manage_trigger_check_variable);
|
||||||
|
|
||||||
|
etVariableKeyTrigger = (EditText) findViewById(R.id.etVariableKeyTrigger);
|
||||||
|
etVariableValueTrigger = (EditText) findViewById(R.id.etVariableValueTrigger);
|
||||||
|
chkTriggerVariableDirection = (CheckBox)findViewById(R.id.chkTriggerVariableDirection);
|
||||||
|
bTriggerVariableSave = (Button) findViewById(R.id.bTriggerVariableSave);
|
||||||
|
|
||||||
|
Intent input = getIntent();
|
||||||
|
|
||||||
|
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||||
|
chkTriggerVariableDirection.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||||
|
|
||||||
|
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||||
|
{
|
||||||
|
String[] conditions = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||||
|
etVariableKeyTrigger.setText(conditions[0]);
|
||||||
|
if(conditions.length > 1)
|
||||||
|
etVariableValueTrigger.setText(conditions[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
chkTriggerVariableDirection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||||
|
{
|
||||||
|
if(checked)
|
||||||
|
chkTriggerVariableDirection.setText(getResources().getString(R.string.matches));
|
||||||
|
else
|
||||||
|
chkTriggerVariableDirection.setText(getResources().getString(R.string.doesNotMatch));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bTriggerVariableSave.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkTriggerVariableDirection.isChecked());
|
||||||
|
|
||||||
|
if(StringUtils.isEmpty(etVariableValueTrigger.getText().toString()))
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, etVariableKeyTrigger.getText().toString());
|
||||||
|
else
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, etVariableKeyTrigger.getText().toString() + Trigger.triggerParameter2Split + etVariableValueTrigger.getText().toString());
|
||||||
|
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -104,6 +104,8 @@ public class ActivityManageTriggerDeviceOrientation extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_device_orientation);
|
setContentView(R.layout.activity_manage_trigger_device_orientation);
|
||||||
|
|
||||||
currentAzimuth = (TextView) findViewById(R.id.tvCurrentAzimuth);
|
currentAzimuth = (TextView) findViewById(R.id.tvCurrentAzimuth);
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public class ActivityManageTriggerNfc extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_nfc);
|
setContentView(R.layout.activity_manage_trigger_nfc);
|
||||||
|
|
||||||
etNewNfcIdValue = (EditText)findViewById(R.id.etNewNfcIdValue);
|
etNewNfcIdValue = (EditText)findViewById(R.id.etNewNfcIdValue);
|
||||||
@@ -149,7 +151,12 @@ public class ActivityManageTriggerNfc extends Activity
|
|||||||
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
|
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
|
||||||
final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
|
final PendingIntent pendingIntent;
|
||||||
|
|
||||||
|
if(Miscellaneous.getTargetSDK(activity) >= 31)
|
||||||
|
pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
else
|
||||||
|
pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
|
||||||
|
|
||||||
IntentFilter[] filters = new IntentFilter[1];
|
IntentFilter[] filters = new IntentFilter[1];
|
||||||
String[][] techList = new String[][]{};
|
String[][] techList = new String[][]{};
|
||||||
@@ -184,7 +191,7 @@ public class ActivityManageTriggerNfc extends Activity
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
/**
|
/*
|
||||||
* Call this before onPause, otherwise an IllegalArgumentException is thrown as well.
|
* Call this before onPause, otherwise an IllegalArgumentException is thrown as well.
|
||||||
*/
|
*/
|
||||||
disableForegroundDispatch(this);
|
disableForegroundDispatch(this);
|
||||||
@@ -196,7 +203,7 @@ public class ActivityManageTriggerNfc extends Activity
|
|||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
/**
|
/*
|
||||||
* It's important, that the activity is in the foreground (resumed). Otherwise
|
* It's important, that the activity is in the foreground (resumed). Otherwise
|
||||||
* an IllegalStateException is thrown.
|
* an IllegalStateException is thrown.
|
||||||
*/
|
*/
|
||||||
@@ -230,10 +237,18 @@ public class ActivityManageTriggerNfc extends Activity
|
|||||||
if(currentStatus == 0)
|
if(currentStatus == 0)
|
||||||
{
|
{
|
||||||
generatedId = NfcReceiver.readTag(discoveredTag);
|
generatedId = NfcReceiver.readTag(discoveredTag);
|
||||||
if(generatedId != null && generatedId.length() > 0)
|
if(generatedId != null && generatedId.length() > 0)
|
||||||
tvCurrentNfcId.setText(generatedId);
|
{
|
||||||
|
tvCurrentNfcId.setText(generatedId);
|
||||||
|
bReadNfcTag.setEnabled(true);
|
||||||
|
bUseValueCurrentlyStored.setEnabled(true);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
tvCurrentNfcId.setText(getResources().getString(R.string.nfcTagDataNotUsable));
|
{
|
||||||
|
tvCurrentNfcId.setText(getResources().getString(R.string.nfcTagDataNotUsable));
|
||||||
|
bReadNfcTag.setEnabled(false);
|
||||||
|
bUseValueCurrentlyStored.setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(currentStatus == 1)
|
else if(currentStatus == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -258,6 +258,8 @@ public class ActivityManageTriggerNotification extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_notification);
|
setContentView(R.layout.activity_manage_trigger_notification);
|
||||||
|
|
||||||
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_phone_call);
|
setContentView(R.layout.activity_manage_trigger_phone_call);
|
||||||
|
|
||||||
etTriggerPhoneCallPhoneNumber = (EditText)findViewById(R.id.etTriggerPhoneCallPhoneNumber);
|
etTriggerPhoneCallPhoneNumber = (EditText)findViewById(R.id.etTriggerPhoneCallPhoneNumber);
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ public class ActivityManageTriggerProfile extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_profile);
|
setContentView(R.layout.activity_manage_trigger_profile);
|
||||||
|
|
||||||
bSaveTriggerProfile = (Button)findViewById(R.id.bSaveTriggerProfile);
|
bSaveTriggerProfile = (Button)findViewById(R.id.bSaveTriggerProfile);
|
||||||
|
|||||||
@@ -0,0 +1,172 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
import android.net.wifi.ScanResult;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
|
import com.google.android.material.slider.RangeSlider;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActivityManageTriggerProximity extends Activity
|
||||||
|
{
|
||||||
|
TextView tvTriggerProximityHint, tvProximityCurrentValue;
|
||||||
|
Button bTriggerProximitySave;
|
||||||
|
RangeSlider rsProximity;
|
||||||
|
SeekBar sbProximityTest;
|
||||||
|
|
||||||
|
SensorManager sensorManager;
|
||||||
|
Sensor proximitySensor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
|
||||||
|
/*
|
||||||
|
A modern theme is required for this activity because of the RangeSlider.
|
||||||
|
The value configured in settings is ignored.
|
||||||
|
*/
|
||||||
|
this.setTheme(R.style.AppThemeMaterial);
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_manage_trigger_proximity);
|
||||||
|
|
||||||
|
rsProximity = (RangeSlider) findViewById(R.id.rsProximity);
|
||||||
|
sbProximityTest = (SeekBar) findViewById(R.id.sbProximityTest);
|
||||||
|
tvTriggerProximityHint = (TextView) findViewById(R.id.tvTriggerProximityHint);
|
||||||
|
tvProximityCurrentValue = (TextView) findViewById(R.id.tvProximityCurrentValue);
|
||||||
|
bTriggerProximitySave = (Button) findViewById(R.id.bTriggerProximitySave);
|
||||||
|
|
||||||
|
sbProximityTest.setEnabled(false);
|
||||||
|
tvTriggerProximityHint.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
bTriggerProximitySave.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
Intent response = new Intent();
|
||||||
|
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, String.valueOf(rsProximity.getValues().get(0)) + Trigger.triggerParameter2Split + String.valueOf(rsProximity.getValues().get(1)));
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||||
|
{
|
||||||
|
String[] values = getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||||
|
rsProximity.setValues(Float.parseFloat(values[0]), Float.parseFloat(values[1]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rsProximity.setValues(0f, 10f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
startPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause()
|
||||||
|
{
|
||||||
|
super.onPause();
|
||||||
|
stopPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
void startPreview()
|
||||||
|
{
|
||||||
|
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||||
|
|
||||||
|
// from sensor service we are
|
||||||
|
// calling proximity sensor
|
||||||
|
proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||||
|
|
||||||
|
// handling the case if the proximity
|
||||||
|
// sensor is not present in users device.
|
||||||
|
if (proximitySensor == null)
|
||||||
|
{
|
||||||
|
tvTriggerProximityHint.setVisibility(View.VISIBLE);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// registering our sensor with sensor manager.
|
||||||
|
sensorManager.registerListener(proximitySensorEventListener, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopPreview()
|
||||||
|
{
|
||||||
|
if(proximitySensor != null)
|
||||||
|
sensorManager.unregisterListener(proximitySensorEventListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorEventListener proximitySensorEventListener = new SensorEventListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent sensorEvent)
|
||||||
|
{
|
||||||
|
// check if the sensor type is proximity sensor.
|
||||||
|
if (sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY)
|
||||||
|
{
|
||||||
|
sbProximityTest.setProgress((int)sensorEvent.values[0]);
|
||||||
|
tvProximityCurrentValue.setText((String.valueOf(sensorEvent.values[0])));
|
||||||
|
|
||||||
|
// if (sensorEvent.values[0] == 0)
|
||||||
|
// {
|
||||||
|
// here we are setting our status to our textview..
|
||||||
|
// if sensor event return 0 then object is closed
|
||||||
|
// to sensor else object is away from sensor.
|
||||||
|
// sensorStatusTV.setText("Near");
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// sensorStatusTV.setText("Away");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor sensor, int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -21,6 +21,8 @@ public class ActivityManageTriggerSubSystemState extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_subsystemstate);
|
setContentView(R.layout.activity_manage_trigger_subsystemstate);
|
||||||
|
|
||||||
rbSubSystemStateWifi = (RadioButton)findViewById(R.id.rbSubSystemStateWifi);
|
rbSubSystemStateWifi = (RadioButton)findViewById(R.id.rbSubSystemStateWifi);
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public class ActivityManageTriggerTethering extends Activity
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_tethering);
|
setContentView(R.layout.activity_manage_trigger_tethering);
|
||||||
|
|
||||||
rbTetheringOn = (RadioButton) findViewById(R.id.rbTetheringOn);
|
rbTetheringOn = (RadioButton) findViewById(R.id.rbTetheringOn);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.jens.automation2;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -35,12 +36,23 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
|
||||||
|
/*
|
||||||
|
A modern theme is required for this activity. Classic theme can cause crashes with the TimePicker.
|
||||||
|
The value configured in settings is ignored.
|
||||||
|
*/
|
||||||
|
this.setTheme(R.style.AppThemeCompat);
|
||||||
|
|
||||||
setContentView(R.layout.activity_manage_trigger_timeframe);
|
setContentView(R.layout.activity_manage_trigger_timeframe);
|
||||||
|
|
||||||
|
// if(Build.VERSION.SDK_INT == 34)
|
||||||
|
// Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.Android14TimePickerHint), ActivityManageTriggerTimeFrame.this).show();
|
||||||
|
|
||||||
startPicker = (TimePicker)findViewById(R.id.tpTimeFrameStart);
|
startPicker = (TimePicker)findViewById(R.id.tpTimeFrameStart);
|
||||||
stopPicker = (TimePicker)findViewById(R.id.tpTimeFrameStop);
|
stopPicker = (TimePicker)findViewById(R.id.tpTimeFrameStop);
|
||||||
startPicker.setIs24HourView(true);
|
startPicker.setIs24HourView(true);
|
||||||
stopPicker.setIs24HourView(true);
|
stopPicker.setIs24HourView(true);
|
||||||
|
|
||||||
bSaveTimeFrame = (Button)findViewById(R.id.bSaveTimeFrame);
|
bSaveTimeFrame = (Button)findViewById(R.id.bSaveTimeFrame);
|
||||||
checkMonday = (CheckBox)findViewById(R.id.checkMonday);
|
checkMonday = (CheckBox)findViewById(R.id.checkMonday);
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ import android.net.wifi.WifiConfiguration;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
@@ -43,12 +46,14 @@ public class ActivityManageTriggerWifi extends Activity
|
|||||||
List<String> wifiList = new ArrayList<>();
|
List<String> wifiList = new ArrayList<>();
|
||||||
ArrayAdapter<String> wifiSpinnerAdapter;
|
ArrayAdapter<String> wifiSpinnerAdapter;
|
||||||
private final static int requestCodeLocationPermission = 124;
|
private final static int requestCodeLocationPermission = 124;
|
||||||
TextView tvWifiTriggerNameLocationNotice;
|
TextView tvWifiTriggerNameLocationNotice, tvWifiTriggerDisconnectionHint;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_manage_trigger_wifi);
|
setContentView(R.layout.activity_manage_trigger_wifi);
|
||||||
|
|
||||||
rbTriggerWifiConnected = (RadioButton) findViewById(R.id.rbTriggerWifiConnected);
|
rbTriggerWifiConnected = (RadioButton) findViewById(R.id.rbTriggerWifiConnected);
|
||||||
@@ -58,6 +63,9 @@ public class ActivityManageTriggerWifi extends Activity
|
|||||||
bTriggerWifiSave = (Button) findViewById(R.id.bTriggerWifiSave);
|
bTriggerWifiSave = (Button) findViewById(R.id.bTriggerWifiSave);
|
||||||
bLoadWifiList = (Button) findViewById(R.id.bLoadWifiList);
|
bLoadWifiList = (Button) findViewById(R.id.bLoadWifiList);
|
||||||
tvWifiTriggerNameLocationNotice = (TextView)findViewById(R.id.tvWifiTriggerNameLocationNotice);
|
tvWifiTriggerNameLocationNotice = (TextView)findViewById(R.id.tvWifiTriggerNameLocationNotice);
|
||||||
|
tvWifiTriggerDisconnectionHint = (TextView)findViewById(R.id.tvWifiTriggerDisconnectionHint);
|
||||||
|
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||||
|
|
||||||
wifiSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, wifiList);
|
wifiSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, wifiList);
|
||||||
spinnerWifiList.setAdapter(wifiSpinnerAdapter);
|
spinnerWifiList.setAdapter(wifiSpinnerAdapter);
|
||||||
@@ -66,7 +74,7 @@ public class ActivityManageTriggerWifi extends Activity
|
|||||||
if(
|
if(
|
||||||
Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 29
|
Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 29
|
||||||
&&
|
&&
|
||||||
!ActivityPermissions.isPermissionDeclaratedInManifest(Miscellaneous.getAnyContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
!ActivityPermissions.isPermissionDeclaredInManifest(Miscellaneous.getAnyContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||||
)
|
)
|
||||||
tvWifiTriggerNameLocationNotice.setVisibility(View.VISIBLE);
|
tvWifiTriggerNameLocationNotice.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@@ -100,6 +108,11 @@ public class ActivityManageTriggerWifi extends Activity
|
|||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
|
||||||
{
|
{
|
||||||
etTriggerWifiName.setText(wifiList.get(position));
|
etTriggerWifiName.setText(wifiList.get(position));
|
||||||
|
|
||||||
|
if(etTriggerWifiName.getText().toString().length() > 0 && rbTriggerWifiDisconnected.isChecked())
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE);
|
||||||
|
else
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,6 +130,41 @@ public class ActivityManageTriggerWifi extends Activity
|
|||||||
loadWifis();
|
loadWifis();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rbTriggerWifiDisconnected.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b)
|
||||||
|
{
|
||||||
|
if(etTriggerWifiName.getText().toString().length() > 0 && b)
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE);
|
||||||
|
else
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
etTriggerWifiName.addTextChangedListener(new TextWatcher()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||||
|
{
|
||||||
|
if(etTriggerWifiName.getText().toString().length() > 0 && rbTriggerWifiDisconnected.isChecked())
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE);
|
||||||
|
else
|
||||||
|
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable editable)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadWifis()
|
public void loadWifis()
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ public class ActivitySettings extends PreferenceActivity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
|
||||||
|
// Dark Theme doesn't work in PreferenceActivity, so only a bright theme is readable
|
||||||
|
|
||||||
|
if(Settings.uiTheme != 0)
|
||||||
|
this.setTheme(R.style.AppThemeCompatLight);
|
||||||
|
// Miscellaneous.setUiTheme(this);
|
||||||
|
|
||||||
addPreferencesFromResource(layout.activity_settings);
|
addPreferencesFromResource(layout.activity_settings);
|
||||||
|
|
||||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk))
|
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk))
|
||||||
@@ -24,4 +32,11 @@ public class ActivitySettings extends PreferenceActivity
|
|||||||
chkPrefUpdateCheck.setEnabled(true);
|
chkPrefUpdateCheck.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,8 @@ public class ActivityVolumeTest extends Activity
|
|||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Miscellaneous.setDisplayLanguage(this);
|
||||||
|
Miscellaneous.setUiTheme(this);
|
||||||
setContentView(R.layout.activity_volume_calibration);
|
setContentView(R.layout.activity_volume_calibration);
|
||||||
|
|
||||||
tvCurrentVolume = (TextView)findViewById(R.id.tvCurrentVolume);
|
tvCurrentVolume = (TextView)findViewById(R.id.tvCurrentVolume);
|
||||||
@@ -48,20 +50,15 @@ public class ActivityVolumeTest extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(SeekBar seekBar)
|
public void onStopTrackingTouch(SeekBar seekBar)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartTrackingTouch(SeekBar seekBar)
|
public void onStartTrackingTouch(SeekBar seekBar)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress,
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||||
boolean fromUser)
|
|
||||||
{
|
{
|
||||||
etReferenceValue.setText(String.valueOf(sbReferenceValue.getProgress()));
|
etReferenceValue.setText(String.valueOf(sbReferenceValue.getProgress()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.content.Context;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class AsyncTasks
|
public class AsyncTasks
|
||||||
@@ -23,7 +22,7 @@ public class AsyncTasks
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null).trim();
|
String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null, ActivityManageActionTriggerUrl.methodGet, null).trim();
|
||||||
int latestVersion = Integer.parseInt(result);
|
int latestVersion = Integer.parseInt(result);
|
||||||
|
|
||||||
// At this point the update check itself has already been successful.
|
// At this point the update check itself has already been successful.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import static android.app.PendingIntent.FLAG_IMMUTABLE;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
@@ -12,6 +14,7 @@ import android.app.PendingIntent;
|
|||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ServiceInfo;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -28,17 +31,21 @@ import androidx.core.app.NotificationManagerCompat;
|
|||||||
|
|
||||||
import com.jens.automation2.Trigger.Trigger_Enum;
|
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||||
import com.jens.automation2.location.LocationProvider;
|
import com.jens.automation2.location.LocationProvider;
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
import com.jens.automation2.receivers.DateTimeListener;
|
import com.jens.automation2.receivers.DateTimeListener;
|
||||||
import com.jens.automation2.receivers.PackageReplacedReceiver;
|
import com.jens.automation2.receivers.PackageReplacedReceiver;
|
||||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Set;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public class AutomationService extends Service implements OnInitListener
|
public class AutomationService extends Service implements OnInitListener
|
||||||
{
|
{
|
||||||
protected TextToSpeech ttsEngine = null;
|
protected TextToSpeech ttsEngine = null;
|
||||||
|
protected int ttsStatus = -1;
|
||||||
protected final static int notificationId = 1000;
|
protected final static int notificationId = 1000;
|
||||||
protected final static int notificationIdRestrictions = 1005;
|
protected final static int notificationIdRestrictions = 1005;
|
||||||
protected final static int notificationIdLocationRestriction = 1006;
|
protected final static int notificationIdLocationRestriction = 1006;
|
||||||
@@ -63,6 +70,8 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
protected Calendar lockSoundChangesEnd = null;
|
protected Calendar lockSoundChangesEnd = null;
|
||||||
protected boolean isRunning;
|
protected boolean isRunning;
|
||||||
|
|
||||||
|
Map<String,String> variableMap = new HashMap();
|
||||||
|
|
||||||
protected static AutomationService centralInstance = null;
|
protected static AutomationService centralInstance = null;
|
||||||
|
|
||||||
public void nullLockSoundChangesEnd()
|
public void nullLockSoundChangesEnd()
|
||||||
@@ -93,6 +102,11 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
this.lockSoundChangesEnd = lockSoundChangesEnd;
|
this.lockSoundChangesEnd = lockSoundChangesEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTtsStatus()
|
||||||
|
{
|
||||||
|
return ttsStatus;
|
||||||
|
}
|
||||||
|
|
||||||
protected final IBinder myBinder = new LocalBinder();
|
protected final IBinder myBinder = new LocalBinder();
|
||||||
|
|
||||||
protected LocationProvider myLocationProvider;
|
protected LocationProvider myLocationProvider;
|
||||||
@@ -116,6 +130,19 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
|
|
||||||
// Store a reference to myself. Other classes often need a context or something, this can provide that.
|
// Store a reference to myself. Other classes often need a context or something, this can provide that.
|
||||||
centralInstance = this;
|
centralInstance = this;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This has been reported to throw a NullPointerException under
|
||||||
|
rare circumstances. The root cause remains unknown.
|
||||||
|
*/
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Miscellaneous.setDisplayLanguage(AutomationService.this);
|
||||||
|
}
|
||||||
|
catch(NullPointerException e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", "setDisplayLanguage()", Log.getStackTraceString(e), 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkStartupRequirements(Context context, boolean startAtBoot)
|
public boolean checkStartupRequirements(Context context, boolean startAtBoot)
|
||||||
@@ -132,6 +159,15 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
ActivityPermissions.requestSpecificPermission(Manifest.permission.FOREGROUND_SERVICE);
|
ActivityPermissions.requestSpecificPermission(Manifest.permission.FOREGROUND_SERVICE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 34 && !ActivityPermissions.havePermission(Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE, context))
|
||||||
|
{
|
||||||
|
Toast.makeText(context, context.getResources().getString(R.string.permissionForegroundServiceTypeSpecialUseRequired), Toast.LENGTH_LONG).show();
|
||||||
|
Miscellaneous.logEvent("e", "Permission", "Don't have permission FOREGROUND_SERVICE_SPECIAL_USE. Will request it now.", 4);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -144,6 +180,17 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
Rule.getRuleCollection().size() == 0
|
Rule.getRuleCollection().size() == 0
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if(
|
||||||
|
Rule.getRuleCollection().size() > 0
|
||||||
|
&&
|
||||||
|
Rule.getRuleCollection().size() == ActivityPermissions.getAmountOfRulesWhichLackPermissions(Miscellaneous.getAnyContext())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("w", "AutomationService", "Don't have complete permissions for any defined rule. Not starting service.", 1);
|
||||||
|
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStartPermissions), Toast.LENGTH_LONG).show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (startAtBoot)
|
if (startAtBoot)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -211,22 +258,26 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
startUpRoutine();
|
startUpRoutine();
|
||||||
|
|
||||||
Intent myIntent = new Intent(this, ActivityMainTabLayout.class);
|
Intent myIntent = new Intent(this, ActivityMainTabLayout.class);
|
||||||
myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
|
if(getApplicationContext().getApplicationInfo().targetSdkVersion >= 31)
|
||||||
|
myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_MUTABLE);
|
||||||
|
else
|
||||||
|
myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
|
||||||
notificationBuilder = createServiceNotificationBuilder();
|
notificationBuilder = createServiceNotificationBuilder();
|
||||||
|
|
||||||
updateNotification();
|
updateNotification();
|
||||||
|
|
||||||
if (isMainActivityRunning(this))
|
if(isMainActivityRunning(this))
|
||||||
ActivityMainScreen.updateMainScreen();
|
ActivityMainScreen.updateMainScreen();
|
||||||
|
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", "Service", this.getResources().getString(R.string.serviceStarted) + " VERSION_CODE: " + BuildConfig.VERSION_CODE + ", VERSION_NAME: " + BuildConfig.VERSION_NAME + ", flavor: " + BuildConfig.FLAVOR, 1);
|
Miscellaneous.logEvent("i", "Service", this.getResources().getString(R.string.serviceStarted) + " VERSION_CODE: " + BuildConfig.VERSION_CODE + ", VERSION_NAME: " + BuildConfig.VERSION_NAME + ", flavor: " + BuildConfig.FLAVOR, 1);
|
||||||
Toast.makeText(this, this.getResources().getString(R.string.serviceStarted), Toast.LENGTH_LONG).show();
|
if(Settings.showToasts)
|
||||||
|
Toast.makeText(this, this.getResources().getString(R.string.serviceStarted), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
On normal phones the app is supposed to automatically restart in case of any problems.
|
On normal phones the app is supposed to automatically restart in case of any problems.
|
||||||
In the emulator we want it to stop to be able to better pinpoint the root cause.
|
In the emulator we want it to stop to be able to better pinpoint the root cause of sudden stops.
|
||||||
*/
|
*/
|
||||||
if(Miscellaneous.isAndroidEmulator())
|
if(Miscellaneous.isAndroidEmulator())
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
@@ -292,7 +343,10 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
|
|
||||||
ReceiverCoordinator.applySettingsAndRules();
|
ReceiverCoordinator.applySettingsAndRules();
|
||||||
|
|
||||||
DateTimeListener.reloadAlarms();
|
DateTimeListener.setOrResetAlarms();
|
||||||
|
|
||||||
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent) && ActivityPermissions.isPermissionDeclaredInManifest(AutomationService.getInstance(), Manifest.permission.READ_CALENDAR) && ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, AutomationService.getInstance()))
|
||||||
|
CalendarReceiver.armOrRearmTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -302,7 +356,8 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
|
|
||||||
stopRoutine();
|
stopRoutine();
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
Toast.makeText(this, getResources().getString(R.string.serviceStopped), Toast.LENGTH_LONG).show();
|
if(Settings.showToasts)
|
||||||
|
Toast.makeText(this, getResources().getString(R.string.serviceStopped), Toast.LENGTH_LONG).show();
|
||||||
Miscellaneous.logEvent("i", "Service", getResources().getString(R.string.serviceStopped), 1);
|
Miscellaneous.logEvent("i", "Service", getResources().getString(R.string.serviceStopped), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,8 +366,26 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
if (Settings.useTextToSpeechOnNormal || Settings.useTextToSpeechOnSilent || Settings.useTextToSpeechOnVibrate || Rule.isAnyRuleUsing(Action.Action_Enum.speakText))
|
if (Settings.useTextToSpeechOnNormal || Settings.useTextToSpeechOnSilent || Settings.useTextToSpeechOnVibrate || Rule.isAnyRuleUsing(Action.Action_Enum.speakText))
|
||||||
{
|
{
|
||||||
if (ttsEngine == null)
|
if (ttsEngine == null)
|
||||||
ttsEngine = new TextToSpeech(this, this);
|
{
|
||||||
} else
|
ttsEngine = new TextToSpeech(this, new TextToSpeech.OnInitListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onInit(int status)
|
||||||
|
{
|
||||||
|
ttsStatus = status;
|
||||||
|
|
||||||
|
if (status == TextToSpeech.SUCCESS)
|
||||||
|
{
|
||||||
|
ttsEngine.setLanguage(Locale.getDefault());
|
||||||
|
Miscellaneous.logEvent("i", "TTS engine", "TTS engine available.", 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("i", "TTS engine", "TTS engine not available. Status: " + String.valueOf(status), 3);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (ttsEngine != null)
|
if (ttsEngine != null)
|
||||||
ttsEngine.shutdown();
|
ttsEngine.shutdown();
|
||||||
@@ -342,6 +415,20 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
r.activate(AutomationService.this, false);
|
r.activate(AutomationService.this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!Settings.hasBeenDone(Settings.constVersion143StartOtherProgramConfigEditHint))
|
||||||
|
{
|
||||||
|
if(Rule.isAnyRuleUsing(Action.Action_Enum.startOtherActivity))
|
||||||
|
{
|
||||||
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
|
||||||
|
Miscellaneous.createDismissibleNotificationWithDelay(1010, null, getResources().getString(R.string.version143StartOtherActivityHint), 9123, AutomationService.NOTIFICATION_CHANNEL_ID_SERVICE, null);
|
||||||
|
else
|
||||||
|
Miscellaneous.createDismissibleNotification(null, getResources().getString(R.string.version143StartOtherActivityHint), 9123, false, AutomationService.NOTIFICATION_CHANNEL_ID_SERVICE, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings.considerDone(Settings.constVersion143StartOtherProgramConfigEditHint);
|
||||||
|
Settings.writeSettings(Miscellaneous.getAnyContext());
|
||||||
|
}
|
||||||
|
|
||||||
Settings.serviceStartDone = true;
|
Settings.serviceStartDone = true;
|
||||||
Settings.deviceStartDone = true;
|
Settings.deviceStartDone = true;
|
||||||
}
|
}
|
||||||
@@ -428,7 +515,12 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
if(Miscellaneous.googleToBlameForLocation(true))
|
if(Miscellaneous.googleToBlameForLocation(true))
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(AutomationService.this, ActivityMainTabLayout.class);
|
Intent intent = new Intent(AutomationService.this, ActivityMainTabLayout.class);
|
||||||
PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0);
|
PendingIntent pi;
|
||||||
|
|
||||||
|
// if(Miscellaneous.getTargetSDK(AutomationService.this) >= Build.VERSION_CODES.S)
|
||||||
|
pi = PendingIntent.getActivity(AutomationService.this, 0, intent, FLAG_IMMUTABLE);
|
||||||
|
// else
|
||||||
|
// pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0);
|
||||||
|
|
||||||
Miscellaneous.logEvent("w", "Features disabled", "Background location disabled because Google to blame.", 5);
|
Miscellaneous.logEvent("w", "Features disabled", "Background location disabled because Google to blame.", 5);
|
||||||
|
|
||||||
@@ -445,6 +537,7 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
{
|
{
|
||||||
Intent myServiceIntent = new Intent(context, AutomationService.class);
|
Intent myServiceIntent = new Intent(context, AutomationService.class);
|
||||||
myServiceIntent.putExtra("startAtBoot", startAtBoot);
|
myServiceIntent.putExtra("startAtBoot", startAtBoot);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
context.startForegroundService(myServiceIntent);
|
context.startForegroundService(myServiceIntent);
|
||||||
else
|
else
|
||||||
@@ -457,6 +550,10 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
private void stopRoutine()
|
private void stopRoutine()
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "Service", "Stopping service...", 3);
|
Miscellaneous.logEvent("i", "Service", "Stopping service...", 3);
|
||||||
|
|
||||||
|
// Clear variables for trigger/action with same name
|
||||||
|
variableMap.clear();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
myLocationProvider.stopLocationService();
|
myLocationProvider.stopLocationService();
|
||||||
@@ -475,37 +572,6 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
centralInstance = null;
|
centralInstance = null;
|
||||||
Settings.serviceStartDone = false;
|
Settings.serviceStartDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Builder createDefaultNotificationBuilderOld()
|
|
||||||
{
|
|
||||||
Builder builder = new Builder(AutomationService.getInstance());
|
|
||||||
builder.setContentTitle("Automation");
|
|
||||||
|
|
||||||
if(Settings.showIconWhenServiceIsRunning)
|
|
||||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
|
||||||
|
|
||||||
builder.setCategory(Notification.CATEGORY_SERVICE);
|
|
||||||
builder.setWhen(System.currentTimeMillis());
|
|
||||||
builder.setContentIntent(myPendingIntent);
|
|
||||||
|
|
||||||
Notification defaultNotification = builder.build();
|
|
||||||
|
|
||||||
defaultNotification.icon = R.drawable.ic_launcher;
|
|
||||||
defaultNotification.when = System.currentTimeMillis();
|
|
||||||
|
|
||||||
// defaultNotification.defaults |= Notification.DEFAULT_VIBRATE;
|
|
||||||
// defaultNotification.defaults |= Notification.DEFAULT_LIGHTS;
|
|
||||||
|
|
||||||
defaultNotification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
||||||
// defaultNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
|
|
||||||
defaultNotification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
|
|
||||||
|
|
||||||
// defaultNotification.ledARGB = Color.YELLOW;
|
|
||||||
// defaultNotification.ledOnMS = 1500;
|
|
||||||
// defaultNotification.ledOffMS = 1500;
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static NotificationCompat.Builder createServiceNotificationBuilder()
|
protected static NotificationCompat.Builder createServiceNotificationBuilder()
|
||||||
{
|
{
|
||||||
@@ -537,7 +603,12 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
builder.setOnlyAlertOnce(true);
|
builder.setOnlyAlertOnce(true);
|
||||||
|
|
||||||
if(Settings.showIconWhenServiceIsRunning)
|
if(Settings.showIconWhenServiceIsRunning)
|
||||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
{
|
||||||
|
if (BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||||
|
builder.setSmallIcon(R.drawable.crane);
|
||||||
|
else
|
||||||
|
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||||
|
}
|
||||||
|
|
||||||
// builder.setContentText(textToDisplay);
|
// builder.setContentText(textToDisplay);
|
||||||
// builder.setSmallIcon(icon);
|
// builder.setSmallIcon(icon);
|
||||||
@@ -550,6 +621,9 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void updateNotification()
|
public static void updateNotification()
|
||||||
{
|
{
|
||||||
|
if(!Settings.showIconWhenServiceIsRunning && Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
|
||||||
|
return;
|
||||||
|
|
||||||
AutomationService instance = getInstance();
|
AutomationService instance = getInstance();
|
||||||
|
|
||||||
if(instance != null)
|
if(instance != null)
|
||||||
@@ -598,7 +672,11 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
lastRuleString = instance.getResources().getString(R.string.lastRule) + " n./a.";
|
lastRuleString = instance.getResources().getString(R.string.lastRule) + " n./a.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String textToDisplay = bodyText + " " + lastRuleString;
|
String textToDisplay;
|
||||||
|
if(bodyText.length() > 0)
|
||||||
|
textToDisplay = bodyText + " " + lastRuleString;
|
||||||
|
else
|
||||||
|
textToDisplay = lastRuleString;
|
||||||
|
|
||||||
if(notificationBuilder == null)
|
if(notificationBuilder == null)
|
||||||
notificationBuilder = createServiceNotificationBuilder();
|
notificationBuilder = createServiceNotificationBuilder();
|
||||||
@@ -615,7 +693,10 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
myNotification.flags |= Notification.FLAG_NO_CLEAR;
|
myNotification.flags |= Notification.FLAG_NO_CLEAR;
|
||||||
// notificationManager.notify(notificationId, myNotification);
|
// notificationManager.notify(notificationId, myNotification);
|
||||||
|
|
||||||
instance.startForeground(notificationId, myNotification);
|
// if(Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 34)
|
||||||
|
// instance.startForeground(notificationId, myNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
|
||||||
|
// else
|
||||||
|
instance.startForeground(notificationId, myNotification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,8 +711,6 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
@Override
|
@Override
|
||||||
public void onInit(int status)
|
public void onInit(int status)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -663,25 +742,26 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 60; i++)
|
||||||
{
|
{
|
||||||
if(ttsEngine != null)
|
if(ttsEngine == null || ttsStatus != TextToSpeech.SUCCESS)
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "TTS", "Waiting for a moment to give the TTS service time to load...", 4);
|
Miscellaneous.logEvent("i", "TTS", "Waiting for a moment to give the TTS service time to load...", 4);
|
||||||
Thread.sleep(1000); // give the tts engine time to load
|
Thread.sleep(500); // give the tts engine time to load
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "TextToSpeech", "Speaking \"" + text + "\" in language " + ttsEngine.getLanguage().toLanguageTag(), 3);
|
||||||
|
this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Miscellaneous.logEvent("i", "TextToSpeech", "Speaking " + text + " in language " + ttsEngine.getLanguage().toLanguageTag(), 3);
|
Miscellaneous.logEvent("i", "TextToSpeech", "TTS engine not available after waiting 30 seconds, yet. Aborting.", 3);
|
||||||
this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null);
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -691,14 +771,19 @@ public class AutomationService extends Service implements OnInitListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMainActivityRunning(Context context)
|
public Map<String, String> getVariableMap()
|
||||||
{
|
{
|
||||||
|
return variableMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMainActivityRunning(Context context)
|
||||||
|
{
|
||||||
if(ActivityMainScreen.getActivityMainScreenInstance() == null)
|
if(ActivityMainScreen.getActivityMainScreenInstance() == null)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMyServiceRunning(Context context)
|
public static boolean isMyServiceRunning(Context context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityService;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
|
public class MyAccessibilityService extends AccessibilityService
|
||||||
|
{
|
||||||
|
static MyAccessibilityService instance;
|
||||||
|
|
||||||
|
public static MyAccessibilityService getInstance()
|
||||||
|
{
|
||||||
|
if(instance == null)
|
||||||
|
{
|
||||||
|
instance = new MyAccessibilityService();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInterrupt()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate()
|
||||||
|
{
|
||||||
|
super.onCreate();
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onServiceConnected()
|
||||||
|
{
|
||||||
|
super.onServiceConnected();
|
||||||
|
Miscellaneous.logEvent("i", "Accessibility service", "Service started.", 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,7 +79,7 @@ public class News
|
|||||||
if (!(new File(filePath)).exists() || Settings.lastNewsPolltime == Settings.default_lastNewsPolltime || now.getTimeInMillis() >= Settings.lastNewsPolltime + (long)(Settings.newsDisplayForXDays * 24 * 60 * 60 * 1000))
|
if (!(new File(filePath)).exists() || Settings.lastNewsPolltime == Settings.default_lastNewsPolltime || now.getTimeInMillis() >= Settings.lastNewsPolltime + (long)(Settings.newsDisplayForXDays * 24 * 60 * 60 * 1000))
|
||||||
{
|
{
|
||||||
String newsUrl = "https://server47.de/automation/appNews.php";
|
String newsUrl = "https://server47.de/automation/appNews.php";
|
||||||
newsContent = Miscellaneous.downloadURL(newsUrl, null, null);
|
newsContent = Miscellaneous.downloadURL(newsUrl, null, null, ActivityManageActionTriggerUrl.methodGet, null);
|
||||||
|
|
||||||
// Cache content to local storage
|
// Cache content to local storage
|
||||||
if(Miscellaneous.writeStringToFile(filePath, newsContent))
|
if(Miscellaneous.writeStringToFile(filePath, newsContent))
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
|||||||
public void setName(String desiredName)
|
public void setName(String desiredName)
|
||||||
{
|
{
|
||||||
this.oldName = this.name;
|
this.oldName = this.name;
|
||||||
this.name = desiredName;
|
this.name = desiredName.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation()
|
public Location getLocation()
|
||||||
@@ -421,14 +421,18 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
|||||||
public boolean create(Context context)
|
public boolean create(Context context)
|
||||||
{
|
{
|
||||||
for(PointOfInterest poi : PointOfInterest.pointOfInterestCollection)
|
for(PointOfInterest poi : PointOfInterest.pointOfInterestCollection)
|
||||||
if(poi.getName().equals(this.getName()))
|
{
|
||||||
|
if (poi.getName().equals(this.getName()))
|
||||||
{
|
{
|
||||||
Toast.makeText(context, context.getResources().getString(R.string.anotherPoiByThatName), Toast.LENGTH_LONG).show();
|
Toast.makeText(context, context.getResources().getString(R.string.anotherPoiByThatName), Toast.LENGTH_LONG).show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(plausibilityCheck())
|
if(plausibilityCheck())
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Creating POI", this.toStringLong(), 3);
|
||||||
|
|
||||||
PointOfInterest.pointOfInterestCollection.add(this);
|
PointOfInterest.pointOfInterestCollection.add(this);
|
||||||
PointOfInterest.writePoisToFile();
|
PointOfInterest.writePoisToFile();
|
||||||
|
|
||||||
@@ -490,8 +494,10 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
|||||||
Check for change of rule name END
|
Check for change of rule name END
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (plausibilityCheck())
|
if(plausibilityCheck())
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Changing POI", "Old name: " + this.oldName + ", new data: " + this.toStringLong(), 3);
|
||||||
|
|
||||||
if(PointOfInterest.writePoisToFile())
|
if(PointOfInterest.writePoisToFile())
|
||||||
{
|
{
|
||||||
AutomationService service = AutomationService.getInstance();
|
AutomationService service = AutomationService.getInstance();
|
||||||
@@ -688,22 +694,16 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
|||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider)
|
public void onProviderDisabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider)
|
public void onProviderEnabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.jens.automation2;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -37,17 +38,20 @@ public class Profile implements Comparable<Profile>
|
|||||||
protected boolean changeVolumeNotifications;
|
protected boolean changeVolumeNotifications;
|
||||||
protected int volumeNotifications;
|
protected int volumeNotifications;
|
||||||
|
|
||||||
|
protected boolean changeVolumeRingtones;
|
||||||
|
protected int volumeRingtones;
|
||||||
|
|
||||||
protected boolean changeVolumeAlarms;
|
protected boolean changeVolumeAlarms;
|
||||||
protected int volumeAlarms;
|
protected int volumeAlarms;
|
||||||
|
|
||||||
protected boolean changeIncomingCallsRingtone;
|
protected boolean changeIncomingCallsRingtone;
|
||||||
protected File incomingCallsRingtone;
|
protected String incomingCallsRingtone;
|
||||||
|
|
||||||
protected boolean changeVibrateWhenRinging;
|
protected boolean changeVibrateWhenRinging;
|
||||||
protected boolean vibrateWhenRinging;
|
protected boolean vibrateWhenRinging;
|
||||||
|
|
||||||
protected boolean changeNotificationRingtone;
|
protected boolean changeNotificationRingtone;
|
||||||
protected File notificationRingtone;
|
protected String notificationRingtone;
|
||||||
|
|
||||||
protected boolean changeAudibleSelection;
|
protected boolean changeAudibleSelection;
|
||||||
protected boolean audibleSelection;
|
protected boolean audibleSelection;
|
||||||
@@ -62,7 +66,7 @@ public class Profile implements Comparable<Profile>
|
|||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.oldName = this.name;
|
this.oldName = this.name;
|
||||||
this.name = name;
|
this.name = name.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
@@ -144,6 +148,26 @@ public class Profile implements Comparable<Profile>
|
|||||||
return volumeNotifications;
|
return volumeNotifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getChangeVolumeRingtones()
|
||||||
|
{
|
||||||
|
return changeVolumeRingtones;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChangeVolumeRingtones(boolean changeVolumeRingtones)
|
||||||
|
{
|
||||||
|
this.changeVolumeRingtones = changeVolumeRingtones;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVolumeRingtones()
|
||||||
|
{
|
||||||
|
return volumeRingtones;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVolumeRingtones(int volumeRingtones)
|
||||||
|
{
|
||||||
|
this.volumeRingtones = volumeRingtones;
|
||||||
|
}
|
||||||
|
|
||||||
public void setChangeVolumeAlarms(boolean changeVolumeAlarms)
|
public void setChangeVolumeAlarms(boolean changeVolumeAlarms)
|
||||||
{
|
{
|
||||||
this.changeVolumeAlarms = changeVolumeAlarms;
|
this.changeVolumeAlarms = changeVolumeAlarms;
|
||||||
@@ -171,11 +195,11 @@ public class Profile implements Comparable<Profile>
|
|||||||
return changeIncomingCallsRingtone;
|
return changeIncomingCallsRingtone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIncomingCallsRingtone(File incomingCallsRingtone)
|
public void setIncomingCallsRingtone(String incomingCallsRingtone)
|
||||||
{
|
{
|
||||||
this.incomingCallsRingtone = incomingCallsRingtone;
|
this.incomingCallsRingtone = incomingCallsRingtone;
|
||||||
}
|
}
|
||||||
public File getIncomingCallsRingtone()
|
public String getIncomingCallsRingtone()
|
||||||
{
|
{
|
||||||
return incomingCallsRingtone;
|
return incomingCallsRingtone;
|
||||||
}
|
}
|
||||||
@@ -207,11 +231,11 @@ public class Profile implements Comparable<Profile>
|
|||||||
return changeNotificationRingtone;
|
return changeNotificationRingtone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotificationRingtone(File notificationsRingtone)
|
public void setNotificationRingtone(String notificationsRingtone)
|
||||||
{
|
{
|
||||||
this.notificationRingtone = notificationsRingtone;
|
this.notificationRingtone = notificationsRingtone;
|
||||||
}
|
}
|
||||||
public File getNotificationRingtone()
|
public String getNotificationRingtone()
|
||||||
{
|
{
|
||||||
return notificationRingtone;
|
return notificationRingtone;
|
||||||
}
|
}
|
||||||
@@ -292,53 +316,69 @@ public class Profile implements Comparable<Profile>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean applyRingTone(File ringtoneFile, int ringtoneType, Context context)
|
private boolean applyRingTone(String ringtoneFile, int ringtoneType, Context context)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "Profile", "Request to set ringtone to " + ringtoneFile.getAbsolutePath(), 3);
|
Miscellaneous.logEvent("i", "Profile", "Request to set ringtone to " + ringtoneFile, 3);
|
||||||
|
|
||||||
if(!ringtoneFile.exists() || !ringtoneFile.canRead())
|
// if(!ringtoneFile.exists() || !ringtoneFile.canRead())
|
||||||
|
// {
|
||||||
|
// String message = "Ringtone file does not exist or cannot read it: " + ringtoneFile.getAbsolutePath();
|
||||||
|
// Miscellaneous.logEvent("i", "Profile", message, 3);
|
||||||
|
// Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Set by URI
|
||||||
|
if(ringtoneFile.contains("//"))
|
||||||
{
|
{
|
||||||
String message = "Ringtone file does not exist or cannot read it: " + ringtoneFile.getAbsolutePath();
|
Uri target = Uri.parse(ringtoneFile);
|
||||||
Miscellaneous.logEvent("i", "Profile", message, 3);
|
RingtoneManager.setActualDefaultRingtoneUri(context, ringtoneType, target);
|
||||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
Miscellaneous.logEvent("i", "Profile", "Ringtone set to: " + ringtoneFile, 1);
|
||||||
return false;
|
return true;
|
||||||
}
|
} // Set by filepath
|
||||||
|
else
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());
|
|
||||||
values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName());
|
|
||||||
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
|
|
||||||
values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length());
|
|
||||||
values.put(MediaStore.Audio.Media.IS_RINGTONE, ringtoneType == RingtoneManager.TYPE_RINGTONE);
|
|
||||||
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, ringtoneType == RingtoneManager.TYPE_NOTIFICATION);
|
|
||||||
values.put(MediaStore.Audio.Media.IS_ALARM, false);
|
|
||||||
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Uri newRingTone = null;
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(MediaStore.MediaColumns.DATA, ringtoneFile);
|
||||||
|
values.put(MediaStore.MediaColumns.TITLE, ringtoneFile);
|
||||||
|
//values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName());
|
||||||
|
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
|
||||||
|
values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length());
|
||||||
|
values.put(MediaStore.Audio.Media.IS_RINGTONE, ringtoneType == RingtoneManager.TYPE_RINGTONE);
|
||||||
|
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, ringtoneType == RingtoneManager.TYPE_NOTIFICATION);
|
||||||
|
values.put(MediaStore.Audio.Media.IS_ALARM, false);
|
||||||
|
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
|
||||||
|
|
||||||
//TODO: This part needs to be made compatible with Android 11 and above.
|
try
|
||||||
if(Build.VERSION.SDK_INT > 30)
|
|
||||||
{
|
{
|
||||||
Uri existingRingTone = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile.getAbsolutePath());
|
Uri newRingTone = null;
|
||||||
|
|
||||||
if (existingRingTone != null)
|
Uri existingRingTone = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile);
|
||||||
context.getContentResolver().delete(existingRingTone, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile.getAbsolutePath() + "\"", null);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (existingRingTone != null)
|
||||||
|
context.getContentResolver().delete(existingRingTone, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile + "\"", null);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("w","Delete file from ringtones", "Deleting ringtone from library failed: " + Log.getStackTraceString(e), 2);
|
||||||
|
}
|
||||||
|
|
||||||
newRingTone = context.getContentResolver().insert(existingRingTone, values);
|
newRingTone = context.getContentResolver().insert(existingRingTone, values);
|
||||||
}
|
|
||||||
|
|
||||||
RingtoneManager.setActualDefaultRingtoneUri(context, ringtoneType, newRingTone);
|
RingtoneManager.setActualDefaultRingtoneUri(context, ringtoneType, newRingTone);
|
||||||
Miscellaneous.logEvent("i", "Profile", "Ringtone set to: " + newRingTone.toString(), 1);
|
|
||||||
return true;
|
Miscellaneous.logEvent("i", "Profile", "Ringtone set to: " + newRingTone.toString(), 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
String message = "Error setting ringtone: " + Log.getStackTraceString(t);
|
||||||
|
Miscellaneous.logEvent("e", "Profile", message, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
String message = "Error setting ringtone: " + Log.getStackTraceString(t);
|
|
||||||
Miscellaneous.logEvent("e", "Profile", message, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,52 +543,92 @@ public class Profile implements Comparable<Profile>
|
|||||||
{
|
{
|
||||||
AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
|
||||||
if(changeSoundMode)
|
if(changeSoundMode)
|
||||||
Actions.setSound(context, soundMode);
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting sound mode to " + String.valueOf(soundMode), 4);
|
||||||
|
Actions.setSound(context, soundMode);
|
||||||
|
}
|
||||||
|
|
||||||
if(changeDndMode)
|
if(changeDndMode)
|
||||||
Actions.setDoNotDisturb(context, dndMode);
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting DND mode to " + String.valueOf(dndMode), 4);
|
||||||
|
Actions.setDoNotDisturb(context, dndMode);
|
||||||
|
}
|
||||||
|
|
||||||
if(changeVolumeMusicVideoGameMedia)
|
if(changeVolumeMusicVideoGameMedia)
|
||||||
am.setStreamVolume(AudioManager.STREAM_MUSIC, volumeMusic, AudioManager.FLAG_PLAY_SOUND);
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting media volume to " + String.valueOf(volumeMusic), 4);
|
||||||
|
am.setStreamVolume(AudioManager.STREAM_MUSIC, volumeMusic, AudioManager.FLAG_PLAY_SOUND);
|
||||||
|
}
|
||||||
|
|
||||||
if(changeVolumeNotifications)
|
if(changeVolumeNotifications)
|
||||||
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, volumeNotifications, AudioManager.FLAG_PLAY_SOUND);
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting notification volume to " + String.valueOf(volumeNotifications), 4);
|
||||||
|
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, volumeNotifications, AudioManager.FLAG_PLAY_SOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT >= 34)
|
||||||
|
{
|
||||||
|
if (changeVolumeRingtones)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting ring volume to " + String.valueOf(volumeRingtones), 4);
|
||||||
|
am.setStreamVolume(AudioManager.STREAM_RING, volumeRingtones, AudioManager.FLAG_PLAY_SOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(changeVolumeAlarms)
|
if(changeVolumeAlarms)
|
||||||
am.setStreamVolume(AudioManager.STREAM_ALARM, volumeAlarms, AudioManager.FLAG_PLAY_SOUND);
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting alarm volume to " + String.valueOf(volumeAlarms), 4);
|
||||||
|
am.setStreamVolume(AudioManager.STREAM_ALARM, volumeAlarms, AudioManager.FLAG_PLAY_SOUND);
|
||||||
|
}
|
||||||
|
|
||||||
if(changeIncomingCallsRingtone)
|
if(changeIncomingCallsRingtone)
|
||||||
if(incomingCallsRingtone != null)
|
{
|
||||||
applyRingTone(incomingCallsRingtone, RingtoneManager.TYPE_RINGTONE, context);
|
if (incomingCallsRingtone != null)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting ringtone " + incomingCallsRingtone, 4);
|
||||||
|
applyRingTone(incomingCallsRingtone, RingtoneManager.TYPE_RINGTONE, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(changeVibrateWhenRinging)
|
if(changeVibrateWhenRinging)
|
||||||
{
|
{
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting vibrate when ringing to " + String.valueOf(vibrateWhenRinging?1:0), 4);
|
||||||
android.provider.Settings.System.putInt(context.getContentResolver(), "vibrate_when_ringing", vibrateWhenRinging?1:0);
|
android.provider.Settings.System.putInt(context.getContentResolver(), "vibrate_when_ringing", vibrateWhenRinging?1:0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting vibrate when ringing to " + String.valueOf(vibrateWhenRinging), 4);
|
||||||
|
|
||||||
if (vibrateWhenRinging)
|
if (vibrateWhenRinging)
|
||||||
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
|
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
|
||||||
else
|
else
|
||||||
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
|
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(changeNotificationRingtone)
|
if(changeNotificationRingtone)
|
||||||
if(notificationRingtone != null)
|
{
|
||||||
applyRingTone(notificationRingtone, RingtoneManager.TYPE_NOTIFICATION, context);
|
if (notificationRingtone != null)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting notification ringtone to " + String.valueOf(notificationRingtone), 4);
|
||||||
|
applyRingTone(notificationRingtone, RingtoneManager.TYPE_NOTIFICATION, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(changeScreenLockUnlockSound)
|
if(changeScreenLockUnlockSound)
|
||||||
{
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Setting lockscreen sounds enabled to " + String.valueOf(screenLockUnlockSound ? 1 : 0), 4);
|
||||||
android.provider.Settings.System.putInt(context.getContentResolver(), "lockscreen_sounds_enabled" , screenLockUnlockSound ? 1 : 0);
|
android.provider.Settings.System.putInt(context.getContentResolver(), "lockscreen_sounds_enabled" , screenLockUnlockSound ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(changeAudibleSelection)
|
if(changeAudibleSelection)
|
||||||
{
|
{
|
||||||
if(audibleSelection)
|
Miscellaneous.logEvent("i", "Profile", "Setting audible selection to " + String.valueOf(audibleSelection ? 1 : 0), 4);
|
||||||
|
|
||||||
|
if(audibleSelection)
|
||||||
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SOUND_EFFECTS_ENABLED, 1); // enable
|
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SOUND_EFFECTS_ENABLED, 1); // enable
|
||||||
else
|
else
|
||||||
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SOUND_EFFECTS_ENABLED, 0); // dissable
|
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SOUND_EFFECTS_ENABLED, 0); // dissable
|
||||||
@@ -556,7 +636,9 @@ public class Profile implements Comparable<Profile>
|
|||||||
|
|
||||||
if(changeHapticFeedback)
|
if(changeHapticFeedback)
|
||||||
{
|
{
|
||||||
if(hapticFeedback)
|
Miscellaneous.logEvent("i", "Profile", "Setting haptic feedback to " + String.valueOf(hapticFeedback ? 1 : 0), 4);
|
||||||
|
|
||||||
|
if(hapticFeedback)
|
||||||
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 1); // enable
|
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 1); // enable
|
||||||
else
|
else
|
||||||
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0); // disable
|
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0); // disable
|
||||||
@@ -568,17 +650,18 @@ public class Profile implements Comparable<Profile>
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "POI", "Checking for applicable rule after profile " + this.getName() + " has been activated.", 2);
|
Miscellaneous.logEvent("i", "Profile", "Profile activation complete: " + this.getName(), 3);
|
||||||
|
Miscellaneous.logEvent("i", "Profile", "Checking for applicable rules after profile " + this.getName() + " has been activated.", 3);
|
||||||
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.profileActive);
|
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.profileActive);
|
||||||
for(int i=0; i<ruleCandidates.size(); i++)
|
for(int i=0; i<ruleCandidates.size(); i++)
|
||||||
{
|
{
|
||||||
if(ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).getsGreenLight(AutomationService.getInstance()))
|
if(ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).getsGreenLight(AutomationService.getInstance()))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies after " + this.getName() + " has been activated.", 2);
|
Miscellaneous.logEvent("i", "Profile", "Rule " + ruleCandidates.get(i).getName() + " applies after " + this.getName() + " has been activated.", 2);
|
||||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Miscellaneous.logEvent("i", "POI", "Done checking for applicable rule after profile " + this.getName() + " has been activated.", 2);
|
Miscellaneous.logEvent("i", "Profile", "Done checking for applicable rules after profile " + this.getName() + " has been activated.", 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -620,6 +703,15 @@ public class Profile implements Comparable<Profile>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT >= 34)
|
||||||
|
{
|
||||||
|
if (changeVolumeRingtones)
|
||||||
|
{
|
||||||
|
if (am.getStreamVolume(AudioManager.STREAM_RING) != volumeRingtones)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (changeVolumeAlarms)
|
if (changeVolumeAlarms)
|
||||||
{
|
{
|
||||||
if (am.getStreamVolume(AudioManager.STREAM_ALARM) != volumeAlarms)
|
if (am.getStreamVolume(AudioManager.STREAM_ALARM) != volumeAlarms)
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.jens.automation2.location.CellLocationChangedReceiver;
|
import com.jens.automation2.location.CellLocationChangedReceiver;
|
||||||
import com.jens.automation2.location.WifiBroadcastReceiver;
|
import com.jens.automation2.location.WifiBroadcastReceiver;
|
||||||
import com.jens.automation2.receivers.BroadcastListener;
|
import com.jens.automation2.receivers.BroadcastListener;
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
import com.jens.automation2.receivers.DateTimeListener;
|
import com.jens.automation2.receivers.DateTimeListener;
|
||||||
import com.jens.automation2.receivers.AutomationListenerInterface;
|
import com.jens.automation2.receivers.AutomationListenerInterface;
|
||||||
import com.jens.automation2.receivers.BatteryReceiver;
|
import com.jens.automation2.receivers.BatteryReceiver;
|
||||||
@@ -17,6 +19,7 @@ import com.jens.automation2.receivers.MediaPlayerListener;
|
|||||||
import com.jens.automation2.receivers.NoiseListener;
|
import com.jens.automation2.receivers.NoiseListener;
|
||||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||||
import com.jens.automation2.receivers.ProcessListener;
|
import com.jens.automation2.receivers.ProcessListener;
|
||||||
|
import com.jens.automation2.receivers.ProximityReceiver;
|
||||||
import com.jens.automation2.receivers.ScreenStateReceiver;
|
import com.jens.automation2.receivers.ScreenStateReceiver;
|
||||||
import com.jens.automation2.receivers.SubSystemStateReceiver;
|
import com.jens.automation2.receivers.SubSystemStateReceiver;
|
||||||
import com.jens.automation2.receivers.TetheringReceiver;
|
import com.jens.automation2.receivers.TetheringReceiver;
|
||||||
@@ -145,7 +148,8 @@ public class ReceiverCoordinator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// startPhoneStateListener
|
// startPhoneStateListener
|
||||||
PhoneStatusListener.startPhoneStatusListener(AutomationService.getInstance()); // also used to mute anouncements during calls
|
if(!BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||||
|
PhoneStatusListener.startPhoneStatusListener(AutomationService.getInstance()); // also used to mute anouncements during calls
|
||||||
|
|
||||||
// startConnectivityReceiver
|
// startConnectivityReceiver
|
||||||
ConnectivityReceiver.startConnectivityReceiver(AutomationService.getInstance());
|
ConnectivityReceiver.startConnectivityReceiver(AutomationService.getInstance());
|
||||||
@@ -209,6 +213,12 @@ public class ReceiverCoordinator
|
|||||||
|
|
||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.screenState))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.screenState))
|
||||||
ScreenStateReceiver.startScreenStateReceiver(AutomationService.getInstance());
|
ScreenStateReceiver.startScreenStateReceiver(AutomationService.getInstance());
|
||||||
|
|
||||||
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent) && ActivityPermissions.isPermissionDeclaredInManifest(AutomationService.getInstance(), Manifest.permission.READ_CALENDAR) && ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, AutomationService.getInstance()))
|
||||||
|
CalendarReceiver.startCalendarReceiver(AutomationService.getInstance());
|
||||||
|
|
||||||
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.proximity))
|
||||||
|
ProximityReceiver.startProximityReceiver(AutomationService.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stopAllReceivers()
|
public static void stopAllReceivers()
|
||||||
@@ -228,6 +238,7 @@ public class ReceiverCoordinator
|
|||||||
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
TetheringReceiver.getInstance().stopListener(AutomationService.getInstance());
|
TetheringReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||||
SubSystemStateReceiver.getInstance().stopListener(AutomationService.getInstance());
|
SubSystemStateReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||||
|
ProximityReceiver.stopProximityReceiver();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -242,6 +253,7 @@ public class ReceiverCoordinator
|
|||||||
BluetoothReceiver.stopBluetoothReceiver();
|
BluetoothReceiver.stopBluetoothReceiver();
|
||||||
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
|
CalendarReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -391,11 +403,11 @@ public class ReceiverCoordinator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged))
|
||||||
{
|
{
|
||||||
if(!HeadphoneJackListener.isHeadphoneJackListenerActive())
|
if(!HeadphoneJackListener.isHeadphoneJackListenerActive())
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "LocationProvider", "Starting HeadphoneJackListener because used in a new/changed rule.", 4);
|
Miscellaneous.logEvent("i", "HeadphoneJackListener", "Starting HeadphoneJackListener because used in a new/changed rule.", 4);
|
||||||
if(HeadphoneJackListener.getInstance().haveAllPermission())
|
if(HeadphoneJackListener.getInstance().haveAllPermission())
|
||||||
HeadphoneJackListener.getInstance().startListener(AutomationService.getInstance());
|
HeadphoneJackListener.getInstance().startListener(AutomationService.getInstance());
|
||||||
}
|
}
|
||||||
@@ -404,7 +416,7 @@ public class ReceiverCoordinator
|
|||||||
{
|
{
|
||||||
if(HeadphoneJackListener.isHeadphoneJackListenerActive())
|
if(HeadphoneJackListener.isHeadphoneJackListenerActive())
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "LocationProvider", "Shutting down HeadphoneJackListener because not used in any rule.", 4);
|
Miscellaneous.logEvent("i", "HeadphoneJackListener", "Shutting down HeadphoneJackListener because not used in any rule.", 4);
|
||||||
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -463,6 +475,19 @@ public class ReceiverCoordinator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent) && ActivityPermissions.isPermissionDeclaredInManifest(AutomationService.getInstance(), Manifest.permission.READ_CALENDAR) && ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, AutomationService.getInstance()))
|
||||||
|
{
|
||||||
|
if(!CalendarReceiver.getInstance().isListenerRunning())
|
||||||
|
CalendarReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||||
|
else
|
||||||
|
CalendarReceiver.armOrRearmTimer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(CalendarReceiver.getInstance().isListenerRunning())
|
||||||
|
CalendarReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
AutomationService.updateNotification();
|
AutomationService.updateNotification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ public class Settings implements SharedPreferences
|
|||||||
public static final String folderName = "Automation";
|
public static final String folderName = "Automation";
|
||||||
public static final String zipFileName = "automation.zip";
|
public static final String zipFileName = "automation.zip";
|
||||||
|
|
||||||
public static final String constNewsOptInDone ="newsOptInDone";
|
public static final String constNewsOptInDone = "newsOptInDone";
|
||||||
public static final String constNotificationChannelCleanupApk118 ="notificationChannelCleanupApk118";
|
public static final String constNotificationChannelCleanupApk118 = "notificationChannelCleanupApk118";
|
||||||
|
public static final String constVersion143StartOtherProgramConfigEditHint = "constVersion143StartOtherProgramConfigEditHint";
|
||||||
|
|
||||||
public static long minimumDistanceChangeForGpsUpdate;
|
public static long minimumDistanceChangeForGpsUpdate;
|
||||||
public static long minimumDistanceChangeForNetworkUpdate;
|
public static long minimumDistanceChangeForNetworkUpdate;
|
||||||
@@ -29,6 +30,7 @@ public class Settings implements SharedPreferences
|
|||||||
public static int gpsTimeout;
|
public static int gpsTimeout;
|
||||||
public static long minimumTimeBetweenUpdate;
|
public static long minimumTimeBetweenUpdate;
|
||||||
public static boolean startServiceAtSystemBoot;
|
public static boolean startServiceAtSystemBoot;
|
||||||
|
public static boolean logToConsole;
|
||||||
public static boolean writeLogFile;
|
public static boolean writeLogFile;
|
||||||
public static long logLevel;
|
public static long logLevel;
|
||||||
public static int logFileMaxSize;
|
public static int logFileMaxSize;
|
||||||
@@ -61,12 +63,15 @@ public class Settings implements SharedPreferences
|
|||||||
public static int activityDetectionFrequency;
|
public static int activityDetectionFrequency;
|
||||||
public static int activityDetectionRequiredProbability;
|
public static int activityDetectionRequiredProbability;
|
||||||
public static boolean privacyLocationing;
|
public static boolean privacyLocationing;
|
||||||
|
public static int uiTheme;
|
||||||
public static int startScreen;
|
public static int startScreen;
|
||||||
public static int tabsPlacement;
|
public static int tabsPlacement;
|
||||||
public static boolean executeRulesAndProfilesWithSingleClick;
|
public static boolean executeRulesAndProfilesWithSingleClick;
|
||||||
public static boolean displayNewsOnMainScreen;
|
public static boolean displayNewsOnMainScreen;
|
||||||
|
public static boolean showToasts;
|
||||||
public static boolean automaticUpdateCheck;
|
public static boolean automaticUpdateCheck;
|
||||||
public static long musicCheckFrequency;
|
public static long musicCheckFrequency;
|
||||||
|
public static String displayLanguage;
|
||||||
|
|
||||||
public static boolean lockSoundChanges;
|
public static boolean lockSoundChanges;
|
||||||
public static boolean noticeAndroid9MicrophoneShown;
|
public static boolean noticeAndroid9MicrophoneShown;
|
||||||
@@ -95,6 +100,7 @@ public class Settings implements SharedPreferences
|
|||||||
public static final int default_gpsTimeout = 300; // seconds
|
public static final int default_gpsTimeout = 300; // seconds
|
||||||
public static final long default_minimumTimeBetweenUpdate = 30000; // in Milliseconds
|
public static final long default_minimumTimeBetweenUpdate = 30000; // in Milliseconds
|
||||||
public static final boolean default_startServiceAtSystemBoot = false;
|
public static final boolean default_startServiceAtSystemBoot = false;
|
||||||
|
public static final boolean default_logToConsole = false;
|
||||||
public static final boolean default_writeLogFile = false;
|
public static final boolean default_writeLogFile = false;
|
||||||
public static final long default_logLevel = 2;
|
public static final long default_logLevel = 2;
|
||||||
public static final int default_logFileMaxSize = 10;
|
public static final int default_logFileMaxSize = 10;
|
||||||
@@ -126,15 +132,19 @@ public class Settings implements SharedPreferences
|
|||||||
public static final int default_activityDetectionFrequency = 60;
|
public static final int default_activityDetectionFrequency = 60;
|
||||||
public static final int default_activityDetectionRequiredProbability = 75;
|
public static final int default_activityDetectionRequiredProbability = 75;
|
||||||
public static final boolean default_privacyLocationing = false;
|
public static final boolean default_privacyLocationing = false;
|
||||||
|
public static final int default_uiTheme = 0;
|
||||||
public static final int default_startScreen = 0;
|
public static final int default_startScreen = 0;
|
||||||
public static final int default_tabsPlacement = 0;
|
public static final int default_tabsPlacement = 0;
|
||||||
public static final boolean default_executeRulesAndProfilesWithSingleClick = false;
|
public static final boolean default_executeRulesAndProfilesWithSingleClick = false;
|
||||||
public static final boolean default_displayNewsOnMainScreen = false;
|
public static final boolean default_displayNewsOnMainScreen = false;
|
||||||
|
|
||||||
|
public static final boolean default_showToasts = true;
|
||||||
public static final boolean default_automaticUpdateCheck = false;
|
public static final boolean default_automaticUpdateCheck = false;
|
||||||
public static final boolean default_lockSoundChanges = false;
|
public static final boolean default_lockSoundChanges = false;
|
||||||
public static final long default_lastNewsPolltime = -1;
|
public static final long default_lastNewsPolltime = -1;
|
||||||
public static final long default_lastUpdateCheck = -1;
|
public static final long default_lastUpdateCheck = -1;
|
||||||
public static final long default_musicCheckFrequency = 2500;
|
public static final long default_musicCheckFrequency = 2500;
|
||||||
|
public static final String default_displayLanguage = "systemDefaultLanguage";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(String arg0)
|
public boolean contains(String arg0)
|
||||||
@@ -144,56 +154,45 @@ public class Settings implements SharedPreferences
|
|||||||
@Override
|
@Override
|
||||||
public Editor edit()
|
public Editor edit()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ?> getAll()
|
public Map<String, ?> getAll()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean getBoolean(String arg0, boolean arg1)
|
public boolean getBoolean(String arg0, boolean arg1)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public float getFloat(String arg0, float arg1)
|
public float getFloat(String arg0, float arg1)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getInt(String arg0, int arg1)
|
public int getInt(String arg0, int arg1)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getLong(String arg0, long arg1)
|
public long getLong(String arg0, long arg1)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getString(String arg0, String arg1)
|
public String getString(String arg0, String arg1)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener arg0)
|
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener arg0)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener arg0)
|
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener arg0)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readFromPersistentStorage(Context context)
|
public static void readFromPersistentStorage(Context context)
|
||||||
@@ -204,6 +203,7 @@ public class Settings implements SharedPreferences
|
|||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
startServiceAtSystemBoot = prefs.getBoolean("startServiceAtSystemBoot", default_startServiceAtSystemBoot);
|
startServiceAtSystemBoot = prefs.getBoolean("startServiceAtSystemBoot", default_startServiceAtSystemBoot);
|
||||||
|
logToConsole = prefs.getBoolean("logToConsole", default_logToConsole);
|
||||||
writeLogFile = prefs.getBoolean("writeLogFile", default_writeLogFile);
|
writeLogFile = prefs.getBoolean("writeLogFile", default_writeLogFile);
|
||||||
|
|
||||||
boolean useTextToSpeech = false;
|
boolean useTextToSpeech = false;
|
||||||
@@ -266,10 +266,12 @@ public class Settings implements SharedPreferences
|
|||||||
activityDetectionRequiredProbability = Integer.parseInt(prefs.getString("activityDetectionRequiredProbability", String.valueOf(default_activityDetectionRequiredProbability)));
|
activityDetectionRequiredProbability = Integer.parseInt(prefs.getString("activityDetectionRequiredProbability", String.valueOf(default_activityDetectionRequiredProbability)));
|
||||||
|
|
||||||
privacyLocationing = prefs.getBoolean("privacyLocationing", default_privacyLocationing);
|
privacyLocationing = prefs.getBoolean("privacyLocationing", default_privacyLocationing);
|
||||||
|
uiTheme = Integer.parseInt(prefs.getString("uiTheme", String.valueOf(default_uiTheme)));
|
||||||
startScreen = Integer.parseInt(prefs.getString("startScreen", String.valueOf(default_startScreen)));
|
startScreen = Integer.parseInt(prefs.getString("startScreen", String.valueOf(default_startScreen)));
|
||||||
tabsPlacement = Integer.parseInt(prefs.getString("tabsPlacement", String.valueOf(default_tabsPlacement)));
|
tabsPlacement = Integer.parseInt(prefs.getString("tabsPlacement", String.valueOf(default_tabsPlacement)));
|
||||||
|
|
||||||
musicCheckFrequency = Long.parseLong(prefs.getString("musicCheckFrequency", String.valueOf(default_musicCheckFrequency)));
|
musicCheckFrequency = Long.parseLong(prefs.getString("musicCheckFrequency", String.valueOf(default_musicCheckFrequency)));
|
||||||
|
displayLanguage = prefs.getString("displayLanguage", default_displayLanguage);
|
||||||
|
|
||||||
if(Settings.musicCheckFrequency == 0)
|
if(Settings.musicCheckFrequency == 0)
|
||||||
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
||||||
@@ -277,6 +279,7 @@ public class Settings implements SharedPreferences
|
|||||||
executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick);
|
executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick);
|
||||||
automaticUpdateCheck = prefs.getBoolean("automaticUpdateCheck", default_automaticUpdateCheck);
|
automaticUpdateCheck = prefs.getBoolean("automaticUpdateCheck", default_automaticUpdateCheck);
|
||||||
displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
|
displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
|
||||||
|
showToasts = prefs.getBoolean("showToasts", default_showToasts);
|
||||||
|
|
||||||
lockSoundChanges = prefs.getBoolean("lockSoundChanges", default_lockSoundChanges);
|
lockSoundChanges = prefs.getBoolean("lockSoundChanges", default_lockSoundChanges);
|
||||||
noticeAndroid9MicrophoneShown = prefs.getBoolean("noticeAndroid9MicrophoneShown", false);
|
noticeAndroid9MicrophoneShown = prefs.getBoolean("noticeAndroid9MicrophoneShown", false);
|
||||||
@@ -342,6 +345,9 @@ public class Settings implements SharedPreferences
|
|||||||
|
|
||||||
if(!prefs.contains("startServiceAtSystemBoot") || force)
|
if(!prefs.contains("startServiceAtSystemBoot") || force)
|
||||||
editor.putBoolean("startServiceAtSystemBoot", default_startServiceAtSystemBoot);
|
editor.putBoolean("startServiceAtSystemBoot", default_startServiceAtSystemBoot);
|
||||||
|
|
||||||
|
if(!prefs.contains("logToConsole") || force)
|
||||||
|
editor.putBoolean("logToConsole", default_logToConsole);
|
||||||
|
|
||||||
if(!prefs.contains("writeLogFile") || force)
|
if(!prefs.contains("writeLogFile") || force)
|
||||||
editor.putBoolean("writeLogFile", default_writeLogFile);
|
editor.putBoolean("writeLogFile", default_writeLogFile);
|
||||||
@@ -457,6 +463,9 @@ public class Settings implements SharedPreferences
|
|||||||
if(!prefs.contains("privacyLocationing") || force)
|
if(!prefs.contains("privacyLocationing") || force)
|
||||||
editor.putBoolean("privacyLocationing", default_privacyLocationing);
|
editor.putBoolean("privacyLocationing", default_privacyLocationing);
|
||||||
|
|
||||||
|
if(!prefs.contains("uiTheme") || force)
|
||||||
|
editor.putString("uiTheme", String.valueOf(default_uiTheme));
|
||||||
|
|
||||||
if(!prefs.contains("startScreen") || force)
|
if(!prefs.contains("startScreen") || force)
|
||||||
editor.putString("startScreen", String.valueOf(default_startScreen));
|
editor.putString("startScreen", String.valueOf(default_startScreen));
|
||||||
|
|
||||||
@@ -472,9 +481,15 @@ public class Settings implements SharedPreferences
|
|||||||
if(!prefs.contains("displayNewsOnMainScreen") || force)
|
if(!prefs.contains("displayNewsOnMainScreen") || force)
|
||||||
editor.putBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
|
editor.putBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
|
||||||
|
|
||||||
|
if(!prefs.contains("showToasts") || force)
|
||||||
|
editor.putBoolean("showToasts", default_showToasts);
|
||||||
|
|
||||||
if(!prefs.contains("musicCheckFrequency") || force)
|
if(!prefs.contains("musicCheckFrequency") || force)
|
||||||
editor.putLong("musicCheckFrequency", default_musicCheckFrequency);
|
editor.putLong("musicCheckFrequency", default_musicCheckFrequency);
|
||||||
|
|
||||||
|
if(!prefs.contains("displayLanguage") || force)
|
||||||
|
editor.putString("displayLanguage", default_displayLanguage);
|
||||||
|
|
||||||
if(!prefs.contains("lockSoundChanges") || force)
|
if(!prefs.contains("lockSoundChanges") || force)
|
||||||
editor.putBoolean("lockSoundChanges", default_lockSoundChanges);
|
editor.putBoolean("lockSoundChanges", default_lockSoundChanges);
|
||||||
|
|
||||||
@@ -512,6 +527,7 @@ public class Settings implements SharedPreferences
|
|||||||
Editor editor = prefs.edit();
|
Editor editor = prefs.edit();
|
||||||
|
|
||||||
editor.putBoolean("startServiceAtSystemBoot", startServiceAtSystemBoot);
|
editor.putBoolean("startServiceAtSystemBoot", startServiceAtSystemBoot);
|
||||||
|
editor.putBoolean("logToConsole", logToConsole);
|
||||||
editor.putBoolean("writeLogFile", writeLogFile);
|
editor.putBoolean("writeLogFile", writeLogFile);
|
||||||
// editor.putBoolean("useTextToSpeech", useTextToSpeech);
|
// editor.putBoolean("useTextToSpeech", useTextToSpeech);
|
||||||
editor.putBoolean("useTextToSpeechOnNormal", useTextToSpeechOnNormal);
|
editor.putBoolean("useTextToSpeechOnNormal", useTextToSpeechOnNormal);
|
||||||
@@ -550,16 +566,20 @@ public class Settings implements SharedPreferences
|
|||||||
editor.putString("activityDetectionFrequency", String.valueOf(activityDetectionFrequency));
|
editor.putString("activityDetectionFrequency", String.valueOf(activityDetectionFrequency));
|
||||||
editor.putString("activityDetectionRequiredProbability", String.valueOf(activityDetectionRequiredProbability));
|
editor.putString("activityDetectionRequiredProbability", String.valueOf(activityDetectionRequiredProbability));
|
||||||
editor.putBoolean("privacyLocationing", privacyLocationing);
|
editor.putBoolean("privacyLocationing", privacyLocationing);
|
||||||
|
editor.putString("uiTheme", String.valueOf(uiTheme));
|
||||||
editor.putString("startScreen", String.valueOf(startScreen));
|
editor.putString("startScreen", String.valueOf(startScreen));
|
||||||
editor.putString("tabsPlacement", String.valueOf(tabsPlacement));
|
editor.putString("tabsPlacement", String.valueOf(tabsPlacement));
|
||||||
editor.putBoolean("executeRulesAndProfilesWithSingleClick", executeRulesAndProfilesWithSingleClick);
|
editor.putBoolean("executeRulesAndProfilesWithSingleClick", executeRulesAndProfilesWithSingleClick);
|
||||||
editor.putBoolean("automaticUpdateCheck", automaticUpdateCheck);
|
editor.putBoolean("automaticUpdateCheck", automaticUpdateCheck);
|
||||||
editor.putBoolean("displayNewsOnMainScreen", displayNewsOnMainScreen);
|
editor.putBoolean("displayNewsOnMainScreen", displayNewsOnMainScreen);
|
||||||
|
editor.putBoolean("showToasts", showToasts);
|
||||||
|
|
||||||
if(Settings.musicCheckFrequency == 0)
|
if(Settings.musicCheckFrequency == 0)
|
||||||
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
||||||
editor.putString("musicCheckFrequency", String.valueOf(musicCheckFrequency));
|
editor.putString("musicCheckFrequency", String.valueOf(musicCheckFrequency));
|
||||||
|
|
||||||
|
editor.putString("displayLanguage", displayLanguage);
|
||||||
|
|
||||||
editor.putBoolean("lockSoundChanges", lockSoundChanges);
|
editor.putBoolean("lockSoundChanges", lockSoundChanges);
|
||||||
editor.putBoolean("noticeAndroid9MicrophoneShown", noticeAndroid9MicrophoneShown);
|
editor.putBoolean("noticeAndroid9MicrophoneShown", noticeAndroid9MicrophoneShown);
|
||||||
editor.putBoolean("noticeAndroid10WifiShown", noticeAndroid10WifiShown);
|
editor.putBoolean("noticeAndroid10WifiShown", noticeAndroid10WifiShown);
|
||||||
@@ -603,7 +623,6 @@ public class Settings implements SharedPreferences
|
|||||||
@Override
|
@Override
|
||||||
public Set<String> getStringSet(String arg0, Set<String> arg1)
|
public Set<String> getStringSet(String arg0, Set<String> arg1)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.jens.automation2;
|
|||||||
|
|
||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class TimeFrame
|
public class TimeFrame
|
||||||
{
|
{
|
||||||
@@ -20,18 +21,19 @@ public class TimeFrame
|
|||||||
public void setDayList(ArrayList<Integer> dayList)
|
public void setDayList(ArrayList<Integer> dayList)
|
||||||
{
|
{
|
||||||
this.dayList = dayList;
|
this.dayList = dayList;
|
||||||
|
Collections.sort(dayList);
|
||||||
}
|
}
|
||||||
public void setDayListFromString(String dayListString)
|
public void setDayListFromString(String dayListString)
|
||||||
{
|
{
|
||||||
// Log.i("Parsing", "Full string: " + dayListString);
|
|
||||||
char[] dayListCharArray = dayListString.toCharArray();
|
char[] dayListCharArray = dayListString.toCharArray();
|
||||||
|
|
||||||
dayList = new ArrayList<Integer>();
|
dayList = new ArrayList<Integer>();
|
||||||
for(char item : dayListCharArray)
|
for(char item : dayListCharArray)
|
||||||
{
|
{
|
||||||
// Log.i("Parsing", String.valueOf(item));
|
|
||||||
dayList.add(Integer.parseInt(String.valueOf(item)));
|
dayList.add(Integer.parseInt(String.valueOf(item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collections.sort(dayList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeObject getTriggerTimeStart()
|
public TimeObject getTriggerTimeStart()
|
||||||
|
|||||||
@@ -148,6 +148,13 @@ public class XmlFileInterface
|
|||||||
serializer.startTag(null, "volumeNotifications");
|
serializer.startTag(null, "volumeNotifications");
|
||||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getVolumeNotifications()));
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getVolumeNotifications()));
|
||||||
serializer.endTag(null, "volumeNotifications");
|
serializer.endTag(null, "volumeNotifications");
|
||||||
|
|
||||||
|
serializer.startTag(null, "changeVolumeRingtones");
|
||||||
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeVolumeRingtones()));
|
||||||
|
serializer.endTag(null, "changeVolumeRingtones");//
|
||||||
|
serializer.startTag(null, "volumeRingtones");
|
||||||
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getVolumeRingtones()));
|
||||||
|
serializer.endTag(null, "volumeRingtones");
|
||||||
|
|
||||||
serializer.startTag(null, "changeVolumeAlarms");
|
serializer.startTag(null, "changeVolumeAlarms");
|
||||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeVolumeAlarms()));
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeVolumeAlarms()));
|
||||||
@@ -160,9 +167,9 @@ public class XmlFileInterface
|
|||||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeIncomingCallsRingtone()));
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeIncomingCallsRingtone()));
|
||||||
serializer.endTag(null, "changeIncomingCallsRingtone");//
|
serializer.endTag(null, "changeIncomingCallsRingtone");//
|
||||||
serializer.startTag(null, "incomingCallsRingtone");
|
serializer.startTag(null, "incomingCallsRingtone");
|
||||||
File incomingFile = Profile.getProfileCollection().get(i).getIncomingCallsRingtone();
|
String incomingFile = Profile.getProfileCollection().get(i).getIncomingCallsRingtone();
|
||||||
if(incomingFile != null)
|
if(incomingFile != null)
|
||||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getIncomingCallsRingtone().getPath()));
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getIncomingCallsRingtone()));
|
||||||
else
|
else
|
||||||
serializer.text("null");
|
serializer.text("null");
|
||||||
serializer.endTag(null, "incomingCallsRingtone");
|
serializer.endTag(null, "incomingCallsRingtone");
|
||||||
@@ -178,9 +185,9 @@ public class XmlFileInterface
|
|||||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeNotificationRingtone()));
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeNotificationRingtone()));
|
||||||
serializer.endTag(null, "changeNotificationRingtone");//
|
serializer.endTag(null, "changeNotificationRingtone");//
|
||||||
serializer.startTag(null, "notificationRingtone");
|
serializer.startTag(null, "notificationRingtone");
|
||||||
File notificationFile = Profile.getProfileCollection().get(i).getNotificationRingtone();
|
String notificationFile = Profile.getProfileCollection().get(i).getNotificationRingtone();
|
||||||
if(notificationFile != null)
|
if(notificationFile != null)
|
||||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getNotificationRingtone().getPath()));
|
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getNotificationRingtone()));
|
||||||
else
|
else
|
||||||
serializer.text("null");
|
serializer.text("null");
|
||||||
serializer.endTag(null, "notificationRingtone");
|
serializer.endTag(null, "notificationRingtone");
|
||||||
@@ -217,7 +224,7 @@ public class XmlFileInterface
|
|||||||
}
|
}
|
||||||
serializer.endTag(null, "ProfileCollection");
|
serializer.endTag(null, "ProfileCollection");
|
||||||
|
|
||||||
|
|
||||||
serializer.startTag(null, "RuleCollection");
|
serializer.startTag(null, "RuleCollection");
|
||||||
for(int i=0; i<Rule.getRuleCollection().size(); i++)
|
for(int i=0; i<Rule.getRuleCollection().size(); i++)
|
||||||
{
|
{
|
||||||
@@ -619,8 +626,12 @@ public class XmlFileInterface
|
|||||||
newProfile.setVolumeMusic(Integer.parseInt(readTag(parser, "volumeMusic")));
|
newProfile.setVolumeMusic(Integer.parseInt(readTag(parser, "volumeMusic")));
|
||||||
else if (name.equals("changeVolumeNotifications"))
|
else if (name.equals("changeVolumeNotifications"))
|
||||||
newProfile.setChangeVolumeNotifications(Boolean.parseBoolean(readTag(parser, "changeVolumeNotifications")));
|
newProfile.setChangeVolumeNotifications(Boolean.parseBoolean(readTag(parser, "changeVolumeNotifications")));
|
||||||
|
else if (name.equals("changeVolumeRingtones"))
|
||||||
|
newProfile.setChangeVolumeRingtones(Boolean.parseBoolean(readTag(parser, "changeVolumeRingtones")));
|
||||||
else if (name.equals("volumeNotifications"))
|
else if (name.equals("volumeNotifications"))
|
||||||
newProfile.setVolumeNotifications(Integer.parseInt(readTag(parser, "volumeNotifications")));
|
newProfile.setVolumeNotifications(Integer.parseInt(readTag(parser, "volumeNotifications")));
|
||||||
|
else if (name.equals("volumeRingtones"))
|
||||||
|
newProfile.setVolumeRingtones(Integer.parseInt(readTag(parser, "volumeRingtones")));
|
||||||
else if (name.equals("changeVolumeAlarms"))
|
else if (name.equals("changeVolumeAlarms"))
|
||||||
newProfile.setChangeVolumeAlarms(Boolean.parseBoolean(readTag(parser, "changeVolumeAlarms")));
|
newProfile.setChangeVolumeAlarms(Boolean.parseBoolean(readTag(parser, "changeVolumeAlarms")));
|
||||||
else if (name.equals("volumeAlarms"))
|
else if (name.equals("volumeAlarms"))
|
||||||
@@ -631,7 +642,7 @@ public class XmlFileInterface
|
|||||||
{
|
{
|
||||||
String path = readTag(parser, "incomingCallsRingtone");
|
String path = readTag(parser, "incomingCallsRingtone");
|
||||||
if(!path.equals("null"))
|
if(!path.equals("null"))
|
||||||
newProfile.setIncomingCallsRingtone(new File(path));
|
newProfile.setIncomingCallsRingtone(path);
|
||||||
else
|
else
|
||||||
newProfile.setIncomingCallsRingtone(null);
|
newProfile.setIncomingCallsRingtone(null);
|
||||||
}
|
}
|
||||||
@@ -643,7 +654,7 @@ public class XmlFileInterface
|
|||||||
{
|
{
|
||||||
String path = readTag(parser, "notificationRingtone");
|
String path = readTag(parser, "notificationRingtone");
|
||||||
if(!path.equals("null"))
|
if(!path.equals("null"))
|
||||||
newProfile.setNotificationRingtone(new File(path));
|
newProfile.setNotificationRingtone(path);
|
||||||
else
|
else
|
||||||
newProfile.setNotificationRingtone(null);
|
newProfile.setNotificationRingtone(null);
|
||||||
}
|
}
|
||||||
@@ -700,7 +711,7 @@ public class XmlFileInterface
|
|||||||
|
|
||||||
private static Rule readRule(XmlPullParser parser) throws XmlPullParserException, IOException
|
private static Rule readRule(XmlPullParser parser) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
/* FILE EXAMPE:
|
/* FILE EXAMPLE:
|
||||||
* *****************
|
* *****************
|
||||||
* <Automation>
|
* <Automation>
|
||||||
* <PointOfInterestCollection>
|
* <PointOfInterestCollection>
|
||||||
@@ -1084,7 +1095,7 @@ public class XmlFileInterface
|
|||||||
|
|
||||||
private static Action readAction(XmlPullParser parser) throws IOException, XmlPullParserException
|
private static Action readAction(XmlPullParser parser) throws IOException, XmlPullParserException
|
||||||
{
|
{
|
||||||
/* FILE EXAMPE:
|
/* FILE EXAMPLE:
|
||||||
* *****************
|
* *****************
|
||||||
* <Automation>
|
* <Automation>
|
||||||
* <PointOfInterestCollection>
|
* <PointOfInterestCollection>
|
||||||
@@ -1135,28 +1146,10 @@ public class XmlFileInterface
|
|||||||
|
|
||||||
// *** deprecated
|
// *** deprecated
|
||||||
//else
|
//else
|
||||||
if(actionNameString.equals("turnWifiOn"))
|
if(actionNameString.equals("turnUsbTetheringOn"))
|
||||||
newAction.setAction(Action_Enum.turnWifiOn);
|
|
||||||
else if(actionNameString.equals("turnWifiOff"))
|
|
||||||
newAction.setAction(Action_Enum.turnWifiOff);
|
|
||||||
else if(actionNameString.equals("turnBluetoothOn"))
|
|
||||||
newAction.setAction(Action_Enum.turnBluetoothOn);
|
|
||||||
else if(actionNameString.equals("turnBluetoothOff"))
|
|
||||||
newAction.setAction(Action_Enum.turnBluetoothOff);
|
|
||||||
else if(actionNameString.equals("turnUsbTetheringOn"))
|
|
||||||
newAction.setAction(Action_Enum.turnUsbTetheringOn);
|
newAction.setAction(Action_Enum.turnUsbTetheringOn);
|
||||||
else if(actionNameString.equals("turnUsbTetheringOff"))
|
else if(actionNameString.equals("turnUsbTetheringOff"))
|
||||||
newAction.setAction(Action_Enum.turnUsbTetheringOff);
|
newAction.setAction(Action_Enum.turnUsbTetheringOff);
|
||||||
else if(actionNameString.equals("turnWifiTetheringOn"))
|
|
||||||
newAction.setAction(Action_Enum.turnWifiTetheringOn);
|
|
||||||
else if(actionNameString.equals("turnWifiTetheringOff"))
|
|
||||||
newAction.setAction(Action_Enum.turnWifiTetheringOff);
|
|
||||||
else if(actionNameString.equals("enableScreenRotation"))
|
|
||||||
newAction.setAction(Action_Enum.enableScreenRotation);
|
|
||||||
else if(actionNameString.equals("disableScreenRotation"))
|
|
||||||
newAction.setAction(Action_Enum.disableScreenRotation);
|
|
||||||
else if(actionNameString.equals("disableScreenRotation"))
|
|
||||||
newAction.setAction(Action_Enum.disableScreenRotation);
|
|
||||||
else if(actionNameString.equals("playMusic"))
|
else if(actionNameString.equals("playMusic"))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.controlMediaPlayback);
|
newAction.setAction(Action_Enum.controlMediaPlayback);
|
||||||
@@ -1175,31 +1168,7 @@ public class XmlFileInterface
|
|||||||
else if (name.equals("ActionParameter1"))
|
else if (name.equals("ActionParameter1"))
|
||||||
{
|
{
|
||||||
// exclusion for deprecated types
|
// exclusion for deprecated types
|
||||||
if(newAction.getAction().equals(Action_Enum.turnWifiOn))
|
if(newAction.getAction().equals(Action_Enum.turnUsbTetheringOn))
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setWifi);
|
|
||||||
newAction.setParameter1(true);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnWifiOff))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setWifi);
|
|
||||||
newAction.setParameter1(false);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnBluetoothOn))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setBluetooth);
|
|
||||||
newAction.setParameter1(true);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnBluetoothOff))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setBluetooth);
|
|
||||||
newAction.setParameter1(false);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnUsbTetheringOn))
|
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setUsbTethering);
|
newAction.setAction(Action_Enum.setUsbTethering);
|
||||||
newAction.setParameter1(true);
|
newAction.setParameter1(true);
|
||||||
@@ -1211,36 +1180,6 @@ public class XmlFileInterface
|
|||||||
newAction.setParameter1(false);
|
newAction.setParameter1(false);
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
||||||
}
|
}
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnWifiTetheringOn))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setWifiTethering);
|
|
||||||
newAction.setParameter1(true);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnWifiTetheringOff))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setWifiTethering);
|
|
||||||
newAction.setParameter1(false);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.enableScreenRotation))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setDisplayRotation);
|
|
||||||
newAction.setParameter1(true);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.disableScreenRotation))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setDisplayRotation);
|
|
||||||
newAction.setParameter1(false);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.disableScreenRotation))
|
|
||||||
{
|
|
||||||
newAction.setAction(Action_Enum.setDisplayRotation);
|
|
||||||
newAction.setParameter1(false);
|
|
||||||
readTag(parser, "ActionParameter1"); //read the tag for the parser to head on
|
|
||||||
}
|
|
||||||
else if(newAction.getAction().equals(Action_Enum.turnScreenOnOrOff) && newAction.getParameter1())
|
else if(newAction.getAction().equals(Action_Enum.turnScreenOnOrOff) && newAction.getParameter1())
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -1286,20 +1225,24 @@ public class XmlFileInterface
|
|||||||
else
|
else
|
||||||
newTag = tag.replace("/", Action.intentPairSeparator);
|
newTag = tag.replace("/", Action.intentPairSeparator);
|
||||||
|
|
||||||
String[] newTagPieces = newTag.split(";");
|
String[] newTagPieces = new String[0];
|
||||||
|
if(newTag.contains(Action.actionParameter2Split))
|
||||||
|
newTagPieces = newTag.split(Action.actionParameter2Split);
|
||||||
|
else
|
||||||
|
newTag.split(";");
|
||||||
|
|
||||||
if(newTagPieces.length < 2 || (!newTagPieces[0].contains(Actions.dummyPackageString) && newTagPieces[1].contains(Action.intentPairSeparator)))
|
if(newTagPieces.length < 2 || (!newTagPieces[0].contains(Actions.dummyPackageString) && newTagPieces[1].contains(Action.intentPairSeparator)))
|
||||||
{
|
{
|
||||||
newTag = Actions.dummyPackageString + ";" + newTag;
|
newTag = Actions.dummyPackageString + Action.actionParameter2Split + newTag;
|
||||||
newTagPieces = newTag.split(";");
|
newTagPieces = newTag.split(Action.actionParameter2Split);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newTagPieces.length < 3)
|
if(newTagPieces.length < 3)
|
||||||
newTag += ";" + ActivityManageActionStartActivity.startByActivityString;
|
newTag += Action.actionParameter2Split + ActivityManageActionStartActivity.startByActivityString;
|
||||||
else if(newTagPieces.length >= 3)
|
else if(newTagPieces.length >= 3)
|
||||||
{
|
{
|
||||||
if(newTagPieces[2].contains(Action.intentPairSeparator))
|
if(newTagPieces[2].contains(Action.intentPairSeparator))
|
||||||
newTag = newTagPieces[0] + ";" + newTagPieces[1] + ";" + ActivityManageActionStartActivity.startByActivityString + ";" + newTagPieces[2];
|
newTag = newTagPieces[0] + Action.actionParameter2Split + newTagPieces[1] + Action.actionParameter2Split + ActivityManageActionStartActivity.startByActivityString + Action.actionParameter2Split + newTagPieces[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
newAction.setParameter2(newTag);
|
newAction.setParameter2(newTag);
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class CellLocationChangedReceiver extends PhoneStateListener
|
|||||||
{
|
{
|
||||||
for(Action action : Rule.getLastActivatedRule().getActionSet())
|
for(Action action : Rule.getLastActivatedRule().getActionSet())
|
||||||
{
|
{
|
||||||
if(action.getAction() == Action.Action_Enum.turnWifiOn)
|
if(action.getAction() == Action.Action_Enum.setWifi && action.getParameter1())
|
||||||
{
|
{
|
||||||
// we will be using wifiReceiver, deactivate AccelerometerTimer if applicable
|
// we will be using wifiReceiver, deactivate AccelerometerTimer if applicable
|
||||||
SensorActivity.stopAccelerometerTimer();
|
SensorActivity.stopAccelerometerTimer();
|
||||||
@@ -88,7 +88,7 @@ public class CellLocationChangedReceiver extends PhoneStateListener
|
|||||||
catch(NullPointerException ne)
|
catch(NullPointerException ne)
|
||||||
{
|
{
|
||||||
// Nothing to do, there is no last activated rule. Wifi hasn't been activated so we don't
|
// Nothing to do, there is no last activated rule. Wifi hasn't been activated so we don't
|
||||||
// deactive accelerometer receiver.
|
// deactivate accelerometer receiver.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -272,29 +272,23 @@ public class CellLocationChangedReceiver extends PhoneStateListener
|
|||||||
locationListenerArmed = false;
|
locationListenerArmed = false;
|
||||||
Miscellaneous.logEvent("i", "LocationListener", "Disarmed location listener, accuracy reached", 4);
|
Miscellaneous.logEvent("i", "LocationListener", "Disarmed location listener, accuracy reached", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Miscellaneous.logEvent("i", "LocationListener", "Giving update to POI class");
|
|
||||||
// PointOfInterest.positionUpdate(up2DateLocation, parentLocationProvider.parentService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider)
|
public void onProviderDisabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider)
|
public void onProviderEnabled(String provider)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,10 +363,10 @@ public class CellLocationChangedReceiver extends PhoneStateListener
|
|||||||
// Miscellaneous.logEvent("i", "cellReceiver", "Not starting cellLocationListener because we have no data connection.", 4);
|
// Miscellaneous.logEvent("i", "cellReceiver", "Not starting cellLocationListener because we have no data connection.", 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("w", "cellReceiver", "Wanted to activate CellLocationChangedReceiver, but Wifi-Receiver says not to.", 4);
|
Miscellaneous.logEvent("w", "cellReceiver", "Wanted to activate CellLocationChangedReceiver, but Wifi-Receiver says not to.", 5);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "cellReceiver", "Not starting cellLocationListener because Airplane mode is active or SIM_STATE is not ready.", 4);
|
Miscellaneous.logEvent("i", "cellReceiver", "Not starting cellLocationListener because Airplane mode is active or SIM_STATE is not ready.", 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.jens.automation2.ActivityMainScreen;
|
import com.jens.automation2.ActivityMainScreen;
|
||||||
import com.jens.automation2.AutomationService;
|
import com.jens.automation2.AutomationService;
|
||||||
|
import com.jens.automation2.BuildConfig;
|
||||||
import com.jens.automation2.Miscellaneous;
|
import com.jens.automation2.Miscellaneous;
|
||||||
import com.jens.automation2.PointOfInterest;
|
import com.jens.automation2.PointOfInterest;
|
||||||
import com.jens.automation2.R;
|
import com.jens.automation2.R;
|
||||||
@@ -232,6 +233,7 @@ public class LocationProvider
|
|||||||
public void startLocationService()
|
public void startLocationService()
|
||||||
{
|
{
|
||||||
// startPhoneStateListener
|
// startPhoneStateListener
|
||||||
|
if(!BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||||
PhoneStatusListener.startPhoneStatusListener(parentService); // also used to mute anouncements during calls
|
PhoneStatusListener.startPhoneStatusListener(parentService); // also used to mute anouncements during calls
|
||||||
|
|
||||||
// startConnectivityReceiver
|
// startConnectivityReceiver
|
||||||
@@ -400,12 +402,12 @@ public class LocationProvider
|
|||||||
Miscellaneous.logEvent("i", "LocationProvider", this.getParentService().getResources().getString(R.string.applyingSettingsAndRules), 3);
|
Miscellaneous.logEvent("i", "LocationProvider", this.getParentService().getResources().getString(R.string.applyingSettingsAndRules), 3);
|
||||||
|
|
||||||
// *********** SETTING CHANGES ***********
|
// *********** SETTING CHANGES ***********
|
||||||
if(Settings.useWifiForPositioning && !WifiBroadcastReceiver.isWifiListenerActive())
|
if(Settings.useWifiForPositioning && !WifiBroadcastReceiver.isWifiListenerActive() || Rule.isAnyRuleUsing(Trigger_Enum.wifiConnection))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "LocationProvider", "Starting WifiReceiver because settings now allow to.", 4);
|
Miscellaneous.logEvent("i", "LocationProvider", "Starting WifiReceiver because settings now allow to.", 4);
|
||||||
WifiBroadcastReceiver.startWifiReceiver(this);
|
WifiBroadcastReceiver.startWifiReceiver(this);
|
||||||
}
|
}
|
||||||
else if(!Settings.useWifiForPositioning && WifiBroadcastReceiver.isWifiListenerActive())
|
else if(!Settings.useWifiForPositioning && WifiBroadcastReceiver.isWifiListenerActive() && !Rule.isAnyRuleUsing(Trigger_Enum.wifiConnection))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "LocationProvider", "Shutting down WifiReceiver because settings forbid to.", 4);
|
Miscellaneous.logEvent("i", "LocationProvider", "Shutting down WifiReceiver because settings forbid to.", 4);
|
||||||
WifiBroadcastReceiver.stopWifiReceiver();
|
WifiBroadcastReceiver.stopWifiReceiver();
|
||||||
|
|||||||
@@ -64,36 +64,36 @@ public class SensorActivity implements SensorEventListener
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSensorChanged(SensorEvent event)
|
public void onSensorChanged(SensorEvent event)
|
||||||
{
|
{
|
||||||
// Device has been moved
|
// Device has been moved
|
||||||
|
|
||||||
float x = event.values[0];
|
float x = event.values[0];
|
||||||
float y = event.values[1];
|
float y = event.values[1];
|
||||||
float z = event.values[2];
|
float z = event.values[2];
|
||||||
|
|
||||||
if(mInitialized)
|
if(mInitialized)
|
||||||
{
|
{
|
||||||
deltaX = Math.abs(lastX-x);
|
deltaX = Math.abs(lastX-x);
|
||||||
deltaY = Math.abs(lastY-y);
|
deltaY = Math.abs(lastY-y);
|
||||||
deltaZ = Math.abs(lastZ-z);
|
deltaZ = Math.abs(lastZ-z);
|
||||||
//Wenn das jetzt einen gewissen Grenzwert übersteigt, müßten wir den CellListener wieder aktivieren
|
// If that exceeds a certain delta we need to start CellLocationListener again
|
||||||
if(deltaX > Settings.accelerometerMovementThreshold | deltaY > Settings.accelerometerMovementThreshold | deltaZ > Settings.accelerometerMovementThreshold)
|
if(deltaX > Settings.accelerometerMovementThreshold | deltaY > Settings.accelerometerMovementThreshold | deltaZ > Settings.accelerometerMovementThreshold)
|
||||||
{
|
{
|
||||||
String text = "Device has been moved. " + String.valueOf(deltaX)+" / "+String.valueOf(deltaY)+" / "+String.valueOf(deltaZ);
|
String text = "Device has been moved. " + String.valueOf(deltaX)+" / "+String.valueOf(deltaY)+" / "+String.valueOf(deltaZ);
|
||||||
Miscellaneous.logEvent("i", "Accelerometer", text, 5);
|
Miscellaneous.logEvent("i", "Accelerometer", text, 5);
|
||||||
CellLocationChangedReceiver.resetFollowUpdate();
|
CellLocationChangedReceiver.resetFollowUpdate();
|
||||||
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lastX = x;
|
lastX = x;
|
||||||
lastY = y;
|
lastY = y;
|
||||||
lastZ = z;
|
lastZ = z;
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void startAccelerometerReceiver()
|
protected static void startAccelerometerReceiver()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.jens.automation2.location;
|
package com.jens.automation2.location;
|
||||||
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -18,6 +17,8 @@ import com.jens.automation2.Rule;
|
|||||||
import com.jens.automation2.Settings;
|
import com.jens.automation2.Settings;
|
||||||
import com.jens.automation2.Trigger;
|
import com.jens.automation2.Trigger;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class WifiBroadcastReceiver extends BroadcastReceiver
|
public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||||
@@ -25,11 +26,19 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
public static LocationProvider parentLocationProvider;
|
public static LocationProvider parentLocationProvider;
|
||||||
public static Boolean wasConnected = false;
|
public static Boolean wasConnected = false;
|
||||||
protected static String lastWifiSsid = "";
|
protected static String lastWifiSsid = "";
|
||||||
|
protected static String lastWifiSsidReal = "";
|
||||||
public static boolean lastConnectedState = false;
|
public static boolean lastConnectedState = false;
|
||||||
protected static boolean mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
protected static boolean mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
||||||
protected static WifiBroadcastReceiver wifiBrInstance;
|
protected static WifiBroadcastReceiver wifiBrInstance;
|
||||||
protected static IntentFilter wifiListenerIntentFilter;
|
protected static IntentFilter wifiListenerIntentFilter;
|
||||||
protected static boolean wifiListenerActive=false;
|
protected static boolean wifiListenerActive = false;
|
||||||
|
|
||||||
|
final static String unknownSsidName = "<unknown ssid>";
|
||||||
|
|
||||||
|
public static String getLastWifiSsidReal()
|
||||||
|
{
|
||||||
|
return lastWifiSsidReal;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getLastWifiSsid()
|
public static String getLastWifiSsid()
|
||||||
{
|
{
|
||||||
@@ -38,11 +47,18 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
|
|
||||||
public static void setLastWifiSsid(String newWifiSsid)
|
public static void setLastWifiSsid(String newWifiSsid)
|
||||||
{
|
{
|
||||||
|
// Remove double quotes that sometimes come
|
||||||
if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\""))
|
if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\""))
|
||||||
newWifiSsid = newWifiSsid.substring(1, newWifiSsid.length()-1);
|
newWifiSsid = newWifiSsid.substring(1, newWifiSsid.length()-1);
|
||||||
|
|
||||||
|
// If it's a real name, not an empty string, it's stored as the last ssid
|
||||||
if(newWifiSsid.length() > 0)
|
if(newWifiSsid.length() > 0)
|
||||||
|
{
|
||||||
|
if(!newWifiSsid.equals(unknownSsidName))
|
||||||
|
WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid;
|
||||||
|
|
||||||
WifiBroadcastReceiver.lastWifiSsid = newWifiSsid;
|
WifiBroadcastReceiver.lastWifiSsid = newWifiSsid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWifiListenerActive()
|
public static boolean isWifiListenerActive()
|
||||||
@@ -60,24 +76,20 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// int state = -1;
|
if(!StringUtils.isEmpty(intent.getAction()))
|
||||||
|
Miscellaneous.logEvent("i", "WifiReceiver", "Received signal with action \""+ intent.getAction() + "\".", 4);
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("i", "WifiReceiver", "Received signal with empty action.", 4);
|
||||||
|
|
||||||
NetworkInfo myWifi = null;
|
NetworkInfo myWifi = null;
|
||||||
|
|
||||||
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection
|
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection
|
||||||
{
|
{
|
||||||
// state = intent.getIntExtra(WifiManager.NETWORK_STATE_CHANGED_ACTION, -1);
|
|
||||||
// Miscellaneous.logEvent("i", "WifiReceiver", "NETWORK_STATE_CHANGED_ACTION: " + String.valueOf(state));
|
|
||||||
myWifi = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
myWifi = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiManager myWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
WifiManager myWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
||||||
// ConnectivityManager connManager = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE);
|
|
||||||
// myWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
|
||||||
// myWifi = state
|
|
||||||
// WifiInfo wifiInfo = myWifiManager.getConnectionInfo();
|
|
||||||
|
|
||||||
// SupplicantState supState = wifiInfo.getSupplicantState();
|
|
||||||
|
|
||||||
if(intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) // fired upon connection
|
if(intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) // fired upon connection
|
||||||
{
|
{
|
||||||
String ssid = myWifiManager.getConnectionInfo().getSSID();
|
String ssid = myWifiManager.getConnectionInfo().getSSID();
|
||||||
@@ -93,8 +105,8 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
CellLocationChangedReceiver.stopCellLocationChangedReceiver();
|
CellLocationChangedReceiver.stopCellLocationChangedReceiver();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: Every time the screen is turned on, we receiver a "wifi has been connected"-event.
|
TODO: Every time the screen is turned on, we receive a "wifi has been connected"-event.
|
||||||
This is technically wrong and not really any changed to when the screen was off. It has
|
This is technically wrong and not really any change to when the screen was off. It has
|
||||||
to be filtered.
|
to be filtered.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@@ -120,12 +132,12 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
}
|
}
|
||||||
else if(!myWifi.isConnectedOrConnecting()) // really disconnected? because sometimes also fires on connect
|
else if(!myWifi.isConnectedOrConnecting()) // really disconnected? because sometimes also fires on connect
|
||||||
{
|
{
|
||||||
if(wasConnected) // wir könnten einfach noch nicht daheim sein
|
if(wasConnected) // we could simply not be home yet
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wasConnected = false;
|
wasConnected = false;
|
||||||
Miscellaneous.logEvent("i", "WifiReceiver", String.format(context.getResources().getString(R.string.disconnectedFromWifi), getLastWifiSsid()) + " Switching to CellLocationChangedReceiver.", 3);
|
Miscellaneous.logEvent("i", "WifiReceiver", "Disconnected from wifi \"" + getLastWifiSsid() + "\". Switching to CellLocationChangedReceiver.", 3);
|
||||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
||||||
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
||||||
lastConnectedState = false;
|
lastConnectedState = false;
|
||||||
@@ -214,17 +226,16 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(wifiListenerActive)
|
if (wifiListenerActive)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "Wifi Listener", "Stopping wifiListener", 4);
|
Miscellaneous.logEvent("i", "Wifi Listener", "Stopping wifiListener", 4);
|
||||||
wifiListenerActive = false;
|
wifiListenerActive = false;
|
||||||
parentLocationProvider.getParentService().unregisterReceiver(wifiBrInstance);
|
parentLocationProvider.getParentService().unregisterReceiver(wifiBrInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("e", "Wifi Listener", "Error stopping wifiListener: " + Log.getStackTraceString(ex), 3);
|
Miscellaneous.logEvent("e", "Wifi Listener", "Error stopping wifiListener: " + Log.getStackTraceString(ex), 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package com.jens.automation2.receivers;
|
package com.jens.automation2.receivers;
|
||||||
|
|
||||||
|
import static android.os.BatteryManager.*;
|
||||||
|
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.BatteryManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.jens.automation2.ActivityPermissions;
|
import com.jens.automation2.ActivityPermissions;
|
||||||
import com.jens.automation2.AutomationService;
|
import com.jens.automation2.AutomationService;
|
||||||
@@ -19,35 +20,40 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class BatteryReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
public class BatteryReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||||
{
|
{
|
||||||
private static int batteryLevel = -1; // initialize with a better value than this
|
public static final int batteryChargingTypeAny = 0;
|
||||||
public static AutomationService automationServiceRef = null;
|
public static final int batteryChargingTypeAc = BatteryManager.BATTERY_PLUGGED_AC;
|
||||||
private static boolean usbHostConnected = false;
|
public static final int batteryChargingTypeUsb = BatteryManager.BATTERY_PLUGGED_USB;
|
||||||
|
public static final int batteryChargingTypeWireless = BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||||
|
|
||||||
private static boolean batteryReceiverActive = false;
|
public static AutomationService automationServiceRef = null;
|
||||||
private static IntentFilter batteryIntentFilter = null;
|
static int batteryLevel = -1; // initialize with a better value than this
|
||||||
private static Intent batteryStatus = null;
|
static boolean usbHostConnected = false;
|
||||||
private static BroadcastReceiver batteryInfoReceiverInstance = null;
|
static boolean batteryReceiverActive = false;
|
||||||
|
static IntentFilter batteryIntentFilter = null;
|
||||||
|
static Intent batteryStatus = null;
|
||||||
|
|
||||||
|
private static int currentChargingState = 0; //0=unknown, 1=no, 2=yes
|
||||||
|
private static int currentChargingType = 0; //AC, wireless, USB
|
||||||
|
static BroadcastReceiver batteryInfoReceiverInstance = null;
|
||||||
|
|
||||||
public static void startBatteryReceiver(final AutomationService automationServiceRef)
|
public static void startBatteryReceiver(final AutomationService automationServiceRef)
|
||||||
{
|
{
|
||||||
if(!batteryReceiverActive)
|
if(!batteryReceiverActive)
|
||||||
{
|
{
|
||||||
BatteryReceiver.automationServiceRef = automationServiceRef;
|
BatteryReceiver.automationServiceRef = automationServiceRef;
|
||||||
|
|
||||||
if(batteryInfoReceiverInstance == null)
|
if(batteryInfoReceiverInstance == null)
|
||||||
batteryInfoReceiverInstance = new BatteryReceiver();
|
batteryInfoReceiverInstance = new BatteryReceiver();
|
||||||
|
|
||||||
if(batteryIntentFilter == null)
|
if(batteryIntentFilter == null)
|
||||||
{
|
{
|
||||||
batteryIntentFilter = new IntentFilter();
|
batteryIntentFilter = new IntentFilter();
|
||||||
batteryIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
batteryIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||||
batteryIntentFilter.addAction(Intent.ACTION_BATTERY_LOW);
|
batteryIntentFilter.addAction(Intent.ACTION_BATTERY_LOW);
|
||||||
// batteryIntentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
|
|
||||||
// batteryIntentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
batteryStatus = automationServiceRef.registerReceiver(batteryInfoReceiverInstance, batteryIntentFilter);
|
batteryStatus = automationServiceRef.registerReceiver(batteryInfoReceiverInstance, batteryIntentFilter);
|
||||||
|
|
||||||
batteryReceiverActive = true;
|
batteryReceiverActive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,16 +66,16 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
automationServiceRef.unregisterReceiver(batteryInfoReceiverInstance);
|
automationServiceRef.unregisterReceiver(batteryInfoReceiverInstance);
|
||||||
batteryInfoReceiverInstance = null;
|
batteryInfoReceiverInstance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
batteryReceiverActive = false;
|
batteryReceiverActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBatteryReceiverActive()
|
public static boolean isBatteryReceiverActive()
|
||||||
{
|
{
|
||||||
return batteryReceiverActive;
|
return batteryReceiverActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUsbHostConnected()
|
public static boolean isUsbHostConnected()
|
||||||
{
|
{
|
||||||
return usbHostConnected;
|
return usbHostConnected;
|
||||||
@@ -80,8 +86,6 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
return batteryLevel;
|
return batteryLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int currentChargingState = 0; //0=unknown, 1=no, 2=yes
|
|
||||||
|
|
||||||
public static int getCurrentChargingState()
|
public static int getCurrentChargingState()
|
||||||
{
|
{
|
||||||
return currentChargingState;
|
return currentChargingState;
|
||||||
@@ -90,12 +94,12 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
// Log.i("Battery", "Some battery event");
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Received event " + intent.getAction(), 5);
|
||||||
|
|
||||||
if (intent == null)
|
if (intent == null)
|
||||||
return;
|
return;
|
||||||
if (context == null)
|
if (context == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(intent.getAction().equals(Intent.ACTION_BATTERY_LOW))
|
if(intent.getAction().equals(Intent.ACTION_BATTERY_LOW))
|
||||||
{
|
{
|
||||||
@@ -105,39 +109,46 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
batteryLevel = intent.getIntExtra(EXTRA_LEVEL, -1);
|
||||||
// int scale = -1;
|
// int scale = -1;
|
||||||
// int voltage = -1;
|
// int voltage = -1;
|
||||||
// int temp = -1;
|
// int temp = -1;
|
||||||
// scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
// scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||||
// temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
|
// temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
|
||||||
// voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
|
// voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
|
||||||
Log.i("Battery", "Level: " + String.valueOf(batteryLevel));
|
Log.i("Battery", "Level: " + String.valueOf(batteryLevel));
|
||||||
this.actionBatteryLevel(context);
|
this.actionBatteryLevel(context);
|
||||||
|
|
||||||
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
int status = intent.getIntExtra(EXTRA_STATUS, -1);
|
||||||
int statusPlugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
int statusPlugged = intent.getIntExtra(EXTRA_PLUGGED, -1);
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Status: " + String.valueOf(statusPlugged), 5);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Status: " + String.valueOf(statusPlugged), 5);
|
||||||
|
|
||||||
switch(statusPlugged)
|
switch(statusPlugged)
|
||||||
{
|
{
|
||||||
case BatteryManager.BATTERY_PLUGGED_AC:
|
case BATTERY_PLUGGED_AC:
|
||||||
// Toast.makeText(context, "Regular charging", Toast.LENGTH_LONG).show();
|
// Toast.makeText(context, "Regular charging", Toast.LENGTH_LONG).show();
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Regular charging.", 5);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Regular charging.", 5);
|
||||||
this.actionCharging(context);
|
this.actionCharging(context, statusPlugged);
|
||||||
break;
|
break;
|
||||||
case BatteryManager.BATTERY_PLUGGED_USB:
|
case BATTERY_PLUGGED_WIRELESS:
|
||||||
|
// Toast.makeText(context, "Regular charging", Toast.LENGTH_LONG).show();
|
||||||
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Wireless charging.", 5);
|
||||||
|
this.actionCharging(context, statusPlugged);
|
||||||
|
break;
|
||||||
|
case BATTERY_PLUGGED_USB:
|
||||||
this.actionUsbConnected(context);
|
this.actionUsbConnected(context);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(status)
|
switch(status)
|
||||||
{
|
{
|
||||||
case BatteryManager.BATTERY_STATUS_FULL:
|
case BATTERY_STATUS_CHARGING:
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Device has been fully charged.", 5);
|
case BATTERY_STATUS_FULL:
|
||||||
this.actionCharging(context);
|
// Miscellaneous.logEvent("i", "BatteryReceiver", "Device has been fully charged.", 5);
|
||||||
|
this.actionCharging(context, statusPlugged);
|
||||||
break;
|
break;
|
||||||
case BatteryManager.BATTERY_STATUS_DISCHARGING:
|
case BATTERY_STATUS_DISCHARGING:
|
||||||
|
case BATTERY_STATUS_NOT_CHARGING:
|
||||||
this.actionDischarging(context);
|
this.actionDischarging(context);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -148,34 +159,39 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int isDeviceCharging(Context context)
|
public static int isDeviceCharging(Context context)
|
||||||
{
|
{
|
||||||
switch(currentChargingState)
|
switch(currentChargingState)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
Miscellaneous.logEvent("w", "ChargingInfo", "Status of device charging was requested. Information isn't available, yet.", 4);
|
Miscellaneous.logEvent("w", "ChargingInfo", "Information isn't available, yet.", 4);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Miscellaneous.logEvent("i", "ChargingInfo", "Status of device charging was requested. Device is discharging.", 3);
|
Miscellaneous.logEvent("i", "ChargingInfo", "Device is discharging.", 3);
|
||||||
break;
|
break;
|
||||||
case BatteryManager.BATTERY_STATUS_CHARGING:
|
case BATTERY_STATUS_CHARGING:
|
||||||
Miscellaneous.logEvent("i", "ChargingInfo", "Status of device charging was requested. Device is charging.", 3);
|
Miscellaneous.logEvent("i", "ChargingInfo", "Device is charging.", 3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentChargingState;
|
return currentChargingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionCharging(Context context)
|
public static int getCurrentChargingType()
|
||||||
{
|
{
|
||||||
if(currentChargingState != BatteryManager.BATTERY_STATUS_CHARGING) // Avoid flooding the log. This event will occur on a regular basis even though charging state wasn't changed.
|
return currentChargingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void actionCharging(Context context, int statusPlugged)
|
||||||
|
{
|
||||||
|
if(currentChargingState != BATTERY_STATUS_CHARGING) // Avoid flooding the log. This event will occur on a regular basis even though charging state wasn't changed.
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery is charging or full.", 3);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery is charging or full.", 3);
|
||||||
currentChargingState = BatteryManager.BATTERY_STATUS_CHARGING;
|
currentChargingState = BATTERY_STATUS_CHARGING;
|
||||||
//activate rule(s)
|
currentChargingType = statusPlugged;
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.charging);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.charging);
|
||||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(true);
|
|
||||||
for(int i=0; i<ruleCandidates.size(); i++)
|
for(int i=0; i<ruleCandidates.size(); i++)
|
||||||
{
|
{
|
||||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||||
@@ -183,7 +199,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionBatteryLevel(Context context)
|
private void actionBatteryLevel(Context context)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery level has changed.", 3);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery level has changed.", 3);
|
||||||
@@ -195,13 +211,13 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionDischarging(Context context)
|
private void actionDischarging(Context context)
|
||||||
{
|
{
|
||||||
if(currentChargingState != BatteryManager.BATTERY_STATUS_UNKNOWN) // Avoid flooding the log. This event will occur on a regular basis even though charging state wasn't changed.
|
if(currentChargingState != BATTERY_STATUS_UNKNOWN) // Avoid flooding the log. This event will occur on a regular basis even though charging state wasn't changed.
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery is discharging.", 3);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery is discharging.", 3);
|
||||||
currentChargingState = BatteryManager.BATTERY_STATUS_UNKNOWN;
|
currentChargingState = BATTERY_STATUS_UNKNOWN;
|
||||||
//activate rule(s)
|
//activate rule(s)
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.charging);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.charging);
|
||||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(false);
|
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(false);
|
||||||
@@ -210,44 +226,43 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.actionUsbDisconnected(context);
|
this.actionUsbDisconnected(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionUsbConnected(Context context)
|
private void actionUsbConnected(Context context)
|
||||||
{
|
{
|
||||||
// Event usbConnected
|
// Event usbConnected
|
||||||
|
|
||||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "BATTERY_PLUGGED_USB");
|
// Miscellaneous.logEvent("i", "BatteryReceiver", "BATTERY_PLUGGED_USB");
|
||||||
|
|
||||||
if(!usbHostConnected)
|
if(!usbHostConnected)
|
||||||
{
|
{
|
||||||
usbHostConnected = true;
|
usbHostConnected = true;
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Connected to computer.", 3);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Connected to computer.", 3);
|
||||||
Toast.makeText(context, "Connected to computer.", Toast.LENGTH_LONG).show();
|
// Toast.makeText(context, "Connected to computer.", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.usb_host_connection);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.usb_host_connection);
|
||||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(true);
|
|
||||||
for(Rule oneRule : ruleCandidates)
|
for(Rule oneRule : ruleCandidates)
|
||||||
{
|
{
|
||||||
if(oneRule.getsGreenLight(context))
|
if(oneRule.getsGreenLight(context))
|
||||||
oneRule.activate(automationServiceRef, false);
|
oneRule.activate(automationServiceRef, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.actionCharging(context);
|
this.actionCharging(context, BATTERY_PLUGGED_USB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionUsbDisconnected(Context context)
|
private void actionUsbDisconnected(Context context)
|
||||||
{
|
{
|
||||||
// Event usbDisConnected
|
// Event usbDisConnected
|
||||||
|
|
||||||
if(usbHostConnected)
|
if(usbHostConnected)
|
||||||
{
|
{
|
||||||
usbHostConnected = false;
|
usbHostConnected = false;
|
||||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Disconnected from computer.", 3);
|
Miscellaneous.logEvent("i", "BatteryReceiver", "Disconnected from computer.", 3);
|
||||||
Toast.makeText(context, "Disconnected from computer.", Toast.LENGTH_LONG).show();
|
// Toast.makeText(context, "Disconnected from computer.", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.usb_host_connection);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.usb_host_connection);
|
||||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(false);
|
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(false);
|
||||||
@@ -285,7 +300,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
|||||||
@Override
|
@Override
|
||||||
public Trigger_Enum[] getMonitoredTrigger()
|
public Trigger_Enum[] getMonitoredTrigger()
|
||||||
{
|
{
|
||||||
// actually monitores several
|
// actually monitors several
|
||||||
return new Trigger_Enum[] { Trigger_Enum.batteryLevel, Trigger_Enum.charging, Trigger_Enum.usb_host_connection };
|
return new Trigger_Enum[] { Trigger_Enum.batteryLevel, Trigger_Enum.charging, Trigger_Enum.usb_host_connection };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.jens.automation2.ActivityPermissions;
|
import com.jens.automation2.ActivityPermissions;
|
||||||
import com.jens.automation2.AutomationService;
|
import com.jens.automation2.AutomationService;
|
||||||
@@ -94,20 +95,21 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
// Miscellaneous.logEvent("i", "BluetoothReceiver", "Bluetooth event.", 4);
|
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
|
Miscellaneous.logEvent("i", "BluetoothReceiver", "Bluetooth event: " + action, 5);
|
||||||
|
|
||||||
BluetoothDevice bluetoothDevice = null;
|
BluetoothDevice bluetoothDevice = null;
|
||||||
|
|
||||||
if(action.equals(BluetoothDevice.ACTION_ACL_CONNECTED) | action.equals("android.bluetooth.device.action.ACL_CONNECTED"))
|
if(action.equals(BluetoothDevice.ACTION_ACL_CONNECTED) || action.equals("android.bluetooth.device.action.ACL_CONNECTED"))
|
||||||
{
|
{
|
||||||
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
lastAffectedDevice = bluetoothDevice;
|
lastAffectedDevice = bluetoothDevice;
|
||||||
lastAction = action;
|
lastAction = action;
|
||||||
connectedDevices.add(bluetoothDevice);
|
connectedDevices.add(bluetoothDevice);
|
||||||
Miscellaneous.logEvent("i", "BluetoothReceiver", String.format(context.getResources().getString(R.string.bluetoothConnectionTo), bluetoothDevice.getName()), 3);
|
Miscellaneous.logEvent("i", "BluetoothReceiver", String.format(context.getResources().getString(R.string.bluetoothConnectionTo), bluetoothDevice.getName()), 3);
|
||||||
}
|
}
|
||||||
else if(action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) | action.equals(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED) | action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECTED") | action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECT_REQUESTED"))
|
else if(action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) || action.equals(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED) || action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECTED") || action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECT_REQUESTED"))
|
||||||
{
|
{
|
||||||
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
lastAffectedDevice = bluetoothDevice;
|
lastAffectedDevice = bluetoothDevice;
|
||||||
@@ -115,7 +117,7 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
|||||||
connectedDevices.remove(bluetoothDevice);
|
connectedDevices.remove(bluetoothDevice);
|
||||||
Miscellaneous.logEvent("i", "BluetoothReceiver", String.format(context.getResources().getString(R.string.bluetoothDisconnectFrom), bluetoothDevice.getName()), 3);
|
Miscellaneous.logEvent("i", "BluetoothReceiver", String.format(context.getResources().getString(R.string.bluetoothDisconnectFrom), bluetoothDevice.getName()), 3);
|
||||||
}
|
}
|
||||||
else if(action.equals(BluetoothDevice.ACTION_FOUND) | action.equals("android.bluetooth.device.ACTION_FOUND"))
|
else if(action.equals(BluetoothDevice.ACTION_FOUND) || action.equals("android.bluetooth.device.ACTION_FOUND"))
|
||||||
{
|
{
|
||||||
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
lastAffectedDevice = bluetoothDevice;
|
lastAffectedDevice = bluetoothDevice;
|
||||||
@@ -148,8 +150,6 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
|||||||
{
|
{
|
||||||
return lhs.getName().compareTo(rhs.getName());
|
return lhs.getName().compareTo(rhs.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(NullPointerException e)
|
catch(NullPointerException e)
|
||||||
@@ -158,6 +158,12 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
|||||||
|
|
||||||
returnArray = new BluetoothDevice[] {};
|
returnArray = new BluetoothDevice[] {};
|
||||||
}
|
}
|
||||||
|
catch(SecurityException se)
|
||||||
|
{
|
||||||
|
Toast.makeText(Miscellaneous.getAnyContext(), Miscellaneous.getAnyContext().getResources().getString(R.string.permissionRequiredBluetooth), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
returnArray = new BluetoothDevice[] {};
|
||||||
|
}
|
||||||
|
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,13 @@ public class BroadcastListener extends android.content.BroadcastReceiver impleme
|
|||||||
{
|
{
|
||||||
broadcastsCollection.add(new EventOccurrence(Calendar.getInstance(), intent.getAction()));
|
broadcastsCollection.add(new EventOccurrence(Calendar.getInstance(), intent.getAction()));
|
||||||
|
|
||||||
for(String key : intent.getExtras().keySet())
|
Miscellaneous.logEvent("i", "Broadcast received", "Broadcast " + intent.getAction() + " received.", 4);
|
||||||
|
if(intent.getExtras() != null && intent.getExtras().size() > 0)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
|
for (String key : intent.getExtras().keySet())
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.broadcastReceived);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.broadcastReceived);
|
||||||
@@ -125,7 +129,10 @@ public class BroadcastListener extends android.content.BroadcastReceiver impleme
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter);
|
if(Build.VERSION.SDK_INT >= 33)
|
||||||
|
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter, Context.RECEIVER_EXPORTED);
|
||||||
|
else
|
||||||
|
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter);
|
||||||
broadcastReceiverActive = true;
|
broadcastReceiverActive = true;
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
|
|||||||
@@ -0,0 +1,671 @@
|
|||||||
|
package com.jens.automation2.receivers;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.CalendarContract;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.jens.automation2.AutomationService;
|
||||||
|
import com.jens.automation2.Miscellaneous;
|
||||||
|
import com.jens.automation2.Rule;
|
||||||
|
import com.jens.automation2.Trigger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class CalendarReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||||
|
{
|
||||||
|
static CalendarReceiver calendarReceiverInstance = null;
|
||||||
|
static boolean calendarReceiverActive = false;
|
||||||
|
static IntentFilter calendarIntentFilter = null;
|
||||||
|
private static Intent calendarIntent = null;
|
||||||
|
|
||||||
|
public static final int AVAILABILITY_OUT_OF_OFFICE = 4;
|
||||||
|
public static final int AVAILABILITY_WORKING_ELSEWHERE = 5;
|
||||||
|
public static final String calendarAlarmAction = "ALARM_FOR_CALENDAR";
|
||||||
|
|
||||||
|
static List<AndroidCalendar> calendarsCache = null;
|
||||||
|
static List<CalendarEvent> calendarEventsCache = null;
|
||||||
|
static List<CalendarEvent> calendarEventsReoccurringCache = null;
|
||||||
|
|
||||||
|
// To determine for which events which rules have been executed
|
||||||
|
static List<RuleEventPair> calendarEventsUsed = new ArrayList<>();
|
||||||
|
|
||||||
|
static Timer timer = null;
|
||||||
|
static TimerTask timerTask = null;
|
||||||
|
static Calendar nextWakeup = null;
|
||||||
|
static AlarmManager alarmManager = null;
|
||||||
|
static boolean wakeupNeedsToBeScheduledOrRescheduled = false;
|
||||||
|
|
||||||
|
public static CalendarEvent getLastTriggeringEvent()
|
||||||
|
{
|
||||||
|
if(calendarEventsUsed.size() > 0)
|
||||||
|
{
|
||||||
|
return calendarEventsUsed.get(calendarEventsUsed.size() -1).event;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RuleEventPair
|
||||||
|
{
|
||||||
|
Rule rule;
|
||||||
|
CalendarEvent event;
|
||||||
|
|
||||||
|
public RuleEventPair(Rule rule, CalendarEvent event)
|
||||||
|
{
|
||||||
|
this.rule = rule;
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addUsedPair(RuleEventPair pair)
|
||||||
|
{
|
||||||
|
// Add pair only if it's not in the list already.
|
||||||
|
for(RuleEventPair usedPair : calendarEventsUsed)
|
||||||
|
{
|
||||||
|
if(usedPair.rule.equals(pair.rule) && usedPair.event.equals(pair.event))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
calendarEventsUsed.add(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CalendarReceiver getInstance()
|
||||||
|
{
|
||||||
|
if(calendarReceiverInstance == null)
|
||||||
|
calendarReceiverInstance = new CalendarReceiver();
|
||||||
|
|
||||||
|
return calendarReceiverInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "CalendarReceiver", "Received " + intent.getAction(), 4);
|
||||||
|
|
||||||
|
if(intent.getAction().equalsIgnoreCase(Intent.ACTION_PROVIDER_CHANGED))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "CalendarReceiver", "Clearing calendar caches.", 4);
|
||||||
|
|
||||||
|
clearCaches();
|
||||||
|
|
||||||
|
routineAtAlarm();
|
||||||
|
}
|
||||||
|
else if(intent.getAction().equalsIgnoreCase(calendarAlarmAction))
|
||||||
|
{
|
||||||
|
routineAtAlarm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkForRules(Context context)
|
||||||
|
{
|
||||||
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent);
|
||||||
|
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||||
|
{
|
||||||
|
if (ruleCandidates.get(i).getsGreenLight(context))
|
||||||
|
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startListener(AutomationService automationServiceRef)
|
||||||
|
{
|
||||||
|
startCalendarReceiver(automationServiceRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clearCaches()
|
||||||
|
{
|
||||||
|
calendarsCache = null;
|
||||||
|
calendarEventsCache = null;
|
||||||
|
calendarEventsReoccurringCache = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopListener(AutomationService automationService)
|
||||||
|
{
|
||||||
|
if(calendarReceiverActive)
|
||||||
|
{
|
||||||
|
if(calendarReceiverInstance != null)
|
||||||
|
{
|
||||||
|
AutomationService.getInstance().unregisterReceiver(calendarReceiverInstance);
|
||||||
|
calendarReceiverInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearCaches();
|
||||||
|
calendarEventsUsed.clear();
|
||||||
|
|
||||||
|
calendarReceiverActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isListenerRunning()
|
||||||
|
{
|
||||||
|
return calendarReceiverActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||||
|
{
|
||||||
|
return new Trigger.Trigger_Enum[]{Trigger.Trigger_Enum.calendarEvent};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AndroidCalendar
|
||||||
|
{
|
||||||
|
public int calendarId;
|
||||||
|
public String displayName;
|
||||||
|
public String accountString;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return displayName + " (" + accountString + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CalendarEvent
|
||||||
|
{
|
||||||
|
public AndroidCalendar calendar;
|
||||||
|
public int calendarId;
|
||||||
|
public String eventId;
|
||||||
|
public String title;
|
||||||
|
public String description;
|
||||||
|
public String location;
|
||||||
|
public String availability;
|
||||||
|
public Calendar start, end;
|
||||||
|
public boolean allDay, reoccurring;
|
||||||
|
|
||||||
|
public boolean isCurrentlyActive()
|
||||||
|
{
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
return now.getTimeInMillis() >= start.getTimeInMillis() && now.getTimeInMillis() < end.getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "Title: " + title + ", location: " + location + ", description: " + description + ", start: " + Miscellaneous.formatDate(start.getTime()) + ", end: " + Miscellaneous.formatDate(end.getTime()) + ", is currently active: " + String.valueOf(isCurrentlyActive()) + ", all day: " + String.valueOf(allDay) + ", availability: " + availability;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CalendarEvent compareEvent = (CalendarEvent) obj;
|
||||||
|
return calendarId == compareEvent.calendarId
|
||||||
|
&&
|
||||||
|
eventId.equals(compareEvent.eventId)
|
||||||
|
&&
|
||||||
|
title.equals(compareEvent.title)
|
||||||
|
&&
|
||||||
|
description.equals(compareEvent.description)
|
||||||
|
&&
|
||||||
|
location.equals(compareEvent.location)
|
||||||
|
&&
|
||||||
|
availability.equals(compareEvent.availability)
|
||||||
|
&&
|
||||||
|
start.getTimeInMillis() == compareEvent.start.getTimeInMillis()
|
||||||
|
&&
|
||||||
|
end.getTimeInMillis() == compareEvent.end.getTimeInMillis()
|
||||||
|
&&
|
||||||
|
allDay == compareEvent.allDay;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", "CalendarReceiver compare()", Log.getStackTraceString(e), 5);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<AndroidCalendar> readCalendars(Context context)
|
||||||
|
{
|
||||||
|
if(calendarsCache == null)
|
||||||
|
{
|
||||||
|
calendarsCache = new ArrayList<>();
|
||||||
|
|
||||||
|
Cursor cursor;
|
||||||
|
|
||||||
|
cursor = context.getContentResolver().query(
|
||||||
|
Uri.parse("content://com.android.calendar/calendars"),
|
||||||
|
|
||||||
|
new String[]{ CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.OWNER_ACCOUNT, },
|
||||||
|
null, null, null);
|
||||||
|
|
||||||
|
cursor.moveToFirst();
|
||||||
|
// fetching calendars name
|
||||||
|
String CNames[] = new String[cursor.getCount()];
|
||||||
|
|
||||||
|
for (int i = 0; i < CNames.length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AndroidCalendar calendar = new AndroidCalendar();
|
||||||
|
calendar.calendarId = Integer.parseInt(cursor.getString(0));
|
||||||
|
calendar.displayName = cursor.getString(1);
|
||||||
|
calendar.accountString = cursor.getString(2);
|
||||||
|
|
||||||
|
calendarsCache.add(calendar);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
cursor.moveToNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor != null)
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return calendarsCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CalendarEvent> readCalendarEvents(Context context, boolean includeReoccurring, boolean includePastEvents)
|
||||||
|
{
|
||||||
|
if(calendarEventsCache == null)
|
||||||
|
{
|
||||||
|
calendarEventsCache = new ArrayList<>();
|
||||||
|
|
||||||
|
Cursor cursor;
|
||||||
|
|
||||||
|
cursor = context.getContentResolver().query(
|
||||||
|
Uri.parse("content://com.android.calendar/events"),
|
||||||
|
new String[] {
|
||||||
|
CalendarContract.Events.CALENDAR_ID,
|
||||||
|
CalendarContract.Events._ID,
|
||||||
|
CalendarContract.Events.TITLE,
|
||||||
|
CalendarContract.Events.DESCRIPTION,
|
||||||
|
CalendarContract.Events.ALL_DAY,
|
||||||
|
CalendarContract.Events.DTSTART,
|
||||||
|
CalendarContract.Events.DTEND,
|
||||||
|
CalendarContract.Events.EVENT_LOCATION,
|
||||||
|
CalendarContract.Events.AVAILABILITY
|
||||||
|
},
|
||||||
|
null, null, null);
|
||||||
|
|
||||||
|
cursor.moveToFirst();
|
||||||
|
// fetching calendars name
|
||||||
|
String CNames[] = new String[cursor.getCount()];
|
||||||
|
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
|
||||||
|
for (int i = 0; i < CNames.length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CalendarEvent event = new CalendarEvent();
|
||||||
|
event.calendarId = Integer.parseInt(cursor.getString(0));
|
||||||
|
|
||||||
|
for(AndroidCalendar cal : readCalendars(context))
|
||||||
|
{
|
||||||
|
if(cal.calendarId == event.calendarId)
|
||||||
|
{
|
||||||
|
event.calendar = cal;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.eventId = cursor.getString(1);
|
||||||
|
event.title = cursor.getString(2);
|
||||||
|
event.description = cursor.getString(3);
|
||||||
|
event.allDay = cursor.getString(4).equals("1");
|
||||||
|
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||||
|
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(6)));
|
||||||
|
event.location = cursor.getString(7);
|
||||||
|
event.availability = cursor.getString(8);
|
||||||
|
event.reoccurring = false;
|
||||||
|
|
||||||
|
if(includePastEvents || event.end.getTimeInMillis() > now.getTimeInMillis())
|
||||||
|
calendarEventsCache.add(event);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{}
|
||||||
|
cursor.moveToNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cursor != null)
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(includeReoccurring && calendarEventsReoccurringCache == null)
|
||||||
|
{
|
||||||
|
calendarEventsReoccurringCache = new ArrayList<>();
|
||||||
|
|
||||||
|
Cursor cursor;
|
||||||
|
|
||||||
|
Calendar queryStart, queryEnd;
|
||||||
|
if(includePastEvents)
|
||||||
|
queryStart = Miscellaneous.calendarFromLong(0);
|
||||||
|
else
|
||||||
|
queryStart = Calendar.getInstance();
|
||||||
|
|
||||||
|
queryEnd = Calendar.getInstance();
|
||||||
|
queryEnd.add(Calendar.YEAR, 1);
|
||||||
|
|
||||||
|
cursor = context.getContentResolver().query(
|
||||||
|
Uri.parse("content://com.android.calendar/instances/when/" + queryStart.getTimeInMillis() + "/" + queryEnd.getTimeInMillis()),
|
||||||
|
new String[] {
|
||||||
|
CalendarContract.Instances.CALENDAR_ID,
|
||||||
|
CalendarContract.Instances._ID,
|
||||||
|
CalendarContract.Instances.TITLE,
|
||||||
|
CalendarContract.Instances.DESCRIPTION,
|
||||||
|
CalendarContract.Instances.ALL_DAY,
|
||||||
|
CalendarContract.Instances.BEGIN,
|
||||||
|
CalendarContract.Instances.END,
|
||||||
|
CalendarContract.Instances.EVENT_LOCATION,
|
||||||
|
CalendarContract.Instances.AVAILABILITY
|
||||||
|
},
|
||||||
|
null, null, null);
|
||||||
|
|
||||||
|
cursor.moveToFirst();
|
||||||
|
String CNames[] = new String[cursor.getCount()];
|
||||||
|
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
|
||||||
|
for (int i = 0; i < CNames.length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CalendarEvent event = new CalendarEvent();
|
||||||
|
event.calendarId = Integer.parseInt(cursor.getString(0));
|
||||||
|
|
||||||
|
for(AndroidCalendar cal : readCalendars(context))
|
||||||
|
{
|
||||||
|
if(cal.calendarId == event.calendarId)
|
||||||
|
{
|
||||||
|
event.calendar = cal;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.eventId = cursor.getString(1);
|
||||||
|
event.title = cursor.getString(2);
|
||||||
|
event.description = cursor.getString(3);
|
||||||
|
event.allDay = cursor.getString(4).equals("1");
|
||||||
|
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||||
|
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(6)));
|
||||||
|
event.location = cursor.getString(7);
|
||||||
|
event.availability = cursor.getString(8);
|
||||||
|
event.reoccurring = true;
|
||||||
|
|
||||||
|
if(includePastEvents || event.end.getTimeInMillis() > now.getTimeInMillis())
|
||||||
|
{
|
||||||
|
// For the moment keeping separate records to some extent
|
||||||
|
calendarEventsReoccurringCache.add(event);
|
||||||
|
calendarEventsCache.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{}
|
||||||
|
cursor.moveToNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cursor != null)
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return calendarEventsCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void routineAtAlarm()
|
||||||
|
{
|
||||||
|
checkForRules(Miscellaneous.getAnyContext());
|
||||||
|
|
||||||
|
// Set next timer
|
||||||
|
calculateNextWakeup();
|
||||||
|
armOrRearmTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void armOrRearmTimer()
|
||||||
|
{
|
||||||
|
PendingIntent pi = null;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
{
|
||||||
|
if (alarmManager == null)
|
||||||
|
{
|
||||||
|
alarmManager = (AlarmManager) Miscellaneous.getAnyContext().getSystemService(Context.ALARM_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pi == null)
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(Miscellaneous.getAnyContext(), CalendarReceiver.class);
|
||||||
|
intent.setAction(calendarAlarmAction);
|
||||||
|
pi = PendingIntent.getBroadcast(AutomationService.getInstance(), 0, intent, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timerTask = new TimerTask()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
routineAtAlarm();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(timer != null)
|
||||||
|
{
|
||||||
|
timer.cancel();
|
||||||
|
timer.purge();
|
||||||
|
}
|
||||||
|
timer = new Timer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nextWakeup == null)
|
||||||
|
{
|
||||||
|
readCalendarEvents(Miscellaneous.getAnyContext(), true,false);
|
||||||
|
calculateNextWakeup();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's now filled, go on
|
||||||
|
if(nextWakeup != null && wakeupNeedsToBeScheduledOrRescheduled)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && alarmManager.canScheduleExactAlarms()))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
alarmManager.cancel(pi);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
Miscellaneous.logEvent("i", "armOrRearmTimer()", "Scheduling wakeup for calendar at " + Miscellaneous.formatDate(nextWakeup.getTime()), 4);
|
||||||
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi);
|
||||||
|
wakeupNeedsToBeScheduledOrRescheduled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
timer.schedule(timerTask, nextWakeup.getTimeInMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void calculateNextWakeup()
|
||||||
|
{
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
List<CalendarEvent> events = readCalendarEvents(Miscellaneous.getAnyContext(), true, false);
|
||||||
|
|
||||||
|
if(events.size() == 0)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeup()", "Supposedly no future events in calendar. Reading again...", 4);
|
||||||
|
events = readCalendarEvents(Miscellaneous.getAnyContext(), true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (events.size() == 0)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeup()", "No future events, nothing to schedule.", 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeup()", String.valueOf(events.size()) + " future events in calendar. Checking if one applies.", 4);
|
||||||
|
|
||||||
|
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent);
|
||||||
|
List<Long> wakeUpCandidatesList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (CalendarEvent event : events)
|
||||||
|
{
|
||||||
|
for (Rule r : ruleCandidates)
|
||||||
|
{
|
||||||
|
for (Trigger t : r.getTriggerSet())
|
||||||
|
{
|
||||||
|
if (t.getTriggerType().equals(Trigger.Trigger_Enum.calendarEvent) && t.checkCalendarEvent(event, true))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Device needs to wakeup at start AND end of events, no matter what is specified in triggers.
|
||||||
|
This is because we also need to know when a trigger doesn't apply anymore to make it
|
||||||
|
count for hasStateNotAppliedSinceLastRuleExecution().
|
||||||
|
Otherwise the same rule would not get executed again even after calendar events have come and gone.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(event.start.getTimeInMillis() > now.getTimeInMillis())
|
||||||
|
wakeUpCandidatesList.add(event.start.getTimeInMillis());
|
||||||
|
|
||||||
|
if(event.end.getTimeInMillis() > now.getTimeInMillis())
|
||||||
|
wakeUpCandidatesList.add(event.end.getTimeInMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(wakeUpCandidatesList);
|
||||||
|
|
||||||
|
if(wakeUpCandidatesList.size() == 0)
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Not scheduling any calendar related wakeup as there are no future events that might match a configured trigger.", 4);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (nextWakeup == null || nextWakeup.getTimeInMillis() != wakeUpCandidatesList.get(0))
|
||||||
|
{
|
||||||
|
Calendar newAlarm = Miscellaneous.calendarFromLong(wakeUpCandidatesList.get(0));
|
||||||
|
if (nextWakeup == null)
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Chose " + Miscellaneous.formatDate(newAlarm.getTime()) + " as next wakeup for calendar triggers. Old was null.", 4);
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Chose " + Miscellaneous.formatDate(newAlarm.getTime()) + " as next wakeup for calendar triggers. Old was " + Miscellaneous.formatDate(nextWakeup.getTime()), 4);
|
||||||
|
nextWakeup = newAlarm;
|
||||||
|
if (!wakeupNeedsToBeScheduledOrRescheduled)
|
||||||
|
wakeupNeedsToBeScheduledOrRescheduled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Alarm " + Miscellaneous.formatDate(nextWakeup.getTime()) + " has been selected as next wakeup, but not rescheduling since this was not a change.", 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startCalendarReceiver(final AutomationService automationServiceRef)
|
||||||
|
{
|
||||||
|
if (!calendarReceiverActive)
|
||||||
|
{
|
||||||
|
if (calendarReceiverInstance == null)
|
||||||
|
calendarReceiverInstance = new CalendarReceiver();
|
||||||
|
|
||||||
|
if (calendarIntentFilter == null)
|
||||||
|
{
|
||||||
|
calendarIntentFilter = new IntentFilter();
|
||||||
|
calendarIntentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED);
|
||||||
|
calendarIntentFilter.addDataScheme("content");
|
||||||
|
calendarIntentFilter.addDataAuthority("com.android.calendar", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT >= 33)
|
||||||
|
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter, Context.RECEIVER_EXPORTED);
|
||||||
|
else
|
||||||
|
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter);
|
||||||
|
|
||||||
|
calendarReceiverActive = true;
|
||||||
|
|
||||||
|
armOrRearmTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean mayRuleStillBeActivatedForPendingCalendarEvents(Rule rule)
|
||||||
|
{
|
||||||
|
for(RuleEventPair pair : calendarEventsUsed)
|
||||||
|
Miscellaneous.logEvent("i", "mayRuleStillBeActivatedForPendingCalendarEvents()", "Existing pair of " + pair.rule.getName() + " and " + pair.event, 5);
|
||||||
|
|
||||||
|
for(CalendarEvent event : readCalendarEvents(Miscellaneous.getAnyContext(), true,false))
|
||||||
|
{
|
||||||
|
for(Trigger t : rule.getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(Trigger.Trigger_Enum.calendarEvent) && t.checkCalendarEvent(event, false))
|
||||||
|
{
|
||||||
|
if (!hasEventBeenUsedInRule(rule, event))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
If there are multiple parallel calendar events and a rule has multiple
|
||||||
|
triggers of type calendar event, we don't want the rule to fire only once.
|
||||||
|
*/
|
||||||
|
if(rule.getAmountOfTriggersForType(Trigger.Trigger_Enum.calendarEvent) == 1)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "mayRuleStillBeActivatedForPendingCalendarEvents()", "Rule " + rule.getName() + " has not been used in conjunction with event " + event, 4);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasEventBeenUsedInRule(Rule rule, CalendarEvent event)
|
||||||
|
{
|
||||||
|
for (RuleEventPair executedPair : calendarEventsUsed)
|
||||||
|
{
|
||||||
|
if (executedPair.rule.equals(rule) && executedPair.event.equals(event))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CalendarReceiver.CalendarEvent> getApplyingCalendarEvents(Rule rule)
|
||||||
|
{
|
||||||
|
List<CalendarReceiver.CalendarEvent> returnList = new ArrayList<>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<CalendarReceiver.CalendarEvent> calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true,false);
|
||||||
|
|
||||||
|
for(Trigger t : rule.getTriggerSet())
|
||||||
|
{
|
||||||
|
if(t.getTriggerType().equals(Trigger.Trigger_Enum.calendarEvent))
|
||||||
|
{
|
||||||
|
for (CalendarReceiver.CalendarEvent event : calendarEvents)
|
||||||
|
{
|
||||||
|
if (t.checkCalendarEvent(event, false))
|
||||||
|
returnList.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", "getApplyingCalendarEvents()", Log.getStackTraceString(e), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -136,7 +136,12 @@ public class ConnectivityReceiver extends BroadcastReceiver implements Automatio
|
|||||||
// Airplane mode status has changed.
|
// Airplane mode status has changed.
|
||||||
Miscellaneous.logEvent("i", "Connectivity", "Airplane mode changed.", 2);
|
Miscellaneous.logEvent("i", "Connectivity", "Airplane mode changed.", 2);
|
||||||
boolean isAirplaneMode = isAirplaneMode(context);
|
boolean isAirplaneMode = isAirplaneMode(context);
|
||||||
automationServiceRef.getLocationProvider().handleAirplaneMode(isAirplaneMode);
|
|
||||||
|
/*
|
||||||
|
If the user doesn't have any locations this service is probably off and therefore null.
|
||||||
|
*/
|
||||||
|
if(automationServiceRef.getLocationProvider() != null)
|
||||||
|
automationServiceRef.getLocationProvider().handleAirplaneMode(isAirplaneMode);
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.airplaneMode);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.airplaneMode);
|
||||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByAirplaneMode(isAirplaneMode);
|
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByAirplaneMode(isAirplaneMode);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.content.Intent;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.jens.automation2.AutomationService;
|
import com.jens.automation2.AutomationService;
|
||||||
@@ -18,10 +19,10 @@ import com.jens.automation2.TimeObject;
|
|||||||
import com.jens.automation2.Trigger;
|
import com.jens.automation2.Trigger;
|
||||||
import com.jens.automation2.Trigger.Trigger_Enum;
|
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||||
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class DateTimeListener extends BroadcastReceiver implements AutomationListenerInterface
|
public class DateTimeListener extends BroadcastReceiver implements AutomationListenerInterface
|
||||||
@@ -34,7 +35,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
static PendingIntent alarmPendingIntent = null;
|
static PendingIntent alarmPendingIntent = null;
|
||||||
|
|
||||||
public static void startAlarmListener(final AutomationService automationServiceRef)
|
public static void startAlarmListener(final AutomationService automationServiceRef)
|
||||||
{
|
{
|
||||||
DateTimeListener.startAlarmListenerInternal(automationServiceRef);
|
DateTimeListener.startAlarmListenerInternal(automationServiceRef);
|
||||||
}
|
}
|
||||||
public static void stopAlarmListener(Context context)
|
public static void stopAlarmListener(Context context)
|
||||||
@@ -46,37 +47,37 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
{
|
{
|
||||||
return alarmListenerActive;
|
return alarmListenerActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "AlarmListener", "Alarm received", 2);
|
Miscellaneous.logEvent("i", "AlarmListener", "Alarm received", 2);
|
||||||
|
|
||||||
ArrayList<Rule> allRulesWithNowInTimeFrame = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
ArrayList<Rule> allRulesWithTimeFrame = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
||||||
for(int i=0; i < allRulesWithNowInTimeFrame.size(); i++)
|
for(int i=0; i < allRulesWithTimeFrame.size(); i++)
|
||||||
{
|
{
|
||||||
if(allRulesWithNowInTimeFrame.get(i).getsGreenLight(context))
|
if(allRulesWithTimeFrame.get(i).getsGreenLight(context))
|
||||||
allRulesWithNowInTimeFrame.get(i).activate(automationServiceRef, false);
|
allRulesWithTimeFrame.get(i).activate(automationServiceRef, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAlarms();
|
setOrResetAlarms();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||||
public static void setAlarms()
|
public static void setOrResetAlarms()
|
||||||
{
|
{
|
||||||
alarmCandidates.clear();
|
alarmCandidates.clear();
|
||||||
|
|
||||||
Calendar calNow = Calendar.getInstance();
|
Calendar calNow = Calendar.getInstance();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm");
|
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm");
|
||||||
|
|
||||||
clearAlarms();
|
clearAlarms();
|
||||||
|
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
ArrayList<Rule> allRulesWithTimeFrames = new ArrayList<Rule>();
|
ArrayList<Rule> allRulesWithTimeFrames = new ArrayList<Rule>();
|
||||||
allRulesWithTimeFrames = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
allRulesWithTimeFrames = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
||||||
// allRulesWithTimeFrames = Rule.findRuleCandidatesByTimeFrame();
|
|
||||||
/*
|
/*
|
||||||
* Take care of regular executions, no repetitions in between.
|
* Take care of regular executions, no repetitions in between.
|
||||||
*/
|
*/
|
||||||
@@ -190,18 +191,17 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
* 4. Take div result +1 and add this on top of starting time
|
* 4. Take div result +1 and add this on top of starting time
|
||||||
* 5. Is this next possible execution still inside timeframe? Also consider timeframes spanning over midnight
|
* 5. Is this next possible execution still inside timeframe? Also consider timeframes spanning over midnight
|
||||||
*/
|
*/
|
||||||
Calendar calSet;
|
|
||||||
Time setTime;
|
|
||||||
TimeFrame tf = new TimeFrame(oneTrigger.getTriggerParameter2());
|
TimeFrame tf = new TimeFrame(oneTrigger.getTriggerParameter2());
|
||||||
|
|
||||||
if(tf.getRepetition() > 0)
|
if(tf.getRepetition() > 0)
|
||||||
{
|
{
|
||||||
if(oneTrigger.applies(calNow, Miscellaneous.getAnyContext()))
|
// if(oneTrigger.applies(calNow, Miscellaneous.getAnyContext()))
|
||||||
{
|
// {
|
||||||
Calendar calSchedule = getNextRepeatedExecutionAfter(oneTrigger, calNow);
|
Calendar calSchedule = getNextRepeatedExecution(oneTrigger);
|
||||||
|
|
||||||
alarmCandidates.add(new ScheduleElement(calSchedule, "Rule " + oneRule.getName() + ", trigger " + oneTrigger.toString()));
|
alarmCandidates.add(new ScheduleElement(calSchedule, "Rule " + oneRule.getName() + ", trigger " + oneTrigger.toString()));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,15 +212,15 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleNextAlarm();
|
scheduleNextAlarm();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleNextAlarm()
|
private static void scheduleNextAlarm()
|
||||||
{
|
{
|
||||||
Long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
ScheduleElement scheduleCandidate = null;
|
ScheduleElement scheduleCandidate = null;
|
||||||
|
|
||||||
if(alarmCandidates.size() == 0)
|
if(alarmCandidates.size() == 0)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "AlarmManager", "No alarms to be scheduled.", 3);
|
Miscellaneous.logEvent("i", "AlarmManager", "No alarms to be scheduled.", 3);
|
||||||
@@ -234,38 +234,48 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
else if(alarmCandidates.size() > 1)
|
else if(alarmCandidates.size() > 1)
|
||||||
{
|
{
|
||||||
scheduleCandidate = alarmCandidates.get(0);
|
scheduleCandidate = alarmCandidates.get(0);
|
||||||
|
|
||||||
for(ScheduleElement alarmCandidate : alarmCandidates)
|
for(ScheduleElement alarmCandidate : alarmCandidates)
|
||||||
{
|
{
|
||||||
if(Math.abs(currentTime - alarmCandidate.time.getTimeInMillis()) < Math.abs(currentTime - scheduleCandidate.time.getTimeInMillis()))
|
if(Math.abs(currentTime - alarmCandidate.time.getTimeInMillis()) < Math.abs(currentTime - scheduleCandidate.time.getTimeInMillis()))
|
||||||
scheduleCandidate = alarmCandidate;
|
scheduleCandidate = alarmCandidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
||||||
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
if(Miscellaneous.getAnyContext().getApplicationContext().getApplicationInfo().targetSdkVersion >= 31)
|
||||||
|
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
else
|
||||||
|
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
centralAlarmManagerInstance.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
||||||
|
else
|
||||||
|
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm:ss");
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(scheduleCandidate.time.getTimeInMillis());
|
calendar.setTimeInMillis(scheduleCandidate.time.getTimeInMillis());
|
||||||
Miscellaneous.logEvent("i", "AlarmManager", "Chose " + sdf.format(calendar.getTime()) + " as next scheduled alarm.", 4);
|
Miscellaneous.logEvent("i", "AlarmManager", "Chose " + sdf.format(calendar.getTime()) + " as next scheduled alarm.", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearAlarms()
|
public static void clearAlarms()
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "AlarmManager", "Clearing possibly standing alarms.", 4);
|
Miscellaneous.logEvent("i", "AlarmManager", "Clearing possibly standing alarms.", 4);
|
||||||
|
|
||||||
for(int requestCode : requestCodeList)
|
for(int requestCode : requestCodeList)
|
||||||
{
|
{
|
||||||
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
||||||
if(alarmPendingIntent == null)
|
if(alarmPendingIntent == null)
|
||||||
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
|
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
|
||||||
// Miscellaneous.logEvent("i", "AlarmManager", "Clearing alarm with request code: " + String.valueOf(requestCode));
|
|
||||||
centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestCodeList.clear();
|
requestCodeList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startAlarmListenerInternal(AutomationService givenAutomationServiceRef)
|
private static void startAlarmListenerInternal(AutomationService givenAutomationServiceRef)
|
||||||
{
|
{
|
||||||
if(!alarmListenerActive)
|
if(!alarmListenerActive)
|
||||||
@@ -273,12 +283,11 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
Miscellaneous.logEvent("i", "AlarmListener", "Starting alarm listener.", 4);
|
Miscellaneous.logEvent("i", "AlarmListener", "Starting alarm listener.", 4);
|
||||||
DateTimeListener.automationServiceRef = givenAutomationServiceRef;
|
DateTimeListener.automationServiceRef = givenAutomationServiceRef;
|
||||||
centralAlarmManagerInstance = (AlarmManager)automationServiceRef.getSystemService(automationServiceRef.ALARM_SERVICE);
|
centralAlarmManagerInstance = (AlarmManager)automationServiceRef.getSystemService(automationServiceRef.ALARM_SERVICE);
|
||||||
// alarmIntent = new Intent(automationServiceRef, AlarmListener.class);
|
|
||||||
// alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, 0);
|
|
||||||
alarmListenerActive = true;
|
alarmListenerActive = true;
|
||||||
Miscellaneous.logEvent("i", "AlarmListener", "Alarm listener started.", 4);
|
Miscellaneous.logEvent("i", "AlarmListener", "Alarm listener started.", 4);
|
||||||
DateTimeListener.setAlarms();
|
DateTimeListener.setOrResetAlarms();
|
||||||
|
|
||||||
// // get a Calendar object with current time
|
// // get a Calendar object with current time
|
||||||
// Calendar cal = Calendar.getInstance();
|
// Calendar cal = Calendar.getInstance();
|
||||||
// // add 5 minutes to the calendar object
|
// // add 5 minutes to the calendar object
|
||||||
@@ -288,7 +297,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "AlarmListener", "Request to start AlarmListener. But it's already active.", 5);
|
Miscellaneous.logEvent("i", "AlarmListener", "Request to start AlarmListener. But it's already active.", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void stopAlarmListenerInternal()
|
private static void stopAlarmListenerInternal()
|
||||||
{
|
{
|
||||||
if(alarmListenerActive)
|
if(alarmListenerActive)
|
||||||
@@ -301,10 +310,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "AlarmListener", "Request to stop AlarmListener. But it's not running.", 5);
|
Miscellaneous.logEvent("i", "AlarmListener", "Request to stop AlarmListener. But it's not running.", 5);
|
||||||
}
|
}
|
||||||
public static void reloadAlarms()
|
|
||||||
{
|
|
||||||
DateTimeListener.setAlarms();
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public void startListener(AutomationService automationService)
|
public void startListener(AutomationService automationService)
|
||||||
{
|
{
|
||||||
@@ -362,46 +368,217 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
static int getNextDayIntForExecution(Trigger trigger)
|
||||||
public static Calendar getNextRepeatedExecutionAfter(Trigger trigger, Calendar now)
|
|
||||||
{
|
{
|
||||||
Calendar calSet;
|
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||||
TimeObject setTime;
|
Calendar now = Calendar.getInstance();
|
||||||
|
|
||||||
|
if(tf.getDayList().contains(now.get(Calendar.DAY_OF_WEEK)))
|
||||||
|
return now.get(Calendar.DAY_OF_WEEK);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int dayNumberOfNextExecution = now.get(Calendar.DAY_OF_WEEK);
|
||||||
|
|
||||||
|
while(!tf.getDayList().contains(dayNumberOfNextExecution))
|
||||||
|
{
|
||||||
|
dayNumberOfNextExecution++;
|
||||||
|
if(dayNumberOfNextExecution > 6)
|
||||||
|
dayNumberOfNextExecution = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dayNumberOfNextExecution;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getDayDelta(Calendar now, int dayNumberOfNextExecution)
|
||||||
|
{
|
||||||
|
int result = dayNumberOfNextExecution - now.get(Calendar.DAY_OF_WEEK);
|
||||||
|
|
||||||
|
if(result >= 0)
|
||||||
|
return result;
|
||||||
|
else
|
||||||
|
return 6 + result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
|
public static Calendar getNextRepeatedExecution(Trigger trigger)
|
||||||
|
{
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
Miscellaneous.logEvent("i", "DateTimeListener", "Checking for next repetition execution after " + Miscellaneous.formatDate(now.getTime()), 5);
|
||||||
|
Calendar calculationStart, calSchedule = null;
|
||||||
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||||
|
|
||||||
if(tf.getRepetition() > 0)
|
if(tf.getRepetition() > 0)
|
||||||
{
|
{
|
||||||
if(trigger.getTriggerParameter())
|
|
||||||
setTime = tf.getTriggerTimeStart();
|
|
||||||
else
|
|
||||||
setTime = tf.getTriggerTimeStop();
|
|
||||||
|
|
||||||
calSet = (Calendar) now.clone();
|
|
||||||
calSet.set(Calendar.HOUR_OF_DAY, setTime.getHours());
|
|
||||||
calSet.set(Calendar.MINUTE, setTime.getMinutes());
|
|
||||||
calSet.set(Calendar.SECOND, 0);
|
|
||||||
calSet.set(Calendar.MILLISECOND, 0);
|
|
||||||
|
|
||||||
// If the starting time is a day ahead remove 1 day.
|
|
||||||
if(calSet.getTimeInMillis() > now.getTimeInMillis())
|
|
||||||
calSet.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
|
|
||||||
long differenceInSeconds = Math.abs(now.getTimeInMillis() - calSet.getTimeInMillis()) / 1000;
|
|
||||||
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
|
||||||
long nextScheduleTimestamp = (calSet.getTimeInMillis() / 1000) + (nextExecutionMultiplier * tf.getRepetition());
|
|
||||||
Calendar calSchedule = Calendar.getInstance();
|
|
||||||
calSchedule.setTimeInMillis(nextScheduleTimestamp * 1000);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Das war mal aktiviert. Allerdings: Die ganze Funktion liefert zurück, wenn die Regel NOCH nicht
|
Are we inside of the timeframe or outside?
|
||||||
* zutrifft, aber wir z.B. gleich den zeitlichen Bereich betreten.
|
|
||||||
|
Inside -> is this demanded?
|
||||||
|
Yes:
|
||||||
|
If last execution known, calculate from it
|
||||||
|
If not known, calculate from start of timeframe
|
||||||
|
No:
|
||||||
|
Use end-time and add repetition
|
||||||
|
|
||||||
|
Outside? -> is this demanded?
|
||||||
|
Yes:
|
||||||
|
If last execution known, calculate from it
|
||||||
|
If not known, calculate from end of timeframe
|
||||||
|
No:
|
||||||
|
Use start-time and add repetition
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return calSchedule;
|
if(areWeInTimeFrame(trigger, new Date()))
|
||||||
|
{
|
||||||
|
if(trigger.getTriggerParameter())
|
||||||
|
{
|
||||||
|
if(trigger.getParentRule().getLastExecution() != null)
|
||||||
|
{
|
||||||
|
calculationStart = (Calendar) trigger.getParentRule().getLastExecution().clone();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calculationStart = (Calendar) now.clone();
|
||||||
|
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStart().getHours());
|
||||||
|
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStart().getMinutes());
|
||||||
|
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStart().getSeconds());
|
||||||
|
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||||
|
}
|
||||||
|
long differenceInSeconds = Math.abs(now.getTimeInMillis() - calculationStart.getTimeInMillis()) / 1000;
|
||||||
|
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||||
|
calSchedule = (Calendar) calculationStart.clone();
|
||||||
|
calSchedule.add(Calendar.SECOND, (int) (nextExecutionMultiplier * tf.getRepetition()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calculationStart = (Calendar) now.clone();
|
||||||
|
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStop().getHours());
|
||||||
|
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStop().getMinutes());
|
||||||
|
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStop().getSeconds());
|
||||||
|
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||||
|
calSchedule = (Calendar) calculationStart.clone();
|
||||||
|
calSchedule.add(Calendar.SECOND, (int) tf.getRepetition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // not in timeframe
|
||||||
|
{
|
||||||
|
if (!trigger.getTriggerParameter())
|
||||||
|
{
|
||||||
|
if (trigger.getParentRule().getLastExecution() != null)
|
||||||
|
{
|
||||||
|
calculationStart = (Calendar) trigger.getParentRule().getLastExecution().clone();
|
||||||
|
long differenceInSeconds = Math.abs(now.getTimeInMillis() - calculationStart.getTimeInMillis()) / 1000;
|
||||||
|
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||||
|
calSchedule = (Calendar) calculationStart.clone();
|
||||||
|
calSchedule.add(Calendar.SECOND, (int) (nextExecutionMultiplier * tf.getRepetition()));
|
||||||
|
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Chose " + Miscellaneous.formatDate(calSchedule.getTime()) + " as next repeated execution time.", 5);
|
||||||
|
return calSchedule;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calculationStart = (Calendar) now.clone();
|
||||||
|
if(tf.getDayList().contains(now.get(Calendar.DAY_OF_WEEK)))
|
||||||
|
{
|
||||||
|
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStop().getHours());
|
||||||
|
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStop().getMinutes());
|
||||||
|
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStop().getSeconds());
|
||||||
|
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||||
|
calculationStart.add(Calendar.SECOND, (int) tf.getRepetition());
|
||||||
|
|
||||||
|
int dayDelta = getDayDelta(now, getNextDayIntForExecution(trigger));
|
||||||
|
calculationStart.add(Calendar.DAY_OF_WEEK, dayDelta);
|
||||||
|
}
|
||||||
|
calSchedule = (Calendar) calculationStart.clone();
|
||||||
|
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Chose " + Miscellaneous.formatDate(calSchedule.getTime()) + " as next repeated execution time.", 5);
|
||||||
|
return calSchedule;
|
||||||
|
}
|
||||||
|
/*long differenceInSeconds = Math.abs(now.getTimeInMillis() - calculationStart.getTimeInMillis()) / 1000;
|
||||||
|
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||||
|
calSchedule = (Calendar) calculationStart.clone();
|
||||||
|
calSchedule.add(Calendar.SECOND, (int) (nextExecutionMultiplier * tf.getRepetition()));*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calculationStart = (Calendar) now.clone();
|
||||||
|
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStart().getHours());
|
||||||
|
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStart().getMinutes());
|
||||||
|
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStart().getSeconds());
|
||||||
|
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||||
|
calSchedule = (Calendar) calculationStart.clone();
|
||||||
|
calSchedule.add(Calendar.SECOND, (int) (tf.getRepetition()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Miscellaneous.compareTimes(calSchedule, now) > 0)
|
||||||
|
calSchedule.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int dayDelta = getDayDelta(now, getNextDayIntForExecution(trigger));
|
||||||
|
calSchedule.add(Calendar.DAY_OF_WEEK, dayDelta);
|
||||||
|
|
||||||
|
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Chose " + Miscellaneous.formatDate(calSchedule.getTime()) + " as next repeated execution time.", 5);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "DateTimeListener", "Trigger " + trigger.toString() + " is not executed repeatedly.", 5);
|
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Trigger " + trigger.toString() + " is not configured to repeat.", 5);
|
||||||
|
|
||||||
return null;
|
return calSchedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean areWeInTimeFrame(Trigger trigger, Object triggeringObject)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Use format known from Automation
|
||||||
|
* 07:30:00/17:30:00/23456/300 <-- last parameter is optional: repetition in seconds
|
||||||
|
* Also required: inside or outside that interval
|
||||||
|
*/
|
||||||
|
|
||||||
|
Date triggeringTime;
|
||||||
|
// if(triggeringObject instanceof Date)
|
||||||
|
// triggeringTime = (Date)triggeringObject;
|
||||||
|
// else
|
||||||
|
triggeringTime = new Date();
|
||||||
|
|
||||||
|
String timeString = String.valueOf(triggeringTime.getHours()) + ":" + String.valueOf(triggeringTime.getMinutes()) + ":" + String.valueOf(triggeringTime.getSeconds());
|
||||||
|
TimeObject nowTime = TimeObject.valueOf(timeString);
|
||||||
|
Calendar calNow = Calendar.getInstance();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||||
|
|
||||||
|
if(tf.getDayList().contains(calNow.get(Calendar.DAY_OF_WEEK)))
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
// Regular case, start time is lower than end time
|
||||||
|
(
|
||||||
|
Miscellaneous.compareTimes(tf.getTriggerTimeStart(), nowTime) >= 0
|
||||||
|
&&
|
||||||
|
Miscellaneous.compareTimes(nowTime, tf.getTriggerTimeStop()) > 0
|
||||||
|
)
|
||||||
|
||
|
||||||
|
// Other case, start time higher than end time, timeframe goes over midnight
|
||||||
|
(
|
||||||
|
Miscellaneous.compareTimes(tf.getTriggerTimeStart(), tf.getTriggerTimeStop()) < 0
|
||||||
|
&&
|
||||||
|
(Miscellaneous.compareTimes(tf.getTriggerTimeStart(), nowTime) >= 0
|
||||||
|
||
|
||||||
|
Miscellaneous.compareTimes(nowTime, tf.getTriggerTimeStop()) > 0)
|
||||||
|
)
|
||||||
|
||
|
||||||
|
// further case: start and end times are identical, meaning a 24h window
|
||||||
|
(
|
||||||
|
Miscellaneous.compareTimes(tf.getTriggerTimeStart(), tf.getTriggerTimeStop()) == 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", "Trigger", "There was an error while checking if the time based trigger applies: " + Log.getStackTraceString(e), 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,11 +34,11 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
|
|||||||
static int sensorValueCounter = 0;
|
static int sensorValueCounter = 0;
|
||||||
|
|
||||||
// Gravity rotational data
|
// Gravity rotational data
|
||||||
float gravity[];
|
float[] gravity;
|
||||||
// Magnetic rotational data
|
// Magnetic rotational data
|
||||||
float magnetic[]; //for magnetic rotational data
|
float[] magnetic; //for magnetic rotational data
|
||||||
float accels[] = new float[3];
|
float[] accels = new float[3];
|
||||||
float mags[] = new float[3];
|
float[] mags = new float[3];
|
||||||
float[] values = new float[3];
|
float[] values = new float[3];
|
||||||
boolean hasMagneticSensor=false;
|
boolean hasMagneticSensor=false;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
|||||||
private static boolean headsetConnected = false;
|
private static boolean headsetConnected = false;
|
||||||
private static int headphoneType = -1;
|
private static int headphoneType = -1;
|
||||||
|
|
||||||
protected static boolean headphoneJackListenerActive=false;
|
protected static boolean headphoneJackListenerActive = false;
|
||||||
protected static IntentFilter headphoneJackListenerIntentFilter = null;
|
protected static IntentFilter headphoneJackListenerIntentFilter = null;
|
||||||
protected static HeadphoneJackListener instance;
|
protected static HeadphoneJackListener instance;
|
||||||
|
|
||||||
@@ -53,12 +53,14 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/*Broadcast Action: Wired Headset plugged in or unplugged.
|
/*
|
||||||
The intent will have the following extra values:
|
Broadcast Action: Wired Headset plugged in or unplugged.
|
||||||
|
The intent will have the following extra values:
|
||||||
state - 0 for unplugged, 1 for plugged.
|
|
||||||
name - Headset type, human readable string
|
state - 0 for unplugged, 1 for plugged.
|
||||||
microphone - 1 if headset has a microphone, 0 otherwise*/
|
name - Headset type, human readable string
|
||||||
|
microphone - 1 if headset has a microphone, 0 otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
int state = intent.getExtras().getInt("state");
|
int state = intent.getExtras().getInt("state");
|
||||||
String name = intent.getExtras().getString("name");
|
String name = intent.getExtras().getString("name");
|
||||||
@@ -76,7 +78,6 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.headsetPlugged);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.headsetPlugged);
|
||||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByHeadphoneJack(isHeadsetConnected());
|
|
||||||
for(int i=0; i<ruleCandidates.size(); i++)
|
for(int i=0; i<ruleCandidates.size(); i++)
|
||||||
{
|
{
|
||||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||||
@@ -104,13 +105,12 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
|||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "HeadsetJackListener", "Starting HeadsetJackListener", 4);
|
Miscellaneous.logEvent("i", "HeadsetJackListener", "Starting HeadsetJackListener", 4);
|
||||||
headphoneJackListenerActive = true;
|
headphoneJackListenerActive = true;
|
||||||
// getInstance().startHeadphoneJackListener(AutomationService.getInstance(), headphoneJackListenerIntentFilter);
|
|
||||||
automationService.registerReceiver(this, headphoneJackListenerIntentFilter);
|
automationService.registerReceiver(this, headphoneJackListenerIntentFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("e", "ActivityDetectionReceiver", "Error starting HeadsetJackListener: " + Log.getStackTraceString(ex), 3);
|
Miscellaneous.logEvent("e", "HeadsetJackListener", "Error starting HeadsetJackListener: " + Log.getStackTraceString(ex), 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,6 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
|||||||
if(headphoneJackListenerActive)
|
if(headphoneJackListenerActive)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "HeadsetJackListener", "Stopping HeadsetJackListener", 4);
|
Miscellaneous.logEvent("i", "HeadsetJackListener", "Stopping HeadsetJackListener", 4);
|
||||||
// getInstance().stopHeadphoneJackListener(AutomationService.getInstance());
|
|
||||||
automationService.unregisterReceiver(this);
|
automationService.unregisterReceiver(this);
|
||||||
headphoneJackListenerActive = false;
|
headphoneJackListenerActive = false;
|
||||||
}
|
}
|
||||||
@@ -150,5 +149,4 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
|||||||
{
|
{
|
||||||
return new Trigger_Enum[] { Trigger_Enum.headsetPlugged };
|
return new Trigger_Enum[] { Trigger_Enum.headsetPlugged };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -8,10 +8,10 @@ import android.nfc.NdefMessage;
|
|||||||
import android.nfc.NdefRecord;
|
import android.nfc.NdefRecord;
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.nfc.Tag;
|
import android.nfc.Tag;
|
||||||
|
import android.nfc.tech.IsoDep;
|
||||||
import android.nfc.tech.Ndef;
|
import android.nfc.tech.Ndef;
|
||||||
import android.nfc.tech.NdefFormatable;
|
import android.nfc.tech.NdefFormatable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -36,18 +36,8 @@ public class NfcReceiver
|
|||||||
public static NfcAdapter getNfcAdapter(Context context)
|
public static NfcAdapter getNfcAdapter(Context context)
|
||||||
{
|
{
|
||||||
if(nfcAdapter == null)
|
if(nfcAdapter == null)
|
||||||
{
|
nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
||||||
if(Build.VERSION.SDK_INT <= 10)
|
|
||||||
{
|
|
||||||
// NFC not supported until after Gingerbread.
|
|
||||||
Miscellaneous.logEvent("w", "NFC", context.getResources().getString(R.string.nfcNotSupportedInThisAndroidVersionYet), 3);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nfcAdapter;
|
return nfcAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +56,9 @@ public class NfcReceiver
|
|||||||
if(action == null)
|
if(action == null)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "NFC", "action=null", 5);
|
Miscellaneous.logEvent("i", "NFC", "action=null", 5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(action.equals(NfcAdapter.ACTION_NDEF_DISCOVERED))
|
if(action.equals(NfcAdapter.ACTION_NDEF_DISCOVERED))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "NFC", "ACTION_NDEF_DISCOVERED", 4);
|
Miscellaneous.logEvent("i", "NFC", "ACTION_NDEF_DISCOVERED", 4);
|
||||||
@@ -91,28 +81,6 @@ public class NfcReceiver
|
|||||||
new NdefReaderTask().execute(tag);
|
new NdefReaderTask().execute(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action))
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// // In case we would still use the Tech Discovered Intent
|
|
||||||
// Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
|
|
||||||
// String[] techList = tag.getTechList();
|
|
||||||
// String searchedTech = Ndef.class.getName();
|
|
||||||
//
|
|
||||||
// for (String tech : techList)
|
|
||||||
// {
|
|
||||||
// if (searchedTech.equals(tech))
|
|
||||||
// {
|
|
||||||
// new NdefReaderTask().execute(tag);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// // No NFC NDEF intent
|
|
||||||
// Miscellaneous.logEvent("w", "NFC", context.getResources().getString(R.string.nfcNoNdefIntentBut) + " " + action + ".", 5);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@@ -307,7 +275,7 @@ public class NfcReceiver
|
|||||||
{
|
{
|
||||||
format.connect();
|
format.connect();
|
||||||
format.format(completeMessageToWrite);
|
format.format(completeMessageToWrite);
|
||||||
Miscellaneous.logEvent("i", "NFC", "Done writing tag.", 2);
|
Miscellaneous.logEvent("i", "NFC", "Done writing tag.", 2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
catch(IOException e)
|
||||||
@@ -322,7 +290,7 @@ public class NfcReceiver
|
|||||||
Miscellaneous.logEvent("e", "NFC", "Error writing tag: " + Log.getStackTraceString(e), 2);
|
Miscellaneous.logEvent("e", "NFC", "Error writing tag: " + Log.getStackTraceString(e), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkNfcRequirements(Context context, boolean showErrorMessage)
|
public static boolean checkNfcRequirements(Context context, boolean showErrorMessage)
|
||||||
@@ -334,15 +302,7 @@ public class NfcReceiver
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(Build.VERSION.SDK_INT <= 10)
|
|
||||||
{
|
|
||||||
// NFC not supported until after Gingerbread.
|
|
||||||
if(showErrorMessage)
|
|
||||||
Toast.makeText(context, context.getResources().getString(R.string.nfcNotSupportedInThisAndroidVersionYet), Toast.LENGTH_LONG).show();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,15 +3,13 @@ package com.jens.automation2.receivers;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.bluetooth.BluetoothDevice;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.jens.automation2.AutomationService;
|
import com.jens.automation2.AutomationService;
|
||||||
@@ -21,6 +19,7 @@ import com.jens.automation2.Trigger;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
// See here for reference: http://gmariotti.blogspot.com/2013/11/notificationlistenerservice-and-kitkat.html
|
// See here for reference: http://gmariotti.blogspot.com/2013/11/notificationlistenerservice-and-kitkat.html
|
||||||
|
|
||||||
@@ -28,8 +27,6 @@ import java.util.Calendar;
|
|||||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||||
public class NotificationListener extends NotificationListenerService// implements AutomationListenerInterface
|
public class NotificationListener extends NotificationListenerService// implements AutomationListenerInterface
|
||||||
{
|
{
|
||||||
static Calendar lastResponseToNotification = null;
|
|
||||||
static boolean listenerRunning = false;
|
|
||||||
static NotificationListener instance;
|
static NotificationListener instance;
|
||||||
static SimpleNotification lastNotification = null;
|
static SimpleNotification lastNotification = null;
|
||||||
|
|
||||||
@@ -45,13 +42,30 @@ public class NotificationListener extends NotificationListenerService// implemen
|
|||||||
// a bitmap to be used instead of the small icon when showing the notification payload
|
// a bitmap to be used instead of the small icon when showing the notification payload
|
||||||
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
|
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
|
||||||
|
|
||||||
protected static IntentFilter notificationReceiverIntentFilter = null;
|
public static void setLastNotification(SimpleNotification notification)
|
||||||
|
{
|
||||||
|
lastNotification = notification;
|
||||||
|
}
|
||||||
public static SimpleNotification getLastNotification()
|
public static SimpleNotification getLastNotification()
|
||||||
{
|
{
|
||||||
return lastNotification;
|
return lastNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To determine for which notifications which rules have been executed
|
||||||
|
static List<RuleNotificationPair> notificationUsed = new ArrayList<>();
|
||||||
|
|
||||||
|
public static class RuleNotificationPair
|
||||||
|
{
|
||||||
|
Rule rule;
|
||||||
|
SimpleNotification notification;
|
||||||
|
|
||||||
|
public RuleNotificationPair(Rule rule, SimpleNotification sn)
|
||||||
|
{
|
||||||
|
this.rule = rule;
|
||||||
|
this.notification = sn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
@@ -86,6 +100,7 @@ public class NotificationListener extends NotificationListenerService// implemen
|
|||||||
|
|
||||||
synchronized boolean checkNotification(boolean created, StatusBarNotification sbn)
|
synchronized boolean checkNotification(boolean created, StatusBarNotification sbn)
|
||||||
{
|
{
|
||||||
|
//TODO: Merge with function in Trigger class
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
||||||
{
|
{
|
||||||
lastNotification = convertNotificationToSimpleNotification(created, sbn);
|
lastNotification = convertNotificationToSimpleNotification(created, sbn);
|
||||||
@@ -131,13 +146,13 @@ public class NotificationListener extends NotificationListenerService// implemen
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (extras.containsKey(EXTRA_TEXT))
|
if (extras.containsKey(EXTRA_TEXT))
|
||||||
text = extras.getString(EXTRA_TEXT).toString();
|
text = String.valueOf(extras.getCharSequence(EXTRA_TEXT));
|
||||||
}
|
}
|
||||||
catch (NullPointerException e)
|
catch (NullPointerException e)
|
||||||
{
|
{
|
||||||
// in stacked notifications the "surrounding" element has no text, only a title
|
// in stacked notifications the "surrounding" element has no text, only a title
|
||||||
if (extras.containsKey(EXTRA_TEXT) && extras.get(EXTRA_TEXT) != null)
|
if (extras.containsKey(EXTRA_TEXT) && extras.get(EXTRA_TEXT) != null)
|
||||||
text = extras.get(EXTRA_TEXT).toString();
|
text = String.valueOf(extras.getCharSequence(EXTRA_TEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleNotification returnNotification = new SimpleNotification();
|
SimpleNotification returnNotification = new SimpleNotification();
|
||||||
@@ -217,6 +232,19 @@ public class NotificationListener extends NotificationListenerService// implemen
|
|||||||
", text='" + text + '\'' +
|
", text='" + text + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
this.publishTime.getTimeInMillis() == ((SimpleNotification)obj).publishTime.getTimeInMillis()
|
||||||
|
&&
|
||||||
|
this.app.equals(((SimpleNotification)obj).app)
|
||||||
|
&&
|
||||||
|
this.title.equals(((SimpleNotification)obj).title)
|
||||||
|
&&
|
||||||
|
this.text.equals(((SimpleNotification)obj).text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -237,7 +265,6 @@ public class NotificationListener extends NotificationListenerService// implemen
|
|||||||
cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
|
cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
|
||||||
else
|
else
|
||||||
cancelNotification(sbn.getKey());
|
cancelNotification(sbn.getKey());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||||
|
|||||||
@@ -6,10 +6,15 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.jens.automation2.ActivityPermissions;
|
import com.jens.automation2.ActivityPermissions;
|
||||||
import com.jens.automation2.AutomationService;
|
import com.jens.automation2.AutomationService;
|
||||||
import com.jens.automation2.Miscellaneous;
|
import com.jens.automation2.Miscellaneous;
|
||||||
@@ -22,6 +27,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class PhoneStatusListener implements AutomationListenerInterface
|
public class PhoneStatusListener implements AutomationListenerInterface
|
||||||
{
|
{
|
||||||
|
static int problematicAndroidLevel = 29;
|
||||||
protected static String lastPhoneNumber="";
|
protected static String lastPhoneNumber="";
|
||||||
protected static int lastPhoneDirection = -1; //0=incoming, 1=outgoing
|
protected static int lastPhoneDirection = -1; //0=incoming, 1=outgoing
|
||||||
protected static int currentState = -1;
|
protected static int currentState = -1;
|
||||||
@@ -70,7 +76,76 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
|||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IncomingCallsReceiver extends PhoneStateListener
|
public static interface IncomingCallsReceiver
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void workWithIncomingCallData(int state, String incomingNumber)
|
||||||
|
{
|
||||||
|
if(lastPhoneDirection == 2 && currentState != TelephonyManager.CALL_STATE_IDLE)
|
||||||
|
{
|
||||||
|
// This status update is actually for an outgoing call
|
||||||
|
setCurrentState(state);
|
||||||
|
|
||||||
|
if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
||||||
|
setLastPhoneNumber(incomingNumber);
|
||||||
|
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case TelephonyManager.CALL_STATE_IDLE:
|
||||||
|
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
||||||
|
break;
|
||||||
|
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||||
|
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
||||||
|
break;
|
||||||
|
case TelephonyManager.CALL_STATE_RINGING:
|
||||||
|
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), incomingNumber), 4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||||
|
for(int i=0; i<ruleCandidates.size(); i++)
|
||||||
|
{
|
||||||
|
AutomationService asInstance = AutomationService.getInstance();
|
||||||
|
if(asInstance != null)
|
||||||
|
if(ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||||
|
ruleCandidates.get(i).activate(asInstance, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setCurrentState(state);
|
||||||
|
setLastPhoneDirection(1);
|
||||||
|
|
||||||
|
if (incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
||||||
|
setLastPhoneNumber(incomingNumber);
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case TelephonyManager.CALL_STATE_IDLE:
|
||||||
|
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
||||||
|
break;
|
||||||
|
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||||
|
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
||||||
|
break;
|
||||||
|
case TelephonyManager.CALL_STATE_RINGING:
|
||||||
|
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||||
|
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||||
|
{
|
||||||
|
AutomationService asInstance = AutomationService.getInstance();
|
||||||
|
if (asInstance != null)
|
||||||
|
if (ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||||
|
ruleCandidates.get(i).activate(asInstance, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IncomingCallsReceiverOld extends PhoneStateListener implements IncomingCallsReceiver
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(int state, String incomingNumber)
|
public void onCallStateChanged(int state, String incomingNumber)
|
||||||
@@ -86,65 +161,42 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
|||||||
If the last call was outgoing the state has not changed to idle this is kind of a fake alert.
|
If the last call was outgoing the state has not changed to idle this is kind of a fake alert.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(lastPhoneDirection == 2 && currentState != TelephonyManager.CALL_STATE_IDLE)
|
workWithIncomingCallData(state, incomingNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.S)
|
||||||
|
public static class IncomingCallsReceiverNew extends BroadcastReceiver implements IncomingCallsReceiver
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
this code detects both incoming and outgoing,
|
||||||
|
if the state changes idle => ringing you know it's an incoming call,
|
||||||
|
if the state changes idle => offhook, you know it's an outgoing call
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL))
|
||||||
{
|
{
|
||||||
// This status update is actually for an outgoing call
|
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
|
||||||
setCurrentState(state);
|
int state = 99;
|
||||||
|
|
||||||
if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
switch(stateStr)
|
||||||
setLastPhoneNumber(incomingNumber);
|
|
||||||
|
|
||||||
switch(state)
|
|
||||||
{
|
{
|
||||||
case TelephonyManager.CALL_STATE_IDLE:
|
case "RINGING":
|
||||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
state = TelephonyManager.CALL_STATE_RINGING;
|
||||||
break;
|
break;
|
||||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
case "IDLE":
|
||||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
state = TelephonyManager.CALL_STATE_IDLE;
|
||||||
break;
|
break;
|
||||||
case TelephonyManager.CALL_STATE_RINGING:
|
case "OFFHOOK":
|
||||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), incomingNumber), 4);
|
state = TelephonyManager.CALL_STATE_OFFHOOK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||||
for(int i=0; i<ruleCandidates.size(); i++)
|
Log.i("test", "test");
|
||||||
{
|
|
||||||
AutomationService asInstance = AutomationService.getInstance();
|
|
||||||
if(asInstance != null)
|
|
||||||
if(ruleCandidates.get(i).getsGreenLight(asInstance))
|
|
||||||
ruleCandidates.get(i).activate(asInstance, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setCurrentState(state);
|
|
||||||
setLastPhoneDirection(1);
|
|
||||||
|
|
||||||
if (incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
|
||||||
setLastPhoneNumber(incomingNumber);
|
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case TelephonyManager.CALL_STATE_IDLE:
|
|
||||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
|
||||||
break;
|
|
||||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
|
||||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
|
||||||
break;
|
|
||||||
case TelephonyManager.CALL_STATE_RINGING:
|
|
||||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
|
||||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
|
||||||
{
|
|
||||||
AutomationService asInstance = AutomationService.getInstance();
|
|
||||||
if (asInstance != null)
|
|
||||||
if (ruleCandidates.get(i).getsGreenLight(asInstance))
|
|
||||||
ruleCandidates.get(i).activate(asInstance, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +253,12 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(incomingCallsReceiverInstance == null)
|
if(incomingCallsReceiverInstance == null)
|
||||||
incomingCallsReceiverInstance = new IncomingCallsReceiver();
|
{
|
||||||
|
// if(Build.VERSION.SDK_INT >= 31)
|
||||||
|
// incomingCallsReceiverInstance = new IncomingCallsReceiverNew();
|
||||||
|
// else
|
||||||
|
incomingCallsReceiverInstance = new IncomingCallsReceiverOld();
|
||||||
|
}
|
||||||
|
|
||||||
if(outgoingCallsReceiverInstance == null)
|
if(outgoingCallsReceiverInstance == null)
|
||||||
outgoingCallsReceiverInstance = new OutgoingCallsReceiver();
|
outgoingCallsReceiverInstance = new OutgoingCallsReceiver();
|
||||||
@@ -211,8 +268,17 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
|||||||
if(!incomingCallsReceiverActive)
|
if(!incomingCallsReceiverActive)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "PhoneStatusListener", "Starting PhoneStatusListener->incomingCallsReceiver", 4);
|
Miscellaneous.logEvent("i", "PhoneStatusListener", "Starting PhoneStatusListener->incomingCallsReceiver", 4);
|
||||||
TelephonyManager tm = (TelephonyManager)automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
// if(Build.VERSION.SDK_INT >= problematicAndroidLevel)
|
||||||
tm.listen(incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE);
|
// {
|
||||||
|
// IntentFilter callsFilter = new IntentFilter();
|
||||||
|
// callsFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
||||||
|
// automationService.registerReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance, callsFilter);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE);
|
||||||
|
// }
|
||||||
incomingCallsReceiverActive = true;
|
incomingCallsReceiverActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,8 +302,15 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
|||||||
if(incomingCallsReceiverActive)
|
if(incomingCallsReceiverActive)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "PhoneStatusListener", "Stopping phoneStatusListener", 4);
|
Miscellaneous.logEvent("i", "PhoneStatusListener", "Stopping phoneStatusListener", 4);
|
||||||
TelephonyManager tm = (TelephonyManager)automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
// if(Build.VERSION.SDK_INT >= 31)
|
||||||
tm.listen(incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE);
|
// {
|
||||||
|
// automationService.unregisterReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE);
|
||||||
|
// }
|
||||||
incomingCallsReceiverActive = false;
|
incomingCallsReceiverActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package com.jens.automation2.receivers;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
|
||||||
|
import com.jens.automation2.ActivityPermissions;
|
||||||
|
import com.jens.automation2.AutomationService;
|
||||||
|
import com.jens.automation2.Miscellaneous;
|
||||||
|
import com.jens.automation2.Rule;
|
||||||
|
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ProximityReceiver implements AutomationListenerInterface
|
||||||
|
{
|
||||||
|
public static AutomationService automationServiceRef = null;
|
||||||
|
static float proximityLevel = -1; // initialize with a better value than this
|
||||||
|
static boolean proximityReceiverActive = false;
|
||||||
|
|
||||||
|
SensorManager sensorManager;
|
||||||
|
Sensor proximitySensor;
|
||||||
|
|
||||||
|
static ProximityReceiver proximityReceiverInstance = null;
|
||||||
|
|
||||||
|
public static float getProximityLevel()
|
||||||
|
{
|
||||||
|
return proximityLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startProximityReceiver(final AutomationService automationServiceRef)
|
||||||
|
{
|
||||||
|
if(!proximityReceiverActive)
|
||||||
|
{
|
||||||
|
ProximityReceiver.automationServiceRef = automationServiceRef;
|
||||||
|
|
||||||
|
if(proximityReceiverInstance == null)
|
||||||
|
proximityReceiverInstance = new ProximityReceiver();
|
||||||
|
|
||||||
|
proximityReceiverInstance.startListener(automationServiceRef);
|
||||||
|
|
||||||
|
proximityReceiverActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void stopProximityReceiver()
|
||||||
|
{
|
||||||
|
if(proximityReceiverActive)
|
||||||
|
{
|
||||||
|
if(proximityReceiverInstance != null)
|
||||||
|
{
|
||||||
|
proximityReceiverInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
proximityReceiverActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startListener(AutomationService automationService)
|
||||||
|
{
|
||||||
|
if(!proximityReceiverActive)
|
||||||
|
{
|
||||||
|
ProximityReceiver.automationServiceRef = automationServiceRef;
|
||||||
|
|
||||||
|
sensorManager = (SensorManager) automationService.getSystemService(Context.SENSOR_SERVICE);
|
||||||
|
|
||||||
|
// from sensor service we are
|
||||||
|
// calling proximity sensor
|
||||||
|
proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||||
|
|
||||||
|
// handling the case if the proximity
|
||||||
|
// sensor is not present in users device.
|
||||||
|
if (proximitySensor == null)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("w", "No proximity sensor", "Device doesn\'t seem to have a proximity sensor.", 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// registering our sensor with sensor manager.
|
||||||
|
sensorManager.registerListener(proximitySensorEventListener, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
proximityReceiverActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopListener(AutomationService automationService)
|
||||||
|
{
|
||||||
|
if(proximityReceiverActive)
|
||||||
|
{
|
||||||
|
if(proximityReceiverInstance != null)
|
||||||
|
{
|
||||||
|
if(proximitySensor != null)
|
||||||
|
sensorManager.unregisterListener(proximitySensorEventListener);
|
||||||
|
|
||||||
|
proximityReceiverInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
proximityReceiverActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorEventListener proximitySensorEventListener = new SensorEventListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent sensorEvent)
|
||||||
|
{
|
||||||
|
// check if the sensor type is proximity sensor.
|
||||||
|
if (sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY)
|
||||||
|
{
|
||||||
|
proximityLevel = (int)sensorEvent.values[0];
|
||||||
|
|
||||||
|
Miscellaneous.logEvent("i", "Proximity", String.valueOf(proximityLevel), 5);
|
||||||
|
|
||||||
|
// if (sensorEvent.values[0] == 0)
|
||||||
|
// {
|
||||||
|
//// sensorStatusTV.setText("Near");
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
//// sensorStatusTV.setText("Away");
|
||||||
|
// }
|
||||||
|
|
||||||
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.proximity);
|
||||||
|
for(Rule oneRule : ruleCandidates)
|
||||||
|
{
|
||||||
|
if(oneRule.getsGreenLight(automationServiceRef))
|
||||||
|
oneRule.activate(automationServiceRef, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor sensor, int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean haveAllPermission()
|
||||||
|
{
|
||||||
|
return ActivityPermissions.havePermission(ActivityPermissions.permissionNameProximity, Miscellaneous.getAnyContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isListenerRunning()
|
||||||
|
{
|
||||||
|
return proximityReceiverActive;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Trigger_Enum[] getMonitoredTrigger()
|
||||||
|
{
|
||||||
|
// actually monitors several
|
||||||
|
return new Trigger_Enum[] { Trigger_Enum.proximity };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,12 +11,13 @@ import com.jens.automation2.Settings;
|
|||||||
|
|
||||||
public class StartupIntentReceiver extends BroadcastReceiver
|
public class StartupIntentReceiver extends BroadcastReceiver
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
Settings.readFromPersistentStorage(context);
|
Settings.readFromPersistentStorage(context);
|
||||||
|
|
||||||
|
Miscellaneous.startupContext = context;
|
||||||
|
|
||||||
// Miscellaneous.logEvent("i", "Boot event", "Received event: " + intent.getAction(), 5);
|
// Miscellaneous.logEvent("i", "Boot event", "Received event: " + intent.getAction(), 5);
|
||||||
|
|
||||||
if(Settings.startServiceAtSystemBoot)
|
if(Settings.startServiceAtSystemBoot)
|
||||||
|
|||||||
@@ -76,12 +76,12 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
|||||||
if(action.equals(Intent.ACTION_TIMEZONE_CHANGED))
|
if(action.equals(Intent.ACTION_TIMEZONE_CHANGED))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device timezone changed. Reloading alarms.", 3);
|
Miscellaneous.logEvent("i", "TimeZoneListener", "Device timezone changed. Reloading alarms.", 3);
|
||||||
DateTimeListener.reloadAlarms();
|
DateTimeListener.setOrResetAlarms();
|
||||||
}
|
}
|
||||||
else if(action.equals(Intent.ACTION_TIME_CHANGED))
|
else if(action.equals(Intent.ACTION_TIME_CHANGED))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device time changed. Reloading alarms.", 3);
|
Miscellaneous.logEvent("i", "TimeZoneListener", "Device time changed. Reloading alarms.", 3);
|
||||||
DateTimeListener.reloadAlarms();
|
DateTimeListener.setOrResetAlarms();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |