Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
#187, #143 Added 1.5 update notification and removed disguise training
Browse files Browse the repository at this point in the history
  • Loading branch information
niccs committed Feb 8, 2016
1 parent 72d7eb2 commit e19e65e
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 19 deletions.
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
<action android:name="org.iilab.pb.SEND_ALERT_ACTION_SINGLE"/>
</intent-filter>
</receiver>

<receiver android:name=".receiver.UpdateReceiver$LegacyUpdateReceiver" android:enabled="@bool/is_at_most_api_11" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.UpdateReceiver" android:enabled="@bool/is_at_least_api_12" >
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<meta-data
android:name="io.fabric.ApiKey"
android:value="869571b41e0cb553a5cb99aa56d26a0f06ca7015" />
Expand Down
63 changes: 61 additions & 2 deletions app/src/main/assets/mobile_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<p>Panic Button has been updated and now uses a new default trigger mechanism. </p><p>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. </p>"
},{
"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": "<p>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?. </p>"
},{
"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": "<p><img src=\"/media/mobile/panic_button_activation_360.gif\" alt=\"\"></p>"
},
{
"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": "<p>It looks like you didn&#39;t succeed in triggering the alert using the phone&#39;s power button.</p><p>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.</p>"
},{
"id": "setup-alarm-test-hardware-success-training_1_5",
"lang": "en",
"type": "simple",
"title": "Well done!",
"action": [
{
"title": "Finish",
"link": "home-ready"
}],
"content": "<p>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.</p>"
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/org/iilab/pb/WizardActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/iilab/pb/common/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/org/iilab/pb/common/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -181,16 +184,14 @@ 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);
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
// Adds the back stack for the Intent
stackBuilder.addNextIntent(homePageIntent).addNextIntent(settingsIntent).addNextIntent(advancedSettingsIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0,
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/org/iilab/pb/receiver/UpdateReceiver.java
Original file line number Diff line number Diff line change
@@ -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());
}

}
6 changes: 6 additions & 0 deletions app/src/main/res/values-v12/version_checks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="is_at_least_api_12" type="bool">true</item>
<item name="is_at_most_api_11" type="bool">false</item>

</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/version_checks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="is_at_least_api_12" type="bool">false</item>
<item name="is_at_most_api_11" type="bool">true</item>

</resources>

0 comments on commit e19e65e

Please sign in to comment.