From 72d7eb24ddf6b14fc9faa70f1d3f7ebb9740f08c Mon Sep 17 00:00:00 2001 From: Neetika Date: Wed, 3 Feb 2016 18:23:40 +1100 Subject: [PATCH 1/2] small fix to update 1.5 release flow #143 --- app/src/main/java/org/iilab/pb/HomeActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/iilab/pb/HomeActivity.java b/app/src/main/java/org/iilab/pb/HomeActivity.java index be9a3ab0..108a0c13 100644 --- a/app/src/main/java/org/iilab/pb/HomeActivity.java +++ b/app/src/main/java/org/iilab/pb/HomeActivity.java @@ -114,7 +114,7 @@ public void onCreate(Bundle savedInstanceState) { /* 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 @@ -122,6 +122,7 @@ public void onCreate(Bundle savedInstanceState) { setFirstRun(getApplicationContext(),true); setAppUpdated(getApplicationContext(), false); }else { + setFirstRun(getApplicationContext(),false); setAppUpdated(getApplicationContext(), true); } new InitializeLocalData().execute(); From e19e65e94ff95e34e78b92997a644ccdd5d29d51 Mon Sep 17 00:00:00 2001 From: Neetika Date: Mon, 8 Feb 2016 14:14:26 +1100 Subject: [PATCH 2/2] #187, #143 Added 1.5 update notification and removed disguise training --- app/src/main/AndroidManifest.xml | 12 ++++ app/src/main/assets/mobile_en.json | 63 ++++++++++++++++++- .../java/org/iilab/pb/WizardActivity.java | 6 +- .../org/iilab/pb/common/AppConstants.java | 2 + .../java/org/iilab/pb/common/AppUtil.java | 2 - .../pb/fragment/AdvancedSettingsFragment.java | 27 ++++---- .../org/iilab/pb/receiver/UpdateReceiver.java | 63 +++++++++++++++++++ .../main/res/values-v12/version_checks.xml | 6 ++ app/src/main/res/values/version_checks.xml | 6 ++ 9 files changed, 168 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/org/iilab/pb/receiver/UpdateReceiver.java create mode 100644 app/src/main/res/values-v12/version_checks.xml create mode 100644 app/src/main/res/values/version_checks.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 48467f98..33f0f8ca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -71,6 +71,18 @@ + + + + + + + + + + + + diff --git a/app/src/main/assets/mobile_en.json b/app/src/main/assets/mobile_en.json index 5206bd51..e10f27b9 100644 --- a/app/src/main/assets/mobile_en.json +++ b/app/src/main/assets/mobile_en.json @@ -826,14 +826,73 @@ "action": [ { "title": "Learn", - "link": "setup-alarm-test-hardware" + "link": "setup-alarm-test-hardware-training_1_5" }, { "title": "Skip", - "link": "home-ready" + "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/app/src/main/java/org/iilab/pb/WizardActivity.java b/app/src/main/java/org/iilab/pb/WizardActivity.java index 12969f99..7012eb58 100644 --- a/app/src/main/java/org/iilab/pb/WizardActivity.java +++ b/app/src/main/java/org/iilab/pb/WizardActivity.java @@ -55,6 +55,8 @@ 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; @@ -226,7 +228,7 @@ protected void onPause() { In short, we block this page - setup-alarm-test-hardware for pause-resume action */ - if (!(pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE)|| pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_RETRAINING))) { + 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; } @@ -301,7 +303,7 @@ 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(PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS) || pageId.equals(PAGE_SETUP_ALARM_TEST_HARDWARE_SUCCESS_RETRAINING))){ + 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 == WIZARD_FLAG_HOME_NOT_CONFIGURED) { diff --git a/app/src/main/java/org/iilab/pb/common/AppConstants.java b/app/src/main/java/org/iilab/pb/common/AppConstants.java index 247997c7..490b6f8e 100644 --- a/app/src/main/java/org/iilab/pb/common/AppConstants.java +++ b/app/src/main/java/org/iilab/pb/common/AppConstants.java @@ -77,6 +77,8 @@ public class AppConstants { 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"; diff --git a/app/src/main/java/org/iilab/pb/common/AppUtil.java b/app/src/main/java/org/iilab/pb/common/AppUtil.java index 73d2299d..457187ed 100644 --- a/app/src/main/java/org/iilab/pb/common/AppUtil.java +++ b/app/src/main/java/org/iilab/pb/common/AppUtil.java @@ -377,8 +377,6 @@ public static void vibrateForHapticFeedback(Context context) { } public static boolean playTrainingForRelease1_5(Context context) { - //TODO for testing purpose only -// setFirstRun(context,false); 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)); diff --git a/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java index 953e084d..cedb9bc1 100644 --- a/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java @@ -51,14 +51,14 @@ public static AdvancedSettingsFragment newInstance(String pageId, int parentActi public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); - if(getString(R.string.custom_modeValue).equals(getTriggerSettings(getActivity()))){ + if (getString(R.string.custom_modeValue).equals(getTriggerSettings(getActivity()))) { enableAdvancedSettings(true); - }else{ + } else { enableAdvancedSettings(false); } - if(isConfirmationFeedback(getActivity())){ + if (isConfirmationFeedback(getActivity())) { enableConfirmationFeedback(true); - }else{ + } else { enableConfirmationFeedback(false); } @@ -105,7 +105,7 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) { if (selectedValue.equals(getString(R.string.confirmationSettingsDefault))) { // disable Confirmation Wait Time/ Confirmation Wait Vibration enableConfirmationFeedback(false); - setConfirmationFeedback(getActivity(),false); + setConfirmationFeedback(getActivity(), false); Log.d(TAG, "default confirmation press deactivated"); } else { // enable Confirmation Wait Time/ Confirmation Wait Vibration @@ -130,11 +130,11 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) { Log.d(TAG, "Extra confirmation click required to trigger alarm"); } else if (selectedValue.equals(getString(R.string.extraConfirmationPressValue))) { //make the press 5 - setInitialClicksForAlertTrigger(getActivity(),"5"); + setInitialClicksForAlertTrigger(getActivity(), "5"); setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_LONG); enableAdvancedSettings(false); enableRedoTraining(true); - Log.d(TAG, "Extra confirmation click required to trigger alarm "+getInitialClicksForAlertTrigger(getActivity())); + Log.d(TAG, "Extra confirmation click required to trigger alarm " + getInitialClicksForAlertTrigger(getActivity())); } else if (selectedValue.equals(getString(R.string.custom_modeValue))) { enableAdvancedSettings(true); // enable all the advanced settings @@ -144,7 +144,8 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) { } }); } - private void enableAdvancedSettings(boolean flag){ + + private void enableAdvancedSettings(boolean flag) { PreferenceCategory prefCatTriggerPatternSettings = (PreferenceCategory) findPreference(getString(R.string.triggerPatternSettingsKey)); PreferenceCategory prefCatTriggerVibrationSettings = (PreferenceCategory) findPreference(getString(R.string.feedbackAlarmActivationKey)); PreferenceCategory prefCatRedoTraining = (PreferenceCategory) findPreference(getString(R.string.redoTrainingPrefCatKey)); @@ -154,11 +155,13 @@ private void enableAdvancedSettings(boolean flag){ prefCatRedoTraining.setEnabled(flag); prefCatPowerButtonTriggerSettings.setEnabled(flag); } - private void enableRedoTraining(boolean flag){ + + private void enableRedoTraining(boolean flag) { PreferenceCategory prefCatRedoTraining = (PreferenceCategory) findPreference(getString(R.string.redoTrainingPrefCatKey)); prefCatRedoTraining.setEnabled(flag); } - private void enableConfirmationFeedback(boolean flag){ + + private void enableConfirmationFeedback(boolean flag) { Preference confirmationWaitTime = (Preference) findPreference(getString(R.string.confirmationWaitTimeKey)); confirmationWaitTime.setEnabled(flag); Preference confirmationWaitVibration = (Preference) findPreference(getString(R.string.hapticFeedbackVibrationPatternKey)); @@ -181,8 +184,6 @@ private void displayNotification() { Context mContext = getActivity(); Intent advancedSettingsIntent = new Intent(mContext, MainActivity.class); advancedSettingsIntent.putExtra(PAGE_ID, PAGE_ADVANCED_SETTINGS); - mContext.startActivity(advancedSettingsIntent); - ((MainActivity) mContext).callFinishActivityReceiver(); Intent settingsIntent = new Intent(mContext, MainActivity.class); settingsIntent.putExtra(PAGE_ID, PAGE_SETTINGS); @@ -190,7 +191,7 @@ private void displayNotification() { 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 + // Adds the back stack for the Intent stackBuilder.addNextIntent(homePageIntent).addNextIntent(settingsIntent).addNextIntent(advancedSettingsIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, 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..d3b1b3e0 --- /dev/null +++ b/app/src/main/java/org/iilab/pb/receiver/UpdateReceiver.java @@ -0,0 +1,63 @@ +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.AppConstants.APP_RELEASE_VERSION_1_5; +import static org.iilab.pb.common.ApplicationSettings.getLastUpdatedVersion; + +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 (getLastUpdatedVersion(context) == APP_RELEASE_VERSION_1_5) + 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/app/src/main/res/values-v12/version_checks.xml b/app/src/main/res/values-v12/version_checks.xml new file mode 100644 index 00000000..b892ad8a --- /dev/null +++ b/app/src/main/res/values-v12/version_checks.xml @@ -0,0 +1,6 @@ + + + true + false + + \ No newline at end of file diff --git a/app/src/main/res/values/version_checks.xml b/app/src/main/res/values/version_checks.xml new file mode 100644 index 00000000..68e4f788 --- /dev/null +++ b/app/src/main/res/values/version_checks.xml @@ -0,0 +1,6 @@ + + + false + true + + \ No newline at end of file