diff --git a/.gitignore b/.gitignore index 8422997f..9e44e854 100644 --- a/.gitignore +++ b/.gitignore @@ -19,23 +19,37 @@ local.properties .classpath .project -# Intellij files -.idea/ -*.iml +# Android Studio files out/ **.DS_Store target/ tmp/ coverage.ec +.idea/libraries +.idea/tasks.xml +.idea/vcs.xml +.idea/workspace.xml +.idea/gradle.xml + +# Gradle files +.gradle/ +.gradletasknamecache +build/ + +# Proguard folder generated by Eclipse +proguard/ -# calabash files +# Log Files +*.log -/test_servers/ -/*.png -*.html -cucumber.json -*.keystore -calabash_settings +###IntelliJ### + +*.iml +*.ipr +*.iws +.idea/ -# Crashlytics -res/values/com_crashlytics_export_strings.xml \ No newline at end of file +# Lint +lint-report.html +lint-report_files/ +lint_result.txt \ No newline at end of file diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index f9fe3459..00000000 --- a/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 60105c1b..00000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1..00000000 --- a/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..dec8e4f0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,54 @@ + +language: android +jdk: oraclejdk7 + +env: + global: + # switch glibc to a memory conserving mode + - MALLOC_ARENA_MAX=2 + # wait 5 minutes for adb to connect to emulator. Travis-ci cancels a + # stalled build after 10 minutes, so this should be shorter than that so + # there is time for the build to report the error. + - ADB_INSTALL_TIMEOUT=5 + +android: + components: + - tools + - platform-tools + - extra-android-m2repository + - build-tools-23.0.2 + - android-23 + licenses: + # only approve the Android software licenses, they match sources + # the Google licenses mean proprietary software with binary blobs + - 'android-sdk-preview-license-52d11cd2' + - 'android-sdk-license-.+' + + +licenses: + # only approve the Android software licenses, they match sources + # the Google licenses mean proprietary software with binary blobs + - 'android-sdk-preview-license-52d11cd2' + - 'android-sdk-license-.+' + +sudo: false +notifications: + email: false + +script: + # 'assemble' everything and run all checks that do not require a device/emulator + # first with the wrapper, then with the system gradle + - ./gradlew clean build + - gradle clean build + # start the emulator after the build to conserve memory + + #- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a + # - emulator -avd test -no-skin -no-audio -no-window & + #- android-wait-for-emulator + #- adb shell input keyevent 82 & + # now run the tests that require a device/emulator + #- gradle connectedCheck + + +after_failure: + - find * -name lint-results.xml | xargs cat diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..99926718 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,75 @@ +# **Change Log** + +All notable changes to this project will be documented in this file. +Unreleased + + +## **[v.1.4.1] - 2015-09-21** + +### **Added** + +- Added “Stop alert message” box in message screen once the setup is done.#69 + +### **Changed** + +- Handling the nested fragments for contact screen programatically. #81 +- Handling the nested fragments for message screen programatically. #98 + -Long press time is reduced from 5 seconds to 3 seconds in disguise screen.#90 + +### **Fixed** + +- On some devices, the contact selection screen was malfunctioning. #57 + +## **[v.1.4.0](https://github.com/PanicInitiative/PanicButton/releases/tag/v1.4.0) - 2015-04-21** + +### **Added** + +- Added “Stop alert message” box in message screen once the setup is done.#69 + +### **Changed** + +- The trigger mechanism has changed and now requires a confirmation press +- When the alert is manually deactivated (after entering your PIN) your contacts will receive a message which says "The alert has been stopped" +- The information text is clearer regarding what Panic Button does. When you trigger the alert, Panic Button will start sending a message with your location every 5 minutes. +- German translation generously contributed by https://github.com/emdete + +### **Fixed** + +- One some devices, the alert activates by itself in the middle of phone calls (it activates without triggering it with the power button or the calc app) #38 +- Shortcut was created by Google Play. #35 + +## **[v.1.4.0 -alpha] (https://github.com/PanicInitiative/PanicButton/releases/tag/1.4.0-alpha)- 2015-04-06** + +### **Changed** +- The trigger mechanism has changed and now requires a confirmation press. +- The information text is clearer regarding what Panic Button does. When you trigger the alert, Panic Button will start sending a message with your location every 5 minutes + +### **Fixed** +- On some devices, the alert activates by itself in the middle of phone calls (it activates without triggering it with the power button or the calc app). #38 +- Shortcut was created by Google Play #35 + + +## **[v.1.3.1-alpha] (https://github.com/PanicInitiative/PanicButton/releases/tag/v1.3.1)- 2014-08-06** + +### **Fixed** + +- On some devices, the alert activates by itself in the middle of phone calls (it activates without triggering it with the power button or the calc app). #38 +- Shortcut was created by Google Play #35 + + +## **[v.1.3.0] (https://github.com/PanicInitiative/PanicButton/releases/tag/v1.3.0)- 2014-06-23** + +### **Changed** + +- The first message is now the customised message, while subsequent ones only contain the location or a location pending message #41 +- Clicking Done on the keyboard when entering the PIN automatically validates it. #27 +- Link to map is now using https: #28 +- Removed Content API to reduce the attack surface. #40 +- The help pages now contain more information about the risk of contact and message exposure #33 + +### **Fixed** + +- Clicking on the Security Tips link in the checklist now links properly to the Help section. #30 +- Fixed bug where two SMS were sent when the alert was active & location was retrieved for the first time +- Fixed problem where pushing the back button from the checklist exited to the calculator disguise. + diff --git a/README.md b/README.md index 9ddcf9c5..71236b96 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - Master [![Build Status](https://ci.iilab.org/buildStatus/icon?job=panic-button)](https://ci.iilab.org/job/panic-button/) Dev [![Build Status](https://ci.iilab.org/buildStatus/icon?job=panic-button-dev)](https://ci.iilab.org/job/panic-button-dev/) [![Stories in Ready](https://badge.waffle.io/PanicInitiative/PanicButton.png?label=ready&title=Ready)](https://waffle.io/PanicInitiative/PanicButton) +Master [![Build Status](https://ci.iilab.org/buildStatus/icon?job=panic-button)](https://ci.iilab.org/job/panic-button/) Dev [![Build Status](https://travis-ci.org/PanicInitiative/PanicButton.svg?branch=dev)](https://travis-ci.org/PanicInitiative/PanicButton) [![Stories in Ready](https://badge.waffle.io/PanicInitiative/PanicButton.png?label=ready&title=Ready)](https://waffle.io/PanicInitiative/PanicButton) # Panic Button @@ -36,18 +36,22 @@ A huge thanks is also owed to the many programmers and designers who have donate ## Technology -### Requirements +### Security -You need an Android phone with a minimum version of 2.3.3 +Read [our security documentation](SECURITY.md) to understand our approach. -### Building +### Requirements -See the [notes to build your own APK](./docs/BUILD.md) +You need an Android phone with a minimum version of 2.3.3 ### Contributing See the [issues tagged with "Help Wanted"](https://github.com/iilab/PanicButton/labels/help%20wanted). -~~See the [notes to setup a development environment](./docs/DEVELOPMENT.md)~~ Outdated. Migration to Android Studio/Gradle in progress see #76. +Migration to Android Studio/Gradle has been completed on the ```dev``` branch which will be merged with ```master``` on the next public release. Code contributions should be sent via github from [feature](http://codeinthehole.com/writing/pull-requests-and-other-good-practices-for-teams-using-github/) [branches](https://guides.github.com/introduction/flow/) (named feature/__descriptive_name_of_feature__) as pull requests [as explained here](https://help.github.com/articles/using-pull-requests). + +### Translations + +We'e working on improving how translations are managed. Read more about this and let us know your ideas on the [dedicated github issue](https://github.com/iilab/PanicButton/issues/82)! diff --git a/docs/SECURITY.md b/SECURITY.md similarity index 100% rename from docs/SECURITY.md rename to SECURITY.md diff --git a/docs/TRANSLATION.md b/TRANSLATION.md similarity index 100% rename from docs/TRANSLATION.md rename to TRANSLATION.md diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 00000000..5fdd539f --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,54 @@ + +apply plugin: 'com.android.application' +apply plugin: 'io.fabric' +apply plugin: 'witness' + + android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "org.iilab.pb" + minSdkVersion 10 + targetSdkVersion 23 + } + lintOptions { + abortOnError false + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} + +dependencies { + compile 'com.google.code.gson:gson:2.3' + compile 'com.android.support:support-v4:23.1.+' + compile 'com.android.support:preference-v7:23.1.0' + testCompile "org.robolectric:robolectric:3.0" + testCompile "org.robolectric:shadows-support-v4:3.0" + testCompile 'junit:junit:4.12' + testCompile "org.mockito:mockito-core:1.9.5" + compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') { + transitive = true; + } +} + +// generate using: `gradle -q calculateChecksums | sort -V` +dependencyVerification { + verify = [ + 'com.google.code.gson:gson:9466512cd8cf0bd66a8a3661685373f7b3deafded11096e044926ff5c82c7a4c', + 'com.android.support:support-v4:5c7dceb6c824089fe80f502e5206264048ef8bffa4e8ddeab180b81723e79b7f', + 'com.android.support:preference-v7:f6d15f2bf404321f6e820eaf2086b67aaa849afdda5c9a69ec7a282b3d76fdb8', + 'com.crashlytics.sdk.android:crashlytics:5bbf76250f6349baf173e082b4f7d14e777aa5a7510f9bea267b445bc439247d', + 'com.android.support:support-annotations:f347a35b9748a4103b39a6714a77e2100f488d623fd6268e259c177b200e9d82', + 'com.android.support:appcompat-v7:b5783b390d1440769c9b8a7b42290523a4ff058ef2d3fb90c983973934ca115b', + 'com.android.support:recyclerview-v7:464ec6e5004400a4fe0310f35343da9e5a2912386a3606db3585f7cf987c444a', + 'com.crashlytics.sdk.android:answers:5af101ef6b58a26dd32cfc13f53c63c33fb2fdcdf6990241eca22e7a8c842847', + 'io.fabric.sdk.android:fabric:15465f60ee6a2bb53dcf84e8dd939ce92dffbffc73bfdd3432b63fa6ee2f7bae', + 'com.crashlytics.sdk.android:crashlytics-core:2f35df62420723d4a8e58f58a376fb640d11e1660656a9aa2959bb041b5b1d15', + 'com.crashlytics.sdk.android:beta:6d7dce749fd70fa20adcf089aaed5d52f9e8e2a08f6666336e90a7555cee9718', + ] +} diff --git a/app/fabric.properties b/app/fabric.properties new file mode 100644 index 00000000..57a924e3 --- /dev/null +++ b/app/fabric.properties @@ -0,0 +1,3 @@ +#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public. +#Mon Oct 05 12:28:54 EST 2015 +apiSecret=d724cfd2763e31304a850c7ef847c60de4f79ef942b15de09a8bed2e0085ce80 diff --git a/app/lint.xml b/app/lint.xml new file mode 100644 index 00000000..20dc2019 --- /dev/null +++ b/app/lint.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/AndroidManifest.xml b/app/src/main/AndroidManifest.xml similarity index 79% rename from AndroidManifest.xml rename to app/src/main/AndroidManifest.xml index 83182779..3c164803 100644 --- a/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,10 +1,9 @@ - - + + - @@ -13,12 +12,11 @@ - - - + @@ -42,11 +40,11 @@ - + - + @@ -71,6 +69,20 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/help_de.json b/app/src/main/assets/help_de.json similarity index 99% rename from assets/help_de.json rename to app/src/main/assets/help_de.json index 23618188..8e61a101 100644 --- a/assets/help_de.json +++ b/app/src/main/assets/help_de.json @@ -1,6 +1,6 @@ { "help": { - "version" : 7, + "version" : "7", "data":[ { "id" : "help", diff --git a/assets/help_en.json b/app/src/main/assets/help_en.json similarity index 99% rename from assets/help_en.json rename to app/src/main/assets/help_en.json index 87893cff..d055cbf2 100644 --- a/assets/help_en.json +++ b/app/src/main/assets/help_en.json @@ -1,6 +1,6 @@ { "help": { - "version" : 7, + "version" : "7", "data":[ { "id" : "help", diff --git a/assets/help_es.json b/app/src/main/assets/help_es.json similarity index 99% rename from assets/help_es.json rename to app/src/main/assets/help_es.json index f952641c..cc47a6ae 100644 --- a/assets/help_es.json +++ b/app/src/main/assets/help_es.json @@ -1,6 +1,6 @@ { "help": { - "version" : 7, + "version" : "7", "data":[ { "id" : "help", diff --git a/assets/help_fr.json b/app/src/main/assets/help_fr.json similarity index 99% rename from assets/help_fr.json rename to app/src/main/assets/help_fr.json index 49ff6886..43d32a28 100644 --- a/assets/help_fr.json +++ b/app/src/main/assets/help_fr.json @@ -1,6 +1,6 @@ { "help": { - "version" : 7, + "version" : "7", "data":[ { "id" : "help", diff --git a/assets/help_ph.json b/app/src/main/assets/help_ph.json similarity index 99% rename from assets/help_ph.json rename to app/src/main/assets/help_ph.json index dee60623..d37cebf9 100644 --- a/assets/help_ph.json +++ b/app/src/main/assets/help_ph.json @@ -1,6 +1,6 @@ { "help": { - "version" : 6, + "version" : "6", "data":[ { "id" : "help", diff --git a/assets/help_pt.json b/app/src/main/assets/help_pt.json similarity index 99% rename from assets/help_pt.json rename to app/src/main/assets/help_pt.json index 0445e596..0a59ed57 100644 --- a/assets/help_pt.json +++ b/app/src/main/assets/help_pt.json @@ -1,6 +1,6 @@ { "help": { - "version" : 6, + "version" : "6", "data":[ { "id" : "help", diff --git a/assets/media/Screenshot_2014-03-06-12-48-51.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-48-51.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-48-51.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-48-51.png diff --git a/assets/media/Screenshot_2014-03-06-12-49-06.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-49-06.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-49-06.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-49-06.png diff --git a/assets/media/Screenshot_2014-03-06-12-49-22.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-49-22.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-49-22.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-49-22.png diff --git a/assets/media/Screenshot_2014-03-06-12-49-53.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-49-53.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-49-53.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-49-53.png diff --git a/assets/media/Screenshot_2014-03-06-12-50-12.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-50-12.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-50-12.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-50-12.png diff --git a/assets/media/Screenshot_2014-03-06-12-50-45.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-50-45.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-50-45.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-50-45.png diff --git a/assets/media/Screenshot_2014-03-06-12-52-19.png b/app/src/main/assets/media/Screenshot_2014-03-06-12-52-19.png similarity index 100% rename from assets/media/Screenshot_2014-03-06-12-52-19.png rename to app/src/main/assets/media/Screenshot_2014-03-06-12-52-19.png diff --git a/assets/media/article-img-2.png b/app/src/main/assets/media/article-img-2.png similarity index 100% rename from assets/media/article-img-2.png rename to app/src/main/assets/media/article-img-2.png diff --git a/assets/media/mobile/home-not-configured-small.png b/app/src/main/assets/media/mobile/home-not-configured-small.png similarity index 100% rename from assets/media/mobile/home-not-configured-small.png rename to app/src/main/assets/media/mobile/home-not-configured-small.png diff --git a/assets/media/mobile/panic_button_activation.png b/app/src/main/assets/media/mobile/panic_button_activation.png similarity index 100% rename from assets/media/mobile/panic_button_activation.png rename to app/src/main/assets/media/mobile/panic_button_activation.png diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360.gif b/app/src/main/assets/media/mobile/panic_button_activation_360.gif new file mode 100644 index 00000000..f681a214 Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360_de.gif b/app/src/main/assets/media/mobile/panic_button_activation_360_de.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360_de.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360_en.gif b/app/src/main/assets/media/mobile/panic_button_activation_360_en.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360_en.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360_es.gif b/app/src/main/assets/media/mobile/panic_button_activation_360_es.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360_es.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360_fr.gif b/app/src/main/assets/media/mobile/panic_button_activation_360_fr.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360_fr.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360_ph.gif b/app/src/main/assets/media/mobile/panic_button_activation_360_ph.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360_ph.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_360_pt.gif b/app/src/main/assets/media/mobile/panic_button_activation_360_pt.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_360_pt.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_de.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_de.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_de.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_en.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_en.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_en.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_es.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_es.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_es.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_fr.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_fr.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_fr.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_ph.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_ph.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_ph.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_pt.gif b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_pt.gif new file mode 100644 index 00000000..6f8dfade Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_5press_confirm_pt.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_7press.gif b/app/src/main/assets/media/mobile/panic_button_activation_7press.gif new file mode 100644 index 00000000..f681a214 Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_7press.gif differ diff --git a/app/src/main/assets/media/mobile/panic_button_activation_custom.gif b/app/src/main/assets/media/mobile/panic_button_activation_custom.gif new file mode 100644 index 00000000..7be3a4e8 Binary files /dev/null and b/app/src/main/assets/media/mobile/panic_button_activation_custom.gif differ diff --git a/assets/mobile_de.json b/app/src/main/assets/mobile_de.json similarity index 96% rename from assets/mobile_de.json rename to app/src/main/assets/mobile_de.json index 536d48d7..aba825f4 100644 --- a/assets/mobile_de.json +++ b/app/src/main/assets/mobile_de.json @@ -1,6 +1,6 @@ { "mobile": { - "version": 8, + "version": "8", "data": [ { "id": "setup-warning", @@ -233,7 +233,8 @@ "action": [ { "title": "Weiter", - "link": "setup-alarm-disguise" +// "link": "setup-alarm-disguise" + "link": "home-not-configured-disguise" } ], "content": "

Dein Test was erfolgreich! In einem echten Notfall würde der Alarm nun zu deinen Kontakten gesendet.

" @@ -269,7 +270,7 @@ "fail": { "link": "setup-alarm-test-hardware-fail" }, - "content": "

\"\"

" + "content": "

\"\"

" }, { "id": "setup-alarm-test-disguise-success", @@ -557,20 +558,6 @@ "link": "setup-disguise" } ], - "items": [ - { - "title": "Über diese App", - "link": "setup-about" - }, - { - "title": "Hilfe", - "link": "help" - }, - { - "title": "Sprach-Einstellung", - "link": "setup-language" - } - ], "content": "

Panik Knopf kann nicht benutzt werden, wenn die Einstellungen nicht vollständig sind.

" }, { @@ -601,20 +588,6 @@ "status": "disabled" } ], - "items": [ - { - "title": "Über", - "link": "setup-about" - }, - { - "title": "Hilfe", - "link": "help" - }, - { - "title": "Sprach-Einstellung", - "link": "setup-language" - } - ], "content": "

Panik Knopf kann nicht benutzt werden, wenn die Einstellungen nicht vollständig sind.

" }, { @@ -628,16 +601,16 @@ "link": "setup-warning" } ], - "items": [ - { - "title": "Über", - "link": "setup-about" - }, - { - "title": "Sprach-Einstellung", - "link": "setup-language" - } - ], + "items": [ + { + "title": "Über", + "link": "setup-about" + }, + { + "title": "Sprach-Einstellung", + "link": "setup-language" + } + ], "content": "

\"Illustration\" Panik Knopf ist eine Android App, die einen stillen Alarm ein deine Kontakte sendet, wenn du in Schwierigkeiten bist. Die App bleibt auf deinem Handy verborgen und sieht wir ein einfacher Rechner aus.

" }, { diff --git a/assets/mobile_en.json b/app/src/main/assets/mobile_en.json similarity index 67% rename from assets/mobile_en.json rename to app/src/main/assets/mobile_en.json index 7bdcd7ca..3384501a 100644 --- a/assets/mobile_en.json +++ b/app/src/main/assets/mobile_en.json @@ -1,6 +1,6 @@ { "mobile": { - "version": 9, + "version": "10", "data": [ { "id": "setup-warning", @@ -13,7 +13,7 @@ "link": "setup-contacts" } ], - "content": "

Panic Button is a useful tool to alert your network quickly when you need help. It can't guarantee your security! Make a plan with your contacts so they are prepared to act fast.

" + "content": "

Panic Button is a useful tool to alert your network quickly when you need help. It can't guarantee your security! Make a plan with your contacts so they are prepared to act fast in an emergency”.

" }, { "id": "setup-message", @@ -29,7 +29,7 @@ "link": "setup-code" } ], - "content": "

Security tips

  • Consider creating code words or phrases in your message that only your contacts will understand.
  • You won't have time to change a message in an emergency, so create something that will work in all scenarios.
  • Enable GPS tracking from your phone settings if you want your location to be included with the message.
" + "content": "

Security tips

  • Enable GPS tracking from your phone settings if you want your location to be included with the message.
  • Consider creating code words or phrases in your message that only your contacts will understand.
  • You won't have time to change a message in an emergency, so create something that will work in all scenarios.
" }, { "id": "setup-language", @@ -70,7 +70,7 @@ "id": "setup-disguise-test-unlock-fail", "lang": "en", "type": "simple", - "title": "Setup Disguise", + "title": "Set up disguise", "action": [ { "title": "Try Again", @@ -83,7 +83,7 @@ "id": "setup-disguise-test-unlock", "lang": "en", "type": "interactive", - "title": "Test Disguise", + "title": "Test disguise", "introduction": "Try now! Hold down any button on the calculator.", "component": "disguise-test-unlock", "timers": { @@ -102,20 +102,20 @@ "id": "setup-disguise-test-success", "lang": "en", "type": "simple", - "title": "Well done", + "title": "Well done!", "action": [ { "title": "Finish", "link": "home-ready" } ], - "content": "

Congratulations you have now successfully configured the Panic Button app!

" + "content": "

Congratulations, you have now successfully configured the Panic Button app!

" }, { "id": "setup-disguise-test-open-fail", "lang": "en", "type": "simple", - "title": "Setup the Disguise", + "title": "Set up disguise", "action": [ { "title": "Try Again", @@ -128,7 +128,7 @@ "id": "setup-disguise-test-open", "lang": "en", "type": "interactive", - "title": "Test Disguise", + "title": "Test disguise", "introduction": "Try now! Open the app by clicking on the Calculate! icon.", "component": "disguise-test-open", "timers": { @@ -147,7 +147,7 @@ "id": "setup-disguise-test-code-fail", "lang": "en", "type": "simple", - "title": "Setup the Disguise", + "title": "Set up disguise", "action": [ { "title": "Try Again", @@ -160,7 +160,7 @@ "id": "setup-disguise-test-code", "lang": "en", "type": "interactive", - "title": "Test Disguise", + "title": "Test disguise", "introduction": "Well done! Now enter your pincode to access settings.", "component": "disguise-test-code", "timers": { @@ -170,7 +170,7 @@ }, "action": [ { - "title": "Ok", + "title": "OK", "link": "setup-disguise-test-success" } ], @@ -185,7 +185,7 @@ "id": "setup-disguise", "lang": "en", "type": "simple", - "title": "Setup Disguise", + "title": "Set up disguise", "action": [ { "title": "Learn", @@ -198,7 +198,7 @@ "id": "setup-contacts", "lang": "en", "type": "interactive", - "title": "Setup contacts", + "title": "Set up contacts", "introduction": "These people will receive the alert every 5 minutes if you activate it.", "warning": "They should know you personally and be able to respond fast.", "component": "contacts", @@ -208,7 +208,7 @@ "link": "setup-message" } ], - "content": "

Security Tips

  • Think about who can practically assist you - there is no point someone knowing you are in trouble if they cannot help.
  • Make a plan with your chosen contacts so that they are prepared to act fast.
  • Be aware of the risks - how might your contact be put at risk?
" + "content": "

Security Tips

  • Think about who can practically assist you - there is no point someone knowing you are in trouble if they cannot help.
  • Make a plan with your chosen contacts so that they are prepared to act fast in an emergency.
  • Be aware of the risks - how might your contact be put at risk?
" }, { "id": "setup-code", @@ -233,16 +233,17 @@ "action": [ { "title": "Next", - "link": "setup-alarm-disguise" +// "link": "setup-alarm-disguise" + "link": "home-not-configured-disguise" } ], - "content": "

Your test was successful! In an actual emergency, your alert will have started to be automatically sent every 5 minutes.

" + "content": "

Your test was successful! In an emergency, you would have activated the alarm and an alert would now be sent out automatically every 5 minutes.

" }, { "id": "setup-alarm-test-hardware-fail", "lang": "en", "type": "simple", - "title": "Setup the Alarm", + "title": "Set up alarm", "action": [ { "title": "Try Again", @@ -255,8 +256,8 @@ "id": "setup-alarm-test-hardware", "lang": "en", "type": "interactive", - "title": "Test Hardware Alarm", - "introduction": "Try Now! Repeatedly press the power button until you feel a vibration. Once the vibration ends, press the power button one more time as a confirmation to trigger alerts.", + "title": "Test hardware alarm", + "introduction": "Try Now! Repeatedly press the power button until you feel a vibration. Using the power button to activate the alarm may lock your screen. Just unlock your screen to continue setting up the app.", "component": "alarm-test-hardware", "timers": { "info": "0", @@ -269,7 +270,7 @@ "fail": { "link": "setup-alarm-test-hardware-fail" }, - "content": "

\"\"

" + "content": "

\"\"

" }, { "id": "setup-alarm-test-disguise-success", @@ -282,26 +283,26 @@ "link": "home-not-configured-disguise" } ], - "content": "

Your test was successful! In an actual emergency, your alert will have started to be automatically sent every 5 minutes.

" + "content": "

Your test was successful! In an emergency, you would have activated the alarm and an alert would now be sent out automatically every 5 minutes.

" }, { "id": "setup-alarm-test-disguise-fail", "lang": "en", "type": "simple", - "title": "Setup Alert", + "title": "Set up alarm", "action": [ { "title": "Try Again", "link": "setup-alarm-test-disguise" } ], - "content": "

It looks like you didn't succeed in triggering the alert.

Remember: repeatedly press a button on the calculator until you feel a vibration.

" + "content": "

It looks like you didn't succeed in triggering the alarm.

Remember: repeatedly press a button on the calculator until you feel a vibration.

" }, { "id": "setup-alarm-test-disguise", "lang": "en", "type": "interactive", - "title": "Test Disguised Alarm", + "title": "Test disguise alarm", "introduction": "Try Now! Repeatedly press a button on the calculator until you feel a vibration.", "component": "alarm-test-disguise", "timers": { @@ -320,34 +321,34 @@ "id": "setup-alarm-disguise", "lang": "en", "type": "simple", - "title": "Setup Alert", + "title": "Set up alarm", "action": [ { "title": "Learn", "link": "setup-alarm-test-disguise" } ], - "content": "

Alternatively, you can trigger the alert directly from the app's disguise screen.

" + "content": "

Alternatively, you can trigger the alarm directly from the app's disguise screen.

" }, { "id": "setup-alarm", "lang": "en", "type": "simple", - "title": "Setup Alert", + "title": "Set up alarm", "action": [ { "title": "Learn", "link": "setup-alarm-test-hardware" } ], - "content": "

Now learn how to trigger the Panic Button in an emergency.

Panic Button is unique because you can trigger the alert from the phone's power button. This means you can do it secretly - for example, from inside a jacket pocket.

" + "content": "

Now learn how to trigger the Panic Button in an emergency.

Panic Button is unique because you can trigger the alarm from the phone's power button. This means you can do it secretly - for example, from inside a jacket pocket.

" }, { "id": "setup-about", "lang": "en", "type": "simple", "title": "About", - "content": "

Panic Button turns your mobile phone into a secret alarm for when you're in trouble.

How Does Panic Button Work?

  • TAKE TIME to set-up Panic Button somewhere safe and quiet
  • Create a plan with your contacts so that they are PREPARED to ACT
  • CHECK you are ready and that your mobile phone has credit and battery
  • ACTIVATE Panic Button in an emergency by rapidly pressing the phone's power button
  • Your network will receive an SMS and regular updates of your location helping them to ACT FAST

The Panic Button project is an initiative of Amnesty International in collaboration with key advisors and partners including Frontline Defenders, iilab and the engine room.

" + "content": "

Panic Button turns your mobile phone into a secret alarm for when you're in trouble.

How Does Panic Button Work?

  • TAKE TIME to set-up Panic Button somewhere safe and quiet
  • Create a plan with your contacts so that they are PREPARED to ACT
  • CHECK you are ready and that your mobile phone has credit and battery
  • ACTIVATE Panic Button in an emergency by rapidly pressing the phone's power button
  • Your network will receive an SMS and regular updates of your location helping them to ACT FAST in an emergency”

The Panic Button project is an initiative of Amnesty International in collaboration with key advisors and partners including Frontline Defenders, iilab and the engine room.

" }, { "id": "settings-reset-confirm", @@ -360,13 +361,13 @@ "link": "home-not-configured" } ], - "content": "

Please confirm that you would like to restart the installation. If you restart the installation, the alert will be deactivated until you complete the wizard

" + "content": "

Please confirm that you would like to restart the installation. If you restart the installation, the alarm will be deactivated until you complete the wizard

" }, { "id": "settings-message", "lang": "en", "type": "interactive", - "title": "Setup alert message", + "title": "Set up alarm message", "introduction": "This is the message that will be sent with your location.", "warning": "Create a plan so your contacts know what to do when they receive this", "component": "message", @@ -377,7 +378,7 @@ "confirmation": "Message saved" } ], - "content": "

Security tips

  • Consider creating code words or phrases in your message that only your contacts will understand.
  • You won't have time to change a message in an emergency, so create something that will work in all situations.
  • Enable GPS tracking from your phone settings if you want your location to be included with the message
" + "content": "

Security tips

  • Enable GPS tracking from your phone settings if you want your location to be included with the message
  • Consider creating code words or phrases in your message that only your contacts will understand.
  • You won't have time to change a message in an emergency, so create something that will work in all situations.
" }, { "id": "settings-language", @@ -418,8 +419,8 @@ "id": "settings-contacts", "lang": "en", "type": "interactive", - "title": "Setup contacts", - "introduction": "These people will receive the alert every 5 minutes if you activate it.", + "title": "Set up contacts", + "introduction": "These people will receive the alarm every 5 minutes if you activate it.", "warning": "They should know you personally and be able to respond fast.", "component": "contacts", "action": [ @@ -429,14 +430,14 @@ "confirmation": "Contacts saved" } ], - "content": "

Security Tips

  • Think about who can practically assist you - there is no point someone knowing you are in trouble if they are not in a position to help you
  • Make a plan with your chosen contacts so that they are prepared to act fast.
  • Be aware of the risks - how might your chosen contact be put at risk?
" + "content": "

Security Tips

  • Think about who can practically assist you - there is no point someone knowing you are in trouble if they are not in a position to help you
  • Make a plan with your chosen contacts so that they are prepared to act fast in an emergency”.
  • Be aware of the risks - how might your chosen contact be put at risk?
" }, { "id": "settings-code", "lang": "en", "type": "interactive", "title": "Create a pincode", - "introduction": "This pincode is needed to stop the app from sending the alert automatically and to access the app settings. It is not needed to alert contacts in an emergency.", + "introduction": "This pincode is needed to stop the app from sending the alarm automatically and to access the app settings. It is not needed to trigger alarm messages in an emergency.", "warning": "Remember your pincode! If you forget it you will need to reinstall the app.", "component": "code", "action": [ @@ -447,6 +448,22 @@ } ] }, + { + "id": "settings-advanced", + "lang": "en", + "type": "interactive", + "title": "Advanced settings", + "introduction": "Advanced settings", + "warning": "Be careful about your battery! Sending alerts too often might drain your battery.", + "component": "advanced", + "action": [ + { + "title": "Save", + "link": "home-ready", + "confirmation": "New settings saved" + } + ] + }, { "id": "settings-alert", "lang": "en", @@ -486,9 +503,13 @@ "link": "settings-alert" }, { - "title": "Code Settings", + "title": "Pin Settings", "link": "settings-code" }, + { + "title": "Advanced Settings", + "link": "settings-advanced" + }, { "title": "Restart the Installation", "link": "settings-reset-confirm" @@ -557,20 +578,6 @@ "link": "setup-disguise" } ], - "items": [ - { - "title": "About", - "link": "setup-about" - }, - { - "title": "Help", - "link": "help" - }, - { - "title": "Language Settings", - "link": "setup-language" - } - ], "content": "

You cannot use Panic Button until it is fully setup.

" }, { @@ -601,20 +608,6 @@ "status": "disabled" } ], - "items": [ - { - "title": "About", - "link": "setup-about" - }, - { - "title": "Help", - "link": "help" - }, - { - "title": "Language Settings", - "link": "setup-language" - } - ], "content": "

You cannot use Panic Button until it is fully setup.

" }, { @@ -638,7 +631,7 @@ "link": "setup-language" } ], - "content": "

\"Illustration\" Panic Button is an Android app that secretly alerts your contacts when you are in trouble. When triggered, it will sends alerts every 5 minutes with your location. The app stays hidden on your phone by looking like a simple calculator.

" + "content": "

\"Illustration\" Panic Button is an Android app that secretly alerts your contacts when you are in trouble. When triggered, it will send alerts every 5 minutes with your location. The app stays hidden on your phone by looking like a simple calculator.

" }, { "id": "home-alerting", @@ -654,11 +647,11 @@ ], "action": [ { - "title": "Stop Alerting", + "title": "Stop Alarm", "link": "home-ready" } ], - "content": "

Panic Button is currently sending alert messages. Click Stop Alerting to cancel messages.

" + "content": "

Panic Button is currently sending alert messages. Click Stop Alarm to cancel messages.

" }, { "id": "code", @@ -695,7 +688,7 @@ "title": "Review security plan and update contacts regularly" }, { - "title": "Test the alert to ensure it is working" + "title": "Test the alarm to ensure it is working" }, { "title": "Ensure sufficient credit on the phone" @@ -708,6 +701,198 @@ } ], "content": "

More security tips...

" + }, + { + "id": "setup-alarm-reTraining", + "lang": "en", + "type": "simple", + "title": "Set up alarm", + "action": [ + { + "title": "Learn", + "link": "setup-alarm-test-hardware-reTraining" + } + ], + "content": "

Test and learn how to trigger the Panic Button in an emergency.

Panic Button is unique because you can trigger the alert from the phone's power button. This means you can do it secretly - for example, from inside a jacket pocket.

" + }, + { + "id": "setup-alarm-test-hardware-reTraining", + "lang": "en", + "type": "interactive", + "title": "Test Hardware Alarm", + "introduction": "Try Now! Repeatedly press the power button until you feel a vibration. Using the power button to activate the alarm may lock your screen. Just unlock your screen to continue setting up the app.", + "component": "alarm-test-hardware", + "timers": { + "info": "0", + "inactive": "10", + "fail": "20" + }, + "success": { + "link": "setup-alarm-test-hardware-success-reTraining" + }, + "fail": { + "link": "setup-alarm-test-hardware-fail-reTraining" + }, + "content": "

\"\"

" + }, + { + "id": "setup-alarm-test-hardware-success-reTraining", + "lang": "en", + "type": "simple", + "title": "Well done!", + "action": [ + { + "title": "Next", +// "link": "setup-alarm-disguise-reTraining" + "link": "setup-alarm-test-disguise-success-reTraining" + } + ], + "content": "

Your test was successful! In an emergency, you would have activated the alarm and an alert would now be sent out automatically every 5 minutes.

" + },{ + "id": "setup-alarm-test-hardware-fail-reTraining", + "lang": "en", + "type": "simple", + "title": "Set up alarm", + "action": [ + { + "title": "Try Again", + "link": "setup-alarm-test-hardware-reTraining" + } + ], + "content": "

It looks like you didn't succeed in triggering the alert using the phone's power button.

Remember: repeatedly press a button on the calculator until you feel a vibration. On some phones, you might need to press the button more than 10 times, and then 2 more times to confirm.

" + }, + { + "id": "setup-alarm-disguise-reTraining", + "lang": "en", + "type": "simple", + "title": "Set up alarm", + "action": [ + { + "title": "Learn", + "link": "setup-alarm-test-disguise-reTraining" + } + ], + "content": "

Alternatively, you can trigger the alert directly from the app's disguise screen.

" + },{ + "id": "setup-alarm-test-disguise-reTraining", + "lang": "en", + "type": "interactive", + "title": "Test disguise alarm", + "introduction": "Try Now! Repeatedly press a button on the calculator until you feel a vibration.", + "component": "alarm-test-disguise", + "timers": { + "info": "0", + "inactive": "10", + "fail": "20" + }, + "success": { + "link": "setup-alarm-test-disguise-success-reTraining" + }, + "fail": { + "link": "setup-alarm-test-disguise-fail-reTraining" + } + }, + { + "id": "setup-alarm-test-disguise-fail-reTraining", + "lang": "en", + "type": "simple", + "title": "Set up alarm", + "action": [ + { + "title": "Try Again", + "link": "setup-alarm-test-disguise-reTraining" + } + ], + "content": "

It looks like you didn't succeed in triggering the alert.

Remember: repeatedly press a button on the calculator until you feel a vibration.

" + }, + { + "id": "setup-alarm-test-disguise-success-reTraining", + "lang": "en", + "type": "simple", + "title": "Well done!", + "action": [ + { + "title": "Finish", + "link": "close-training" + } + ], + "content": "

Congratulations, the new vibration patterns are tested !

" + }, + { + "id": "setup-training_1.5", + "lang": "en", + "type": "simple", + "title": "Set up alarm", + "action": [ + { + "title": "Learn", + "link": "setup-alarm-test-hardware-training_1_5" + }, + { + "title": "Skip", + "link": "skip-training_1_5" + } + ], + "content": "

Panic Button has been updated and now uses a new default trigger mechanism.

Even better, you can now choose your own trigger mechanism to help prevent false triggers. Let's get started and get you up to speed with these new features.

" + },{ + "id": "skip-training_1_5", + "lang": "en", + "type": "warning", + "title": "Warning", + "action": [ + { + "title": "Yes", + "link": "home-ready" + }, + { + "title": "Cancel", + "link": "setup-alarm-test-hardware-training_1_5" + } + ], + "content": "

The panic button activation trigger has changed and we recommend you to test these changes until you are familiar with them. Are you sure you want to skip this training?.

" + },{ + "id": "setup-alarm-test-hardware-training_1_5", + "lang": "en", + "type": "interactive", + "title": "Test hardware alarm", + "introduction": "Try Now! Repeatedly press the power button until you feel a vibration. Using the power button to activate the alarm may lock your screen. Just unlock your screen to continue setting up the app.", + "component": "alarm-test-hardware", + "timers": { + "info": "0", + "inactive": "10", + "fail": "20" + }, + "success": { + "link": "setup-alarm-test-hardware-success-training_1_5" + }, + "fail": { + "link": "setup-alarm-test-hardware-fail-training_1_5" + }, + "content": "

\"\"

" + }, + { + "id": "setup-alarm-test-hardware-fail-training_1_5", + "lang": "en", + "type": "simple", + "title": "Set up alarm", + "action": [ + { + "title": "Try Again", + "link": "setup-alarm-test-hardware-training_1_5" + } + ], + "content": "

It looks like you didn't succeed in triggering the alert using the phone's power button.

Remember: repeatedly press a button on the calculator until you feel a vibration. On some phones, you might need to press the button more than 10 times, and then 2 more times to confirm.

" + },{ + "id": "setup-alarm-test-hardware-success-training_1_5", + "lang": "en", + "type": "simple", + "title": "Well done!", + "action": [ + { + "title": "Finish", + "link": "home-ready" + }], + "content": "

Your test was successful! In an emergency, you would have activated the alarm and an alert would now be sent out automatically every 5 minutes.

" } ] } diff --git a/assets/mobile_es.json b/app/src/main/assets/mobile_es.json similarity index 95% rename from assets/mobile_es.json rename to app/src/main/assets/mobile_es.json index 1e67824a..7a37381c 100644 --- a/assets/mobile_es.json +++ b/app/src/main/assets/mobile_es.json @@ -1,6 +1,6 @@ { "mobile": { - "version": 8, + "version": "8", "data": [ { "id": "setup-warning", @@ -233,7 +233,8 @@ "action": [ { "title": "Siguiente", - "link": "setup-alarm-disguise" +// "link": "setup-alarm-disguise" + "link": "home-not-configured-disguise" } ], "content": "

¡Tu prueba fue exitosa! En una emergencia real, tu alerta se enviará

" @@ -269,7 +270,7 @@ "fail": { "link": "setup-alarm-test-hardware-fail" }, - "content": "

\"\"

" + "content": "

\"\"

" }, { "id": "setup-alarm-test-disguise-success", @@ -556,20 +557,6 @@ "link": "setup-disguise" } ], - "items": [ - { - "title": "Acerca de ", - "link": "setup-about" - }, - { - "title": "Ayuda", - "link": "help" - }, - { - "title": "Configuración de Lenguaje", - "link": "setup-language" - } - ], "content": "

No puedes hacer uso del Botón de Pánico hasta que la instalación haya sido completada.

" }, { @@ -600,20 +587,6 @@ "status": "disabled" } ], - "items": [ - { - "title": "Acerca de ", - "link": "setup-about" - }, - { - "title": "Ayuda", - "link": "help" - }, - { - "title": "Configuraciones de Lenguage", - "link": "setup-language" - } - ], "content": "

No podrás hacer uso del Botón de Pánico hasta que el proceso de instalación haya sido completado.

" }, { @@ -627,16 +600,16 @@ "link": "setup-warning" } ], - "items": [ - { - "title": "Acerca de", - "link": "setup-about" - }, - { - "title": "Configuraciones de lenguaje", - "link": "setup-language" - } - ], + "items": [ + { + "title": "Acerca de", + "link": "setup-about" + }, + { + "title": "Configuraciones de lenguaje", + "link": "setup-language" + } + ], "content": "

\"Illustration\" El Botón de Pánico convierte tu teléfono móvil en una alarma secreta para que tus contactos mas confiables puedan actuar si te encuentras en riesgo.

" }, { diff --git a/assets/mobile_fr.json b/app/src/main/assets/mobile_fr.json similarity index 97% rename from assets/mobile_fr.json rename to app/src/main/assets/mobile_fr.json index 9d7d4bf9..a4a12b8b 100644 --- a/assets/mobile_fr.json +++ b/app/src/main/assets/mobile_fr.json @@ -1,6 +1,6 @@ { "mobile": { - "version": 8, + "version": "8", "data": [ { "id": "setup-warning", @@ -233,7 +233,8 @@ "action": [ { "title": "Suivant", - "link": "setup-alarm-disguise" +// "link": "setup-alarm-disguise" + "link": "home-not-configured-disguise" } ], "content": "

Votre test a fonctionné! Dans une véritable situation d'urgence, votre alerte aurait été envoyée.

" @@ -269,7 +270,7 @@ "fail": { "link": "setup-alarm-test-hardware-fail" }, - "content": "

\"\"

" + "content": "

\"\"

" }, { "id": "setup-alarm-test-disguise-success", @@ -554,20 +555,6 @@ "link": "setup-disguise" } ], - "items": [ - { - "title": "À propos", - "link": "setup-about" - }, - { - "title": "Aide", - "link": "help" - }, - { - "title": "Language Settings", - "link": "Langue" - } - ], "content": "

Vous ne pouvez pas utiliser le Bouton d'urgence avant de l'avoir entièrement configuré.

" }, { @@ -598,20 +585,6 @@ "status": "disabled" } ], - "items": [ - { - "title": "À propos", - "link": "setup-about" - }, - { - "title": "Aide", - "link": "help" - }, - { - "title": "Langue", - "link": "setup-language" - } - ], "content": "

Vous ne pouvez pas utiliser le Bouton d'urgence avant de l'avoir entièrement configuré.

" }, { diff --git a/assets/mobile_ph.json b/app/src/main/assets/mobile_ph.json similarity index 98% rename from assets/mobile_ph.json rename to app/src/main/assets/mobile_ph.json index 483f0806..1ded0790 100644 --- a/assets/mobile_ph.json +++ b/app/src/main/assets/mobile_ph.json @@ -1,6 +1,6 @@ { "mobile": { - "version" : 7, + "version" : "7", "data":[ { "id" : "setup-warning", @@ -150,8 +150,9 @@ "component" : "alarm-test-hardware", "timers" : {"info":"0","inactive":"10","fail":"20"}, "success" : {"link":"setup-alarm-test-hardware-success"}, - "fail" : {"link":"setup-alarm-test-hardware-fail"} - }, + "fail" : {"link":"setup-alarm-test-hardware-fail"}, + "content": "

\"\"

" + }, { "id" : "setup-alarm-test-disguise-success", "lang" : "ph", diff --git a/assets/mobile_pt.json b/app/src/main/assets/mobile_pt.json similarity index 96% rename from assets/mobile_pt.json rename to app/src/main/assets/mobile_pt.json index 84c2242b..6a40c253 100644 --- a/assets/mobile_pt.json +++ b/app/src/main/assets/mobile_pt.json @@ -1,6 +1,6 @@ { "mobile": { - "version": 8, + "version": "8", "data": [ { "id": "setup-warning", @@ -233,7 +233,8 @@ "action": [ { "title": "Próximo", - "link": "setup-alarm-disguise" +// "link": "setup-alarm-disguise" + "link": "home-not-configured-disguise" } ], "content": "

Teste bem sucedido! Em caso de emergência real, o seu alerta seria enviado.

" @@ -269,7 +270,7 @@ "fail": { "link": "setup-alarm-test-hardware-fail" }, - "content": "

\"\"

" + "content": "

\"\"

" }, { "id": "setup-alarm-test-disguise-success", @@ -541,20 +542,6 @@ "link": "setup-disguise" } ], - "items": [ - { - "title": "Sobre", - "link": "setup-about" - }, - { - "title": "Ajuda", - "link": "help" - }, - { - "title": "Configurações de Idioma", - "link": "setup-language" - } - ], "content": "

O Botão de Pânico só poderá ser usado depois de estar totalmente configurado.

" }, { @@ -585,20 +572,6 @@ "status": "disabled" } ], - "items": [ - { - "title": "Sobre", - "link": "setup-about" - }, - { - "title": "Ajuda", - "link": "help" - }, - { - "title": "Configurações de Idioma", - "link": "setup-language" - } - ], "content": "

O Botão de Pânico só poderá ser usado depois de estar totalmente configurado

" }, { diff --git a/src/main/java/org/iilab/pb/BaseFragmentActivity.java b/app/src/main/java/org/iilab/pb/BaseFragmentActivity.java similarity index 92% rename from src/main/java/org/iilab/pb/BaseFragmentActivity.java rename to app/src/main/java/org/iilab/pb/BaseFragmentActivity.java index a43d134e..f6706587 100644 --- a/src/main/java/org/iilab/pb/BaseFragmentActivity.java +++ b/app/src/main/java/org/iilab/pb/BaseFragmentActivity.java @@ -5,10 +5,10 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AppCompatActivity; import android.util.Log; -public class BaseFragmentActivity extends FragmentActivity { +public class BaseFragmentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/main/java/org/iilab/pb/CalculatorActivity.java b/app/src/main/java/org/iilab/pb/CalculatorActivity.java similarity index 85% rename from src/main/java/org/iilab/pb/CalculatorActivity.java rename to app/src/main/java/org/iilab/pb/CalculatorActivity.java index 8ee52cf0..311fff0e 100644 --- a/src/main/java/org/iilab/pb/CalculatorActivity.java +++ b/app/src/main/java/org/iilab/pb/CalculatorActivity.java @@ -9,13 +9,20 @@ import android.widget.Button; import android.widget.TextView; import android.widget.Toast; + import org.iilab.pb.calculator.CalculatorImpl; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.AppUtil; -import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.trigger.MultiClickEvent; +import static org.iilab.pb.common.AppConstants.DISGUISE_UNLOCK_LONGPRESS_TIME; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY; +import static org.iilab.pb.common.AppUtil.behaveAsHomeButton; +import static org.iilab.pb.common.AppUtil.playTrainingForRelease1_5; +import static org.iilab.pb.common.AppUtil.unbindDrawables; +import static org.iilab.pb.common.AppUtil.vibrateForHapticFeedback; +import static org.iilab.pb.common.ApplicationSettings.setWizardState; + public class CalculatorActivity extends PanicButtonActivity { + private static final int[] buttons = {R.id.one, R.id.two, R.id.three, R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine, R.id.zero, R.id.equals_sign, R.id.plus, R.id.minus, R.id.multiply, @@ -26,17 +33,16 @@ public class CalculatorActivity extends PanicButtonActivity { boolean mHasPerformedLongPress; Runnable mPendingCheckForLongPress; - + private static final String TAG = CalculatorActivity.class.getName(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.calculator_layout); registerButtonEvents(); -// startService(new Intent(this, HardwareTriggerService.class)); - calculator = new CalculatorImpl(); - - ApplicationSettings.setWizardState(this, AppConstants.WIZARD_FLAG_HOME_READY); + setWizardState(this, WIZARD_FLAG_HOME_READY); + if(playTrainingForRelease1_5(getApplicationContext()) ) + Toast.makeText(this, "Calculate! has been updated. Go to the settings to find out more!", Toast.LENGTH_LONG).show(); } private void registerButtonEvents() { @@ -119,7 +125,7 @@ public void onClick(View view) { return; } if(multiClickEvent.canStartVibration()){ - getPanicAlert().vibrate(); + vibrateForHapticFeedback(CalculatorActivity.this); CharSequence text = ((Button) view).getText(); //Toast.makeText(getApplicationContext(), "Press the button '" + text + "' once the vibration ends to trigger alerts", Toast.LENGTH_LONG).show(); } @@ -160,7 +166,7 @@ public void run() { mHasPerformedLongPress = false; - v.postDelayed(mPendingCheckForLongPress, 3000); + v.postDelayed(mPendingCheckForLongPress, DISGUISE_UNLOCK_LONGPRESS_TIME); break; case MotionEvent.ACTION_MOVE: @@ -196,7 +202,7 @@ public void run() { // }; private MultiClickEvent resetEvent(View view) { - MultiClickEvent multiClickEvent = new MultiClickEvent(); + MultiClickEvent multiClickEvent = new MultiClickEvent(this); view.setTag(multiClickEvent); return multiClickEvent; } @@ -210,7 +216,7 @@ private void handleButtonPress(CalculatorImpl.Button button) { @Override protected void onDestroy() { super.onDestroy(); - AppUtil.unbindDrawables(getWindow().getDecorView().findViewById(android.R.id.content)); + unbindDrawables(getWindow().getDecorView().findViewById(android.R.id.content)); System.gc(); } @@ -218,7 +224,7 @@ protected void onDestroy() { public void onBackPressed() { // super.onBackPressed(); // finish(); - Log.d("CDA", "onBackPressed Called"); - startActivity(AppUtil.behaveAsHomeButton()); + Log.d(TAG, "onBackPressed Called"); + startActivity(behaveAsHomeButton()); } } \ No newline at end of file diff --git a/app/src/main/java/org/iilab/pb/HomeActivity.java b/app/src/main/java/org/iilab/pb/HomeActivity.java new file mode 100644 index 00000000..466c6f74 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/HomeActivity.java @@ -0,0 +1,264 @@ +package org.iilab.pb; + +import android.app.ProgressDialog; +import android.content.Intent; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.text.TextUtils; +import android.util.Log; + +import com.crashlytics.android.Crashlytics; + +import org.iilab.pb.data.PBDatabase; +import org.iilab.pb.model.Page; +import org.iilab.pb.model.PageAction; +import org.iilab.pb.trigger.HardwareTriggerService; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import io.fabric.sdk.android.Fabric; + +import static org.iilab.pb.common.AppConstants.DEFAULT_LANGUAGE_ENG; +import static org.iilab.pb.common.AppConstants.DELIMITER_COMMA; +import static org.iilab.pb.common.AppConstants.FRESH_INSTALL_APP_RELEASE_NO; +import static org.iilab.pb.common.AppConstants.JSON_ARRAY_DATA; +import static org.iilab.pb.common.AppConstants.JSON_EXTENSION; +import static org.iilab.pb.common.AppConstants.JSON_OBJECT_HELP; +import static org.iilab.pb.common.AppConstants.JSON_OBJECT_MOBILE; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED_ALARM; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED_DISGUISE; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_LANGUAGE; +import static org.iilab.pb.common.AppConstants.PREFIX_HELP_DATA; +import static org.iilab.pb.common.AppConstants.PREFIX_MOBILE_DATA; +import static org.iilab.pb.common.AppConstants.SKIP_WIZARD; +import static org.iilab.pb.common.AppConstants.VERSION; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY; +import static org.iilab.pb.common.AppUtil.insertMobileDataToLocalDB; +import static org.iilab.pb.common.AppUtil.isLanguageDataExists; +import static org.iilab.pb.common.AppUtil.loadJSONFromAsset; +import static org.iilab.pb.common.ApplicationSettings.addDBLoadedLanguage; +import static org.iilab.pb.common.ApplicationSettings.getLastUpdatedVersion; +import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage; +import static org.iilab.pb.common.ApplicationSettings.getSupportedLanguages; +import static org.iilab.pb.common.ApplicationSettings.getWizardState; +import static org.iilab.pb.common.ApplicationSettings.isHardwareTriggerServiceEnabled; +import static org.iilab.pb.common.ApplicationSettings.setAppUpdated; +import static org.iilab.pb.common.ApplicationSettings.setFirstRun; +import static org.iilab.pb.common.ApplicationSettings.setLastUpdatedVersion; +import static org.iilab.pb.common.ApplicationSettings.setPBSupportedLanguages; +import static org.iilab.pb.common.ApplicationSettings.setSelectedLanguage; + + +public class HomeActivity extends AppCompatActivity { + + ProgressDialog pDialog; + + String pageId; + String selectedLang; + int currentLocalContentVersion; + int newLocalContentVersion; + + private static final String TAG = HomeActivity.class.getName(); + String supportedLangs; + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Fabric.with(this, new Crashlytics()); + setContentView(R.layout.welcome_screen); + //deleteShortCut(); + int wizardState = getWizardState(this); + if (SKIP_WIZARD) { + pageId = PAGE_HOME_READY; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED) { + + pageId = PAGE_HOME_NOT_CONFIGURED; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM) { + pageId = PAGE_HOME_NOT_CONFIGURED_ALARM; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE) { + pageId = PAGE_HOME_NOT_CONFIGURED_DISGUISE; + } else if (wizardState == WIZARD_FLAG_HOME_READY) { + pageId = PAGE_HOME_READY; + } + setSelectedLanguage(this, getDefaultOSLanguage()); + selectedLang = getSelectedLanguage(this); + /* + lastLocalDBVersion is used for local db version update. If local db version is changed, then all local data will be deleted, + tables will be reformed & database is blank. So at that point we will force local-data update from assets, then a retrieval-try + from the remote database even if the data was retrieved within last 24-hours period. + */ + + // this is the version number from installed mobile_en.json + currentLocalContentVersion = getLastUpdatedVersion(HomeActivity.this); + + try { + JSONObject jsonObj = new JSONObject(loadJSONFromAsset("mobile_en.json", getApplicationContext())); + JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_MOBILE); + //this is from new assets folder + newLocalContentVersion = Integer.parseInt(mobileObj.getString(VERSION)); + } catch (JSONException | NumberFormatException exception) { + Log.e(TAG, "Exception in reading mobile_en.json from asset" + exception.getMessage()); + exception.printStackTrace(); + } + + /* We update the device language content if the english mobile_en.json version has increased or + * if the language of the device OS was previously not installed*/ + Log.d(TAG, "currentLocalContentVersion is" + currentLocalContentVersion + "and newLocalContentVersion is " + newLocalContentVersion); + if ((newLocalContentVersion > currentLocalContentVersion) || (!isLanguageDataExists(getApplicationContext(), selectedLang))) { + Log.d(TAG, "Update local data as the english mobile_en.json version has increased"); + // to check if the app is installed first time, -1 is the default value + if (currentLocalContentVersion == FRESH_INSTALL_APP_RELEASE_NO) { + setFirstRun(getApplicationContext(), true); + setAppUpdated(getApplicationContext(), false); + } else { + setFirstRun(getApplicationContext(), false); + setAppUpdated(getApplicationContext(), true); + } + new InitializeLocalData().execute(); + addDBLoadedLanguage(getApplicationContext(), selectedLang); + + } else { + Log.d(TAG, "no update of local data needed"); + startNextActivity(); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + private String getDefaultOSLanguage() { + // Default language of OS: + return Locale.getDefault().getLanguage(); + } + + private void deleteShortCut() { + + Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); + shortcutIntent.setClassName("org.iilab.pb", "HomeActivity"); + shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + Intent removeIntent = new Intent(); + removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); + removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName"); + removeIntent.putExtra("duplicate", false); + + removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); + sendBroadcast(removeIntent); + } + + private void setSupportedLanguages(Page languagesPage) { + List allowedLanguages = new ArrayList<>(); + List actionLanguages = languagesPage.getAction(); + for (PageAction actionLanguage : actionLanguages) { + allowedLanguages.add(actionLanguage.getLanguage()); + } + supportedLangs = TextUtils.join(DELIMITER_COMMA, allowedLanguages); + setPBSupportedLanguages(this, supportedLangs); + } + + private void startNextActivity() { + Log.d(TAG, "starting next activity"); + int wizardState = getWizardState(this); + + //TODO remove after testing +// wizardState = WIZARD_FLAG_HOME_READY; + if (wizardState != WIZARD_FLAG_HOME_READY) { + Log.d(TAG, "First run TRUE, running WizardActivity with pageId = " + pageId); + + supportedLangs = getSupportedLanguages(this); + Log.d(TAG, "Checking supported languages " + supportedLangs); + if (null == supportedLangs) { + PBDatabase dbInstance = new PBDatabase(this); + dbInstance.open(); + Page languagesPage = dbInstance.retrievePage(PAGE_SETUP_LANGUAGE, DEFAULT_LANGUAGE_ENG); + setSupportedLanguages(languagesPage); + dbInstance.close(); + } + if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) { + setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG); + } + + Intent i = new Intent(HomeActivity.this, WizardActivity.class); + i.putExtra(PAGE_ID, pageId); + startActivity(i); + } else { + Log.d(TAG, "First run FALSE, running CalculatorActivity"); + Intent i = new Intent(HomeActivity.this, CalculatorActivity.class); + // Make sure the HardwareTriggerService is started + if (isHardwareTriggerServiceEnabled(this)) { + startService(new Intent(this, HardwareTriggerService.class)); + } + startActivity(i); + } + } + + private class InitializeLocalData extends AsyncTask { + int lastUpdatedVersion; + + @Override + protected void onPreExecute() { + super.onPreExecute(); + pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Installing...", true, false); + } + + @Override + protected Boolean doInBackground(Void... params) { + Log.d(TAG, "starting loading of json files in background thread"); + String dataFileName = PREFIX_MOBILE_DATA + selectedLang + JSON_EXTENSION; + String helpFileName = PREFIX_HELP_DATA + selectedLang + JSON_EXTENSION; + try { + JSONObject jsonObj = new JSONObject(loadJSONFromAsset(dataFileName, getApplicationContext())); + JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_MOBILE); + + lastUpdatedVersion = mobileObj.getInt(VERSION); + setLastUpdatedVersion(HomeActivity.this, lastUpdatedVersion); + + JSONArray dataArray = mobileObj.getJSONArray(JSON_ARRAY_DATA); + insertMobileDataToLocalDB(dataArray, getApplicationContext()); + } catch (JSONException jsonException) { + Log.e(TAG, "Exception in reading mobile_en.json from asset" + jsonException.getMessage()); + jsonException.printStackTrace(); + } + + try { + JSONObject jsonObj = new JSONObject(loadJSONFromAsset(helpFileName, getApplicationContext())); + JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_HELP); + + JSONArray dataArray = mobileObj.getJSONArray(JSON_ARRAY_DATA); + insertMobileDataToLocalDB(dataArray, getApplicationContext()); + } catch (JSONException jsonException) { + Log.e(TAG, "Exception in reading help_en.json from asset" + jsonException.getMessage()); + jsonException.printStackTrace(); + } + + return true; + } + + @Override + protected void onPostExecute(Boolean response) { + super.onPostExecute(response); + if (pDialog.isShowing()) + try { + pDialog.dismiss(); + } catch (Exception e) { + Log.e(TAG, "Exception while dismissing progress dialog " + e.getMessage()); + e.printStackTrace(); + } + startNextActivity(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/iilab/pb/LoginActivity.java b/app/src/main/java/org/iilab/pb/LoginActivity.java new file mode 100644 index 00000000..a603c04d --- /dev/null +++ b/app/src/main/java/org/iilab/pb/LoginActivity.java @@ -0,0 +1,88 @@ +package org.iilab.pb; + +import android.content.Intent; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.View; +import android.view.View.OnKeyListener; +import android.widget.Button; +import android.widget.EditText; + +import org.iilab.pb.trigger.HardwareTriggerService; + +import static org.iilab.pb.common.AppConstants.PAGE_HOME_ALERTING; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_TRAINING_1_5; +import static org.iilab.pb.common.AppUtil.playTrainingForRelease1_5; +import static org.iilab.pb.common.AppUtil.setError; +import static org.iilab.pb.common.ApplicationSettings.isAlertActive; +import static org.iilab.pb.common.ApplicationSettings.passwordMatches; +import static org.iilab.pb.common.ApplicationSettings.setFirstRun; +import static org.iilab.pb.common.ApplicationSettings.setTrainingDoneRelease1_5; + +public class LoginActivity extends PanicButtonActivity { + private static final String TAG = LoginActivity.class.getName(); + private EditText passwordEditText; + private Button bAction; + private int tryCount = 0; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.login_screen_layout); + passwordEditText = (EditText) findViewById(R.id.create_pin_edittext); + passwordEditText.requestFocus(); + passwordEditText.setOnKeyListener(new OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Perform action on key press + actionOnKeyPress(); + } + return false; + } + }); + bAction = (Button) findViewById(R.id.b_action); + bAction.setText(getResources().getString(R.string.code_ok)); + bAction.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + actionOnKeyPress(); + } + }); + + } + private void actionOnKeyPress(){ + String password = passwordEditText.getText().toString(); + if (passwordMatches(getApplicationContext(), password)) { + Intent i; + + // check if db update version is 1.5 and play training + if(playTrainingForRelease1_5(getApplicationContext())) { + i = new Intent(LoginActivity.this, WizardActivity.class); + i.putExtra(PAGE_ID, PAGE_SETUP_TRAINING_1_5); + setTrainingDoneRelease1_5(getApplicationContext(), true); + setFirstRun(getApplicationContext(),false); + //in training mode of alarm trigger, stop the send alert hardware service. + getApplicationContext().stopService(new Intent(getApplicationContext(), HardwareTriggerService.class)); + + }else { + i = new Intent(LoginActivity.this, MainActivity.class); + if (isAlertActive(LoginActivity.this)) { + i.putExtra(PAGE_ID, PAGE_HOME_ALERTING); + } else { + i.putExtra(PAGE_ID, PAGE_HOME_READY); + } + } + startActivity(i); + + finish(); + return; + } + setError(LoginActivity.this, passwordEditText, ((tryCount < 2) ? R.string.incorrect_pin : R.string.incorrect_pin_3_times)); + tryCount++; + } + +} \ No newline at end of file diff --git a/src/main/java/org/iilab/pb/MainActivity.java b/app/src/main/java/org/iilab/pb/MainActivity.java similarity index 50% rename from src/main/java/org/iilab/pb/MainActivity.java rename to app/src/main/java/org/iilab/pb/MainActivity.java index 7f8f3426..7021af59 100644 --- a/src/main/java/org/iilab/pb/MainActivity.java +++ b/app/src/main/java/org/iilab/pb/MainActivity.java @@ -7,15 +7,17 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.support.v7.preference.PreferenceFragmentCompat; +import android.support.v7.preference.PreferenceScreen; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Toast; import org.iilab.pb.alert.PanicAlert; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.data.PBDatabase; +import org.iilab.pb.fragment.AdvancedSettingsFragment; +import org.iilab.pb.fragment.AdvancedSettingsSubScreenFragment; import org.iilab.pb.fragment.LanguageSettingsFragment; import org.iilab.pb.fragment.MainSetupAlertFragment; import org.iilab.pb.fragment.SetupCodeFragment; @@ -26,11 +28,30 @@ import org.iilab.pb.model.Page; import org.iilab.pb.trigger.HardwareTriggerService; +import static org.iilab.pb.common.AppConstants.FROM_MAIN_ACTIVITY; +import static org.iilab.pb.common.AppConstants.IS_BACK_BUTTON_PRESSED; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_ADVANCED_SETTINGS; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_ALERT; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_CODE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_CONTACTS; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_LANGUAGE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_MESSAGE; +import static org.iilab.pb.common.AppConstants.PAGE_FROM_NOT_IMPLEMENTED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_MODAL; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_SIMPLE; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_WARNING; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage; +import static org.iilab.pb.common.ApplicationSettings.isAlertActive; +import static org.iilab.pb.common.ApplicationSettings.setWizardState; /** * Created by aoe on 2/15/14. */ -public class MainActivity extends BaseFragmentActivity { +public class MainActivity extends BaseFragmentActivity implements PreferenceFragmentCompat.OnPreferenceStartScreenCallback { TextView tvToastMessage; @@ -39,32 +60,33 @@ public class MainActivity extends BaseFragmentActivity { String selectedLang; Boolean flagRiseFromPause = false; - + private static final String TAG = MainActivity.class.getName(); + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.root_layout); - + tvToastMessage = (TextView) findViewById(R.id.tv_toast); try { - pageId = getIntent().getExtras().getString("page_id"); + pageId = getIntent().getExtras().getString(PAGE_ID); } catch (Exception e) { - pageId = "home-not-configured"; + pageId = PAGE_HOME_NOT_CONFIGURED; e.printStackTrace(); } - selectedLang = ApplicationSettings.getSelectedLanguage(this); + selectedLang = getSelectedLanguage(this); - Log.e("MainActivity.onCreate", "pageId = " + pageId); + Log.i(TAG, "pageId = " + pageId); - if(pageId.equals("home-not-configured")){ - Log.e("??????????????", "Restarting the Wizard"); + if (pageId.equals(PAGE_HOME_NOT_CONFIGURED)) { + Log.d(TAG, "Restarting the Wizard"); - if((ApplicationSettings.isAlertActive(this))){ + if ((isAlertActive(this))) { new PanicAlert(this).deActivate(); } - ApplicationSettings.setWizardState(MainActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED); + setWizardState(MainActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED); changeAppIcontoPB(); // We're restarting the wizard so we deactivate the HardwareTriggerService @@ -72,7 +94,7 @@ public void onCreate(Bundle savedInstanceState) { Intent i = new Intent(MainActivity.this, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); callFinishActivityReceiver(); @@ -91,9 +113,9 @@ public void onCreate(Bundle savedInstanceState) { dbInstance.close(); if (currentPage == null) { - Log.e(">>>>>>", "page = null"); + Log.d(TAG, "page = null"); Toast.makeText(this, "Still to be implemented.", Toast.LENGTH_SHORT).show(); - AppConstants.PAGE_FROM_NOT_IMPLEMENTED = true; + PAGE_FROM_NOT_IMPLEMENTED = true; finish(); return; } else { @@ -102,34 +124,35 @@ public void onCreate(Bundle savedInstanceState) { Fragment fragment = null; - if (currentPage.getType().equals("simple")) { + if (currentPage.getType().equals(PAGE_TYPE_SIMPLE)) { tvToastMessage.setVisibility(View.INVISIBLE); - fragment = new SimpleFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - }else if (currentPage.getType().equals("warning")) { - tvToastMessage.setVisibility(View.INVISIBLE); - fragment = new WarningFragment().newInstance(pageId,AppConstants.FROM_MAIN_ACTIVITY); - - } else if (currentPage.getType().equals("modal")){ + fragment = new SimpleFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + } else if (currentPage.getType().equals(PAGE_TYPE_WARNING)) { + tvToastMessage.setVisibility(View.INVISIBLE); + fragment = new WarningFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + + } else if (currentPage.getType().equals(PAGE_TYPE_MODAL)) { tvToastMessage.setVisibility(View.INVISIBLE); Intent i = new Intent(MainActivity.this, MainModalActivity.class); - i.putExtra("page_id", pageId); -// i.putExtra("parent_activity", AppConstants.FROM_MAIN_ACTIVITY); + i.putExtra(PAGE_ID, pageId); startActivity(i); finish(); return; } else { - if (currentPage.getComponent().equals("contacts")) - fragment = new SetupContactsFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - else if (currentPage.getComponent().equals("message")) - fragment = new SetupMessageFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - else if (currentPage.getComponent().equals("code")) - fragment = new SetupCodeFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - else if (currentPage.getComponent().equals("alert")) - fragment = new MainSetupAlertFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - else if (currentPage.getComponent().equals("language")) - fragment = new LanguageSettingsFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - else - fragment = new SimpleFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + if (currentPage.getComponent().equals(PAGE_COMPONENT_CONTACTS)) + fragment = new SetupContactsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_MESSAGE)) + fragment = new SetupMessageFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_CODE)) + fragment = new SetupCodeFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_ALERT)) + fragment = new MainSetupAlertFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_LANGUAGE)) + fragment = new LanguageSettingsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { + fragment = new AdvancedSettingsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + } else + fragment = new SimpleFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); } fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); @@ -138,8 +161,8 @@ else if (currentPage.getComponent().equals("language")) private void changeAppIcontoPB() { - Log.e("MainActivity.changeAppIcontoPB", ""); - getPackageManager().setComponentEnabledSetting( + Log.d(TAG, " changeAppIcontoPB"); + getPackageManager().setComponentEnabledSetting( new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-setup"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); @@ -151,7 +174,7 @@ private void changeAppIcontoPB() { @Override protected void onResume() { super.onResume(); - Log.e("MainActivity.onResume", "pageId = " + pageId + " and flagRiseFromPause = " + flagRiseFromPause); + Log.d(TAG, "pageId = " + pageId + " and flagRiseFromPause = " + flagRiseFromPause); /* @@ -159,9 +182,9 @@ protected void onResume() { if this page is resumed from the page still not implemented, then we'll handle it here. If we don't do this check, then the resume procedure falls under Check-3 & execute that code snippet, which is not proper. */ - if (AppConstants.PAGE_FROM_NOT_IMPLEMENTED) { - Log.e("MainActivity.onResume", "returning from not-implemented page."); - AppConstants.PAGE_FROM_NOT_IMPLEMENTED = false; + if (PAGE_FROM_NOT_IMPLEMENTED) { + Log.d(TAG, "returning from not-implemented page."); + PAGE_FROM_NOT_IMPLEMENTED = false; return; } @@ -170,13 +193,13 @@ protected void onResume() { if this page is resumed by navigating-back from the next page, then we'll handle it here. If we don't do this check, then the resume procedure falls under Check-3 & execute that code snippet, which is not proper. */ - if (AppConstants.IS_BACK_BUTTON_PRESSED) { - Log.e("MainActivity.onResume", "back button pressed"); - AppConstants.IS_BACK_BUTTON_PRESSED = false; + if (IS_BACK_BUTTON_PRESSED) { + Log.d(TAG, "back button pressed"); + IS_BACK_BUTTON_PRESSED = false; return; } - + if (flagRiseFromPause) { Intent i = new Intent(MainActivity.this, CalculatorActivity.class); startActivity(i); @@ -189,18 +212,17 @@ protected void onResume() { } return; } - + @Override protected void onPause() { super.onPause(); - Log.e("MainActivity.onPause", "."); - Log.e("MainActivity.onPause", "flagRiseFromPause = " + true); + Log.d(TAG, "flagRiseFromPause = " + true); flagRiseFromPause = true; } - - protected void onStop(){ + + protected void onStop() { super.onStop(); - Log.e("MainActivity.onStop", "."); + Log.d(TAG, "onStop"); } @Override @@ -208,29 +230,50 @@ protected void onStart() { super.onStart(); // if(pageId.equals("home-not-configured")){ // Log.e("??????????????", "home-not-configured"); -// ApplicationSettings.setWizardState(MainActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED); +// ApplicationSettings.setWizardState(MainActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED); // Intent i = new Intent(MainActivity.this, WizardActivity.class); // i.putExtra("page_id", "home-not-configured"); // startActivity(i); // } - Log.e("MainActivity.onStart", "."); + Log.d(TAG, "onStart"); } @Override public void onBackPressed() { - if(pageId.equals("home-ready")){ + Log.d(TAG, " fragment back pressed in " + currentPage.getId()+" "+pageId); + if (pageId.equals(PAGE_HOME_READY)) { +// if (pageId.equals(PAGE_SETUP_ALARM_RETRAINING)){ // don't go back // finish(); // startActivity(AppUtil.behaveAsHomeButton()); - } - else{ + } else if (currentPage.getComponent() != null && currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { + if (getSupportFragmentManager().getBackStackEntryCount() > 0) { + getSupportFragmentManager().popBackStack(); + } + else { + super.onBackPressed(); + IS_BACK_BUTTON_PRESSED = true; + } + } else { super.onBackPressed(); - AppConstants.IS_BACK_BUTTON_PRESSED = true; + IS_BACK_BUTTON_PRESSED = true; } } - - + @Override + public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, + PreferenceScreen preferenceScreen) { + Log.d(TAG, "callback called to attach the preference sub screen"); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + AdvancedSettingsSubScreenFragment fragment = AdvancedSettingsSubScreenFragment.newInstance(pageId, FROM_MAIN_ACTIVITY); + Bundle args = new Bundle(); + args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); + fragment.setArguments(args); + ft.replace(R.id.fragment_container, fragment, preferenceScreen.getKey()); + ft.addToBackStack(null); + ft.commit(); + return true; + } } diff --git a/src/main/java/org/iilab/pb/MainModalActivity.java b/app/src/main/java/org/iilab/pb/MainModalActivity.java similarity index 100% rename from src/main/java/org/iilab/pb/MainModalActivity.java rename to app/src/main/java/org/iilab/pb/MainModalActivity.java diff --git a/src/main/java/org/iilab/pb/PanicButtonActivity.java b/app/src/main/java/org/iilab/pb/PanicButtonActivity.java similarity index 100% rename from src/main/java/org/iilab/pb/PanicButtonActivity.java rename to app/src/main/java/org/iilab/pb/PanicButtonActivity.java diff --git a/src/main/java/org/iilab/pb/WizardActivity.java b/app/src/main/java/org/iilab/pb/WizardActivity.java similarity index 56% rename from src/main/java/org/iilab/pb/WizardActivity.java rename to app/src/main/java/org/iilab/pb/WizardActivity.java index 27d17364..b37174db 100644 --- a/src/main/java/org/iilab/pb/WizardActivity.java +++ b/app/src/main/java/org/iilab/pb/WizardActivity.java @@ -16,14 +16,54 @@ import android.view.WindowManager; import android.widget.TextView; import android.widget.Toast; -import org.iilab.pb.common.AppConstants; + import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.common.MyTagHandler; import org.iilab.pb.data.PBDatabase; -import org.iilab.pb.fragment.*; +import org.iilab.pb.fragment.LanguageSettingsFragment; +import org.iilab.pb.fragment.SetupCodeFragment; +import org.iilab.pb.fragment.SetupContactsFragment; +import org.iilab.pb.fragment.SetupMessageFragment; +import org.iilab.pb.fragment.SimpleFragment; +import org.iilab.pb.fragment.WarningFragment; +import org.iilab.pb.fragment.WizardAlarmTestDisguiseFragment; +import org.iilab.pb.fragment.WizardAlarmTestHardwareFragment; +import org.iilab.pb.fragment.WizardTestDisguiseCodeFragment; +import org.iilab.pb.fragment.WizardTestDisguiseOpenFragment; +import org.iilab.pb.fragment.WizardTestDisguiseUnlockFragment; import org.iilab.pb.model.Page; import org.iilab.pb.trigger.HardwareTriggerService; +import static org.iilab.pb.common.AppConstants.FROM_WIZARD_ACTIVITY; +import static org.iilab.pb.common.AppConstants.IS_BACK_BUTTON_PRESSED; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_ALARM_TEST_DISGUISE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_ALARM_TEST_HARDWARE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_CODE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_CONTACTS; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_DISGUISE_TEST_CODE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_DISGUISE_TEST_OPEN; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_DISGUISE_TEST_UNLOCK; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_LANGUAGE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_MESSAGE; +import static org.iilab.pb.common.AppConstants.PAGE_FROM_NOT_IMPLEMENTED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED_ALARM; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED_DISGUISE; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE_RETRAINING; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_RETRAINING; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_TRAINING_1_5; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE_TRAINING_1_5; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_SIMPLE; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_WARNING; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY; + public class WizardActivity extends BaseFragmentActivity { @@ -35,6 +75,7 @@ public class WizardActivity extends BaseFragmentActivity { Boolean flagRiseFromPause = false; private Handler inactiveHandler = new Handler(); + private static final String TAG = WizardActivity.class.getName(); @Override public void onCreate(Bundle savedInstanceState) { @@ -44,14 +85,14 @@ public void onCreate(Bundle savedInstanceState) { tvToastMessage = (TextView) findViewById(R.id.tv_toast); try { - pageId = getIntent().getExtras().getString("page_id"); + pageId = getIntent().getExtras().getString(PAGE_ID); } catch (Exception e) { - pageId = "home-not-configured"; + pageId = PAGE_HOME_NOT_CONFIGURED; e.printStackTrace(); } selectedLang = ApplicationSettings.getSelectedLanguage(this); - Log.e("WizardActivity.onCreate", "pageId = " + pageId); + Log.d(TAG, "pageId = " + pageId); PBDatabase dbInstance = new PBDatabase(this); dbInstance.open(); @@ -59,20 +100,19 @@ public void onCreate(Bundle savedInstanceState) { dbInstance.close(); if (currentPage == null) { - Log.e(">>>>>>", "page = null"); + Log.d(TAG, "page = null"); Toast.makeText(this, "Still to be implemented.", Toast.LENGTH_SHORT).show(); - AppConstants.PAGE_FROM_NOT_IMPLEMENTED = true; + PAGE_FROM_NOT_IMPLEMENTED = true; finish(); return; - } else if (currentPage.getId().equals("home-ready")) { -// ApplicationSettings.setFirstRun(WizardActivity.this, false); - ApplicationSettings.setWizardState(WizardActivity.this, AppConstants.WIZARD_FLAG_HOME_READY); + } else if (currentPage.getId().equals(PAGE_HOME_READY)) { + ApplicationSettings.setWizardState(WizardActivity.this, WIZARD_FLAG_HOME_READY); changeAppIcontoCalculator(); - - startService(new Intent(this, HardwareTriggerService.class)); - + if(ApplicationSettings.isHardwareTriggerServiceEnabled(this)) { + startService(new Intent(this, HardwareTriggerService.class)); + } Intent i = new Intent(WizardActivity.this, MainActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); callFinishActivityReceiver(); @@ -85,12 +125,12 @@ public void onCreate(Bundle savedInstanceState) { setup the milestone of the wizard state if the app flow reaches to THREE specific page, i.e. home-not-configured, home-not-configured-alarm and home-not-configured-disguise. */ - if (currentPage.getId().equals("home-not-configured")) { - ApplicationSettings.setWizardState(WizardActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED); - } else if (currentPage.getId().equals("home-not-configured-alarm")) { - ApplicationSettings.setWizardState(WizardActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM); - } else if (currentPage.getId().equals("home-not-configured-disguise")) { - ApplicationSettings.setWizardState(WizardActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE); + if (currentPage.getId().equals(PAGE_HOME_NOT_CONFIGURED)) { + ApplicationSettings.setWizardState(WizardActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED); + } else if (currentPage.getId().equals(PAGE_HOME_NOT_CONFIGURED_ALARM)) { + ApplicationSettings.setWizardState(WizardActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM); + } else if (currentPage.getId().equals(PAGE_HOME_NOT_CONFIGURED_DISGUISE)) { + ApplicationSettings.setWizardState(WizardActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE); } FragmentManager fragmentManager = getSupportFragmentManager(); @@ -98,56 +138,61 @@ public void onCreate(Bundle savedInstanceState) { Fragment fragment = null; - if (currentPage.getType().equals("simple")) { + if (currentPage.getType().equals(PAGE_TYPE_SIMPLE)) { tvToastMessage.setVisibility(View.INVISIBLE); - fragment = new SimpleFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); - } else if (currentPage.getType().equals("warning")) { + fragment = new SimpleFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); + } else if (currentPage.getType().equals(PAGE_TYPE_WARNING)) { tvToastMessage.setVisibility(View.INVISIBLE); - fragment = new WarningFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); + fragment = new WarningFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); } else { // type = interactive - if (currentPage.getComponent().equals("contacts")) - fragment = new SetupContactsFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); - else if (currentPage.getComponent().equals("message")) - fragment = new SetupMessageFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); - else if (currentPage.getComponent().equals("code")) - fragment = new SetupCodeFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); - else if (currentPage.getComponent().equals("language")) - fragment = new LanguageSettingsFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); - else if (currentPage.getComponent().equals("alarm-test-hardware")) { + if (currentPage.getComponent().equals(PAGE_COMPONENT_CONTACTS)) + fragment = new SetupContactsFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_MESSAGE)) + fragment = new SetupMessageFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_CODE)) + fragment = new SetupCodeFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_LANGUAGE)) + fragment = new LanguageSettingsFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); + else if (currentPage.getComponent().equals(PAGE_COMPONENT_ALARM_TEST_HARDWARE)) { tvToastMessage.setVisibility(View.VISIBLE); if (currentPage.getIntroduction() != null) { tvToastMessage.setText(Html.fromHtml(currentPage.getIntroduction(), null, new MyTagHandler())); } fragment = new WizardAlarmTestHardwareFragment().newInstance(pageId); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); - } else if (currentPage.getComponent().equals("alarm-test-disguise")) { + } else if (currentPage.getComponent().equals(PAGE_COMPONENT_ALARM_TEST_DISGUISE)) { tvToastMessage.setVisibility(View.VISIBLE); if (currentPage.getIntroduction() != null) { tvToastMessage.setText(Html.fromHtml(currentPage.getIntroduction(), null, new MyTagHandler())); } fragment = new WizardAlarmTestDisguiseFragment().newInstance(pageId); - } else if (currentPage.getComponent().equals("disguise-test-open")) { + } else if (currentPage.getComponent().equals(PAGE_COMPONENT_DISGUISE_TEST_OPEN)) { findViewById(R.id.wizard_layout_root).setBackgroundColor(Color.BLACK); tvToastMessage.setVisibility(View.VISIBLE); if (currentPage.getIntroduction() != null) { tvToastMessage.setText(Html.fromHtml(currentPage.getIntroduction(), null, new MyTagHandler())); } fragment = new WizardTestDisguiseOpenFragment().newInstance(pageId); - } else if (currentPage.getComponent().equals("disguise-test-unlock")) { + } else if (currentPage.getComponent().equals(PAGE_COMPONENT_DISGUISE_TEST_UNLOCK)) { tvToastMessage.setVisibility(View.VISIBLE); if (currentPage.getIntroduction() != null) { tvToastMessage.setText(Html.fromHtml(currentPage.getIntroduction(), null, new MyTagHandler())); } fragment = new WizardTestDisguiseUnlockFragment().newInstance(pageId); - } else if (currentPage.getComponent().equals("disguise-test-code")) { + } else if (currentPage.getComponent().equals(PAGE_COMPONENT_DISGUISE_TEST_CODE)) { tvToastMessage.setVisibility(View.VISIBLE); if (currentPage.getIntroduction() != null) { tvToastMessage.setText(Html.fromHtml(currentPage.getIntroduction(), null, new MyTagHandler())); } fragment = new WizardTestDisguiseCodeFragment().newInstance(pageId); - } else - fragment = new SimpleFragment().newInstance(pageId, AppConstants.FROM_WIZARD_ACTIVITY); + } +// //TODO remove this, just for testing +// else if (currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { +// fragment = new AdvancedSettingsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); +// } + else + fragment = new SimpleFragment().newInstance(pageId, FROM_WIZARD_ACTIVITY); } fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); @@ -155,11 +200,11 @@ else if (currentPage.getComponent().equals("alarm-test-hardware")) { } private void changeAppIcontoCalculator() { - Log.e("WizardActivity.changeAppIcontoCalculator", ""); + Log.i(TAG, "changeAppIcontoCalculator"); - getPackageManager().setComponentEnabledSetting( - new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-calculator"), - PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); + getPackageManager().setComponentEnabledSetting( + new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-calculator"), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); getPackageManager().setComponentEnabledSetting( new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-setup"), @@ -169,7 +214,7 @@ private void changeAppIcontoCalculator() { @Override protected void onPause() { super.onPause(); - Log.e("WizardActivity.onPause", "page = " + pageId); + Log.i(TAG, "page = " + pageId); // if (currentPage.getId().equals("home-ready") && ApplicationSettings.isRestartedSetup(WizardActivity.this)) { // Log.e("WizardActivity.onPause", "false->RestartedSetup"); @@ -183,8 +228,8 @@ protected void onPause() { In short, we block this page - setup-alarm-test-hardware for pause-resume action */ - if (!pageId.equals("setup-alarm-test-hardware")) { - Log.e(">>>>>>", "assert flagRiseFromPause = " + true); + if (!(pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE) || pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_RETRAINING) || pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_TRAINING_1_5))) { + Log.d(TAG, "assert flagRiseFromPause = " + true); flagRiseFromPause = true; } } @@ -192,14 +237,14 @@ protected void onPause() { @Override protected void onStop() { super.onStop(); - Log.d("WizardActivity.onStop", "page = " + pageId); + Log.i(TAG, "page = " + pageId); } @Override public void onDestroy() { super.onDestroy(); - Log.e("WizardActivity", "onDestroy"); + Log.i(TAG, "onDestroy"); inactiveHandler.removeCallbacks(runnableInteractive); } @@ -208,13 +253,13 @@ public void onDestroy() { @Override protected void onStart() { super.onStart(); - Log.d("WizardActivity.onStart", "page = " + pageId); + Log.i(TAG, "page = " + pageId); } @Override protected void onResume() { super.onResume(); - Log.e("WizardActivity.onResume", "pageId = " + pageId + " and flagRiseFromPause = " + flagRiseFromPause); + Log.i(TAG, "pageId = " + pageId + " and flagRiseFromPause = " + flagRiseFromPause); int wizardState = ApplicationSettings.getWizardState(WizardActivity.this); @@ -223,9 +268,9 @@ protected void onResume() { if this page is resumed from the page still not implemented, then we'll handle it here. If we don't do this check, then the resume procedure falls under Check-3 & execute that code snippet, which is not proper. */ - if (AppConstants.PAGE_FROM_NOT_IMPLEMENTED) { - Log.e("WizardActivity.onResume", "returning from not-implemented page."); - AppConstants.PAGE_FROM_NOT_IMPLEMENTED = false; + if (PAGE_FROM_NOT_IMPLEMENTED) { + Log.d(TAG, "returning from not-implemented page."); + PAGE_FROM_NOT_IMPLEMENTED = false; return; } @@ -234,9 +279,9 @@ protected void onResume() { if this page is resumed by navigating-back from the next page, then we'll handle it here. If we don't do this check, then the resume procedure falls under Check-3 & execute that code snippet, which is not proper. */ - if (AppConstants.IS_BACK_BUTTON_PRESSED) { - Log.e("WizardActivity.onResume", "back button pressed"); - AppConstants.IS_BACK_BUTTON_PRESSED = false; + if (IS_BACK_BUTTON_PRESSED) { + Log.d(TAG, "back button pressed"); + IS_BACK_BUTTON_PRESSED = false; return; } @@ -258,21 +303,21 @@ Every time device gets resumed, flagRiseFromPause becomes true(except for setup- Side Effect - if we are in this page - setup-alarm-test-hardware-success & go to home & come back, still this page will be there as the opening page of the app. */ - if (flagRiseFromPause && !pageId.equals("setup-alarm-test-hardware-success")) { + if (flagRiseFromPause && !(pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS) || pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_RETRAINING) || (pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_TRAINING_1_5)))) { flagRiseFromPause = false; - if (wizardState == AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED) { - pageId = "home-not-configured"; - } else if (wizardState == AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM) { - pageId = "home-not-configured-alarm"; - } else if (wizardState == AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE) { - pageId = "home-not-configured-disguise"; - } else if (wizardState == AppConstants.WIZARD_FLAG_HOME_READY) { - pageId = "home-ready"; + if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED) { + pageId = PAGE_HOME_NOT_CONFIGURED; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM) { + pageId =PAGE_HOME_NOT_CONFIGURED_ALARM; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE) { + pageId = PAGE_HOME_NOT_CONFIGURED_DISGUISE; + } else if (wizardState == WIZARD_FLAG_HOME_READY) { + pageId = PAGE_HOME_READY; } Intent i = new Intent(WizardActivity.this, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); callFinishActivityReceiver(); @@ -282,16 +327,16 @@ Every time device gets resumed, flagRiseFromPause becomes true(except for setup- @Override public void onUserInteraction() { - Log.e("WizardActivity", "onUserInteraction"); + Log.i(TAG, "onUserInteraction"); super.onUserInteraction(); hideToastMessageInInteractiveFragment(); if (currentPage != null && currentPage.getComponent() != null && ( - currentPage.getComponent().equals("alarm-test-hardware") - || currentPage.getComponent().equals("alarm-test-disguise") - || currentPage.getComponent().equals("disguise-test-open") - || currentPage.getComponent().equals("disguise-test-unlock") - || currentPage.getComponent().equals("disguise-test-code") + currentPage.getComponent().equals(PAGE_COMPONENT_ALARM_TEST_HARDWARE) + || currentPage.getComponent().equals(PAGE_COMPONENT_ALARM_TEST_DISGUISE) + || currentPage.getComponent().equals(PAGE_COMPONENT_DISGUISE_TEST_OPEN) + || currentPage.getComponent().equals(PAGE_COMPONENT_DISGUISE_TEST_UNLOCK) + || currentPage.getComponent().equals(PAGE_COMPONENT_DISGUISE_TEST_CODE) ) ) { inactiveHandler.postDelayed(runnableInteractive, Integer.parseInt(currentPage.getTimers().getFail()) * 1000); @@ -303,15 +348,19 @@ public void hideToastMessageInInteractiveFragment() { } - public void confirmationToastMessage() { + public void confirmationPressToastMessage() { tvToastMessage.setText(Html.fromHtml(getApplication().getString(R.string.confirmation_message), null, new MyTagHandler())); tvToastMessage.setVisibility(View.VISIBLE); } + public void customAlarmToastMessage(String customToastMessage) { + tvToastMessage.setText(customToastMessage); + tvToastMessage.setVisibility(View.VISIBLE); + } @Override public void onBackPressed() { super.onBackPressed(); - AppConstants.IS_BACK_BUTTON_PRESSED = true; + IS_BACK_BUTTON_PRESSED = true; } @@ -322,7 +371,7 @@ public void run() { String pageId = currentPage.getFailedId(); Intent i = new Intent(WizardActivity.this, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); finish(); } diff --git a/src/main/java/org/iilab/pb/WizardModalActivity.java b/app/src/main/java/org/iilab/pb/WizardModalActivity.java similarity index 100% rename from src/main/java/org/iilab/pb/WizardModalActivity.java rename to app/src/main/java/org/iilab/pb/WizardModalActivity.java diff --git a/src/main/java/org/iilab/pb/adapter/AppInfoAdapter.java b/app/src/main/java/org/iilab/pb/adapter/AppInfoAdapter.java similarity index 100% rename from src/main/java/org/iilab/pb/adapter/AppInfoAdapter.java rename to app/src/main/java/org/iilab/pb/adapter/AppInfoAdapter.java diff --git a/src/main/java/org/iilab/pb/adapter/PageActionAdapter.java b/app/src/main/java/org/iilab/pb/adapter/PageActionAdapter.java similarity index 76% rename from src/main/java/org/iilab/pb/adapter/PageActionAdapter.java rename to app/src/main/java/org/iilab/pb/adapter/PageActionAdapter.java index b88cd555..23424828 100644 --- a/src/main/java/org/iilab/pb/adapter/PageActionAdapter.java +++ b/app/src/main/java/org/iilab/pb/adapter/PageActionAdapter.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,16 +11,18 @@ import android.widget.Button; import android.widget.ImageView; - -import java.util.List; - import org.iilab.pb.CalculatorActivity; import org.iilab.pb.MainActivity; import org.iilab.pb.R; import org.iilab.pb.WizardActivity; import org.iilab.pb.common.AppConstants; +import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.model.PageAction; +import org.iilab.pb.trigger.HardwareTriggerService; +import java.util.List; + +import static org.iilab.pb.common.AppConstants.*; /** * Created by aoe on 1/5/14. @@ -30,6 +33,7 @@ public class PageActionAdapter extends ArrayAdapter { private boolean isPageStatusAvailable; private LayoutInflater mInflater; private int parentActivity; + private static final String TAG = PageActionAdapter.class.getName(); public PageActionAdapter(Context context, List actionList, boolean isPageStatusAvailable, int parentActivity) { super(context, R.layout.row_page_action); @@ -67,10 +71,10 @@ public View getView(final int position, View convertView, ViewGroup parent) { PageAction item = getItem(position); - if(isPageStatusAvailable){ + if (isPageStatusAvailable) { holder.bActionWithoutStatus.setVisibility(View.INVISIBLE); holder.bActionWithStatus.setVisibility(View.VISIBLE); - } else{ + } else { holder.bActionWithoutStatus.setVisibility(View.VISIBLE); holder.bActionWithStatus.setVisibility(View.INVISIBLE); } @@ -82,19 +86,34 @@ public View getView(final int position, View convertView, ViewGroup parent) { public void onClick(View v) { String pageId = getItem(position).getLink(); - if (pageId.equals("close")) { + if (pageId.equals(PAGE_CLOSE)) { // ApplicationSettings.setFirstRun(mContext, false); Intent i = new Intent(mContext, CalculatorActivity.class); // i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); mContext.startActivity(i); - ((MainActivity)mContext).callFinishActivityReceiver(); + ((MainActivity) mContext).callFinishActivityReceiver(); // ((Activity) mContext).overridePendingTransition(R.anim.show_from_bottom, R.anim.hide_to_top); - } else { + } + else if (pageId.equals(PAGE_CLOSE_TRAINING)){ + Log.d(TAG,"inside close training "); + Intent i = new Intent(mContext, MainActivity.class); + i.putExtra(PAGE_ID, PAGE_ADVANCED_SETTINGS); + mContext.startActivity(i); + int wizardState = ApplicationSettings.getWizardState(mContext.getApplicationContext()); + Log.e(TAG, "wizardState = " + wizardState); + if (wizardState == WIZARD_FLAG_HOME_READY && ApplicationSettings.isHardwareTriggerServiceEnabled(mContext)) { + //after the redo training exercise is done, we need to restart the hardware trigger service. + mContext.startService(new Intent(mContext, HardwareTriggerService.class)); + } + ((WizardActivity) mContext).callFinishActivityReceiver(); + } + else { Intent i = new Intent(mContext, WizardActivity.class); - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == AppConstants.FROM_WIZARD_ACTIVITY) { i = new Intent(mContext, WizardActivity.class); - } else{ + + } else { // AppUtil.showToast("Real alert deactivated.", 1000, mContext); // new PanicAlert(mContext).deActivate(); // if(pageId.equalsIgnoreCase("home-not-configured")) @@ -104,16 +123,16 @@ public void onClick(View v) { } // Intent i = new Intent(mContext, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); mContext.startActivity(i); - + } } }); if (item.getStatus() != null) { holder.bActionWithoutStatus.setEnabled(false); - if (item.getStatus().equals("checked")) { + if (item.getStatus().equals(PAGE_STATUS_CHECKED)) { holder.ivTick.setVisibility(View.VISIBLE); } else { // status = "disabled" holder.ivTick.setVisibility(View.INVISIBLE); @@ -124,7 +143,6 @@ public void onClick(View v) { } - holder.bActionWithStatus.setText(item.getTitle()); holder.bActionWithStatus.setOnClickListener(new View.OnClickListener() { @@ -132,7 +150,7 @@ public void onClick(View v) { public void onClick(View v) { String pageId = getItem(position).getLink(); - if (pageId.equals("close")) { + if (pageId.equals(PAGE_CLOSE)) { // ApplicationSettings.setFirstRun(mContext, false); Intent i = new Intent(mContext.getApplicationContext(), CalculatorActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); @@ -141,13 +159,13 @@ public void onClick(View v) { } else { Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == AppConstants.FROM_WIZARD_ACTIVITY) { i = new Intent(mContext, WizardActivity.class); - } else{ + } else { i = new Intent(mContext, MainActivity.class); } // Intent i = new Intent(mContext, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); mContext.startActivity(i); } } @@ -155,7 +173,7 @@ public void onClick(View v) { if (item.getStatus() != null) { holder.bActionWithStatus.setEnabled(false); - if (item.getStatus().equals("checked")) { + if (item.getStatus().equals(PAGE_STATUS_CHECKED)) { holder.ivTick.setVisibility(View.VISIBLE); } else { // status = "disabled" holder.ivTick.setVisibility(View.INVISIBLE); diff --git a/src/main/java/org/iilab/pb/adapter/PageActionFakeAdapter.java b/app/src/main/java/org/iilab/pb/adapter/PageActionFakeAdapter.java similarity index 100% rename from src/main/java/org/iilab/pb/adapter/PageActionFakeAdapter.java rename to app/src/main/java/org/iilab/pb/adapter/PageActionFakeAdapter.java diff --git a/src/main/java/org/iilab/pb/adapter/PageCheckListAdapter.java b/app/src/main/java/org/iilab/pb/adapter/PageCheckListAdapter.java similarity index 100% rename from src/main/java/org/iilab/pb/adapter/PageCheckListAdapter.java rename to app/src/main/java/org/iilab/pb/adapter/PageCheckListAdapter.java diff --git a/src/main/java/org/iilab/pb/adapter/PageItemAdapter.java b/app/src/main/java/org/iilab/pb/adapter/PageItemAdapter.java similarity index 100% rename from src/main/java/org/iilab/pb/adapter/PageItemAdapter.java rename to app/src/main/java/org/iilab/pb/adapter/PageItemAdapter.java diff --git a/app/src/main/java/org/iilab/pb/adapter/PageLanguageSettingsAdapter.java b/app/src/main/java/org/iilab/pb/adapter/PageLanguageSettingsAdapter.java new file mode 100644 index 00000000..9b15f7dd --- /dev/null +++ b/app/src/main/java/org/iilab/pb/adapter/PageLanguageSettingsAdapter.java @@ -0,0 +1,256 @@ +package org.iilab.pb.adapter; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.content.res.Resources; +import android.os.AsyncTask; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Toast; + +import org.iilab.pb.MainActivity; +import org.iilab.pb.R; +import org.iilab.pb.WizardActivity; +import org.iilab.pb.model.PageAction; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.List; +import java.util.Locale; + +import static org.iilab.pb.common.AppConstants.DEFAULT_CONFIRMATION_MESSAGE; +import static org.iilab.pb.common.AppConstants.FROM_WIZARD_ACTIVITY; +import static org.iilab.pb.common.AppConstants.JSON_ARRAY_DATA; +import static org.iilab.pb.common.AppConstants.JSON_EXTENSION; +import static org.iilab.pb.common.AppConstants.JSON_OBJECT_HELP; +import static org.iilab.pb.common.AppConstants.JSON_OBJECT_MOBILE; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED_ALARM; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED_DISGUISE; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PREFIX_HELP_DATA; +import static org.iilab.pb.common.AppConstants.PREFIX_MOBILE_DATA; +import static org.iilab.pb.common.AppConstants.VERSION; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY; +import static org.iilab.pb.common.AppUtil.insertMobileDataToLocalDB; +import static org.iilab.pb.common.AppUtil.isLanguageDataExists; +import static org.iilab.pb.common.AppUtil.loadJSONFromAsset; +import static org.iilab.pb.common.ApplicationSettings.addDBLoadedLanguage; +import static org.iilab.pb.common.ApplicationSettings.getLastUpdatedVersion; +import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage; +import static org.iilab.pb.common.ApplicationSettings.getWizardState; +import static org.iilab.pb.common.ApplicationSettings.isAppUpdated; +import static org.iilab.pb.common.ApplicationSettings.setSelectedLanguage; + + +/** + * Created by aoe on 2/25/14. + */ +public class PageLanguageSettingsAdapter extends ArrayAdapter { + + private Context mContext; + private LayoutInflater mInflater; + private ProgressDialog pDialog; + private String currentLang; + private String selectedLang; + private int lastUpdatedVersion; + private int latestVersion; + private int parentActivity; + private static final String TAG = PageLanguageSettingsAdapter.class.getName(); + + + public PageLanguageSettingsAdapter(Context context, int parentActivity) { + + super(context, R.layout.row_page_language_settings); + this.mContext = context; + mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.currentLang = getSelectedLanguage(mContext); + latestVersion = -1; + lastUpdatedVersion = getLastUpdatedVersion(mContext); + this.parentActivity = parentActivity; + } + + private static class ViewHolder { + Button bAction; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + ViewHolder holder; + if (convertView == null) { + convertView = mInflater.inflate(R.layout.row_page_language_settings, null); + holder = new ViewHolder(); + holder.bAction = (Button) convertView.findViewById(R.id.b_action); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + final PageAction item = getItem(position); + holder.bAction.setText(item.getTitle()); + holder.bAction.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + String url = null; + selectedLang = item.getLanguage(); + + if (currentLang.equals(selectedLang)) { + Toast.makeText(mContext,"Language already applied.", Toast.LENGTH_SHORT); + + /* why we need to restart app here? + we are finishing this fragment & activity just below, so it will go to previous activity's onResume. + As we are not handling the scenario explicitly in Main/Wizard activity's onResume method that what will happen + when we return from language-fragment, we do a restart app so that the flow will go to home-ready page automatically after the restart. + */ + restartApp(); + + ((Activity) mContext).finish(); + return; + } +// else if (!AppUtil.hasInternet(mContext)) { +// changeStaticLanguageSettings(((item.getConfirmation() == null) ? DEFAULT_CONFIRMATION_MESSAGE : item.getConfirmation())); +// return; +// } + changeStaticLanguageSettings(((item.getConfirmation() == null) ? DEFAULT_CONFIRMATION_MESSAGE : item.getConfirmation())); +// new GetLatestVersion(((item.getConfirmation() == null) ? DEFAULT_CONFIRMATION_MESSAGE : item.getConfirmation())).execute(); + + } + }); + + return convertView; + } + + public void restartApp() { + + int wizardState = getWizardState(mContext); + String pageId = null; + if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED) { + pageId = PAGE_HOME_NOT_CONFIGURED; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM) { + pageId = PAGE_HOME_NOT_CONFIGURED_ALARM; + } else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE) { + pageId = PAGE_HOME_NOT_CONFIGURED_DISGUISE; + } else if (wizardState == WIZARD_FLAG_HOME_READY) { + pageId = PAGE_HOME_READY; + } + Log.d(TAG, "restarting app with pageId = " + pageId); + + if (parentActivity == FROM_WIZARD_ACTIVITY) { + Intent i = new Intent(mContext, WizardActivity.class); + i.putExtra(PAGE_ID, pageId); + mContext.startActivity(i); + + ((WizardActivity) mContext).callFinishActivityReceiver(); + } else { + Intent i = new Intent(mContext, MainActivity.class); + i.putExtra(PAGE_ID, pageId); + mContext.startActivity(i); + + ((MainActivity) mContext).callFinishActivityReceiver(); + } + + ((Activity) mContext).finish(); + } + + public void setData(List actionList) { + clear(); + if (actionList != null) { + for (int i = 0; i < actionList.size(); i++) { + add(actionList.get(i)); + } + } + } + + private void changeStaticLanguageSettings(String confirmation) { + Toast.makeText(mContext, confirmation, Toast.LENGTH_SHORT).show(); + setSelectedLanguage(mContext, selectedLang); + + Resources res = mContext.getResources(); + DisplayMetrics dm = res.getDisplayMetrics(); + android.content.res.Configuration conf = res.getConfiguration(); + + loadLanguageData(selectedLang); + + conf.locale = new Locale(selectedLang); + res.updateConfiguration(conf, dm); + } + + + private void loadLanguageData(String language) { + //Only load language data if it doesn't exists locally + if (!isLanguageDataExists(mContext, language)|| isAppUpdated(mContext) ) { + new LoadLanguageData().execute(); + addDBLoadedLanguage(mContext, language); + } else { + restartApp(); + } + } + + private class LoadLanguageData extends AsyncTask { + int lastUpdatedVersion; + + @Override + protected void onPreExecute() { + + pDialog = ProgressDialog.show(mContext, "Application", "Loading...", true, false); + } + + @Override + protected Boolean doInBackground(Void... params) { + Log.i(TAG, "starting loading of json files in background thread"); + String dataFileName = PREFIX_MOBILE_DATA + selectedLang + JSON_EXTENSION; + String helpFileName = PREFIX_HELP_DATA + selectedLang + JSON_EXTENSION; + Log.d(TAG, "selected language is " + getSelectedLanguage(mContext)); + Log.d(TAG, "Loading mobile data "); + try { + JSONObject jsonObj = new JSONObject(loadJSONFromAsset(dataFileName, mContext)); + JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_MOBILE); + lastUpdatedVersion = mobileObj.getInt(VERSION); + JSONArray dataArray = mobileObj.getJSONArray(JSON_ARRAY_DATA); + insertMobileDataToLocalDB(dataArray, mContext); + } catch (JSONException jsonException) { + Log.e(TAG, "Exception in reading" + dataFileName + " from asset" + jsonException.getMessage()); + jsonException.printStackTrace(); + } + + try { + Log.d(TAG, "Loading help data "); + JSONObject jsonObj = new JSONObject(loadJSONFromAsset(helpFileName, mContext)); + JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_HELP); + + JSONArray dataArray = mobileObj.getJSONArray(JSON_ARRAY_DATA); + insertMobileDataToLocalDB(dataArray, mContext); + } catch (JSONException jsonException) { + Log.e(TAG, "Exception in reading " + helpFileName + " from asset" + jsonException.getMessage()); + jsonException.printStackTrace(); + } + return true; + } + + @Override + protected void onPostExecute(Boolean response) { + super.onPostExecute(response); + if (pDialog.isShowing()) + try { + pDialog.dismiss(); + } catch (Exception e) { + Log.e(TAG, "Exception while dismissing progress dialog " + e.getMessage()); + e.printStackTrace(); + } + restartApp(); + + } + } +} diff --git a/src/main/java/org/iilab/pb/alert/AlarmReceiver.java b/app/src/main/java/org/iilab/pb/alert/AlarmReceiver.java similarity index 100% rename from src/main/java/org/iilab/pb/alert/AlarmReceiver.java rename to app/src/main/java/org/iilab/pb/alert/AlarmReceiver.java diff --git a/src/main/java/org/iilab/pb/alert/AlertStatus.java b/app/src/main/java/org/iilab/pb/alert/AlertStatus.java similarity index 100% rename from src/main/java/org/iilab/pb/alert/AlertStatus.java rename to app/src/main/java/org/iilab/pb/alert/AlertStatus.java diff --git a/src/main/java/org/iilab/pb/alert/PanicAlert.java b/app/src/main/java/org/iilab/pb/alert/PanicAlert.java similarity index 65% rename from src/main/java/org/iilab/pb/alert/PanicAlert.java rename to app/src/main/java/org/iilab/pb/alert/PanicAlert.java index 37ce7b7e..beca46d0 100644 --- a/src/main/java/org/iilab/pb/alert/PanicAlert.java +++ b/app/src/main/java/org/iilab/pb/alert/PanicAlert.java @@ -1,47 +1,58 @@ package org.iilab.pb.alert; -import android.app.ActivityManager; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.location.Location; import android.location.LocationManager; -import android.os.Build; import android.os.SystemClock; -import android.os.Vibrator; -import android.telephony.TelephonyManager; import android.util.Log; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.AppUtil; -import org.iilab.pb.common.ApplicationSettings; + import org.iilab.pb.common.Intents; import org.iilab.pb.location.CurrentLocationProvider; -import java.util.Iterator; -import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import static android.location.LocationManager.GPS_PROVIDER; import static android.location.LocationManager.NETWORK_PROVIDER; +import static org.iilab.pb.common.AppConstants.GPS_MIN_DISTANCE; +import static org.iilab.pb.common.AppConstants.GPS_MIN_TIME; +import static org.iilab.pb.common.AppConstants.GPS_MIN_TIME_IN_FIRST_ONE_MINUTE; +import static org.iilab.pb.common.AppConstants.NETWORK_MIN_DISTANCE; +import static org.iilab.pb.common.AppConstants.NETWORK_MIN_TIME; +import static org.iilab.pb.common.AppConstants.NETWORK_MIN_TIME_IN_FIRST_ONE_MINUTE; +import static org.iilab.pb.common.AppConstants.ONE_MINUTE; +import static org.iilab.pb.common.AppUtil.close; +import static org.iilab.pb.common.AppUtil.vibrateForConfirmationOfAlertTriggered; +import static org.iilab.pb.common.ApplicationSettings.getAlertDelay; +import static org.iilab.pb.common.ApplicationSettings.isAlertActive; +import static org.iilab.pb.common.ApplicationSettings.isFirstMsgWithLocationTriggered; +import static org.iilab.pb.common.ApplicationSettings.setAlertActive; +import static org.iilab.pb.common.ApplicationSettings.setFirstMsgSent; +import static org.iilab.pb.common.ApplicationSettings.setFirstMsgWithLocationTriggered; import static org.iilab.pb.common.Intents.locationPendingIntent; public class PanicAlert { + private static final String TAG = PanicAlert.class.getName(); private LocationManager locationManager; private Context context; private AlarmManager alarmManager1, alarmManager2; + public PanicAlert(Context context) { this.context = context; locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); alarmManager1 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager2 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + } public void activate() { - AppUtil.close(context); - vibrateOnce(); + close(context); + + vibrateForConfirmationOfAlertTriggered(context); if (isActive() // || ApplicationSettings.isRestartedSetup(context) @@ -49,7 +60,7 @@ public void activate() { return; } - ApplicationSettings.setAlertActive(context, true); + setAlertActive(context, true); getExecutorService().execute( new Runnable() { @Override @@ -60,34 +71,33 @@ public void run() { ); } - private void vibrateOnce() { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - vibrator.vibrate(AppConstants.ALERT_CONFIRMATION_VIBRATION_DURATION); - } + private void activateAlert() { - ApplicationSettings.setAlertActive(context, true); + setAlertActive(context, true); sendFirstAlert(); registerLocationUpdate(); scheduleFutureAlert(); } public void deActivate() { - Log.e("", "Deactivating???"); - ApplicationSettings.setAlertActive(context, false); + Log.d(TAG, "Deactivating the triggered alert"); + setAlertActive(context, false); locationManager.removeUpdates(locationPendingIntent(context)); alarmManager2.cancel(Intents.alarmPendingIntent(context)); - ApplicationSettings.setFirstMsgWithLocationTriggered(context, false); - ApplicationSettings.setFirstMsgSent(context, false); + setFirstMsgWithLocationTriggered(context, false); + setFirstMsgSent(context, false); } private void sendFirstAlert() { + Log.d(TAG, "inside of sendFirstAlert"); CurrentLocationProvider currentLocationProvider = getCurrentLocationProvider(); Location loc = getLocation(currentLocationProvider); - if(loc != null) { - ApplicationSettings.setFirstMsgWithLocationTriggered(context, true); + Log.d(TAG, "Identified location is "+loc); + if (loc != null) { + setFirstMsgWithLocationTriggered(context, true); } else { -// ApplicationSettings.setFirstMsgWithLocationTriggered(context, false); +// setFirstMsgWithLocationTriggered(context, false); scheduleFirstLocationAlert(); } createPanicMessage().sendAlertMessage(loc); @@ -103,27 +113,27 @@ CurrentLocationProvider getCurrentLocationProvider() { private void scheduleFirstLocationAlert() { PendingIntent alarmPendingIntent = Intents.singleAlarmPendingIntent(context); - long firstTimeTriggerAt = SystemClock.elapsedRealtime() + AppConstants.ONE_MINUTE * 1; // we schedule this alarm after 1 minute + long firstTimeTriggerAt = SystemClock.elapsedRealtime() + ONE_MINUTE * 1; // we schedule this alarm after 1 minute alarmManager1.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTimeTriggerAt, alarmPendingIntent); // alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTimeTriggerAt, interval, alarmPendingIntent); } private void scheduleFutureAlert() { PendingIntent alarmPendingIntent = Intents.alarmPendingIntent(context); - long firstTimeTriggerAt = SystemClock.elapsedRealtime() + AppConstants.ONE_MINUTE * ApplicationSettings.getAlertDelay(context); - long interval = AppConstants.ONE_MINUTE * ApplicationSettings.getAlertDelay(context); + long firstTimeTriggerAt = SystemClock.elapsedRealtime() + ONE_MINUTE * getAlertDelay(context); + long interval = ONE_MINUTE * getAlertDelay(context); alarmManager2.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTimeTriggerAt, interval, alarmPendingIntent); } private void registerLocationUpdate() { // if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) -// locationManager.requestLocationUpdates(GPS_PROVIDER, AppConstants.GPS_MIN_TIME_IN_FIRST_ONE_MINUTE, AppConstants.GPS_MIN_DISTANCE, locationPendingIntent(context)); +// locationManager.requestLocationUpdates(GPS_PROVIDER, GPS_MIN_TIME_IN_FIRST_ONE_MINUTE, GPS_MIN_DISTANCE, locationPendingIntent(context)); // if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) -// locationManager.requestLocationUpdates(NETWORK_PROVIDER, AppConstants.NETWORK_MIN_TIME_IN_FIRST_ONE_MINUTE, AppConstants.NETWORK_MIN_DISTANCE, locationPendingIntent(context)); +// locationManager.requestLocationUpdates(NETWORK_PROVIDER, NETWORK_MIN_TIME_IN_FIRST_ONE_MINUTE, NETWORK_MIN_DISTANCE, locationPendingIntent(context)); // int threadRunCount = 0; - while(!ApplicationSettings.isFirstMsgWithLocationTriggered(context) && threadRunCount < 4){ + while (!isFirstMsgWithLocationTriggered(context) && threadRunCount < 4) { try { Thread.sleep(20000); threadRunCount++; @@ -132,11 +142,15 @@ private void registerLocationUpdate() { locationManager.removeUpdates(locationPendingIntent(context)); } if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) - locationManager.requestLocationUpdates(GPS_PROVIDER, AppConstants.GPS_MIN_TIME_IN_FIRST_ONE_MINUTE, AppConstants.GPS_MIN_DISTANCE, locationPendingIntent(context)); + locationManager.requestLocationUpdates(GPS_PROVIDER, GPS_MIN_TIME_IN_FIRST_ONE_MINUTE, GPS_MIN_DISTANCE, locationPendingIntent(context)); if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) - locationManager.requestLocationUpdates(NETWORK_PROVIDER, AppConstants.NETWORK_MIN_TIME_IN_FIRST_ONE_MINUTE, AppConstants.NETWORK_MIN_DISTANCE, locationPendingIntent(context)); - Log.e(">>>>>>>>", "threadRunCount = " + threadRunCount); + locationManager.requestLocationUpdates(NETWORK_PROVIDER, NETWORK_MIN_TIME_IN_FIRST_ONE_MINUTE, NETWORK_MIN_DISTANCE, locationPendingIntent(context)); + Log.d(TAG, "threadRunCount = " + threadRunCount); + } catch (SecurityException e) { + Log.e(TAG, "SecurityException exception " + e.getMessage()); + e.printStackTrace(); } catch (InterruptedException e) { + Log.e(TAG, "SecurityException exception " + e.getMessage()); e.printStackTrace(); } } @@ -144,11 +158,15 @@ private void registerLocationUpdate() { if (locationManager != null && locationPendingIntent(context) != null) { locationManager.removeUpdates(locationPendingIntent(context)); } - if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) - locationManager.requestLocationUpdates(GPS_PROVIDER, AppConstants.GPS_MIN_TIME, AppConstants.GPS_MIN_DISTANCE, locationPendingIntent(context)); - if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) - locationManager.requestLocationUpdates(NETWORK_PROVIDER, AppConstants.NETWORK_MIN_TIME, AppConstants.NETWORK_MIN_DISTANCE, locationPendingIntent(context)); - + try { + if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) + locationManager.requestLocationUpdates(GPS_PROVIDER, GPS_MIN_TIME, GPS_MIN_DISTANCE, locationPendingIntent(context)); + if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) + locationManager.requestLocationUpdates(NETWORK_PROVIDER, NETWORK_MIN_TIME, NETWORK_MIN_DISTANCE, locationPendingIntent(context)); + } catch (SecurityException e) { + Log.e(TAG, "SecurityException exception " + e.getMessage()); + e.printStackTrace(); + } // HomeActivity.runOnUiThread(new Runnable() { // @Override // public void run() { @@ -160,24 +178,23 @@ private void registerLocationUpdate() { // locationManager.removeUpdates(locationPendingIntent(context)); // } // if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) -// locationManager.requestLocationUpdates(GPS_PROVIDER, AppConstants.GPS_MIN_TIME, AppConstants.GPS_MIN_DISTANCE, locationPendingIntent(context)); +// locationManager.requestLocationUpdates(GPS_PROVIDER, GPS_MIN_TIME, GPS_MIN_DISTANCE, locationPendingIntent(context)); // if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) -// locationManager.requestLocationUpdates(NETWORK_PROVIDER, AppConstants.NETWORK_MIN_TIME, AppConstants.NETWORK_MIN_DISTANCE, locationPendingIntent(context)); +// locationManager.requestLocationUpdates(NETWORK_PROVIDER, NETWORK_MIN_TIME, NETWORK_MIN_DISTANCE, locationPendingIntent(context)); // } // }, 60 * 1000); // after 1 minute // } // }); - } + } public boolean isActive() { - return ApplicationSettings.isAlertActive(context); + return isAlertActive(context); } - public void vibrate() { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - vibrator.vibrate(AppConstants.HAPTIC_FEEDBACK_DURATION); - } + + + private Location getLocation(CurrentLocationProvider currentLocationProvider) { Location location = null; diff --git a/src/main/java/org/iilab/pb/alert/PanicMessage.java b/app/src/main/java/org/iilab/pb/alert/PanicMessage.java similarity index 91% rename from src/main/java/org/iilab/pb/alert/PanicMessage.java rename to app/src/main/java/org/iilab/pb/alert/PanicMessage.java index 791cf5fd..e7ae04a1 100644 --- a/src/main/java/org/iilab/pb/alert/PanicMessage.java +++ b/app/src/main/java/org/iilab/pb/alert/PanicMessage.java @@ -2,6 +2,7 @@ import android.content.Context; import android.location.Location; +import android.util.Log; import org.iilab.pb.R; import org.iilab.pb.common.ApplicationSettings; @@ -13,7 +14,7 @@ import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS; public class PanicMessage { -// public static final int TWITTER_MAX_LENGTH = 140; + private static final String TAG= PanicMessage.class.getName(); private Context context; private Location location; @@ -33,8 +34,8 @@ public void sendAlertMessage(Location location) { } public void sendStopAlertMessage() { - String message = context.getResources().getString(R.string.stop_alert_message); - + String message = SMSSettings.retrieveStopAlertMessage(context); + Log.d(TAG, "Stop Alert message is " + message); sendMessage(message, getPhoneNumbers()); } diff --git a/src/main/java/org/iilab/pb/alert/SMSAdapter.java b/app/src/main/java/org/iilab/pb/alert/SMSAdapter.java similarity index 70% rename from src/main/java/org/iilab/pb/alert/SMSAdapter.java rename to app/src/main/java/org/iilab/pb/alert/SMSAdapter.java index 32bb3d12..671ca316 100644 --- a/src/main/java/org/iilab/pb/alert/SMSAdapter.java +++ b/app/src/main/java/org/iilab/pb/alert/SMSAdapter.java @@ -7,19 +7,20 @@ import org.iilab.pb.common.ApplicationSettings; public class SMSAdapter { - private static final String LOG_TAG = SMSAdapter.class.getName(); + private static final String TAG = SMSAdapter.class.getName(); public void sendSMS(Context context, String phoneNumber, String message) { -// Log.e("20140411", "sending fake SMS -> " + message); if(!ApplicationSettings.isFirstMsgSent(context)){ ApplicationSettings.setFirstMsgSent(context, true); } SmsManager smsManager = getSmsManager(); + Log.d(TAG, "Sms manager is : " + getSmsManager()); try { smsManager.sendTextMessage(phoneNumber, null, message, null, null); - Log.i(LOG_TAG, "Sms sent: " + message); + Log.d(TAG, "Sms sent: " + message); } catch (Exception exception) { - Log.e(LOG_TAG, "Sending SMS failed " + exception.getMessage()); + exception.printStackTrace(); + Log.e(TAG, "Sending SMS failed " + exception.getMessage()); } } diff --git a/src/main/java/org/iilab/pb/calculator/Calculator.java b/app/src/main/java/org/iilab/pb/calculator/Calculator.java similarity index 100% rename from src/main/java/org/iilab/pb/calculator/Calculator.java rename to app/src/main/java/org/iilab/pb/calculator/Calculator.java diff --git a/src/main/java/org/iilab/pb/calculator/CalculatorImpl.java b/app/src/main/java/org/iilab/pb/calculator/CalculatorImpl.java similarity index 100% rename from src/main/java/org/iilab/pb/calculator/CalculatorImpl.java rename to app/src/main/java/org/iilab/pb/calculator/CalculatorImpl.java diff --git a/app/src/main/java/org/iilab/pb/common/AppConstants.java b/app/src/main/java/org/iilab/pb/common/AppConstants.java new file mode 100644 index 00000000..ef5f4241 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/common/AppConstants.java @@ -0,0 +1,143 @@ +package org.iilab.pb.common; + +public class AppConstants { + //Test values + public static final boolean SKIP_WIZARD = false; + //public static final int PHONE_NUMBER_LIMIT = 3; + + //Prod values + //public static final boolean SKIP_WIZARD = false; + public static final int PHONE_NUMBER_LIMIT = 3; + public static final long ONE_MINUTE = 1000 * 60; + public static final int ONE_SECOND = 1000 ; + + public static final String DEFAULT_HAPTIC_FEEDBACK_DURATION = "2"; + public static final int ALERT_CONFIRMATION_VIBRATION_DURATION = 500; + + public static final int DEFAULT_ALARM_INTERVAL = 5; // in minute + + public static final float GPS_MIN_DISTANCE = 0; + public static final long GPS_MIN_TIME_IN_FIRST_ONE_MINUTE = 1000 * 20; + public static final long GPS_MIN_TIME = 1000 * 60 * 2; + + public static final float NETWORK_MIN_DISTANCE = 0; + public static final long NETWORK_MIN_TIME_IN_FIRST_ONE_MINUTE = 1000 * 20; + public static final long NETWORK_MIN_TIME = 1000 * 60 * 2; + + public static final int WARNING_TRAINING_MESSAGE_MINIMUM_CHARACTER = 30; + + public static final int WIZARD_FLAG_HOME_NOT_CONFIGURED = 601; + public static final int WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM = 602; + public static final int WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE = 603; + public static final int WIZARD_FLAG_HOME_READY = 604; + + public static boolean IS_BACK_BUTTON_PRESSED = false; + public static boolean PAGE_FROM_NOT_IMPLEMENTED = false; + + public static final int FROM_WIZARD_ACTIVITY = 1; + public static final int FROM_MAIN_ACTIVITY = 2; + + public static final double IMAGE_SCALABILITY_FACTOR = 0.5; + + public static final String TABLE_PRIMARY_KEY = "_id"; + +// public static final String BASE_URL = "https://panicbutton.io"; +// public static final String HELP_DATA_URL = "/api/help.json"; +// public static final String VERSION_CHECK_URL = "/api/version.json"; + + public static final int DATABASE_VERSION = 17; + + public static final String DEFAULT_CONFIRMATION_MESSAGE = "Settings saved"; + + public static final int SPLASH_DELAY_TIME = 200; + + public static final int IMAGE_DOWNLOAD_TIMEOUT_MS = 3000; + + public static final int IMAGE_FULL_WIDTH = 1; + public static final int IMAGE_INLINE = 2; + + //added a constant for changing the disguise screen unlock time from 5 sec to 3 sec + public static final int DISGUISE_UNLOCK_LONGPRESS_TIME = 1800; + + public static final String PARENT_ACTIVITY = "parent_activity"; + public static final String PAGE_ID = "page_id"; + + public static final String COLOR_RED="red"; + public static final String PAGE_HOME_READY = "home-ready"; + public static final String PAGE_HOME_ALERTING = "home-alerting"; + public static final String PAGE_CLOSE = "close"; + public static final String PAGE_HOME_NOT_CONFIGURED = "home-not-configured"; + public static final String PAGE_HOME_NOT_CONFIGURED_ALARM = "home-not-configured-alarm"; + public static final String PAGE_HOME_NOT_CONFIGURED_DISGUISE = "home-not-configured-disguise"; + public static final String PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS = "setup-alarm-test-hardware-success"; + public static final String PAGE_SETUP_ALARM_TEST_DISGUISE_SUCCESS = "setup-alarm-test-disguise-success"; + public static final String PAGE_SETUP_ALARM_RETRAINING = "setup-alarm-reTraining"; + public static final String PAGE_CLOSE_TRAINING = "close-training"; + public static final String PAGE_SETUP_ALARM_TEST_HARDWARE = "setup-alarm-test-hardware"; + public static final String PAGE_SETUP_ALARM_TEST_HARDWARE_RETRAINING = "setup-alarm-test-hardware-reTraining"; + public static final String PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_RETRAINING = "setup-alarm-test-hardware-success-reTraining"; + public static final String PAGE_SETUP_TRAINING_1_5 = "setup-training_1.5"; + public static final String PAGE_SETUP_ALARM_TEST_HARDWARE_TRAINING_1_5 = "setup-alarm-test-hardware-training_1_5"; + public static final String PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_TRAINING_1_5 = "setup-alarm-test-hardware-success-training_1_5"; + + public static final String PAGE_STATUS_CHECKED = "checked"; + + public static final String DEFAULT_LANGUAGE_ENG = "en"; + public static final String PAGE_SETUP_LANGUAGE = "setup-language"; + public static final String JSON_EXTENSION=".json"; + + public static final String JSON_OBJECT_MOBILE = "mobile"; + public static final String JSON_ARRAY_DATA = "data"; + public static final String JSON_OBJECT_HELP = "help"; + public static final String VERSION = "version"; + public static final String PREFIX_MOBILE_DATA = "mobile_"; + public static final String PREFIX_HELP_DATA = "help_"; + public static final String DELIMITER_COMMA=","; + + + public static final String PAGE_TYPE_SIMPLE = "simple"; + public static final String PAGE_TYPE_WARNING = "warning"; + public static final String PAGE_TYPE_MODAL = "modal"; + public static final String PAGE_COMPONENT_CONTACTS = "contacts"; + public static final String PAGE_COMPONENT_MESSAGE = "message"; + public static final String PAGE_COMPONENT_CODE = "code"; + public static final String PAGE_COMPONENT_ALERT = "alert"; + public static final String PAGE_COMPONENT_LANGUAGE = "language"; + public static final String PAGE_COMPONENT_ADVANCED_SETTINGS = "advanced"; + public static final String PAGE_COMPONENT_ALARM_TEST_HARDWARE = "alarm-test-hardware"; + public static final String PAGE_COMPONENT_ALARM_TEST_DISGUISE = "alarm-test-disguise"; + public static final String PAGE_COMPONENT_DISGUISE_TEST_OPEN = "disguise-test-open"; + public static final String PAGE_COMPONENT_DISGUISE_TEST_UNLOCK = "disguise-test-unlock"; + public static final String PAGE_COMPONENT_DISGUISE_TEST_CODE = "disguise-test-code"; + public static final String PAGE_ADVANCED_SETTINGS = "settings-advanced"; + public static final String PAGE_SETTINGS = "settings"; + + public static final String ALARM_SENDING_CONFIRMATION_PATTERN_LONG = "1"; + public static final String ALARM_SENDING_CONFIRMATION_PATTERN_REPEATED_SHORT = "2"; + public static final String ALARM_SENDING_CONFIRMATION_PATTERN_THREESHORT_PAUSE_THREESHORT = "3"; + // Three short - Three long - Three short + public static final String ALARM_SENDING_CONFIRMATION_PATTERN_SOS = "4"; + public static final String ALARM_SENDING_CONFIRMATION_PATTERN_NONE = "5"; + public static final String ALARM_NOT_CONFIRMED_THREE_FAST = "2"; + + public static final int FRESH_INSTALL_APP_RELEASE_NO = -1; + public static final int APP_RELEASE_VERSION_1_5 = 10; + + public static final int VIBRATION_DURATION_SHORT = 400; + public static final int VIBRATION_PAUSE_SHORT = 200; + public static final int VIBRATION_DURATION_LONG = 600; + public static final int VIBRATION_PAUSE_LONG = 400; + public static final int VIBRATION_PAUSE_VERY_LONG = 1000; + + public static final String ALARM_5_REPEATED_CLICKS = "5"; + public static final String ALARM_7_REPEATED_CLICKS = "7"; + public static final String ALARM_CONFIRMATION_REQUIRED = "2"; + public static final String ALARM_CONFIRMATION_NOT_REQUIRED = "1"; + + public static final String DEFAULT_7_REPEATED_PRESS = "7PRESS"; + public static final String ALARM_5_PRESS_PLUS_CONFIRMATION = "5PRESS_PLUS_CONFIRMATION"; + public static final String ALARM_CUSTOM = "CUSTOM"; + + +} + diff --git a/src/main/java/org/iilab/pb/common/AppUtil.java b/app/src/main/java/org/iilab/pb/common/AppUtil.java similarity index 52% rename from src/main/java/org/iilab/pb/common/AppUtil.java rename to app/src/main/java/org/iilab/pb/common/AppUtil.java index afe54581..cf4a7bb9 100644 --- a/src/main/java/org/iilab/pb/common/AppUtil.java +++ b/app/src/main/java/org/iilab/pb/common/AppUtil.java @@ -1,10 +1,12 @@ package org.iilab.pb.common; + import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.drawable.Drawable; +import android.os.Vibrator; import android.text.Html; import android.text.Spanned; import android.util.DisplayMetrics; @@ -13,15 +15,39 @@ import android.view.ViewGroup; import android.widget.EditText; import android.widget.TextView; -import android.widget.Toast; + +import org.iilab.pb.R; +import org.iilab.pb.data.PBDatabase; +import org.iilab.pb.model.Page; +import org.json.JSONArray; import java.io.IOException; +import java.io.InputStream; import java.util.Calendar; import java.util.HashMap; import java.util.List; -public class AppUtil { +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_LONG; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_REPEATED_SHORT; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_SOS; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_THREESHORT_PAUSE_THREESHORT; +import static org.iilab.pb.common.AppConstants.ALERT_CONFIRMATION_VIBRATION_DURATION; +import static org.iilab.pb.common.AppConstants.APP_RELEASE_VERSION_1_5; +import static org.iilab.pb.common.AppConstants.ONE_SECOND; +import static org.iilab.pb.common.AppConstants.VIBRATION_DURATION_LONG; +import static org.iilab.pb.common.AppConstants.VIBRATION_DURATION_SHORT; +import static org.iilab.pb.common.AppConstants.VIBRATION_PAUSE_LONG; +import static org.iilab.pb.common.AppConstants.VIBRATION_PAUSE_SHORT; +import static org.iilab.pb.common.AppConstants.VIBRATION_PAUSE_VERY_LONG; +import static org.iilab.pb.common.ApplicationSettings.getDBLoadedLanguages; +import static org.iilab.pb.common.ApplicationSettings.getInitialClicksForAlertTrigger; +import static org.iilab.pb.common.ApplicationSettings.getLastUpdatedVersion; +import static org.iilab.pb.common.ApplicationSettings.isAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.isFirstRun; +import static org.iilab.pb.common.ApplicationSettings.isTrainingDoneRelease1_5; +public class AppUtil { + private static final String TAG = AppUtil.class.getName(); public static HashMap mImageCache = new HashMap(); public static void setError(Context context, EditText editText, int messageId) { @@ -99,11 +125,11 @@ public static Boolean isToday(long millis) { public static Drawable setDownloadedImageMetrices(Drawable drawable, DisplayMetrics metrics, double densityRatio, int imageScaleFlag) { - Log.e("AppUtil -> setDownloadedImageMetrices", "density ratio = " + densityRatio + " and metrics =" + metrics); + Log.d(TAG," setDownloadedImageMetrices"+ "density ratio = " + densityRatio + " and metrics =" + metrics); int width, height; int originalWidthScaled = (int) (drawable.getIntrinsicWidth()* metrics.density * densityRatio); - int originalHeightScaled = (int) (drawable.getIntrinsicHeight()* metrics.density * densityRatio); - Log.e("AppUtil -> setDownloadedImageMetrices", "originalWidthScaled = " + originalWidthScaled + " and originalHeightScaled = " + originalHeightScaled); + int originalHeightScaled = (int) (drawable.getIntrinsicHeight() * metrics.density * densityRatio); + Log.d(TAG," setDownloadedImageMetrices"+ "originalWidthScaled = " + originalWidthScaled + " and originalHeightScaled = " + originalHeightScaled); if (imageScaleFlag == AppConstants.IMAGE_FULL_WIDTH) { height = drawable.getIntrinsicHeight() * metrics.widthPixels / drawable.getIntrinsicWidth(); @@ -118,10 +144,10 @@ public static Drawable setDownloadedImageMetrices(Drawable drawable, width = originalWidthScaled; } } - Log.e("AppUtil -> setDownloadedImageMetrices", "final width = " + width + " and height = " + height); + Log.e(TAG," setDownloadedImageMetrices"+ "final width = " + width + " and height = " + height); try { drawable.setBounds(0, 0, width, height); - Log.e(">>>>>>>>>>>>>>", "image width = " + width + " & height = "+ height); + Log.e(TAG, "image width = " + width + " & height = "+ height); } catch (Exception ex) { } @@ -159,16 +185,6 @@ public static Intent behaveAsHomeButton(){ return i; } - /*-----This method show Toast.-----*/ - public static void showToast(String message, int time,Context context) { - Toast.makeText(context, message, time).show(); - } - - - - - - public static void updateImages(final boolean downloadImages, final String textHtml, final Context context, final DisplayMetrics metrics, final TextView tvContent, final int imageScaleFlag) { if (textHtml == null) return; @@ -181,7 +197,7 @@ public Drawable getDrawable(final String source) { // !AppUtil.hasInternet(context) && downloadImages){ try { - Log.e(">>>>>>>>>>>", "Source = " + source); + Log.d(TAG, "Source = " + source); Drawable drawable = Drawable.createFromStream(context.getAssets().open(source.substring(1, source.length())), null); drawable = AppUtil.setDownloadedImageMetrices(drawable, metrics, AppConstants.IMAGE_SCALABILITY_FACTOR * metrics.scaledDensity, imageScaleFlag); @@ -189,7 +205,7 @@ public Drawable getDrawable(final String source) { updateImages(false, textHtml, context, metrics, tvContent, imageScaleFlag); return drawable; } catch (IOException e) { - Log.e(">>>>>>>>>>>>>>","Failed to load image from asset"); + Log.e(TAG,"Failed to load image from asset"); e.printStackTrace(); } return null; @@ -249,5 +265,134 @@ public Drawable getDrawable(final String source) { tvContent.setText(spanned); } + public static void insertMobileDataToLocalDB(JSONArray dataArray,Context context) { + Log.d(TAG,"inserting mobile data to local DB"); + List pageList = Page.parsePages(dataArray); + PBDatabase dbInstance = new PBDatabase(context); + dbInstance.open(); + + for (int indexPage = 0; indexPage < pageList.size(); indexPage++) { + dbInstance.insertOrUpdatePage(pageList.get(indexPage)); + } + dbInstance.close(); + } + + public static String loadJSONFromAsset(String jsonFileName ,Context context) { + Log.d(TAG,"loading JSON from asset"); + String json = null; + try { + InputStream is = context.getAssets().open(jsonFileName); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + json = new String(buffer, "UTF-8"); + } catch (IOException ioException) { + Log.e(TAG, "Exception while loading json file" + ioException.getMessage()); + ioException.printStackTrace(); + return null; + } + return json; + } + + public static boolean isLanguageDataExists(Context context, String lang){ + return (getDBLoadedLanguages(context).contains(lang)); + } + + + public static void vibrateForConfirmationOfAlertTriggered(Context context) { + String confirmationFeedbackPattern = ApplicationSettings.getConfirmationFeedbackVibrationPattern(context); + + Log.d(TAG, "confirmation feedback pattern 1-Long, 2-Repeated short, 3-Three short pause three short, 4-SOS, 5-None " + confirmationFeedbackPattern); + Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + + if (ALARM_SENDING_CONFIRMATION_PATTERN_LONG.equals(confirmationFeedbackPattern)) { + vibrateContinusly(vibrator, ALERT_CONFIRMATION_VIBRATION_DURATION); + } else if (ALARM_SENDING_CONFIRMATION_PATTERN_REPEATED_SHORT.equals(confirmationFeedbackPattern)) { + repeatedThreeShortVibrations(vibrator); + } else if (ALARM_SENDING_CONFIRMATION_PATTERN_THREESHORT_PAUSE_THREESHORT.equals(confirmationFeedbackPattern)) { + vibrateThreeShortPauseThreeShort(vibrator); + } else if (ALARM_SENDING_CONFIRMATION_PATTERN_SOS.equals(confirmationFeedbackPattern)) { + vibrateSOS(vibrator); + } + } + private static void vibrateContinusly(Vibrator vibrator, int feedbackDuration) { + vibrator.vibrate(feedbackDuration); + } + + private static void vibrateEverySecond(Vibrator vibrator, int feedbackDuration) { + Log.d(TAG, "vibrate every second pattern selected and feedback duration is " + feedbackDuration); + + vibrator.vibrate(getPattern(feedbackDuration), -1); + } + + private static long[] getPattern(int i) { + switch (i) { + case 1: + // pattern {0, 600, 400}; + return new long[]{0, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG}; + case 2: + // pattern {0, 600, 400,600, 400}; + return new long[]{0, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG}; + + case 3: + // pattern {0, 600, 400,600, 400,600, 400} + return new long[]{0, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG}; + case 4: + // pattern {0, 600, 400,600, 400,600, 400,600, 400} + return new long[]{0, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG}; + } + return new long[]{0, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG}; + } + private static void repeatedThreeShortVibrations(Vibrator vibrator) { + // pattern = {0, 400, 200,400, 200,400}; + long[] pattern = {0, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT}; + vibrator.vibrate(pattern, -1); + } + + private static void vibrateThreeShortPauseThreeShort(Vibrator vibrator) { + //pattern = {0, 400,200,400,200,400,1000,400,200,400,200,400}; + long[] pattern = {0, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_VERY_LONG, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT}; + vibrator.vibrate(pattern, -1); + + } + + // SOS: Three short - Three long - Three short + private static void vibrateSOS(Vibrator vibrator) { + //pattern = {0, 400,200,400,200,400,1000,400,1000,400,1000,400, 400,200,400,200,400,200}; + long[] pattern = {0, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_VERY_LONG,//three short + VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG, VIBRATION_DURATION_LONG, VIBRATION_PAUSE_LONG,// Three long + VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT, VIBRATION_PAUSE_SHORT, VIBRATION_DURATION_SHORT};//three short + vibrator.vibrate(pattern, -1); + } + + public static void vibrateForHapticFeedback(Context context) { + Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + Log.d(TAG, "haptic feedback pattern 1-continues, 2-vibrate every second : " + ApplicationSettings.getHapticFeedbackVibrationPattern(context)); + //Code to fetch the Haptic feedback pattern + if (context.getString(R.string.hapticFeedbackDefaultPattern).equals(ApplicationSettings.getHapticFeedbackVibrationPattern(context))) { + vibrateContinusly(vibrator, (ONE_SECOND * Integer.parseInt(ApplicationSettings.getConfirmationWaitVibrationDuration(context)))); + } else { + vibrateEverySecond(vibrator, Integer.parseInt(ApplicationSettings.getConfirmationWaitVibrationDuration(context))); + } + } + + public static boolean playTrainingForRelease1_5(Context context) { + Log.d(TAG, "is App a fresh install " + isFirstRun(context)); + Log.d(TAG, "is 1.5 update training played once "+ isTrainingDoneRelease1_5(context)); + Log.d(TAG, "the version no of app installed in device. 10 corresponds to 1.5 release"+ getLastUpdatedVersion(context)); + if (getLastUpdatedVersion(context) == APP_RELEASE_VERSION_1_5 && !isTrainingDoneRelease1_5(context) && !isFirstRun(context)) { + return true; + } + return false; + } + + public static String getCustomTrainingToastMessage(Context context){ + String confirmationString=""; + if(isAlarmConfirmationRequired(context)) + confirmationString=context.getString(R.string.confirmationRequired); + return getInitialClicksForAlertTrigger(context)+" " +context.getString(R.string.InitialPressesText) +" "+ confirmationString; + + } } diff --git a/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java b/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java new file mode 100644 index 00000000..c6649b0e --- /dev/null +++ b/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java @@ -0,0 +1,280 @@ +package org.iilab.pb.common; + +import android.app.Application; +import android.content.Context; +import android.content.SharedPreferences; +import android.location.Location; +import android.preference.PreferenceManager; + +import com.google.gson.Gson; + +import org.iilab.pb.R; + +import static org.iilab.pb.common.AppConstants.ALARM_5_PRESS_PLUS_CONFIRMATION; +import static org.iilab.pb.common.AppConstants.ALARM_CONFIRMATION_NOT_REQUIRED; +import static org.iilab.pb.common.AppConstants.ALARM_CONFIRMATION_REQUIRED; +import static org.iilab.pb.common.AppConstants.ALARM_CUSTOM; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE; +import static org.iilab.pb.common.AppConstants.DEFAULT_7_REPEATED_PRESS; +import static org.iilab.pb.common.AppConstants.DEFAULT_ALARM_INTERVAL; +import static org.iilab.pb.common.AppConstants.DEFAULT_HAPTIC_FEEDBACK_DURATION; +import static org.iilab.pb.common.AppConstants.FRESH_INSTALL_APP_RELEASE_NO; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; + + + +public class ApplicationSettings extends Application { + + private static final int ALERT_FREQUENCY = 10 * 60000; // 10 minute + + public static final String FIRST_RUN = "FIRST_RUN"; + public static final String HARDCODE_INSERT = "HARDCODE_INSERT"; + public static final String LAST_RUN = "LAST_RUN"; + private static final String PASS_CODE = "PASS_CODE"; + private static final String IS_ALERT_ACTIVE = "IS_ALERT_ACTIVE"; + private static final String WIZARD_STATE = "WIZARD_STATE"; + public static final String BEST_LOCATION = "BEST_LOCATION"; + public static final String SELECTED_LANGUAGE = "SELECTED_LANGUAGE"; + public static final String LAST_UPDATED_VERSION = "LAST_UPDATED_VERSION"; + public static final String LAST_UPDATED_DB_VERSION = "LAST_UPDATED_DB_VERSION"; + public static final String ALERT_DELAY = "ALERT_DELAY"; + public static final String IS_FIRST_MSG_WITH_LOCATION_TRIGGERED = "is_first_msg_with_location_triggered"; + public static final String IS_FIRST_MSG_SENT = "is_first_msg_sent"; + public static final String SUPPORTED_LANGUAGES = "SUPPORTED_LANGUAGES"; + public static final String DB_LOADED_LANGUAGES = "DB_LOADED_LANGUAGES"; + public static final String APP_UPDATED = "APP_UPDATED"; + public static final String CONFIRMATION_FEEDBACK = "CONFIRMATION_FEEDBACK"; + //fla specific to 1.5 release + public static final String TRAINING_DONE = "TRAINING_DONE"; + + + /*following methods are used to check whether the app is fresh install or an update.Its used to play explicitly 1.5 release major changes training sequence + if the app is not a fresh install*/ + public static void setFirstRun(Context context, boolean isFirstRun) { + saveBoolean(context, FIRST_RUN, isFirstRun); + } + + public static boolean isFirstRun(Context context) { + return sharedPreferences(context).getBoolean(FIRST_RUN, false); + } + +// public static void setLocalDataInsertion(Context context, boolean flag) { +// saveBoolean(context, HARDCODE_INSERT, flag); +// } +// +// public static boolean getLocalDataInsertion(Context context) { +// return sharedPreferences(context).getBoolean(HARDCODE_INSERT, false); +// } + + public static void savePassword(Context context, String password) { + saveString(context, PASS_CODE, password); + } + + public static boolean passwordMatches(Context context, String otherPassword) { + String actualPassword = sharedPreferences(context).getString(PASS_CODE, ""); + return actualPassword.equals(otherPassword); + } + + public static boolean isAlertActive(Context context) { + return sharedPreferences(context).getBoolean(IS_ALERT_ACTIVE, false); + } + + public static void setAlertActive(Context context, boolean isActive) { + saveBoolean(context, IS_ALERT_ACTIVE, isActive); + } + + + public static int getWizardState(Context context) { + return sharedPreferences(context).getInt(WIZARD_STATE, WIZARD_FLAG_HOME_NOT_CONFIGURED); + } + + public static void setWizardState(Context context, int state) { + saveInt(context, WIZARD_STATE, state); + } + + public static Location getCurrentBestLocation(Context context) { + String locationJson = sharedPreferences(context).getString(BEST_LOCATION, null); + return (locationJson == null) ? null : constructLocation(locationJson); + } + + private static Location constructLocation(String locationJson) { + Location location = new Gson().fromJson(locationJson, Location.class); + long timeDelta = System.currentTimeMillis() - location.getTime(); + return (timeDelta <= ALERT_FREQUENCY) ? location : null; + } + + public static void setCurrentBestLocation(Context context, Location location) { + saveString(context, BEST_LOCATION, new Gson().toJson(location)); + } + + private static SharedPreferences sharedPreferences(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context); + } + + private static void saveBoolean(Context context, String key, boolean value) { + SharedPreferences.Editor editor = sharedPreferences(context).edit(); + editor.putBoolean(key, value); + editor.commit(); + } + + private static void saveString(Context context, String key, String value) { + SharedPreferences.Editor editor = sharedPreferences(context).edit(); + editor.putString(key, value); + editor.commit(); + } + + private static void saveLong(Context context, String key, Long value) { + SharedPreferences.Editor editor = sharedPreferences(context).edit(); + editor.putLong(key, value); + editor.commit(); + } + + private static void saveInt(Context context, String key, int value) { + SharedPreferences.Editor editor = sharedPreferences(context).edit(); + editor.putInt(key, value); + editor.commit(); + } + + + public static String getSelectedLanguage(Context context) { + return sharedPreferences(context).getString(SELECTED_LANGUAGE, "en"); + } + + public static void setSelectedLanguage(Context context, String lang) { + saveString(context, SELECTED_LANGUAGE, lang); + } + + public static void setPBSupportedLanguages(Context context, String lang) { + saveString(context, SUPPORTED_LANGUAGES, lang); + } + + public static String getSupportedLanguages(Context context) { + return sharedPreferences(context).getString(SUPPORTED_LANGUAGES, null); + } + + public static void addDBLoadedLanguage(Context context, String language) { + if(!getDBLoadedLanguages(context).contains(language)) + saveString(context, DB_LOADED_LANGUAGES, getDBLoadedLanguages(context).concat("," + language)); + } + + public static String getDBLoadedLanguages(Context context) { + return sharedPreferences(context).getString(DB_LOADED_LANGUAGES, ""); + } + + public static int getLastUpdatedVersion(Context context) { + return sharedPreferences(context).getInt(LAST_UPDATED_VERSION, FRESH_INSTALL_APP_RELEASE_NO); + } + + public static void setLastUpdatedVersion(Context context, int versionNumber) { + saveInt(context, LAST_UPDATED_VERSION, versionNumber); + } + +// public static int getLastUpdatedDBVersion(Context context) { +// return sharedPreferences(context).getInt(LAST_UPDATED_DB_VERSION, -1); +// } +// +// public static void setLastUpdatedDBVersion(Context context, int versionNumber) { +// saveInt(context, LAST_UPDATED_DB_VERSION, versionNumber); +// } + + public static void setAlertDelay(Context context, int alertDelay) { + saveInt(context, ALERT_DELAY, alertDelay); + } + + public static int getAlertDelay(Context context) { + return sharedPreferences(context).getInt(ALERT_DELAY, DEFAULT_ALARM_INTERVAL); + } + + public static void setFirstMsgWithLocationTriggered(Context context, Boolean flag) { + saveBoolean(context, IS_FIRST_MSG_WITH_LOCATION_TRIGGERED, flag); + } + + public static Boolean isFirstMsgWithLocationTriggered(Context context) { + return sharedPreferences(context).getBoolean(IS_FIRST_MSG_WITH_LOCATION_TRIGGERED, false); + } + + public static void setFirstMsgSent(Context context, Boolean flag) { + saveBoolean(context, IS_FIRST_MSG_SENT, flag); + } + + public static Boolean isFirstMsgSent(Context context) { + return sharedPreferences(context).getBoolean(IS_FIRST_MSG_SENT, false); + } + + + public static boolean isHardwareTriggerServiceEnabled(Context context) { + String powerButtonTriggerStatus = sharedPreferences(context).getString(context.getString(R.string.configurePowerButtonTriggerKey), context.getString(R.string.activate_power_button_trigger)); + return (context.getString(R.string.activate_power_button_trigger).equals(powerButtonTriggerStatus) ? true : false); + } + + + public static void setInitialClicksForAlertTrigger(Context context, String initialPresses) { + saveString(context,context.getString(R.string.initialPressesKey),initialPresses); + } + public static String getInitialClicksForAlertTrigger(Context context) { + return sharedPreferences(context).getString(context.getString(R.string.initialPressesKey), context.getString(R.string.initialPressesDefault)); + } + + + public static String getHapticFeedbackVibrationPattern(Context context) { + return sharedPreferences(context).getString(context.getString(R.string.hapticFeedbackVibrationPatternKey), context.getString(R.string.hapticFeedbackDefaultPattern)); + } + + public static String getConfirmationWaitVibrationDuration(Context context) { + return sharedPreferences(context).getString(context.getString(R.string.confirmationWaitTimeKey), DEFAULT_HAPTIC_FEEDBACK_DURATION); + } + + public static void setConfirmationFeedbackVibrationPattern(Context context, String confirmationFeedbackPattern) { + saveString(context,context.getString(R.string.feedbackAlarmActivationVibrationKey),confirmationFeedbackPattern); + } + public static String getConfirmationFeedbackVibrationPattern(Context context) { + return sharedPreferences(context).getString(context.getString(R.string.feedbackAlarmActivationVibrationKey), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); + } + + public static String getAlarmNotConfirmedPattern(Context context) { + return sharedPreferences(context).getString(context.getString(R.string.alertNotConfirmedKey), context.getString(R.string.alertNotConfirmedDefault)); + } + public static String getInitialClicksMaxTimeLimit(Context context) { + return sharedPreferences(context).getString(context.getString(R.string.initialTimeKey), context.getString(R.string.initialTimeDefault)); + } + public static boolean getCustomSettings(Context context) { + return sharedPreferences(context).getBoolean(context.getString(R.string.customKey), false); + } + public static void setTrainingDoneRelease1_5(Context context, Boolean flag) { + saveBoolean(context, TRAINING_DONE, flag); + } + + public static Boolean isTrainingDoneRelease1_5(Context context) { + return sharedPreferences(context).getBoolean(TRAINING_DONE, false); + } + + public static void setAppUpdated(Context context, boolean isAppUpdated) { + saveBoolean(context, APP_UPDATED, isAppUpdated); + } + + public static boolean isAppUpdated(Context context) { + return sharedPreferences(context).getBoolean(APP_UPDATED, false); + } + public static void setAlarmConfirmationRequired(Context context, Boolean isConfirmationRequired) { + saveBoolean(context, CONFIRMATION_FEEDBACK, isConfirmationRequired); + if(isConfirmationRequired) { + saveString(context, context.getString(R.string.confirmationSequenceKey), ALARM_CONFIRMATION_REQUIRED); + }else{ + saveString(context, context.getString(R.string.confirmationSequenceKey), ALARM_CONFIRMATION_NOT_REQUIRED); + } + } + public static boolean isAlarmConfirmationRequired(Context context) { + return sharedPreferences(context).getBoolean(CONFIRMATION_FEEDBACK, false); + } + + public static String getTriggerPattern(Context context) { + if (sharedPreferences(context).getBoolean(context.getString(R.string.default7RepeatedPressKey),false)) { + return DEFAULT_7_REPEATED_PRESS; + }else if (sharedPreferences(context).getBoolean(context.getString(R.string.extraConfirmationPressKey),false)) { + return ALARM_5_PRESS_PLUS_CONFIRMATION; + }else if (sharedPreferences(context).getBoolean(context.getString(R.string.customKey),false)) { + return ALARM_CUSTOM; + } + return DEFAULT_7_REPEATED_PRESS; + } +} diff --git a/src/main/java/org/iilab/pb/common/ContactEditTexts.java b/app/src/main/java/org/iilab/pb/common/ContactEditTexts.java similarity index 100% rename from src/main/java/org/iilab/pb/common/ContactEditTexts.java rename to app/src/main/java/org/iilab/pb/common/ContactEditTexts.java diff --git a/src/main/java/org/iilab/pb/common/ContactPickerFragment.java b/app/src/main/java/org/iilab/pb/common/ContactPickerFragment.java similarity index 61% rename from src/main/java/org/iilab/pb/common/ContactPickerFragment.java rename to app/src/main/java/org/iilab/pb/common/ContactPickerFragment.java index 754ac9de..3cac4f6e 100644 --- a/src/main/java/org/iilab/pb/common/ContactPickerFragment.java +++ b/app/src/main/java/org/iilab/pb/common/ContactPickerFragment.java @@ -1,7 +1,5 @@ package org.iilab.pb.common; -import org.iilab.pb.R; - import android.content.Intent; import android.database.Cursor; import android.net.Uri; @@ -12,12 +10,13 @@ import android.view.View; import android.view.ViewGroup; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageButton; +import org.iilab.pb.R; +import org.iilab.pb.fragment.SetupContactsFragment; import static android.app.Activity.RESULT_OK; -import static android.content.Intent.ACTION_GET_CONTENT; -import static android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE; import static android.view.View.OnClickListener; public class ContactPickerFragment extends Fragment { @@ -25,68 +24,59 @@ public class ContactPickerFragment extends Fragment { private ImageButton contactPickerButton; private EditText phoneNumberEditText; + private static int PICK_CONTACT_FRAGMENT_ID, FRAGMENT_ID; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.contact_picker_fragment, container, false); - contactPickerButton = (ImageButton) view.findViewById(R.id.contact_picker_button); phoneNumberEditText = (EditText) view.findViewById(R.id.contact_edit_text); - return view; } -// private OnClickListener contactPickerListener = new OnClickListener() { -// @Override -// public void onClick(View view) { -// launchContactPicker(view); -// } -// }; - -// @Override -// public void onViewCreated(View view, Bundle savedInstanceState) { -// super.onViewCreated(view, savedInstanceState); -// contactPickerButton.setOnClickListener(contactPickerListener); -// } - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); contactPickerButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - int wizardState = ApplicationSettings.getWizardState(getActivity()); + int wizardState = ApplicationSettings.getWizardState(getActivity()); // if(wizardState != AppConstants.WIZARD_FLAG_HOME_READY){ - AppConstants.IS_BACK_BUTTON_PRESSED = true; - AppConstants.IS_BACK_BUTTON_PRESSED = true; + AppConstants.IS_BACK_BUTTON_PRESSED = true; // } - launchContactPicker(v); + launchContactPicker(); } }); + FRAGMENT_ID = ((FrameLayout) getView().getParent()).getId(); + if (FRAGMENT_ID == R.id.third_contact) { + ((SetupContactsFragment) getParentFragment()).initializeContactNumbers(); + } } - public void launchContactPicker(View view) { - Intent contactPickerIntent = new Intent(ACTION_GET_CONTENT); - contactPickerIntent.setType(CONTENT_ITEM_TYPE); - startActivityForResult(contactPickerIntent, PICK_CONTACT_REQUEST_ID); + private void launchContactPicker() { + Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI); + PICK_CONTACT_FRAGMENT_ID = ((FrameLayout) getView().getParent()).getId(); + getParentFragment().startActivityForResult(contactPickerIntent, PICK_CONTACT_REQUEST_ID); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - if ((requestCode == PICK_CONTACT_REQUEST_ID) && (resultCode == RESULT_OK)) { + if ((requestCode == PICK_CONTACT_REQUEST_ID) && (resultCode == RESULT_OK) && getId() == PICK_CONTACT_FRAGMENT_ID) { phoneNumberEditText.setText(getPhoneNumber(data.getData())); } } private String getPhoneNumber(Uri contactData) { String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER}; + String phoneNumber = ""; Cursor cursor = getCursor(contactData, projection); - cursor.moveToNext(); - return cursor.getString(0); + if (cursor.moveToNext()) { + phoneNumber = cursor.getString(0); + } + return phoneNumber; } Cursor getCursor(Uri contactData, String[] projection) { - return getActivity().managedQuery(contactData, projection, null, null, null); + return getActivity().getContentResolver().query(contactData, projection, null, null, null); } } \ No newline at end of file diff --git a/src/main/java/org/iilab/pb/common/CustomLinkMovementMethod.java b/app/src/main/java/org/iilab/pb/common/CustomLinkMovementMethod.java similarity index 100% rename from src/main/java/org/iilab/pb/common/CustomLinkMovementMethod.java rename to app/src/main/java/org/iilab/pb/common/CustomLinkMovementMethod.java diff --git a/src/main/java/org/iilab/pb/common/GifDecoder.java b/app/src/main/java/org/iilab/pb/common/GifDecoder.java similarity index 100% rename from src/main/java/org/iilab/pb/common/GifDecoder.java rename to app/src/main/java/org/iilab/pb/common/GifDecoder.java diff --git a/src/main/java/org/iilab/pb/common/GifDecoderView.java b/app/src/main/java/org/iilab/pb/common/GifDecoderView.java similarity index 100% rename from src/main/java/org/iilab/pb/common/GifDecoderView.java rename to app/src/main/java/org/iilab/pb/common/GifDecoderView.java diff --git a/src/main/java/org/iilab/pb/common/Intents.java b/app/src/main/java/org/iilab/pb/common/Intents.java similarity index 100% rename from src/main/java/org/iilab/pb/common/Intents.java rename to app/src/main/java/org/iilab/pb/common/Intents.java diff --git a/src/main/java/org/iilab/pb/common/MessageLimitWatcher.java b/app/src/main/java/org/iilab/pb/common/MessageLimitWatcher.java similarity index 100% rename from src/main/java/org/iilab/pb/common/MessageLimitWatcher.java rename to app/src/main/java/org/iilab/pb/common/MessageLimitWatcher.java diff --git a/app/src/main/java/org/iilab/pb/common/MessageTextView.java b/app/src/main/java/org/iilab/pb/common/MessageTextView.java new file mode 100644 index 00000000..e37d54b7 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/common/MessageTextView.java @@ -0,0 +1,66 @@ +package org.iilab.pb.common; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.widget.TextView; + +import org.iilab.pb.R; + +/** + * This is a customized text view holding the values of styled attributes of message fragment + */ +public class MessageTextView extends TextView { + public String getMessageHeader() { + return mMessageHeader; + } + + public void setMessageHeader(String mMessageHeader) { + this.mMessageHeader = mMessageHeader; + } + + public int getMaxCharacters() { + return mMaxCharacters; + } + + public void setMaxCharacters(int mMaxCharacters) { + this.mMaxCharacters = mMaxCharacters; + } + + private String mMessageHeader; + private int mMaxCharacters; + private String mStopAlertHeader; + + public MessageTextView(Context context) { + super(context); + init(null, 0); + } + + public String getStopAlertMsgHeader() { + return mStopAlertHeader; + } + + public void setStopAlertHeader(String stopAlertHeader) { + this.mStopAlertHeader = stopAlertHeader; + } + + public MessageTextView(Context context, AttributeSet attrs) { + super(context, attrs); + init(attrs, 0); + } + + public MessageTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(attrs, defStyle); + } + + private void init(AttributeSet attrs, int defStyle) { + final TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.MessageFragmentArguments); + mMessageHeader = arr.getString(R.styleable.MessageFragmentArguments_message_header); + mMaxCharacters = arr.getInteger(R.styleable.MessageFragmentArguments_max_characters, 0); + mStopAlertHeader= arr.getString(R.styleable.MessageFragmentArguments_stop_alert_message_header); + arr.recycle(); + + } + +} diff --git a/src/main/java/org/iilab/pb/common/MyTagHandler.java b/app/src/main/java/org/iilab/pb/common/MyTagHandler.java similarity index 100% rename from src/main/java/org/iilab/pb/common/MyTagHandler.java rename to app/src/main/java/org/iilab/pb/common/MyTagHandler.java diff --git a/src/main/java/org/iilab/pb/common/NestedListView.java b/app/src/main/java/org/iilab/pb/common/NestedListView.java similarity index 100% rename from src/main/java/org/iilab/pb/common/NestedListView.java rename to app/src/main/java/org/iilab/pb/common/NestedListView.java diff --git a/src/main/java/org/iilab/pb/common/SoftKeyboard.java b/app/src/main/java/org/iilab/pb/common/SoftKeyboard.java similarity index 100% rename from src/main/java/org/iilab/pb/common/SoftKeyboard.java rename to app/src/main/java/org/iilab/pb/common/SoftKeyboard.java diff --git a/src/test/java/org/iilab/pb/common/TestFragmentActivity.java b/app/src/main/java/org/iilab/pb/common/TestFragmentActivity.java similarity index 100% rename from src/test/java/org/iilab/pb/common/TestFragmentActivity.java rename to app/src/main/java/org/iilab/pb/common/TestFragmentActivity.java diff --git a/src/main/java/org/iilab/pb/data/HelpPageDbManager.java b/app/src/main/java/org/iilab/pb/data/HelpPageDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/HelpPageDbManager.java rename to app/src/main/java/org/iilab/pb/data/HelpPageDbManager.java diff --git a/src/main/java/org/iilab/pb/data/PBDatabase.java b/app/src/main/java/org/iilab/pb/data/PBDatabase.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PBDatabase.java rename to app/src/main/java/org/iilab/pb/data/PBDatabase.java diff --git a/src/main/java/org/iilab/pb/data/PageActionDbManager.java b/app/src/main/java/org/iilab/pb/data/PageActionDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PageActionDbManager.java rename to app/src/main/java/org/iilab/pb/data/PageActionDbManager.java diff --git a/src/main/java/org/iilab/pb/data/PageChecklistDbManager.java b/app/src/main/java/org/iilab/pb/data/PageChecklistDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PageChecklistDbManager.java rename to app/src/main/java/org/iilab/pb/data/PageChecklistDbManager.java diff --git a/src/main/java/org/iilab/pb/data/PageDbManager.java b/app/src/main/java/org/iilab/pb/data/PageDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PageDbManager.java rename to app/src/main/java/org/iilab/pb/data/PageDbManager.java diff --git a/src/main/java/org/iilab/pb/data/PageItemDbManager.java b/app/src/main/java/org/iilab/pb/data/PageItemDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PageItemDbManager.java rename to app/src/main/java/org/iilab/pb/data/PageItemDbManager.java diff --git a/src/main/java/org/iilab/pb/data/PageStatusDbManager.java b/app/src/main/java/org/iilab/pb/data/PageStatusDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PageStatusDbManager.java rename to app/src/main/java/org/iilab/pb/data/PageStatusDbManager.java diff --git a/src/main/java/org/iilab/pb/data/PageTimerDbManager.java b/app/src/main/java/org/iilab/pb/data/PageTimerDbManager.java similarity index 100% rename from src/main/java/org/iilab/pb/data/PageTimerDbManager.java rename to app/src/main/java/org/iilab/pb/data/PageTimerDbManager.java diff --git a/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java new file mode 100644 index 00000000..87e7dbf9 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java @@ -0,0 +1,223 @@ +package org.iilab.pb.fragment; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; +import android.support.v4.app.TaskStackBuilder; +import android.support.v7.preference.CheckBoxPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceFragmentCompat; +import android.util.Log; + +import org.iilab.pb.MainActivity; +import org.iilab.pb.R; +import org.iilab.pb.WizardActivity; +import org.iilab.pb.trigger.HardwareTriggerService; + +import static org.iilab.pb.common.AppConstants.ALARM_5_REPEATED_CLICKS; +import static org.iilab.pb.common.AppConstants.ALARM_7_REPEATED_CLICKS; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_LONG; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE; +import static org.iilab.pb.common.AppConstants.PAGE_ADVANCED_SETTINGS; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_SETTINGS; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_RETRAINING; +import static org.iilab.pb.common.AppConstants.PARENT_ACTIVITY; +import static org.iilab.pb.common.ApplicationSettings.getCustomSettings; +import static org.iilab.pb.common.ApplicationSettings.getInitialClicksForAlertTrigger; +import static org.iilab.pb.common.ApplicationSettings.isAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.setAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern; +import static org.iilab.pb.common.ApplicationSettings.setInitialClicksForAlertTrigger; + +public class AdvancedSettingsFragment extends PreferenceFragmentCompat { + private static final String TAG = AdvancedSettingsFragment.class.getName(); + public static AdvancedSettingsFragment newInstance(String pageId, int parentActivity) { + AdvancedSettingsFragment f = new AdvancedSettingsFragment(); + Bundle args = new Bundle(); + args.putString(PAGE_ID, pageId); + args.putInt(PARENT_ACTIVITY, parentActivity); + f.setArguments(args); + return (f); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.preferences); + final CheckBoxPreference default7RepeatedPress = (CheckBoxPreference) findPreference(getString(R.string.default7RepeatedPressKey)); + final CheckBoxPreference extraConfirmationClick = (CheckBoxPreference) findPreference(getString(R.string.extraConfirmationPressKey)); + final CheckBoxPreference customPreference = (CheckBoxPreference) findPreference(getString(R.string.customKey)); + final Preference customSettings = (Preference) findPreference(getString(R.string.customSettingsKey)); + if (getCustomSettings(getActivity())) { + default7RepeatedPress.setChecked(false); + extraConfirmationClick.setChecked(false); + customPreference.setChecked(true); + customSettings.setEnabled(true); + } else { + customPreference.setChecked(false); + customSettings.setEnabled(false); + } + if (isAlarmConfirmationRequired(getActivity())) { + enableConfirmationPatterns(true); + } else { + enableConfirmationPatterns(false); + } + customPreference.setSummary(getCustomSummary()); + + Preference redoTrainingButton = (Preference) findPreference(getString(R.string.redoTrainingKey)); + redoTrainingButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Log.d(TAG, "Testing redo training redoTrainingButton"); + // During redo exercise of alarm trigger, stop the send alert hardware service. + getActivity().stopService(new Intent(getActivity(), HardwareTriggerService.class)); + Intent i = new Intent(getActivity(), WizardActivity.class); + i.putExtra(PAGE_ID, PAGE_SETUP_ALARM_RETRAINING); + startActivity(i); + return true; + } + }); + + Preference powerButtonAlarmTrigger = (Preference) findPreference(getString(R.string.configurePowerButtonTriggerKey)); + powerButtonAlarmTrigger.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside on preference change of power redoTrainingButton trigger setting"); + + if (selectedValue.equals(getString(R.string.activate_power_button_trigger))) { + getActivity().startService(new Intent(getActivity(), HardwareTriggerService.class)); + Log.d(TAG, "Power redoTraining Button alarm trigger is enabled"); + } else { + getActivity().stopService(new Intent(getActivity(), HardwareTriggerService.class)); + displayNotification(); + Log.d(TAG, "Power redoTrainingButton alarm trigger is disabled"); + } + return true; + } + }); + + default7RepeatedPress.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside on preference change of default 7 repeated press checkbox " + selectedValue.getClass()); + + if ((Boolean) selectedValue) { + extraConfirmationClick.setChecked(false); + customPreference.setChecked(false); + customSettings.setEnabled(false); + setInitialClicksForAlertTrigger(getActivity(), ALARM_7_REPEATED_CLICKS); + setAlarmConfirmationRequired(getActivity(),false); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); + Log.d(TAG, "Default 7 presses to trigger alarm without confirmation click"); + } + customPreference.setSummary(getCustomSummary()); + return true; + } + }); + extraConfirmationClick.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside on preference change of 5 presses and a confirmation click " + selectedValue.getClass()); + + if ((Boolean) selectedValue) { + default7RepeatedPress.setChecked(false); + customPreference.setChecked(false); + customSettings.setEnabled(false); + // make the press 5 plus confirm + setAlarmConfirmationRequired(getActivity(), true); + setInitialClicksForAlertTrigger(getActivity(), ALARM_5_REPEATED_CLICKS); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_LONG); + Log.d(TAG, "Default 5 presses to trigger alarm with confirmation click"); + } + customPreference.setSummary(getCustomSummary()); + return true; + } + }); + + customPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside on preference change of custom checkbox selection " + selectedValue.getClass()); + + if ((Boolean) selectedValue) { + default7RepeatedPress.setChecked(false); + extraConfirmationClick.setChecked(false); + customSettings.setEnabled(true); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); + Log.d(TAG, "Custom setting are enabled and confirmation click defaults to false"); + }else{ + customSettings.setEnabled(false); + } + return true; + } + }); + } + + private void enableConfirmationPatterns(boolean flag) { + Preference confirmationWaitTime = (Preference) findPreference(getString(R.string.confirmationWaitTimeKey)); + confirmationWaitTime.setEnabled(flag); + Preference confirmationWaitVibration = (Preference) findPreference(getString(R.string.hapticFeedbackVibrationPatternKey)); + confirmationWaitVibration.setEnabled(flag); + } + + private void displayNotification() { + // Invoking the default notification service + Log.d(TAG, "inside displayNotification for power button alarm trigger"); + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getActivity()); + int notifyID = 1; + mBuilder.setContentTitle("Power Button Trigger"); + mBuilder.setContentText("The power button trigger is deactivated"); + mBuilder.setSmallIcon(R.drawable.warning); + mBuilder.setAutoCancel(true); + // Creates an explicit intent for an Activity in your app + Context mContext = getActivity(); + Intent advancedSettingsIntent = new Intent(mContext, MainActivity.class); + advancedSettingsIntent.putExtra(PAGE_ID, PAGE_ADVANCED_SETTINGS); + + Intent settingsIntent = new Intent(mContext, MainActivity.class); + settingsIntent.putExtra(PAGE_ID, PAGE_SETTINGS); + Intent homePageIntent = new Intent(mContext, MainActivity.class); + homePageIntent.putExtra(PAGE_ID, PAGE_HOME_READY); + //This ensures that navigating backward from the Activity leads out of the app to Home page + TaskStackBuilder stackBuilder = TaskStackBuilder.create((MainActivity) mContext); + // Adds the back stack for the Intent + stackBuilder.addNextIntent(homePageIntent).addNextIntent(settingsIntent).addNextIntent(advancedSettingsIntent); + PendingIntent resultPendingIntent = + stackBuilder.getPendingIntent(0, + PendingIntent.FLAG_UPDATE_CURRENT //can only be used once + ); + // start the activity when the user clicks the notification text + mBuilder.setContentIntent(resultPendingIntent); + NotificationManagerCompat myNotificationManager = NotificationManagerCompat.from(mContext); + // pass the Notification object to the system + myNotificationManager.notify(notifyID, mBuilder.build()); + } + + + @Override + public void onResume() { + super.onResume(); + Log.d(TAG, "on Resume for AdvancedSettingsFragment is called"); + CheckBoxPreference customPreference = (CheckBoxPreference) findPreference(getString(R.string.customKey)); + customPreference.setSummary(getCustomSummary()); + } + + @Override + public void onPause() { + super.onPause(); + Log.d(TAG, "on Pause for AdvancedSettingsFragment is called"); + } + + private String getCustomSummary(){ + String initialClicks=getInitialClicksForAlertTrigger(getActivity()); + String confirmationString=(isAlarmConfirmationRequired(getActivity())? "with ":"with no "); + + return (initialClicks + " Repeated press "+confirmationString+"confirmation"); + } +} + diff --git a/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsSubScreenFragment.java b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsSubScreenFragment.java new file mode 100644 index 00000000..493149c0 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsSubScreenFragment.java @@ -0,0 +1,73 @@ +package org.iilab.pb.fragment; + +import android.os.Bundle; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceFragmentCompat; +import android.util.Log; + +import org.iilab.pb.R; + +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_LONG; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PARENT_ACTIVITY; +import static org.iilab.pb.common.ApplicationSettings.isAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.setAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern; + +public class AdvancedSettingsSubScreenFragment extends PreferenceFragmentCompat { + + private static final String TAG = AdvancedSettingsSubScreenFragment.class.getName(); + public static AdvancedSettingsSubScreenFragment newInstance(String pageId, int parentActivity) { + AdvancedSettingsSubScreenFragment f = new AdvancedSettingsSubScreenFragment(); + Bundle args = new Bundle(); + args.putString(PAGE_ID, pageId); + args.putInt(PARENT_ACTIVITY, parentActivity); + f.setArguments(args); + return (f); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + // Load the preferences from an XML resource + setPreferencesFromResource(R.xml.preferences, rootKey); + Log.d(TAG, "onCreatePreferences of the sub screen " + rootKey); + Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.confirmationSequenceKey)); + if (isAlarmConfirmationRequired(getActivity())) { + enableConfirmationPatterns(true); + } else { + enableConfirmationPatterns(false); + } + alertConfirmationSettings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside of Alarm confirmation settings"); + + if (selectedValue.equals(getString(R.string.confirmationSequenceDefault))) { + // disable Confirmation Wait Time/ Confirmation Wait Vibration + enableConfirmationPatterns(false); + setAlarmConfirmationRequired(getActivity(), false); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); + Log.d(TAG, "default confirmation press deactivated"); + } else { + // enable Confirmation Wait Time/ Confirmation Wait Vibration + enableConfirmationPatterns(true); + setAlarmConfirmationRequired(getActivity(), true); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_LONG); + Log.d(TAG, "Confirmation press enabled"); + } + return true; + } + }); + } + + private void enableConfirmationPatterns(boolean flag) { + Preference confirmationWaitTime = (Preference) findPreference(getString(R.string.confirmationWaitTimeKey)); + confirmationWaitTime.setEnabled(flag); + Preference confirmationWaitVibration = (Preference) findPreference(getString(R.string.hapticFeedbackVibrationPatternKey)); + confirmationWaitVibration.setEnabled(flag); + } + +} + diff --git a/src/main/java/org/iilab/pb/fragment/LanguageSettingsFragment.java b/app/src/main/java/org/iilab/pb/fragment/LanguageSettingsFragment.java similarity index 100% rename from src/main/java/org/iilab/pb/fragment/LanguageSettingsFragment.java rename to app/src/main/java/org/iilab/pb/fragment/LanguageSettingsFragment.java diff --git a/src/main/java/org/iilab/pb/fragment/MainSetupAlertFragment.java b/app/src/main/java/org/iilab/pb/fragment/MainSetupAlertFragment.java similarity index 100% rename from src/main/java/org/iilab/pb/fragment/MainSetupAlertFragment.java rename to app/src/main/java/org/iilab/pb/fragment/MainSetupAlertFragment.java diff --git a/app/src/main/java/org/iilab/pb/fragment/MessageTextFragment.java b/app/src/main/java/org/iilab/pb/fragment/MessageTextFragment.java new file mode 100644 index 00000000..15f67295 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/fragment/MessageTextFragment.java @@ -0,0 +1,130 @@ +package org.iilab.pb.fragment; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.InputFilter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RelativeLayout; + +import org.iilab.pb.R; +import org.iilab.pb.common.AppConstants; +import org.iilab.pb.common.MessageLimitWatcher; +import org.iilab.pb.common.MessageTextView; +import org.iilab.pb.model.SMSSettings; + +import static java.lang.String.valueOf; + +public class MessageTextFragment extends Fragment { + + private MessageTextView charactersLeftView, stopAlertCharView; + private MessageTextView messageHeaderView,stopAlertMsgView; + private EditText messageEditText,stopAlertEditText; + private RelativeLayout rv_stopAlertMsgEditTextContainer,rv_stopAlertHeaderContainer; + + private MessageLimitWatcher messageLimitWatcher,stopAlertmessageLimitWatcher; + private Button bAction; + boolean isParentMainActivity; + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.message_fragment, container, false); + + charactersLeftView = (MessageTextView) view.findViewById(R.id.characters_left_view); + messageHeaderView = (MessageTextView) view.findViewById(R.id.message_fragment_header); + messageEditText = (EditText) view.findViewById(R.id.message_edit_text); + messageEditText.requestFocus(); + View parentView = getParentFragment().getView(); + if (parentView != null) { + bAction = (Button) parentView.findViewById(R.id.fragment_action); + } + + int parentActivity = getArguments().getInt(AppConstants.PARENT_ACTIVITY); + if (parentActivity == AppConstants.FROM_MAIN_ACTIVITY) { + isParentMainActivity=true; + rv_stopAlertHeaderContainer =(RelativeLayout)view.findViewById(R.id.stop_message_header_container); + rv_stopAlertMsgEditTextContainer=(RelativeLayout)view.findViewById(R.id.stop_message_container); + rv_stopAlertHeaderContainer.setVisibility(View.VISIBLE); + rv_stopAlertMsgEditTextContainer.setVisibility(View.VISIBLE); + stopAlertCharView = (MessageTextView) view.findViewById(R.id.stop_alert_characters_left_view); + stopAlertMsgView = (MessageTextView) view.findViewById(R.id.stop_alert_message_fragment_header); + stopAlertEditText = (EditText) view.findViewById(R.id.stop_alert_message_edit_text); + } + return view; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + String currentEmergencyMsg = SMSSettings.retrieveMessage(getActivity()); + if (currentEmergencyMsg != null) { + displayEmergencyMsg(currentEmergencyMsg); + } + setActionButtonStateListener(bAction); + bAction.setEnabled(!(messageEditText.getText().toString().trim().equals(""))); + messageEditText.setImeOptions(EditorInfo.IME_FLAG_NAVIGATE_NEXT); + messageEditText.selectAll(); + if(isParentMainActivity) { + String currentStopAlertMsg = SMSSettings.retrieveStopAlertMessage(getActivity()); + if (currentStopAlertMsg != null) { + displayStopAlertMsg(currentStopAlertMsg); + } + bAction.setEnabled(!(stopAlertEditText.getText().toString().trim().equals(""))); + stopAlertEditText.setImeOptions(EditorInfo.IME_FLAG_NAVIGATE_NEXT); + stopAlertEditText.selectAll(); + } + + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + } + + public void setActionButtonStateListener(Button bAction) { + this.bAction = bAction; + int maxCharacters = charactersLeftView.getMaxCharacters(); + String prefix = getString(R.string.characters_left); + messageLimitWatcher = new MessageLimitWatcher(charactersLeftView, prefix, maxCharacters, bAction); + messageEditText.addTextChangedListener(messageLimitWatcher); + InputFilter[] filters = {new InputFilter.LengthFilter(maxCharacters)}; + messageEditText.setFilters(filters); + messageEditText.setSelection(messageEditText.getText().length()); + + charactersLeftView.setText(prefix + valueOf(maxCharacters - messageEditText.getText().length())); + messageHeaderView.setText(messageHeaderView.getMessageHeader()); + + if(isParentMainActivity) { + int stopAlertMaxCharacters = stopAlertCharView.getMaxCharacters(); + stopAlertmessageLimitWatcher = new MessageLimitWatcher(stopAlertCharView, prefix, stopAlertMaxCharacters, bAction); + stopAlertEditText.addTextChangedListener(stopAlertmessageLimitWatcher); + InputFilter[] filterStopAlert = {new InputFilter.LengthFilter(maxCharacters)}; + stopAlertEditText.setFilters(filterStopAlert); + stopAlertEditText.setSelection(stopAlertEditText.getText().length()); + stopAlertCharView.setText(prefix + valueOf(maxCharacters - stopAlertEditText.getText().length())); + stopAlertMsgView.setText(stopAlertMsgView.getStopAlertMsgHeader()); + } + } + + public void displayEmergencyMsg(String emergencyMessage) { + messageEditText.setText(emergencyMessage); + } + + public void displayStopAlertMsg(String stopAlertMessage) { + stopAlertEditText.setText(stopAlertMessage); + } + public String getEmergencyMsgFromView() { + String message = messageEditText.getText().toString().trim(); + return message; + } + + public String getStopAlertMsgFromView() { + String message = stopAlertEditText.getText().toString().trim(); + return message; + } +} diff --git a/app/src/main/java/org/iilab/pb/fragment/SetupCodeFragment.java b/app/src/main/java/org/iilab/pb/fragment/SetupCodeFragment.java new file mode 100644 index 00000000..776312ee --- /dev/null +++ b/app/src/main/java/org/iilab/pb/fragment/SetupCodeFragment.java @@ -0,0 +1,202 @@ +package org.iilab.pb.fragment; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.Html; +import android.text.TextWatcher; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnKeyListener; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import org.iilab.pb.MainActivity; +import org.iilab.pb.R; +import org.iilab.pb.WizardActivity; +import org.iilab.pb.common.AppUtil; +import org.iilab.pb.common.ApplicationSettings; +import org.iilab.pb.common.MessageTextView; +import org.iilab.pb.common.MyTagHandler; +import org.iilab.pb.data.PBDatabase; +import org.iilab.pb.model.Page; + +import static org.iilab.pb.common.AppConstants.DEFAULT_CONFIRMATION_MESSAGE; +import static org.iilab.pb.common.AppConstants.FROM_MAIN_ACTIVITY; +import static org.iilab.pb.common.AppConstants.FROM_WIZARD_ACTIVITY; +import static org.iilab.pb.common.AppConstants.IMAGE_INLINE; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PARENT_ACTIVITY; +public class SetupCodeFragment extends Fragment { + private static final int ALLOWED_LENGTH_FOR_CODE = 4; + private EditText passwordEditText,confirmPasswordEditText; + private Activity activity; + DisplayMetrics metrics; + TextView tvTitle, tvContent, tvIntro, tvWarning; + Button bAction; + LinearLayout llWarning; + Page currentPage; + private MessageTextView codeHeaderView; + private static final String TAG = SetupCodeFragment.class.getName(); + public static SetupCodeFragment newInstance(String pageId, int parentActivity) { + SetupCodeFragment f = new SetupCodeFragment(); + Bundle args = new Bundle(); + args.putString(PAGE_ID, pageId); + args.putInt(PARENT_ACTIVITY, parentActivity); + f.setArguments(args); + return(f); + } + + private boolean onEnterKeyPress(int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + Log.d(TAG, "key Enter Key Pressed"); + onCodeSaving(); + } + return false; + } + + private void onCodeSaving() { + Log.i(TAG, "Perform action on Enter key press or on press of Save Button"); + // Perform action on key press + String password = passwordEditText.getText().toString(); + String confirmPwd = confirmPasswordEditText.getText().toString(); + if ((password != null) && password.equals(confirmPwd) && isPINLengthVerified()) { + Log.d(TAG, "Code matched and verified length "); + ApplicationSettings.savePassword(getActivity(), passwordEditText.getText().toString()); + String pageId = currentPage.getAction().get(0).getLink(); + int parentActivity = getArguments().getInt(PARENT_ACTIVITY); + Intent i; + + if (parentActivity == FROM_WIZARD_ACTIVITY) { + i = new Intent(activity, WizardActivity.class); + } else { + String confirmation = (currentPage.getAction().get(0).getConfirmation() == null) + ? DEFAULT_CONFIRMATION_MESSAGE + : currentPage.getAction().get(0).getConfirmation(); + Toast.makeText(activity, confirmation, Toast.LENGTH_SHORT).show(); + + i = new Intent(activity, MainActivity.class); + } + i.putExtra(PAGE_ID, pageId); + startActivity(i); + + if (parentActivity == FROM_MAIN_ACTIVITY) { + activity.finish(); + } + } else { + Log.d(TAG, "Code not matched "); + AppUtil.setError(activity, confirmPasswordEditText, R.string.incorrect_pin); + } + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_type_interactive_code, container, false); + codeHeaderView = (MessageTextView) view.findViewById(R.id.confirm_pin_header); + passwordEditText = (EditText) view.findViewById(R.id.create_pin_edittext); + confirmPasswordEditText=(EditText)view.findViewById(R.id.confirm_pin_edittext); + passwordEditText.addTextChangedListener(passwordTextChangeListener); + confirmPasswordEditText.addTextChangedListener(passwordTextChangeListener); + passwordEditText.setOnKeyListener(new OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + Log.d(TAG, "key Pressed event for passwordEditText called "); + return onEnterKeyPress(keyCode, event); + } + }); + passwordEditText.requestFocus(); + + confirmPasswordEditText.setOnKeyListener(new OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + Log.d(TAG, "key Pressed event for confirmPasswordEditText called "); + return onEnterKeyPress(keyCode, event); + } + }); + tvTitle = (TextView) view.findViewById(R.id.fragment_title); + tvIntro = (TextView) view.findViewById(R.id.fragment_intro); + tvContent = (TextView) view.findViewById(R.id.fragment_contents); + + bAction = (Button) view.findViewById(R.id.fragment_action); + bAction.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d(TAG, "action button pressed"); + onCodeSaving(); + } + }); + llWarning = (LinearLayout) view.findViewById(R.id.ll_fragment_warning); + tvWarning = (TextView) view.findViewById(R.id.fragment_warning); + return view; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + activity = getActivity(); + if (activity != null) { + metrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + bAction.setEnabled(isPINLengthVerified()); + + String pageId = getArguments().getString(PAGE_ID); + String selectedLang = ApplicationSettings.getSelectedLanguage(activity); + + PBDatabase dbInstance = new PBDatabase(activity); + dbInstance.open(); + currentPage = dbInstance.retrievePage(pageId, selectedLang); + dbInstance.close(); + + tvTitle.setText(currentPage.getTitle()); + + if(currentPage.getContent() == null) + tvContent.setVisibility(View.GONE); + else + tvContent.setText(Html.fromHtml(currentPage.getContent(), null, new MyTagHandler())); + + if(currentPage.getIntroduction() == null) + tvIntro.setVisibility(View.GONE); + else + tvIntro.setText(currentPage.getIntroduction()); + + if(currentPage.getWarning() == null) + llWarning.setVisibility(View.GONE); + else + tvWarning.setText(currentPage.getWarning()); + + bAction.setText(currentPage.getAction().get(0).getTitle()); + codeHeaderView.setText(codeHeaderView.getMessageHeader()); + AppUtil.updateImages(true, currentPage.getContent(), activity, metrics, tvContent, IMAGE_INLINE); + } + } + + private boolean isPINLengthVerified() { + return ((passwordEditText.getText().length() == ALLOWED_LENGTH_FOR_CODE) && + confirmPasswordEditText.getText().length() == ALLOWED_LENGTH_FOR_CODE); + } + + private TextWatcher passwordTextChangeListener = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence text, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable text) { + bAction.setEnabled(isPINLengthVerified()); + } + }; +} diff --git a/src/main/java/org/iilab/pb/fragment/SetupContactsFragment.java b/app/src/main/java/org/iilab/pb/fragment/SetupContactsFragment.java similarity index 76% rename from src/main/java/org/iilab/pb/fragment/SetupContactsFragment.java rename to app/src/main/java/org/iilab/pb/fragment/SetupContactsFragment.java index 69f0f42f..ef31b528 100644 --- a/src/main/java/org/iilab/pb/fragment/SetupContactsFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/SetupContactsFragment.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.text.Html; import android.util.DisplayMetrics; import android.util.Log; @@ -17,9 +18,6 @@ import android.widget.TextView; import android.widget.Toast; - -import java.util.List; - import org.iilab.pb.MainActivity; import org.iilab.pb.R; import org.iilab.pb.WizardActivity; @@ -28,12 +26,16 @@ import org.iilab.pb.common.AppUtil; import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.common.ContactEditTexts; +import org.iilab.pb.common.ContactPickerFragment; import org.iilab.pb.common.MyTagHandler; import org.iilab.pb.data.PBDatabase; import org.iilab.pb.model.Page; import org.iilab.pb.model.PageItem; import org.iilab.pb.model.SMSSettings; +import java.util.Arrays; +import java.util.List; + /** * Created by aoe on 12/11/13. */ @@ -43,16 +45,14 @@ public class SetupContactsFragment extends Fragment { private static final String PAGE_ID = "page_id"; private static final String PARENT_ACTIVITY = "parent_activity"; private Activity activity; - DisplayMetrics metrics; - TextView tvTitle, tvContent, tvIntro, tvWarning; Button bAction; ListView lvItems; LinearLayout llWarning; - Page currentPage; PageItemAdapter pageItemAdapter; + List fragmentIds = Arrays.asList(R.id.first_contact, R.id.second_contact, R.id.third_contact); public static SetupContactsFragment newInstance(String pageId, int parentActivity) { SetupContactsFragment f = new SetupContactsFragment(); @@ -72,19 +72,27 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa tvContent = (TextView) view.findViewById(R.id.fragment_contents); bAction = (Button) view.findViewById(R.id.fragment_action); + ContactPickerFragment contactPickerFragment=(ContactPickerFragment)getChildFragmentManager().findFragmentById(R.id.first_contact); + if(contactPickerFragment==null) { + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + for (Integer id : fragmentIds) { + contactPickerFragment = new ContactPickerFragment(); + transaction.replace(id, contactPickerFragment); + } + transaction.commit(); + } bAction.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.e(">>>>", "action button pressed"); - SMSSettings newSMSSettings = getSMSSettingsFromView(); + SMSSettings newSMSSettings = getContactNumbersFromView(); SMSSettings.saveContacts(activity, newSMSSettings); - displaySettings(newSMSSettings); + displayContactNumbers(); String pageId = currentPage.getAction().get(0).getLink(); int parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ i = new Intent(activity, WizardActivity.class); } else{ @@ -95,7 +103,7 @@ public void onClick(View v) { i = new Intent(activity, MainActivity.class); } - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); if(parentActivity == AppConstants.FROM_MAIN_ACTIVITY){ @@ -120,19 +128,16 @@ public void onItemClick(AdapterView parent, View view, int position, long id) int parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == AppConstants.FROM_WIZARD_ACTIVITY) { i = new Intent(activity, WizardActivity.class); - } else{ + } else { i = new Intent(activity, MainActivity.class); } - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); } }); - -// initializeViews(view); - return view; } @@ -144,15 +149,6 @@ public void onActivityCreated(Bundle savedInstanceState) { if (activity != null) { metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); - - contactEditTexts = new ContactEditTexts(getFragmentManager(), bAction, activity); - - SMSSettings currentSettings = SMSSettings.retrieve(activity); - if(currentSettings.isConfigured()) { - displaySettings(currentSettings); - } - bAction.setEnabled(contactEditTexts.hasAtleastOneValidPhoneNumber()); - String pageId = getArguments().getString(PAGE_ID); String selectedLang = ApplicationSettings.getSelectedLanguage(activity); @@ -185,18 +181,35 @@ public void onActivityCreated(Bundle savedInstanceState) { pageItemAdapter.setData(currentPage.getItems()); AppUtil.updateImages(true, currentPage.getContent(), activity, metrics, tvContent, AppConstants.IMAGE_INLINE); - } } - - private void displaySettings(SMSSettings settings) { + public void initializeContactNumbers(){ + contactEditTexts = new ContactEditTexts(getChildFragmentManager(), bAction, getActivity()); + SMSSettings currentSettings = SMSSettings.retrieve(activity); + if(currentSettings.isConfigured()) { + displayContactNumbers(); + } + bAction.setEnabled(contactEditTexts.hasAtleastOneValidPhoneNumber()); + } + private void displayContactNumbers() { contactEditTexts.maskPhoneNumbers(); } - private SMSSettings getSMSSettingsFromView() { + private SMSSettings getContactNumbersFromView() { List phoneNumbers = contactEditTexts.getPhoneNumbers(); return new SMSSettings(phoneNumbers); } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + super.onActivityResult(requestCode, resultCode, intent); + List fragments = getChildFragmentManager().getFragments(); + if (fragments != null) { + for (Fragment fragment : fragments) { + fragment.onActivityResult(requestCode, resultCode, intent); + } + } + } + } diff --git a/src/main/java/org/iilab/pb/fragment/SetupMessageFragment.java b/app/src/main/java/org/iilab/pb/fragment/SetupMessageFragment.java similarity index 61% rename from src/main/java/org/iilab/pb/fragment/SetupMessageFragment.java rename to app/src/main/java/org/iilab/pb/fragment/SetupMessageFragment.java index 35b85e32..29ecf043 100644 --- a/src/main/java/org/iilab/pb/fragment/SetupMessageFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/SetupMessageFragment.java @@ -1,25 +1,10 @@ package org.iilab.pb.fragment; -import android.content.Context; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import org.iilab.pb.MainActivity; -import org.iilab.pb.R; -import org.iilab.pb.WizardActivity; -import org.iilab.pb.adapter.PageItemAdapter; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.AppUtil; -import org.iilab.pb.common.ApplicationSettings; -import org.iilab.pb.common.MyTagHandler; -import org.iilab.pb.data.PBDatabase; -import org.iilab.pb.model.Page; -import org.iilab.pb.model.PageItem; -import org.iilab.pb.model.SMSSettings; - import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.text.Html; import android.util.DisplayMetrics; import android.util.Log; @@ -28,30 +13,45 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Button; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import org.iilab.pb.MainActivity; +import org.iilab.pb.R; +import org.iilab.pb.WizardActivity; +import org.iilab.pb.adapter.PageItemAdapter; +import org.iilab.pb.common.MyTagHandler; +import org.iilab.pb.data.PBDatabase; +import org.iilab.pb.model.Page; +import org.iilab.pb.model.PageItem; +import org.iilab.pb.model.SMSSettings; + +import static org.iilab.pb.common.AppConstants.DEFAULT_CONFIRMATION_MESSAGE; +import static org.iilab.pb.common.AppConstants.FROM_MAIN_ACTIVITY; +import static org.iilab.pb.common.AppConstants.FROM_WIZARD_ACTIVITY; +import static org.iilab.pb.common.AppConstants.IMAGE_INLINE; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PARENT_ACTIVITY; +import static org.iilab.pb.common.AppUtil.updateImages; +import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage; + /** * Created by aoe on 12/12/13. */ public class SetupMessageFragment extends Fragment { - private EditText smsEditText; - private static final String PAGE_ID = "page_id"; - private static final String PARENT_ACTIVITY = "parent_activity"; + private static final String TAG = SetupMessageFragment.class.getName(); private Activity activity; - DisplayMetrics metrics; + int parentActivity; TextView tvTitle, tvContent, tvIntro, tvWarning; Button bAction; ListView lvItems; LinearLayout llWarning; - Page currentPage; PageItemAdapter pageItemAdapter; @@ -61,7 +61,7 @@ public static SetupMessageFragment newInstance(String pageId, int parentActivity args.putString(PAGE_ID, pageId); args.putInt(PARENT_ACTIVITY, parentActivity); f.setArguments(args); - return(f); + return (f); } @@ -73,46 +73,62 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa tvTitle = (TextView) view.findViewById(R.id.fragment_title); tvIntro = (TextView) view.findViewById(R.id.fragment_intro); tvContent = (TextView) view.findViewById(R.id.fragment_contents); + parentActivity = getArguments().getInt(PARENT_ACTIVITY); + MessageTextFragment childFragment = (MessageTextFragment) getChildFragmentManager().findFragmentById(R.id.sms_message); + if (childFragment == null) { + childFragment = new MessageTextFragment(); + Bundle args = new Bundle(); + args.putInt(PARENT_ACTIVITY, parentActivity); + childFragment.setArguments(args); + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + transaction.replace(R.id.sms_message, childFragment); + transaction.commit(); + } bAction = (Button) view.findViewById(R.id.fragment_action); bAction.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Log.e(">>>>", "action button pressed"); - String msg = getSMSSettingsFromView(); - - SMSSettings.saveMessage(activity, msg); - displaySettings(msg); - + Log.d(TAG, "action button pressed"); + + MessageTextFragment childFragment = (MessageTextFragment) getChildFragmentManager().findFragmentById(R.id.sms_message); + String emergencyMessage = childFragment.getEmergencyMsgFromView(); + SMSSettings.saveMessage(activity, emergencyMessage); + childFragment.displayEmergencyMsg(emergencyMessage); + String stopAlertMessage=getString(R.string.stop_alert_message); + if (parentActivity == FROM_MAIN_ACTIVITY) { + stopAlertMessage=childFragment.getStopAlertMsgFromView(); + Log.d(TAG, "stop alert message is " + stopAlertMessage); + childFragment.displayStopAlertMsg(stopAlertMessage); + } + SMSSettings.saveStopAlertMessage(activity, stopAlertMessage); String pageId = currentPage.getAction().get(0).getLink(); - int parentActivity = getArguments().getInt(PARENT_ACTIVITY); +// parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == FROM_WIZARD_ACTIVITY) { i = new Intent(activity, WizardActivity.class); - } else{ -// AppUtil.showToast("Message saved.", 1000, activity); + } else { +// showToast("Message saved.", 1000, activity); String confirmation = (currentPage.getAction().get(0).getConfirmation() == null) - ? AppConstants.DEFAULT_CONFIRMATION_MESSAGE + ? DEFAULT_CONFIRMATION_MESSAGE : currentPage.getAction().get(0).getConfirmation(); Toast.makeText(activity, confirmation, Toast.LENGTH_SHORT).show(); i = new Intent(activity, MainActivity.class); } - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); - if(parentActivity == AppConstants.FROM_MAIN_ACTIVITY){ + if (parentActivity == FROM_MAIN_ACTIVITY) { activity.finish(); } } }); - - lvItems = (ListView) view.findViewById(R.id.fragment_item_list); llWarning = (LinearLayout) view.findViewById(R.id.ll_fragment_warning); - tvWarning = (TextView) view.findViewById(R.id.fragment_warning); + tvWarning = (TextView) view.findViewById(R.id.fragment_warning); lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -124,12 +140,12 @@ public void onItemClick(AdapterView parent, View view, int position, long id) int parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == FROM_WIZARD_ACTIVITY) { i = new Intent(activity, WizardActivity.class); - } else{ + } else { i = new Intent(activity, MainActivity.class); } - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); } @@ -148,19 +164,8 @@ public void onActivityCreated(Bundle savedInstanceState) { metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); - Fragment fragment = getFragmentManager().findFragmentById(R.id.sms_message); - ((MessageTextFragment)fragment).setActionButtonStateListener(bAction); - smsEditText = (EditText) fragment.getView().findViewById(R.id.message_edit_text); - - String currentMsg = SMSSettings.retrieveMessage(activity); - if(currentMsg != null) { - displaySettings(currentMsg); - } - bAction.setEnabled(!smsEditText.getText().toString().trim().equals("")); - smsEditText.setImeOptions(EditorInfo.IME_FLAG_NAVIGATE_NEXT); - smsEditText.selectAll(); String pageId = getArguments().getString(PAGE_ID); - String selectedLang = ApplicationSettings.getSelectedLanguage(activity); + String selectedLang = getSelectedLanguage(activity); PBDatabase dbInstance = new PBDatabase(activity); dbInstance.open(); @@ -169,17 +174,17 @@ public void onActivityCreated(Bundle savedInstanceState) { tvTitle.setText(currentPage.getTitle()); - if(currentPage.getContent() == null) + if (currentPage.getContent() == null) tvContent.setVisibility(View.GONE); else tvContent.setText(Html.fromHtml(currentPage.getContent(), null, new MyTagHandler())); - if(currentPage.getIntroduction() == null) + if (currentPage.getIntroduction() == null) tvIntro.setVisibility(View.GONE); else tvIntro.setText(currentPage.getIntroduction()); - if(currentPage.getWarning() == null) + if (currentPage.getWarning() == null) llWarning.setVisibility(View.GONE); else tvWarning.setText(currentPage.getWarning()); @@ -190,19 +195,9 @@ public void onActivityCreated(Bundle savedInstanceState) { lvItems.setAdapter(pageItemAdapter); pageItemAdapter.setData(currentPage.getItems()); - AppUtil.updateImages(true, currentPage.getContent(), activity, metrics, tvContent, AppConstants.IMAGE_INLINE); + updateImages(true, currentPage.getContent(), activity, metrics, tvContent, IMAGE_INLINE); } } - - private void displaySettings(String msg) { - smsEditText.setText(msg); - } - - - private String getSMSSettingsFromView() { - String message = smsEditText.getText().toString().trim(); - return message; - } } diff --git a/src/main/java/org/iilab/pb/fragment/SimpleFragment.java b/app/src/main/java/org/iilab/pb/fragment/SimpleFragment.java similarity index 70% rename from src/main/java/org/iilab/pb/fragment/SimpleFragment.java rename to app/src/main/java/org/iilab/pb/fragment/SimpleFragment.java index 805e3a79..f4d095c1 100644 --- a/src/main/java/org/iilab/pb/fragment/SimpleFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/SimpleFragment.java @@ -19,9 +19,6 @@ import android.widget.LinearLayout; import android.widget.TextView; - -import java.util.HashMap; - import org.iilab.pb.MainActivity; import org.iilab.pb.R; import org.iilab.pb.WizardActivity; @@ -39,14 +36,22 @@ import org.iilab.pb.model.Page; import org.iilab.pb.model.PageItem; +import java.util.HashMap; + +import static org.iilab.pb.common.AppConstants.COLOR_RED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_ALERTING; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_DISGUISE_SUCCESS; +import static org.iilab.pb.common.AppConstants.PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS; +import static org.iilab.pb.common.AppConstants.PARENT_ACTIVITY; /** * Created by aoe on 1/3/14. */ public class SimpleFragment extends Fragment { - private static final String PAGE_ID = "page_id"; - private static final String PARENT_ACTIVITY = "parent_activity"; private HashMap mImageCache = new HashMap(); private Activity activity; @@ -56,12 +61,13 @@ public class SimpleFragment extends Fragment { NestedListView lvItems; NestedListView lvActions; LinearLayout llWarning, llStatus; - Button bAction; + Button bActionStopAlert; Page currentPage; PageItemAdapter pageItemAdapter; PageActionAdapter pageActionAdapter; boolean isPageStatusAvailable; + private static final String TAG = SimpleFragment.class.getName(); public static SimpleFragment newInstance(String pageId, int parentActivity) { SimpleFragment f = new SimpleFragment(); @@ -69,14 +75,14 @@ public static SimpleFragment newInstance(String pageId, int parentActivity) { args.putString(PAGE_ID, pageId); args.putInt(PARENT_ACTIVITY, parentActivity); f.setArguments(args); - return(f); + return (f); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_type_simple, container, false); - Log.e(">>>>>", "SimpleFragment.onCreateView"); + Log.i(TAG, "onCreateView called"); tvTitle = (TextView) view.findViewById(R.id.fragment_title); tvIntro = (TextView) view.findViewById(R.id.fragment_intro); @@ -89,26 +95,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa special case for page id = "home-alerting" This button will be visible only when we are in home-alerting page. */ - bAction = (Button) view.findViewById(R.id.b_action); - bAction.setOnClickListener(new View.OnClickListener() { + bActionStopAlert = (Button) view.findViewById(R.id.b_actionStopAlert); + bActionStopAlert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + Log.i(TAG, "on click of \"Stop Alert\" button"); stopAlert(); String pageId = currentPage.getAction().get(0).getLink(); - int parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - // This part needs to be changed. - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY || pageId.equalsIgnoreCase("home-not-configured")){ + if (parentActivity == AppConstants.FROM_WIZARD_ACTIVITY || pageId.equalsIgnoreCase(PAGE_HOME_NOT_CONFIGURED)) { + Log.e(TAG, "This case should never be reached as parent activity can not be WizardActivity"); i = new Intent(activity, WizardActivity.class); i = AppUtil.clearBackStack(i); - } else{ + } else { i = new Intent(activity, MainActivity.class); } - -// Intent i = new Intent(activity, WizardActivity.class); - i.putExtra("page_id", pageId); + Log.d(TAG, "Target page-id is " + pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); activity.finish(); @@ -119,20 +124,17 @@ public void onClick(View v) { llStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { -// AppConstants.IS_ACTION_ITEM_PRESSED = true; - String pageId = currentPage.getStatus().get(0).getLink(); int parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == AppConstants.FROM_WIZARD_ACTIVITY) { i = new Intent(activity, WizardActivity.class); - } else{ + } else { i = new Intent(activity, MainActivity.class); } - -// Intent i = new Intent(activity, WizardActivity.class); - i.putExtra("page_id", pageId); + Log.d(TAG, "Target page-id from status click " + pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); } }); @@ -141,28 +143,24 @@ public void onClick(View v) { lvActions = (NestedListView) view.findViewById(R.id.fragment_action_list); llWarning = (LinearLayout) view.findViewById(R.id.ll_fragment_warning); - tvWarning = (TextView) view.findViewById(R.id.fragment_warning); + tvWarning = (TextView) view.findViewById(R.id.fragment_warning); lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { -// AppConstants.IS_ACTION_ITEM_PRESSED = true; - PageItem selectedItem = (PageItem) parent.getItemAtPosition(position); - -// AppConstants.PAGE_FROM_NOT_IMPLEMENTED = true; - String pageId = selectedItem.getLink(); int parentActivity = getArguments().getInt(PARENT_ACTIVITY); Intent i; - if(parentActivity == AppConstants.FROM_WIZARD_ACTIVITY){ + if (parentActivity == AppConstants.FROM_WIZARD_ACTIVITY) { i = new Intent(activity, WizardActivity.class); - } else{ + } else { i = new Intent(activity, MainActivity.class); } - i.putExtra("page_id", pageId); + Log.d(TAG, "Target page-id from itemList is "+pageId); + i.putExtra(PAGE_ID, pageId); startActivity(i); } }); @@ -172,7 +170,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - Log.e(">>>>>", "SimpleFragment.onActivityCreated"); + Log.i(TAG, "onActivityCreated called"); activity = getActivity(); if (activity != null) { @@ -182,7 +180,8 @@ public void onActivityCreated(Bundle savedInstanceState) { String pageId = getArguments().getString(PAGE_ID); String selectedLang = ApplicationSettings.getSelectedLanguage(activity); int parentActivity = getArguments().getInt(PARENT_ACTIVITY); - + Log.d(TAG, "current page id is : "+pageId); + Log.d(TAG, "Parent activity is : 1=wizard, 2 = Main "+ parentActivity); PBDatabase dbInstance = new PBDatabase(activity); dbInstance.open(); currentPage = dbInstance.retrievePage(pageId, selectedLang); @@ -190,43 +189,54 @@ public void onActivityCreated(Bundle savedInstanceState) { tvTitle.setText(currentPage.getTitle()); - if(currentPage.getStatus() == null || currentPage.getStatus().size() == 0){ + if (currentPage.getStatus() == null || currentPage.getStatus().size() == 0) { isPageStatusAvailable = false; llStatus.setVisibility(View.GONE); - } else{ + } else { isPageStatusAvailable = true; String color = currentPage.getStatus().get(0).getColor(); - if(color.equals("red")) + if (color.equals(COLOR_RED)) tvStatus.setTextColor(Color.RED); else tvStatus.setTextColor(Color.GREEN); tvStatus.setText(currentPage.getStatus().get(0).getTitle()); } - if(currentPage.getContent() == null) + if (currentPage.getContent() == null) tvContent.setVisibility(View.GONE); else { tvContent.setText(Html.fromHtml(currentPage.getContent(), null, new MyTagHandler())); tvContent.setMovementMethod(LinkMovementMethod.getInstance()); } - if(currentPage.getIntroduction() == null) + if (currentPage.getIntroduction() == null) tvIntro.setVisibility(View.GONE); else tvIntro.setText(currentPage.getIntroduction()); - if(currentPage.getWarning() == null) + if (currentPage.getWarning() == null) llWarning.setVisibility(View.GONE); else tvWarning.setText(currentPage.getWarning()); - if(pageId.equals("home-ready") || pageId.equals("home-alerting")){ + if (pageId.equals(PAGE_HOME_READY) || pageId.equals(PAGE_HOME_ALERTING)) { isPageStatusAvailable = false; } + /** + * if page status is "Home-Ready", we can enable the checkbox to disable the Power button Alarm + */ + //TODO-- commented for #80 need to put this in ApplicationSettings fragment +// if (pageId.equals(PAGE_HOME_READY)){ +// powerTriggerRadioGroup.setVisibility(View.VISIBLE); +// configurePowerTriggerHeader.setVisibility(View.VISIBLE); +// }else{ +// powerTriggerRadioGroup.setVisibility(View.GONE); +// configurePowerTriggerHeader.setVisibility(View.GONE); +// } pageActionAdapter = new PageActionAdapter(activity, null, isPageStatusAvailable, parentActivity); - if (pageId.equals("setup-alarm-test-hardware-success") || pageId.equals("setup-alarm-test-disguise-success")) { + if (pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS) || pageId.equals(PAGE_SETUP_ALARM_TEST_DISGUISE_SUCCESS)) { PageActionFakeAdapter pageActionFakeAdapter = new PageActionFakeAdapter(activity, null); lvActions.setAdapter(pageActionFakeAdapter); pageActionFakeAdapter.setData(currentPage.getAction()); @@ -239,14 +249,12 @@ public void run() { pageActionAdapter.setData(currentPage.getAction()); } }, 1000); - } - else if(pageId.equals("home-alerting")){ + } else if (pageId.equals(PAGE_HOME_ALERTING)) { lvActions.setVisibility(View.INVISIBLE); - bAction.setVisibility(View.VISIBLE); + bActionStopAlert.setVisibility(View.VISIBLE); - bAction.setText(currentPage.getAction().get(0).getTitle()); - } - else { + bActionStopAlert.setText(currentPage.getAction().get(0).getTitle()); + } else { lvActions.setAdapter(pageActionAdapter); pageActionAdapter.setData(currentPage.getAction()); } @@ -278,25 +286,25 @@ PanicAlert getPanicAlert() { @Override public void onPause() { super.onPause(); - Log.e("SimpleFragment.onPause", currentPage.getId()); + Log.d(TAG, currentPage.getId()); } @Override - public void onStop(){ + public void onStop() { super.onStop(); - Log.e("SimpleFragment.onStop", currentPage.getId()); + Log.d(TAG, currentPage.getId()); } @Override public void onStart() { super.onStart(); - Log.e("SimpleFragment.onStart", currentPage.getId()); + Log.d(TAG, currentPage.getId()); } @Override public void onResume() { super.onResume(); - Log.e("SimpleFragment.onResume", currentPage.getId()); + Log.d(TAG, currentPage.getId()); } } diff --git a/src/main/java/org/iilab/pb/fragment/WarningFragment.java b/app/src/main/java/org/iilab/pb/fragment/WarningFragment.java similarity index 100% rename from src/main/java/org/iilab/pb/fragment/WarningFragment.java rename to app/src/main/java/org/iilab/pb/fragment/WarningFragment.java diff --git a/src/main/java/org/iilab/pb/fragment/WizardAlarmTestDisguiseFragment.java b/app/src/main/java/org/iilab/pb/fragment/WizardAlarmTestDisguiseFragment.java similarity index 76% rename from src/main/java/org/iilab/pb/fragment/WizardAlarmTestDisguiseFragment.java rename to app/src/main/java/org/iilab/pb/fragment/WizardAlarmTestDisguiseFragment.java index dd835a26..2456a82d 100644 --- a/src/main/java/org/iilab/pb/fragment/WizardAlarmTestDisguiseFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/WizardAlarmTestDisguiseFragment.java @@ -1,14 +1,5 @@ package org.iilab.pb.fragment; -import android.widget.Toast; -import org.iilab.pb.R; -import org.iilab.pb.WizardActivity; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.ApplicationSettings; -import org.iilab.pb.data.PBDatabase; -import org.iilab.pb.model.Page; -import org.iilab.pb.trigger.MultiClickEvent; - import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -20,14 +11,24 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; +import org.iilab.pb.R; +import org.iilab.pb.WizardActivity; +import org.iilab.pb.common.ApplicationSettings; +import org.iilab.pb.data.PBDatabase; +import org.iilab.pb.model.Page; +import org.iilab.pb.trigger.MultiClickEvent; + +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppUtil.vibrateForConfirmationOfAlertTriggered; +import static org.iilab.pb.common.AppUtil.vibrateForHapticFeedback; /** * Created by aoe on 1/16/14. */ public class WizardAlarmTestDisguiseFragment extends Fragment { - private static final String PAGE_ID = "page_id"; private Activity activity; private int[] buttonIds = {R.id.one, R.id.two, R.id.three, R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, @@ -36,6 +37,7 @@ public class WizardAlarmTestDisguiseFragment extends Fragment { private int lastClickId = -1; Page currentPage; + private static final String TAG = WizardAlarmTestDisguiseFragment.class.getName(); public static WizardAlarmTestDisguiseFragment newInstance(String pageId) { WizardAlarmTestDisguiseFragment f = new WizardAlarmTestDisguiseFragment(); @@ -47,11 +49,11 @@ public static WizardAlarmTestDisguiseFragment newInstance(String pageId) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - Log.e(">>>>>", "onCreateView before inflate"); + Log.d(TAG, "onCreateView before inflate"); View view = inflater.inflate(R.layout.calculator_layout, container, false); - Log.e(">>>>>", "onCreateView before registerButtonEvents"); + Log.d(TAG, "onCreateView before registerButtonEvents"); registerButtonEvents(view); - Log.e(">>>>>", "onCreateView after registerButtonEvents"); + Log.d(TAG, "onCreateView after registerButtonEvents"); return view; } @@ -74,25 +76,25 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public void onPause() { super.onPause(); - Log.e(">>>>>", "onPause WizardAlarmTestDisguiseFragment"); + Log.d(TAG, "onPause WizardAlarmTestDisguiseFragment"); } @Override public void onResume() { super.onResume(); - Log.e(">>>>>", "onResume WizardAlarmTestDisguiseFragment"); + Log.d(TAG, "onResume WizardAlarmTestDisguiseFragment"); } @Override public void onDestroyView() { super.onDestroyView(); - Log.e(">>>>>", "onDestroyView WizardAlarmTestDisguiseFragment"); + Log.d(TAG, "onDestroyView WizardAlarmTestDisguiseFragment"); } @Override public void onDestroy() { super.onDestroy(); - Log.e(">>>>>", "onDestroy WizardAlarmTestDisguiseFragment"); + Log.d(TAG, "onDestroy WizardAlarmTestDisguiseFragment"); } @@ -114,12 +116,12 @@ private void unregisterButtonEvents(Activity activity) { @Override public void onClick(View view) { int id = view.getId(); - Log.e(">>>>>", "onClick id " + id); - Log.e(">>>>>", "onClick lastClickId " + lastClickId); + Log.d(TAG, "onClick id " + id); + Log.d(TAG, "onClick lastClickId " + lastClickId); MultiClickEvent multiClickEvent = (MultiClickEvent) view.getTag(); if (multiClickEvent == null) { - Log.e(">>>>>", "multiClickEvent reset"); + Log.d(TAG, "multiClickEvent reset"); multiClickEvent = resetEvent(view); } @@ -128,26 +130,26 @@ public void onClick(View view) { multiClickEvent.registerClick(System.currentTimeMillis()); if(multiClickEvent.skipCurrentClick()){ - Log.e(">>>>>", "multiClickEvent skip"); + Log.d(TAG, "multiClickEvent skip"); multiClickEvent.resetSkipCurrentClickFlag(); return; } if(multiClickEvent.canStartVibration()) { - vibrate(AppConstants.HAPTIC_FEEDBACK_DURATION); - +// vibrate(ONE_SECOND*Integer.parseInt(DEFAULT_HAPTIC_FEEDBACK_DURATION)); + vibrateForHapticFeedback(getActivity()); CharSequence text = ((Button) view).getText(); Toast.makeText(activity, "Press the button '" + text + "' once the vibration ends to trigger alerts", Toast.LENGTH_LONG).show(); } else if(multiClickEvent.isActivated()){ - Log.e(">>>>>", "multiClickEvent isActivated"); - vibrate(AppConstants.ALERT_CONFIRMATION_VIBRATION_DURATION); - + Log.d(TAG, "multiClickEvent isActivated"); +// vibrate(ALERT_CONFIRMATION_VIBRATION_DURATION); + vibrateForConfirmationOfAlertTriggered(getActivity()); resetEvent(view); //unregisterButtonEvents(activity); String pageId = currentPage.getSuccessId(); Intent i = new Intent(activity, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); activity.startActivity(i); activity.finish(); } @@ -160,7 +162,7 @@ private void vibrate(int vibrationDuration) { } private MultiClickEvent resetEvent(View view) { - MultiClickEvent multiClickEvent = new MultiClickEvent(); + MultiClickEvent multiClickEvent = new MultiClickEvent(getActivity()); view.setTag(multiClickEvent); return multiClickEvent; } diff --git a/src/main/java/org/iilab/pb/fragment/WizardAlarmTestHardwareFragment.java b/app/src/main/java/org/iilab/pb/fragment/WizardAlarmTestHardwareFragment.java similarity index 65% rename from src/main/java/org/iilab/pb/fragment/WizardAlarmTestHardwareFragment.java rename to app/src/main/java/org/iilab/pb/fragment/WizardAlarmTestHardwareFragment.java index 101e81e8..8882de12 100644 --- a/src/main/java/org/iilab/pb/fragment/WizardAlarmTestHardwareFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/WizardAlarmTestHardwareFragment.java @@ -16,10 +16,9 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; + import org.iilab.pb.R; import org.iilab.pb.WizardActivity; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.common.GifDecoderView; import org.iilab.pb.common.MyTagHandler; import org.iilab.pb.data.PBDatabase; @@ -30,22 +29,29 @@ import java.io.InputStream; import java.util.HashMap; +import static org.iilab.pb.common.AppConstants.ALARM_5_PRESS_PLUS_CONFIRMATION; +import static org.iilab.pb.common.AppConstants.ALARM_CUSTOM; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppUtil.getCustomTrainingToastMessage; +import static org.iilab.pb.common.AppUtil.vibrateForConfirmationOfAlertTriggered; +import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage; +import static org.iilab.pb.common.ApplicationSettings.getTriggerPattern; + /** * Created by aoe on 1/9/14. */ public class WizardAlarmTestHardwareFragment extends Fragment { - private static final String PAGE_ID = "page_id"; private HashMap mImageCache = new HashMap(); private Activity activity; DisplayMetrics metrics; PowerManager.WakeLock wakeLock; -// TextView tvContent; private GifDecoderView gifView; Page currentPage; + private static final String TAG = SimpleFragment.class.getName(); public static WizardAlarmTestHardwareFragment newInstance(String pageId) { WizardAlarmTestHardwareFragment f = new WizardAlarmTestHardwareFragment(); @@ -58,8 +64,6 @@ public static WizardAlarmTestHardwareFragment newInstance(String pageId) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_type_interactive_test_hardware, container, false); - -// tvContent = (TextView) view.findViewById(R.id.fragment_contents); gifView = (GifDecoderView) view.findViewById(R.id.gif_view); return view; @@ -83,7 +87,7 @@ public void onActivityCreated(Bundle savedInstanceState) { activity.registerReceiver(wizardHardwareReceiver, filter); String pageId = getArguments().getString(PAGE_ID); - String selectedLang = ApplicationSettings.getSelectedLanguage(activity); + String selectedLang = getSelectedLanguage(activity); PBDatabase dbInstance = new PBDatabase(activity); dbInstance.open(); @@ -93,32 +97,43 @@ public void onActivityCreated(Bundle savedInstanceState) { if (currentPage.getContent() == null) gifView.setVisibility(View.GONE); else { - Html.fromHtml(currentPage.getContent(), new Html.ImageGetter() { + Log.d(TAG, getTriggerPattern(getActivity())); + + //check the trigger pattern and accordingly load image.7 repeated press set source is default picked from jsons + // 5 press + confirmation set source to new gif(locale specific) + //custom gif view empty-- show static image with toast of no of clicks and confirmation + String sourceStr = currentPage.getContent(); + + if (ALARM_5_PRESS_PLUS_CONFIRMATION.equals(getTriggerPattern(getActivity()))) { + sourceStr = getString(R.string.resource5PressPlusConfirmation); + } + + if (ALARM_CUSTOM.equals(getTriggerPattern(getActivity()))) { + sourceStr = getString(R.string.resourceCustomImage); + ((WizardActivity) getActivity()).customAlarmToastMessage(getCustomTrainingToastMessage(getActivity())); + } + Log.d(TAG, "the .gif image source name is " + sourceStr); + Html.fromHtml(sourceStr, new Html.ImageGetter() { @SuppressWarnings("unchecked") @Override public Drawable getDrawable(final String source) { try { - Log.e(">>>>>>>>>>>", "Source = " + source); - Drawable drawable = Drawable.createFromStream(activity.getAssets().open(source.substring(1, source.length())), null); + Drawable drawable = Drawable.createFromStream(activity.getAssets().open(source.substring(1, source.length())), null); InputStream is = activity.getAssets().open(source.substring(1, source.length())); gifView.playGif(is, metrics); -// drawable = AppUtil.setDownloadedImageMetrices(drawable, metrics, AppConstants.IMAGE_SCALABILITY_FACTOR * metrics.scaledDensity, imageScaleFlag); mImageCache.put(source, drawable); -// updateImages(false, textHtml, context, metrics, tvContent, imageScaleFlag); return drawable; } catch (IOException e) { - Log.e(">>>>>>>>>>>>>>", "Failed to load gif image from asset"); + Log.e(TAG, "Failed to load gif image from asset"); e.printStackTrace(); } return null; } }, new MyTagHandler()); - Log.e(">>>>>", "content = " + currentPage.getContent()); -// tvContent.setText(Html.fromHtml(currentPage.getContent(), null, new MyTagHandler())); -// AppUtil.updateImages(true, currentPage.getContent(), activity, metrics, tvContent, AppConstants.IMAGE_FULL_WIDTH); + Log.d(TAG, "content = " + currentPage.getContent()); } } } @@ -127,60 +142,64 @@ public Drawable getDrawable(final String source) { public void onPause() { super.onPause(); gifView.stopGif(); - Log.e(">>>>>", "onPause WizardAlarmTestHardwareFragment"); + Log.d(TAG, "onPause WizardAlarmTestHardwareFragment"); } @Override public void onResume() { super.onResume(); - Log.e(">>>>>", "onResume WizardAlarmTestHardwareFragment"); + Log.d(TAG, "onResume WizardAlarmTestHardwareFragment"); } @Override public void onDestroy() { super.onDestroy(); - Log.e("????", "onDestroy"); + Log.d(TAG, "onDestroy"); activity.unregisterReceiver(wizardHardwareReceiver); } - + @Override public void onDestroyView() { - gifView.clear(); - gifView = null; + gifView.clear(); + gifView = null; super.onDestroyView(); - Log.e("????", "onDestroyView"); + Log.d(TAG, "onDestroyView"); } - private BroadcastReceiver wizardHardwareReceiver = new HardwareTriggerReceiver() { + private BroadcastReceiver wizardHardwareReceiver = new HardwareTriggerReceiver(activity) { @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - Log.e("????", "in onReceive in WizardAlarmTest"); + Log.d(TAG, "in onReceive in WizardAlarmTest"); ((WizardActivity) getActivity()).hideToastMessageInInteractiveFragment(); getActivity().onUserInteraction(); - if(multiClickEvent.canStartVibration()){ - ((WizardActivity) getActivity()).confirmationToastMessage(); + if (multiClickEvent.canStartVibration()) { + + //confirmation message needs to be changed + ((WizardActivity) getActivity()).confirmationPressToastMessage(); } } @Override protected void onActivation(Context context) { - Log.e(">>>>>>>", "in onActivation of wizardHWReceiver"); - + Log.d(TAG, "in onActivation of wizardHWReceiver"); + //add vibration code in test fragments Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); - vibrator.vibrate(AppConstants.ALERT_CONFIRMATION_VIBRATION_DURATION); + vibrateForConfirmationOfAlertTriggered(context); +// vibrator.vibrate(ALERT_CONFIRMATION_VIBRATION_DURATION); String pageId = currentPage.getSuccessId(); Intent i = new Intent(activity, WizardActivity.class); - i.putExtra("page_id", pageId); + i.putExtra(PAGE_ID, pageId); activity.startActivity(i); activity.finish(); } + }; } diff --git a/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseCodeFragment.java b/app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseCodeFragment.java similarity index 100% rename from src/main/java/org/iilab/pb/fragment/WizardTestDisguiseCodeFragment.java rename to app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseCodeFragment.java diff --git a/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseOpenFragment.java b/app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseOpenFragment.java similarity index 100% rename from src/main/java/org/iilab/pb/fragment/WizardTestDisguiseOpenFragment.java rename to app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseOpenFragment.java diff --git a/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseUnlockFragment.java b/app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseUnlockFragment.java similarity index 97% rename from src/main/java/org/iilab/pb/fragment/WizardTestDisguiseUnlockFragment.java rename to app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseUnlockFragment.java index 17198397..b5d11e56 100644 --- a/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseUnlockFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/WizardTestDisguiseUnlockFragment.java @@ -2,10 +2,10 @@ import org.iilab.pb.R; import org.iilab.pb.WizardActivity; +import org.iilab.pb.common.AppConstants; import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.data.PBDatabase; import org.iilab.pb.model.Page; - import android.app.Activity; import android.content.Intent; import android.os.Bundle; @@ -19,6 +19,8 @@ import android.widget.Button; + + /** * Created by aoe on 1/17/14. */ @@ -144,7 +146,7 @@ public void run() { mHasPerformedLongPress = false; - v.postDelayed(mPendingCheckForLongPress, 3000); + v.postDelayed(mPendingCheckForLongPress, AppConstants.DISGUISE_UNLOCK_LONGPRESS_TIME); break; case MotionEvent.ACTION_MOVE: diff --git a/src/main/java/org/iilab/pb/location/CurrentLocationProvider.java b/app/src/main/java/org/iilab/pb/location/CurrentLocationProvider.java similarity index 51% rename from src/main/java/org/iilab/pb/location/CurrentLocationProvider.java rename to app/src/main/java/org/iilab/pb/location/CurrentLocationProvider.java index b43d68cc..6a7ab4c5 100644 --- a/src/main/java/org/iilab/pb/location/CurrentLocationProvider.java +++ b/app/src/main/java/org/iilab/pb/location/CurrentLocationProvider.java @@ -16,24 +16,29 @@ public class CurrentLocationProvider extends LocationListenerAdapter { private Location currentLocation; public CurrentLocationProvider(Context context) { - Log.e(">>>>>>", "in CurrentLocationProvider CONSTRUCTOR - trying to retrieve location from getLastKnownLocation()"); - LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - Criteria criteria = new Criteria(); - criteria.setAccuracy(ACCURACY_FINE); - String provider = manager.getBestProvider(criteria, true); - Location bestLocation; - if (provider != null) - bestLocation = manager.getLastKnownLocation(provider); - else - bestLocation = null; - - Location latestLocation = getLatest(bestLocation, manager.getLastKnownLocation(GPS_PROVIDER)); - latestLocation = getLatest(latestLocation, manager.getLastKnownLocation(NETWORK_PROVIDER)); + try { + Log.e(">>>>>>", "in CurrentLocationProvider CONSTRUCTOR - trying to retrieve location from getLastKnownLocation()"); + LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + Criteria criteria = new Criteria(); + criteria.setAccuracy(ACCURACY_FINE); + String provider = manager.getBestProvider(criteria, true); + Location bestLocation; + if (provider != null) + bestLocation = manager.getLastKnownLocation(provider); + else + bestLocation = null; + + Location latestLocation = getLatest(bestLocation, manager.getLastKnownLocation(GPS_PROVIDER)); + latestLocation = getLatest(latestLocation, manager.getLastKnownLocation(NETWORK_PROVIDER)); // latestLocation = getLatest(latestLocation, manager.getLastKnownLocation(PASSIVE_PROVIDER)); - currentLocation = latestLocation; - if (currentLocation != null) - ApplicationSettings.setCurrentBestLocation(context, currentLocation); - return; + currentLocation = latestLocation; + if (currentLocation != null) + ApplicationSettings.setCurrentBestLocation(context, currentLocation); + return; + }catch(SecurityException e){ + Log.e(">>>>>>", "securityException" ); + e.printStackTrace(); + } } private static Location getLatest(final Location location1, final Location location2) { diff --git a/src/main/java/org/iilab/pb/location/LocationFormatter.java b/app/src/main/java/org/iilab/pb/location/LocationFormatter.java similarity index 100% rename from src/main/java/org/iilab/pb/location/LocationFormatter.java rename to app/src/main/java/org/iilab/pb/location/LocationFormatter.java diff --git a/src/main/java/org/iilab/pb/location/LocationListenerAdapter.java b/app/src/main/java/org/iilab/pb/location/LocationListenerAdapter.java similarity index 100% rename from src/main/java/org/iilab/pb/location/LocationListenerAdapter.java rename to app/src/main/java/org/iilab/pb/location/LocationListenerAdapter.java diff --git a/src/test/java/org/iilab/pb/location/LocationTestUtil.java b/app/src/main/java/org/iilab/pb/location/LocationTestUtil.java similarity index 100% rename from src/test/java/org/iilab/pb/location/LocationTestUtil.java rename to app/src/main/java/org/iilab/pb/location/LocationTestUtil.java diff --git a/src/main/java/org/iilab/pb/location/LocationUpdateReceiver.java b/app/src/main/java/org/iilab/pb/location/LocationUpdateReceiver.java similarity index 100% rename from src/main/java/org/iilab/pb/location/LocationUpdateReceiver.java rename to app/src/main/java/org/iilab/pb/location/LocationUpdateReceiver.java diff --git a/src/main/java/org/iilab/pb/model/AppInfo.java b/app/src/main/java/org/iilab/pb/model/AppInfo.java similarity index 100% rename from src/main/java/org/iilab/pb/model/AppInfo.java rename to app/src/main/java/org/iilab/pb/model/AppInfo.java diff --git a/src/main/java/org/iilab/pb/model/AsyncTaskResult.java b/app/src/main/java/org/iilab/pb/model/AsyncTaskResult.java similarity index 100% rename from src/main/java/org/iilab/pb/model/AsyncTaskResult.java rename to app/src/main/java/org/iilab/pb/model/AsyncTaskResult.java diff --git a/src/main/java/org/iilab/pb/model/Coordinates.java b/app/src/main/java/org/iilab/pb/model/Coordinates.java similarity index 100% rename from src/main/java/org/iilab/pb/model/Coordinates.java rename to app/src/main/java/org/iilab/pb/model/Coordinates.java diff --git a/src/main/java/org/iilab/pb/model/HelpImage.java b/app/src/main/java/org/iilab/pb/model/HelpImage.java similarity index 100% rename from src/main/java/org/iilab/pb/model/HelpImage.java rename to app/src/main/java/org/iilab/pb/model/HelpImage.java diff --git a/src/main/java/org/iilab/pb/model/HelpPage.java b/app/src/main/java/org/iilab/pb/model/HelpPage.java similarity index 100% rename from src/main/java/org/iilab/pb/model/HelpPage.java rename to app/src/main/java/org/iilab/pb/model/HelpPage.java diff --git a/src/main/java/org/iilab/pb/model/MarkDownResponse.java b/app/src/main/java/org/iilab/pb/model/MarkDownResponse.java similarity index 100% rename from src/main/java/org/iilab/pb/model/MarkDownResponse.java rename to app/src/main/java/org/iilab/pb/model/MarkDownResponse.java diff --git a/src/main/java/org/iilab/pb/model/Page.java b/app/src/main/java/org/iilab/pb/model/Page.java similarity index 100% rename from src/main/java/org/iilab/pb/model/Page.java rename to app/src/main/java/org/iilab/pb/model/Page.java diff --git a/src/main/java/org/iilab/pb/model/PageAction.java b/app/src/main/java/org/iilab/pb/model/PageAction.java similarity index 100% rename from src/main/java/org/iilab/pb/model/PageAction.java rename to app/src/main/java/org/iilab/pb/model/PageAction.java diff --git a/src/main/java/org/iilab/pb/model/PageChecklist.java b/app/src/main/java/org/iilab/pb/model/PageChecklist.java similarity index 100% rename from src/main/java/org/iilab/pb/model/PageChecklist.java rename to app/src/main/java/org/iilab/pb/model/PageChecklist.java diff --git a/src/main/java/org/iilab/pb/model/PageItem.java b/app/src/main/java/org/iilab/pb/model/PageItem.java similarity index 100% rename from src/main/java/org/iilab/pb/model/PageItem.java rename to app/src/main/java/org/iilab/pb/model/PageItem.java diff --git a/src/main/java/org/iilab/pb/model/PageStatus.java b/app/src/main/java/org/iilab/pb/model/PageStatus.java similarity index 100% rename from src/main/java/org/iilab/pb/model/PageStatus.java rename to app/src/main/java/org/iilab/pb/model/PageStatus.java diff --git a/src/main/java/org/iilab/pb/model/PageTimer.java b/app/src/main/java/org/iilab/pb/model/PageTimer.java similarity index 100% rename from src/main/java/org/iilab/pb/model/PageTimer.java rename to app/src/main/java/org/iilab/pb/model/PageTimer.java diff --git a/src/main/java/org/iilab/pb/model/SMSSettings.java b/app/src/main/java/org/iilab/pb/model/SMSSettings.java similarity index 84% rename from src/main/java/org/iilab/pb/model/SMSSettings.java rename to app/src/main/java/org/iilab/pb/model/SMSSettings.java index 2030e625..0a3d8fb5 100644 --- a/src/main/java/org/iilab/pb/model/SMSSettings.java +++ b/app/src/main/java/org/iilab/pb/model/SMSSettings.java @@ -13,20 +13,23 @@ public class SMSSettings { public static final String PHONE_NUMBER = "PHONE_NUMBER_"; public static final String SMS_MESSAGE = "SMS_MESSAGE"; + public static final String STOP_ALERT_MESSAGE = "STOP_ALERT_MESSAGE"; private static final int MASK_LIMIT = 2; public static final String BLANK = ""; private List phoneNumbers = new ArrayList(); private String message; + private String stopAlertMessage; public SMSSettings(List phoneNumbers) { this.phoneNumbers = phoneNumbers; this.message = null; } - public SMSSettings(List phoneNumbers, String message) { + public SMSSettings(List phoneNumbers, String message,String stopAlertMessage) { this.phoneNumbers = phoneNumbers; this.message = message; + this.stopAlertMessage=stopAlertMessage; } public static void saveContacts(Context context, SMSSettings smsSettings) { @@ -51,7 +54,18 @@ public static SMSSettings retrieve(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Map allPreferences = (Map) sharedPreferences.getAll(); List retrievedPhoneNumbers = retrievePhoneNumbers(allPreferences); - return new SMSSettings(retrievedPhoneNumbers, allPreferences.get(SMS_MESSAGE)); + return new SMSSettings(retrievedPhoneNumbers, allPreferences.get(SMS_MESSAGE),allPreferences.get(STOP_ALERT_MESSAGE)); + } + public static void saveStopAlertMessage(Context context, String stopAlertMessage){ + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = settings.edit(); + editor.putString(STOP_ALERT_MESSAGE, stopAlertMessage); + editor.commit(); + } + public static String retrieveStopAlertMessage(Context context) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + Map allPreferences = (Map) sharedPreferences.getAll(); + return allPreferences.get(STOP_ALERT_MESSAGE); } private static List retrievePhoneNumbers(Map allPreferences) { diff --git a/src/main/java/org/iilab/pb/model/ServerResponse.java b/app/src/main/java/org/iilab/pb/model/ServerResponse.java similarity index 100% rename from src/main/java/org/iilab/pb/model/ServerResponse.java rename to app/src/main/java/org/iilab/pb/model/ServerResponse.java diff --git a/app/src/main/java/org/iilab/pb/receiver/UpdateReceiver.java b/app/src/main/java/org/iilab/pb/receiver/UpdateReceiver.java new file mode 100644 index 00000000..60eeab12 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/receiver/UpdateReceiver.java @@ -0,0 +1,62 @@ +package org.iilab.pb.receiver; + +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; +import android.util.Log; + +import org.iilab.pb.CalculatorActivity; +import org.iilab.pb.R; + +import static org.iilab.pb.common.AppUtil.playTrainingForRelease1_5; + +public class UpdateReceiver extends BroadcastReceiver +{ + private static final String TAG = UpdateReceiver.class.getName(); + public static class LegacyUpdateReceiver extends BroadcastReceiver + { + @Override + public void onReceive(Context context, Intent intent) { + if (intent != null && intent.getData() != null && context.getPackageName().equals(intent.getData().getSchemeSpecificPart())) { + onUpdate(context); + } + } + } + + @Override + public void onReceive(Context context, Intent intent) + { + onUpdate(context); + } + + public static void onUpdate(Context context) + { + Log.d(TAG, "PB app updated"); + if (playTrainingForRelease1_5(context)) + displayNotification(context); + } + + public static void displayNotification(Context context) { + // Invoking the default notification service + Log.d(TAG, "inside displayNotification for update of PB triggerred for 1.5 release"); + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); + int notifyID = 1; + mBuilder.setContentTitle("Calculate!"); + mBuilder.setContentText("Calculate! has been updated!"); + mBuilder.setSmallIcon(R.drawable.warning); + mBuilder.setAutoCancel(true); + Intent calculatorActivityIntent = new Intent(context.getApplicationContext(), CalculatorActivity.class); + calculatorActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, + calculatorActivityIntent, 0); + // start the activity when the user clicks the notification text + mBuilder.setContentIntent(resultPendingIntent); + NotificationManagerCompat myNotificationManager = NotificationManagerCompat.from(context); + // pass the Notification object to the system + myNotificationManager.notify(notifyID, mBuilder.build()); + } + +} diff --git a/src/main/java/org/iilab/pb/trigger/BootReceiver.java b/app/src/main/java/org/iilab/pb/trigger/BootReceiver.java similarity index 73% rename from src/main/java/org/iilab/pb/trigger/BootReceiver.java rename to app/src/main/java/org/iilab/pb/trigger/BootReceiver.java index 6ec2b9b9..6504806a 100644 --- a/src/main/java/org/iilab/pb/trigger/BootReceiver.java +++ b/app/src/main/java/org/iilab/pb/trigger/BootReceiver.java @@ -4,8 +4,8 @@ import android.content.Context; import android.content.Intent; import android.util.Log; + import org.iilab.pb.alert.PanicAlert; -import org.iilab.pb.common.AppConstants; import org.iilab.pb.common.ApplicationSettings; import java.util.Date; @@ -13,9 +13,9 @@ import java.util.Map; import static android.content.Intent.ACTION_BOOT_COMPLETED; - +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY; public class BootReceiver extends BroadcastReceiver { - + private static final String TAG = BootReceiver.class.getName(); @Override public void onReceive(Context context, Intent intent) { Map eventLog = new HashMap(); @@ -23,15 +23,15 @@ public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(ACTION_BOOT_COMPLETED)) { // new PanicAlert(context).deActivate(); if(ApplicationSettings.isAlertActive(context)){ - Log.e("BootReceiver", "Alarm is active"); + Log.e(TAG, "Alarm is active"); ApplicationSettings.setAlertActive(context, false); new PanicAlert(context).activate(); } int wizardState = ApplicationSettings.getWizardState(context.getApplicationContext()); - Log.e("BootReceiver", "wizardState = " + wizardState); - if (wizardState == AppConstants.WIZARD_FLAG_HOME_READY) { - Log.e("BootReceiver", "BootReceiver in Panic Button"); + Log.e(TAG, "wizardState = " + wizardState); + if (wizardState == WIZARD_FLAG_HOME_READY && ApplicationSettings.isHardwareTriggerServiceEnabled(context)) { + Log.e(TAG, "BootReceiver in Panic Button"); context.startService(new Intent(context, HardwareTriggerService.class)); } } diff --git a/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java b/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java similarity index 71% rename from src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java rename to app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java index 7297eb1f..3138139d 100644 --- a/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java +++ b/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java @@ -6,39 +6,45 @@ import android.media.AudioManager; import android.util.Log; import org.iilab.pb.alert.PanicAlert; +import org.iilab.pb.common.AppUtil; import static android.content.Intent.ACTION_SCREEN_OFF; import static android.content.Intent.ACTION_SCREEN_ON; public class HardwareTriggerReceiver extends BroadcastReceiver { private static final String TAG = HardwareTriggerReceiver.class.getName(); - // private MultiClickEvent multiClickEvent; protected MultiClickEvent multiClickEvent; + private Context mContext; - public HardwareTriggerReceiver() { + public HardwareTriggerReceiver(Context context) { + Log.d(TAG, "in constructor of HWReceiver" +context); + mContext=context; resetEvent(); } + @Override public void onReceive(Context context, Intent intent) { - Log.e(">>>>>>>", "in onReceive of HWReceiver"); + Log.d(TAG, "in onReceive of HWReceiver" +multiClickEvent.getContext() +" " +mContext); + multiClickEvent.setContext(context); String action = intent.getAction(); if (!isCallActive(context) && (action.equals(ACTION_SCREEN_OFF) || action.equals(ACTION_SCREEN_ON))) { multiClickEvent.registerClick(System.currentTimeMillis()); if(multiClickEvent.skipCurrentClick()){ - Log.e("*****", "skipped click"); + Log.d(TAG, "skipped click"); multiClickEvent.resetSkipCurrentClickFlag(); } else if(multiClickEvent.canStartVibration()){ - Log.e("*****", "vibration started"); - PanicAlert panicAlert = getPanicAlert(context); - panicAlert.vibrate(); + Log.d(TAG, "vibration started"); + AppUtil.vibrateForHapticFeedback(context); + + } else if (multiClickEvent.isActivated()) { - Log.e("*****", "alerts activated"); + Log.d(TAG, "alerts activated"); onActivation(context); resetEvent(); } @@ -46,7 +52,7 @@ else if (multiClickEvent.isActivated()) { } protected void onActivation(Context context) { - Log.e(">>>>>>>", "in onActivation of HWReceiver"); + Log.d(TAG, "in onActivation of HWReceiver"); activateAlert(getPanicAlert(context)); } @@ -56,7 +62,8 @@ void activateAlert(PanicAlert panicAlert) { } protected void resetEvent() { - multiClickEvent = new MultiClickEvent(); + Log.d(TAG, "in resetevent of HWReceiver" +mContext); + multiClickEvent = new MultiClickEvent(mContext); } protected PanicAlert getPanicAlert(Context context) { diff --git a/src/main/java/org/iilab/pb/trigger/HardwareTriggerService.java b/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerService.java similarity index 76% rename from src/main/java/org/iilab/pb/trigger/HardwareTriggerService.java rename to app/src/main/java/org/iilab/pb/trigger/HardwareTriggerService.java index 9b8c25e7..d6b9dd6e 100644 --- a/src/main/java/org/iilab/pb/trigger/HardwareTriggerService.java +++ b/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerService.java @@ -1,6 +1,7 @@ package org.iilab.pb.trigger; import android.app.Service; +import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.IBinder; @@ -8,21 +9,22 @@ public class HardwareTriggerService extends Service { private HardwareTriggerReceiver hardwareTriggerReceiver; + private static final String TAG = HardwareTriggerService.class.getName(); @Override public void onCreate() { super.onCreate(); - Log.e(">>>>>>", "HardwareTriggerService CREATED."); + Log.d(TAG, "HardwareTriggerService CREATED."); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); - hardwareTriggerReceiver = new HardwareTriggerReceiver(); + hardwareTriggerReceiver = new HardwareTriggerReceiver(this); registerReceiver(hardwareTriggerReceiver, filter); } @Override public void onDestroy() { super.onDestroy(); - Log.e(">>>>>>", "HardwareTriggerService DESTROYED."); + Log.d(TAG, "HardwareTriggerService DESTROYED."); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); diff --git a/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java b/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java new file mode 100644 index 00000000..a2dcfa22 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java @@ -0,0 +1,197 @@ +package org.iilab.pb.trigger; + +import android.content.Context; +import android.os.Vibrator; +import android.util.EventLog; +import android.util.Log; + +import com.google.gson.Gson; + +import org.iilab.pb.common.AppUtil; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.iilab.pb.common.AppConstants.ALARM_NOT_CONFIRMED_THREE_FAST; +import static org.iilab.pb.common.AppConstants.ONE_SECOND; +import static org.iilab.pb.common.ApplicationSettings.getAlarmNotConfirmedPattern; +import static org.iilab.pb.common.ApplicationSettings.getConfirmationWaitVibrationDuration; +import static org.iilab.pb.common.ApplicationSettings.getInitialClicksForAlertTrigger; +import static org.iilab.pb.common.ApplicationSettings.getInitialClicksMaxTimeLimit; +import static org.iilab.pb.common.ApplicationSettings.isAlarmConfirmationRequired; + +public class MultiClickEvent { + //This is the guard time + private static final int MAX_TIME_INTERVAL_FOR_CONFIRMATION = 3000; + // private static final int INITIAL_CLICKS = 5; + private final int IS_STATE_CHANGE_USER_TRIGERRED = 2; + private final String EVENT_LOG_TAG_POWER_SCREEN_STATE = "power_screen_state"; + + private Long firstEventTime; + private int clickCount = 0; + private int IS_POWER_STATE_ASLEEP = 0; + private boolean waitForConfirmation = false; + private Long hapticFeedbackVibrationStartTime; + private boolean isActivated; + private Map eventLog = new HashMap(); + private boolean skipClick = false; + private static final String TAG = MultiClickEvent.class.getName(); + protected Context mContext; + + public MultiClickEvent(Context context) { + mContext = context; + } + + public void reset() { + firstEventTime = null; + clickCount = 0; + eventLog = new HashMap(); + } + + public void setContext(Context context) { + mContext = context; + } + + public Context getContext() { + return mContext; + } + + public void registerClick(Long timeWhenButtonClicked) { + if (waitForConfirmation) { + long confirmationDuration = timeWhenButtonClicked - hapticFeedbackVibrationStartTime; + int hapticFeedbackVibrationDuration = ONE_SECOND * Integer.parseInt(getConfirmationWaitVibrationDuration(mContext)); + boolean isConfirmationClickedBeforeVibrationEnded = confirmationDuration <= hapticFeedbackVibrationDuration; + boolean isConfirmationClickedWithinTimeLimit = (hapticFeedbackVibrationDuration + MAX_TIME_INTERVAL_FOR_CONFIRMATION) >= confirmationDuration; + + if (isConfirmationClickedBeforeVibrationEnded) { + Log.d(TAG, "isConfirmationClickedBeforeVibrationEnded"); + skipClick = true; + return; + } + if (!isConfirmationClickedBeforeVibrationEnded && isConfirmationClickedWithinTimeLimit) { + Log.d(TAG, "!isConfirmationClickedBeforeVibrationEnded && isConfirmationClickedWithinTimeLimit"); + isActivated = true; + waitForConfirmation = false; + return; + } + if (!isConfirmationClickedWithinTimeLimit) { + Log.d(TAG, "!isConfirmationClickedWithinTimeLimit"); + resetClickCount(timeWhenButtonClicked); + + alarmNotConfirmedOnTime(); + } + return; + } + if (isFirstClick() || notWithinLimit(timeWhenButtonClicked) || !isPowerClickBecauseOfUser()) { + Log.d(TAG, "isFirstClick() || notWithinLimit(eventTime) || !isPowerClickBecauseOfUser()"); + resetClickCount(timeWhenButtonClicked); + return; + } else { + clickCount++; + Log.d(TAG, "MultiClickEvent clickCount = " + clickCount + " " + mContext); + eventLog.put(Integer.toString(clickCount) + " click", new Date(timeWhenButtonClicked).toString()); + if (clickCount >= Integer.parseInt(getInitialClicksForAlertTrigger(mContext))) { + + //if no confirmation click required, activate the alarm +// if(ALARM_SENDING_CONFIRMATION_PATTERN_NONE.equals(getConfirmationFeedbackVibrationPattern(mContext))) { + if(!isAlarmConfirmationRequired(mContext)){ + waitForConfirmation=false; + isActivated = true; + AppUtil.vibrateForHapticFeedback(mContext); + }else { + waitForConfirmation = true; + } + eventLog.put("Waiting for confirmation", new Date(timeWhenButtonClicked).toString()); + hapticFeedbackVibrationStartTime = timeWhenButtonClicked; + return; + } + } + } + + private void alarmNotConfirmedOnTime() { + String alarmNotConfirmedPattern = getAlarmNotConfirmedPattern(mContext); + Log.d(TAG, "Alarm not confirmed on time pattern 1-None, 2- three short " + alarmNotConfirmedPattern); + if (ALARM_NOT_CONFIRMED_THREE_FAST.equals(alarmNotConfirmedPattern)) { + //vibrate three times fast + Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); + long[] pattern = {0, 600, 400, 600, 400, 600, 400}; + vibrator.vibrate(pattern, -1); + } + } + + private void resetClickCount(Long eventTime) { + firstEventTime = eventTime; + clickCount = 1; + waitForConfirmation = false; + Log.d(TAG, " Reset clickCount = " + clickCount); + eventLog = new HashMap(); + eventLog.put(Integer.toString(clickCount) + " click", new Date(eventTime).toString()); + } + + //TODO: move this to a class like PowerStateEventLogReader + // - event logs can't be read post Android 4.1 + private boolean isPowerClickBecauseOfUser() { + ArrayList events = new ArrayList(); + try { + int powerScreenStateTagCode = EventLog.getTagCode(EVENT_LOG_TAG_POWER_SCREEN_STATE); + EventLog.readEvents(new int[]{powerScreenStateTagCode}, events); + if (!events.isEmpty()) { + EventLog.Event event = events.get(events.size() - 1); + try { + Object[] powerEventLogData = (Object[]) event.getData(); + if (powerEventLogData.length > 2 && (Integer) powerEventLogData[0] == IS_POWER_STATE_ASLEEP) { + boolean isPowerChangeUserTriggered = (Integer) powerEventLogData[1] == IS_STATE_CHANGE_USER_TRIGERRED; + Log.d(TAG, " is Power change user triggered? " + isPowerChangeUserTriggered); + return isPowerChangeUserTriggered; + } + } catch (ClassCastException ce) { + Object data = event.getData(); + Log.d(TAG, "could not read event data" + new Gson().toJson(data)); + } + } + } catch (IOException e) { + Log.e(TAG, "could not read event logs"); + } + return true; + } + + private boolean notWithinLimit(long current) { + int initialClicksMaxTimeLimit = ONE_SECOND * Integer.parseInt(getInitialClicksMaxTimeLimit(mContext)); + boolean isInitialClicksWithInLimit = (current - firstEventTime) > initialClicksMaxTimeLimit; + Log.d(TAG, "Initial clicks max time limit is " + initialClicksMaxTimeLimit); + Log.d(TAG, "Initial clicks done with in assigned time limit? " + isInitialClicksWithInLimit); + return isInitialClicksWithInLimit; + } + + private boolean isFirstClick() { + return firstEventTime == null; + } + + public boolean isActivated() { + return isActivated; + } + + /** + * Since initial click counts are done, we can start the haptic feedback vibration. + * + * @return + */ + public boolean canStartVibration() { + return waitForConfirmation; + } + + public Map getEventLog() { + return eventLog; + } + + public boolean skipCurrentClick() { + return skipClick; + } + + public void resetSkipCurrentClickFlag() { + skipClick = false; + } +} diff --git a/res/anim/hide_to_bottom.xml b/app/src/main/res/anim/hide_to_bottom.xml similarity index 100% rename from res/anim/hide_to_bottom.xml rename to app/src/main/res/anim/hide_to_bottom.xml diff --git a/res/anim/hide_to_top.xml b/app/src/main/res/anim/hide_to_top.xml similarity index 100% rename from res/anim/hide_to_top.xml rename to app/src/main/res/anim/hide_to_top.xml diff --git a/res/anim/show_from_bottom.xml b/app/src/main/res/anim/show_from_bottom.xml similarity index 100% rename from res/anim/show_from_bottom.xml rename to app/src/main/res/anim/show_from_bottom.xml diff --git a/res/anim/show_from_top.xml b/app/src/main/res/anim/show_from_top.xml similarity index 100% rename from res/anim/show_from_top.xml rename to app/src/main/res/anim/show_from_top.xml diff --git a/res/drawable-hdpi/activate1.jpg b/app/src/main/res/drawable-hdpi/activate1.jpg similarity index 100% rename from res/drawable-hdpi/activate1.jpg rename to app/src/main/res/drawable-hdpi/activate1.jpg diff --git a/res/drawable-hdpi/activate2.jpg b/app/src/main/res/drawable-hdpi/activate2.jpg similarity index 100% rename from res/drawable-hdpi/activate2.jpg rename to app/src/main/res/drawable-hdpi/activate2.jpg diff --git a/res/drawable-hdpi/activate3.jpg b/app/src/main/res/drawable-hdpi/activate3.jpg similarity index 100% rename from res/drawable-hdpi/activate3.jpg rename to app/src/main/res/drawable-hdpi/activate3.jpg diff --git a/res/drawable-hdpi/arrow_next.png b/app/src/main/res/drawable-hdpi/arrow_next.png similarity index 100% rename from res/drawable-hdpi/arrow_next.png rename to app/src/main/res/drawable-hdpi/arrow_next.png diff --git a/res/drawable-hdpi/back.png b/app/src/main/res/drawable-hdpi/back.png similarity index 100% rename from res/drawable-hdpi/back.png rename to app/src/main/res/drawable-hdpi/back.png diff --git a/res/drawable-hdpi/icon_alarm.png b/app/src/main/res/drawable-hdpi/icon_alarm.png similarity index 100% rename from res/drawable-hdpi/icon_alarm.png rename to app/src/main/res/drawable-hdpi/icon_alarm.png diff --git a/res/drawable-hdpi/icon_arrow.png b/app/src/main/res/drawable-hdpi/icon_arrow.png similarity index 100% rename from res/drawable-hdpi/icon_arrow.png rename to app/src/main/res/drawable-hdpi/icon_arrow.png diff --git a/res/drawable-hdpi/icon_calculator.png b/app/src/main/res/drawable-hdpi/icon_calculator.png similarity index 100% rename from res/drawable-hdpi/icon_calculator.png rename to app/src/main/res/drawable-hdpi/icon_calculator.png diff --git a/res/drawable-hdpi/icon_setup.png b/app/src/main/res/drawable-hdpi/icon_setup.png similarity index 100% rename from res/drawable-hdpi/icon_setup.png rename to app/src/main/res/drawable-hdpi/icon_setup.png diff --git a/res/drawable-hdpi/next.png b/app/src/main/res/drawable-hdpi/next.png similarity index 100% rename from res/drawable-hdpi/next.png rename to app/src/main/res/drawable-hdpi/next.png diff --git a/res/drawable-hdpi/plus.png b/app/src/main/res/drawable-hdpi/plus.png similarity index 100% rename from res/drawable-hdpi/plus.png rename to app/src/main/res/drawable-hdpi/plus.png diff --git a/res/drawable-hdpi/save.png b/app/src/main/res/drawable-hdpi/save.png similarity index 100% rename from res/drawable-hdpi/save.png rename to app/src/main/res/drawable-hdpi/save.png diff --git a/res/drawable-hdpi/setup_wizard.png b/app/src/main/res/drawable-hdpi/setup_wizard.png similarity index 100% rename from res/drawable-hdpi/setup_wizard.png rename to app/src/main/res/drawable-hdpi/setup_wizard.png diff --git a/res/drawable-hdpi/socialperson.png b/app/src/main/res/drawable-hdpi/socialperson.png similarity index 100% rename from res/drawable-hdpi/socialperson.png rename to app/src/main/res/drawable-hdpi/socialperson.png diff --git a/res/drawable-hdpi/tick_green.png b/app/src/main/res/drawable-hdpi/tick_green.png similarity index 100% rename from res/drawable-hdpi/tick_green.png rename to app/src/main/res/drawable-hdpi/tick_green.png diff --git a/res/drawable-hdpi/warning.png b/app/src/main/res/drawable-hdpi/warning.png similarity index 100% rename from res/drawable-hdpi/warning.png rename to app/src/main/res/drawable-hdpi/warning.png diff --git a/res/drawable-hdpi/wizard_active.png b/app/src/main/res/drawable-hdpi/wizard_active.png similarity index 100% rename from res/drawable-hdpi/wizard_active.png rename to app/src/main/res/drawable-hdpi/wizard_active.png diff --git a/res/drawable-hdpi/wizard_disguise.jpg b/app/src/main/res/drawable-hdpi/wizard_disguise.jpg similarity index 100% rename from res/drawable-hdpi/wizard_disguise.jpg rename to app/src/main/res/drawable-hdpi/wizard_disguise.jpg diff --git a/res/drawable-hdpi/wizard_inactive.png b/app/src/main/res/drawable-hdpi/wizard_inactive.png similarity index 100% rename from res/drawable-hdpi/wizard_inactive.png rename to app/src/main/res/drawable-hdpi/wizard_inactive.png diff --git a/res/drawable-ldpi/icon_calculator.png b/app/src/main/res/drawable-ldpi/icon_calculator.png similarity index 100% rename from res/drawable-ldpi/icon_calculator.png rename to app/src/main/res/drawable-ldpi/icon_calculator.png diff --git a/res/drawable-ldpi/icon_setup.png b/app/src/main/res/drawable-ldpi/icon_setup.png similarity index 100% rename from res/drawable-ldpi/icon_setup.png rename to app/src/main/res/drawable-ldpi/icon_setup.png diff --git a/res/drawable-mdpi/icon_calculator.png b/app/src/main/res/drawable-mdpi/icon_calculator.png similarity index 100% rename from res/drawable-mdpi/icon_calculator.png rename to app/src/main/res/drawable-mdpi/icon_calculator.png diff --git a/res/drawable-mdpi/icon_setup.png b/app/src/main/res/drawable-mdpi/icon_setup.png similarity index 100% rename from res/drawable-mdpi/icon_setup.png rename to app/src/main/res/drawable-mdpi/icon_setup.png diff --git a/res/drawable-xhdpi/icon_calculator.png b/app/src/main/res/drawable-xhdpi/icon_calculator.png similarity index 100% rename from res/drawable-xhdpi/icon_calculator.png rename to app/src/main/res/drawable-xhdpi/icon_calculator.png diff --git a/res/drawable-xhdpi/icon_setup.png b/app/src/main/res/drawable-xhdpi/icon_setup.png similarity index 100% rename from res/drawable-xhdpi/icon_setup.png rename to app/src/main/res/drawable-xhdpi/icon_setup.png diff --git a/res/drawable/alert_button_focused.xml b/app/src/main/res/drawable/alert_button_focused.xml similarity index 100% rename from res/drawable/alert_button_focused.xml rename to app/src/main/res/drawable/alert_button_focused.xml diff --git a/res/drawable/alert_button_stand_by.xml b/app/src/main/res/drawable/alert_button_stand_by.xml similarity index 100% rename from res/drawable/alert_button_stand_by.xml rename to app/src/main/res/drawable/alert_button_stand_by.xml diff --git a/res/drawable/alert_button_stop.xml b/app/src/main/res/drawable/alert_button_stop.xml similarity index 100% rename from res/drawable/alert_button_stop.xml rename to app/src/main/res/drawable/alert_button_stop.xml diff --git a/res/drawable/back_button.xml b/app/src/main/res/drawable/back_button.xml similarity index 100% rename from res/drawable/back_button.xml rename to app/src/main/res/drawable/back_button.xml diff --git a/res/drawable/back_button_normal.xml b/app/src/main/res/drawable/back_button_normal.xml similarity index 100% rename from res/drawable/back_button_normal.xml rename to app/src/main/res/drawable/back_button_normal.xml diff --git a/res/drawable/back_button_pressed.xml b/app/src/main/res/drawable/back_button_pressed.xml similarity index 100% rename from res/drawable/back_button_pressed.xml rename to app/src/main/res/drawable/back_button_pressed.xml diff --git a/res/drawable/background_warning_fragment.xml b/app/src/main/res/drawable/background_warning_fragment.xml similarity index 100% rename from res/drawable/background_warning_fragment.xml rename to app/src/main/res/drawable/background_warning_fragment.xml diff --git a/res/drawable/drawable_wizard_button.xml b/app/src/main/res/drawable/drawable_wizard_button.xml similarity index 100% rename from res/drawable/drawable_wizard_button.xml rename to app/src/main/res/drawable/drawable_wizard_button.xml diff --git a/res/drawable/drawable_wizard_button_disabled.xml b/app/src/main/res/drawable/drawable_wizard_button_disabled.xml similarity index 100% rename from res/drawable/drawable_wizard_button_disabled.xml rename to app/src/main/res/drawable/drawable_wizard_button_disabled.xml diff --git a/res/drawable/send_alert_button.xml b/app/src/main/res/drawable/send_alert_button.xml similarity index 100% rename from res/drawable/send_alert_button.xml rename to app/src/main/res/drawable/send_alert_button.xml diff --git a/res/drawable/stop_alert_button.xml b/app/src/main/res/drawable/stop_alert_button.xml similarity index 100% rename from res/drawable/stop_alert_button.xml rename to app/src/main/res/drawable/stop_alert_button.xml diff --git a/res/drawable/topbar_button.xml b/app/src/main/res/drawable/topbar_button.xml similarity index 100% rename from res/drawable/topbar_button.xml rename to app/src/main/res/drawable/topbar_button.xml diff --git a/res/drawable/topbar_button_disabled.xml b/app/src/main/res/drawable/topbar_button_disabled.xml similarity index 100% rename from res/drawable/topbar_button_disabled.xml rename to app/src/main/res/drawable/topbar_button_disabled.xml diff --git a/res/drawable/topbar_button_normal.xml b/app/src/main/res/drawable/topbar_button_normal.xml similarity index 100% rename from res/drawable/topbar_button_normal.xml rename to app/src/main/res/drawable/topbar_button_normal.xml diff --git a/res/drawable/topbar_button_pressed.xml b/app/src/main/res/drawable/topbar_button_pressed.xml similarity index 100% rename from res/drawable/topbar_button_pressed.xml rename to app/src/main/res/drawable/topbar_button_pressed.xml diff --git a/res/layout-sw320dp/fragment_type_interactive_disguise_test_open.xml b/app/src/main/res/layout-sw320dp/fragment_type_interactive_disguise_test_open.xml similarity index 100% rename from res/layout-sw320dp/fragment_type_interactive_disguise_test_open.xml rename to app/src/main/res/layout-sw320dp/fragment_type_interactive_disguise_test_open.xml diff --git a/res/layout-sw320dp/griditem_appinfo.xml b/app/src/main/res/layout-sw320dp/griditem_appinfo.xml similarity index 100% rename from res/layout-sw320dp/griditem_appinfo.xml rename to app/src/main/res/layout-sw320dp/griditem_appinfo.xml diff --git a/res/layout-sw360dp/fragment_type_interactive_disguise_test_open.xml b/app/src/main/res/layout-sw360dp/fragment_type_interactive_disguise_test_open.xml similarity index 100% rename from res/layout-sw360dp/fragment_type_interactive_disguise_test_open.xml rename to app/src/main/res/layout-sw360dp/fragment_type_interactive_disguise_test_open.xml diff --git a/res/layout-sw360dp/griditem_appinfo.xml b/app/src/main/res/layout-sw360dp/griditem_appinfo.xml similarity index 100% rename from res/layout-sw360dp/griditem_appinfo.xml rename to app/src/main/res/layout-sw360dp/griditem_appinfo.xml diff --git a/res/layout/alert_status_strip.xml b/app/src/main/res/layout/alert_status_strip.xml similarity index 100% rename from res/layout/alert_status_strip.xml rename to app/src/main/res/layout/alert_status_strip.xml diff --git a/res/layout/calculator_layout.xml b/app/src/main/res/layout/calculator_layout.xml similarity index 100% rename from res/layout/calculator_layout.xml rename to app/src/main/res/layout/calculator_layout.xml diff --git a/res/layout/contact_picker_fragment.xml b/app/src/main/res/layout/contact_picker_fragment.xml similarity index 100% rename from res/layout/contact_picker_fragment.xml rename to app/src/main/res/layout/contact_picker_fragment.xml diff --git a/res/layout/fragment_type_interactive_alert.xml b/app/src/main/res/layout/fragment_type_interactive_alert.xml similarity index 100% rename from res/layout/fragment_type_interactive_alert.xml rename to app/src/main/res/layout/fragment_type_interactive_alert.xml diff --git a/res/layout/fragment_type_interactive_code.xml b/app/src/main/res/layout/fragment_type_interactive_code.xml similarity index 73% rename from res/layout/fragment_type_interactive_code.xml rename to app/src/main/res/layout/fragment_type_interactive_code.xml index 44a3ec85..5214e2e4 100644 --- a/res/layout/fragment_type_interactive_code.xml +++ b/app/src/main/res/layout/fragment_type_interactive_code.xml @@ -1,5 +1,6 @@ - - + +