From e0becd99f06f52b2b65796b0be712f74366df77f Mon Sep 17 00:00:00 2001 From: Neetika Date: Mon, 18 Jan 2016 15:43:48 +1100 Subject: [PATCH] #178 coded new 7 initial press default trigger configurations --- .../org/iilab/pb/common/AppConstants.java | 7 +- .../java/org/iilab/pb/common/AppUtil.java | 7 +- .../iilab/pb/common/ApplicationSettings.java | 24 +----- .../pb/trigger/HardwareTriggerReceiver.java | 3 +- .../org/iilab/pb/trigger/MultiClickEvent.java | 77 ++++++++++--------- app/src/main/res/values-en/strings.xml | 4 +- app/src/main/res/values/strings.xml | 4 +- app/src/main/res/xml/preferences.xml | 5 +- 8 files changed, 59 insertions(+), 72 deletions(-) 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 6f03b647..6189d6c9 100644 --- a/app/src/main/java/org/iilab/pb/common/AppConstants.java +++ b/app/src/main/java/org/iilab/pb/common/AppConstants.java @@ -111,7 +111,7 @@ public class AppConstants { 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 DEFAULT_HAPTIC_FEEDBACK_PATTERN_CONTINUSLY = "1"; +// public static final String DEFAULT_HAPTIC_FEEDBACK_PATTERN_CONTINUSLY = "1"; public static final String HAPTIC_FEEDBACK_PATTERN_VIBRATE_EVERY_SECOND = "2"; public static final String ALARM_SENDING_CONFIRMATION_PATTERN_LONG = "1"; public static final String ALARM_SENDING_CONFIRMATION_PATTERN_REPEATED_SHORT = "2"; @@ -119,11 +119,10 @@ public class AppConstants { // 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 DEFAULT_ALARM_NOT_CONFIRMED_NONE = "1"; +// public static final String DEFAULT_ALARM_NOT_CONFIRMED_NONE = "1"; public static final String ALARM_NOT_CONFIRMED_THREE_FAST = "2"; - public static final String DEFAULT_INITIAL_TIME_FOR_ALARM_TRIGGER = "6"; +// public static final String DEFAULT_INITIAL_TIME_FOR_ALARM_TRIGGER = "6"; // mode 0= no confirmation click, mode 1= 1 confirmation click - public static final String DEFAULT_NO_CONFIRMATION_CLICK_MODE = "0"; public static final int VIBRATION_DURATION_SHORT = 400; public static final int VIBRATION_PAUSE_SHORT = 200; 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 1e1e9ac4..1703b852 100644 --- a/app/src/main/java/org/iilab/pb/common/AppUtil.java +++ b/app/src/main/java/org/iilab/pb/common/AppUtil.java @@ -1,5 +1,6 @@ package org.iilab.pb.common; + import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -27,7 +28,7 @@ import java.util.List; import static org.iilab.pb.common.AppConstants.*; - +import org.iilab.pb.R; public class AppUtil { private static final String TAG = AppUtil.class.getName(); public static HashMap mImageCache = new HashMap(); @@ -298,7 +299,7 @@ public static void vibrateForConfirmationOfAlertTriggered(Context 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 (DEFAULT_ALARM_SENDING_CONFIRMATION_PATTERN_LONG.equals(confirmationFeedbackPattern)) { + 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); @@ -363,7 +364,7 @@ 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 (DEFAULT_HAPTIC_FEEDBACK_PATTERN_CONTINUSLY.equals(ApplicationSettings.getHapticFeedbackVibrationPattern(context))) { + 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))); diff --git a/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java b/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java index 6b9d6e4d..e3311930 100644 --- a/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java +++ b/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java @@ -5,7 +5,6 @@ import android.content.SharedPreferences; import android.location.Location; import android.preference.PreferenceManager; -import android.util.Log; import com.google.gson.Gson; @@ -13,12 +12,7 @@ import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE; import static org.iilab.pb.common.AppConstants.DEFAULT_ALARM_INTERVAL; -import static org.iilab.pb.common.AppConstants.DEFAULT_ALARM_NOT_CONFIRMED_NONE; import static org.iilab.pb.common.AppConstants.DEFAULT_HAPTIC_FEEDBACK_DURATION; -import static org.iilab.pb.common.AppConstants.DEFAULT_HAPTIC_FEEDBACK_PATTERN_CONTINUSLY; -import static org.iilab.pb.common.AppConstants.DEFAULT_INITIAL_CLICKS_ALERT_TRIGGER; -import static org.iilab.pb.common.AppConstants.DEFAULT_INITIAL_TIME_FOR_ALARM_TRIGGER; -import static org.iilab.pb.common.AppConstants.DEFAULT_NO_CONFIRMATION_CLICK_MODE; import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; @@ -214,12 +208,12 @@ public static boolean isHardwareTriggerServiceEnabled(Context context) { public static String getInitialClicksForAlertTrigger(Context context) { - return sharedPreferences(context).getString(context.getString(R.string.initialPressesKey), DEFAULT_INITIAL_CLICKS_ALERT_TRIGGER); + 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), DEFAULT_HAPTIC_FEEDBACK_PATTERN_CONTINUSLY); + return sharedPreferences(context).getString(context.getString(R.string.hapticFeedbackVibrationPatternKey), context.getString(R.string.hapticFeedbackDefaultPattern)); } public static String getConfirmationWaitVibrationDuration(Context context) { @@ -235,20 +229,10 @@ public static String getConfirmationFeedbackVibrationPattern(Context context) { } public static String getAlarmNotConfirmedPattern(Context context) { - return sharedPreferences(context).getString(context.getString(R.string.alertNotConfirmedKey), DEFAULT_ALARM_NOT_CONFIRMED_NONE); + 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), DEFAULT_INITIAL_TIME_FOR_ALARM_TRIGGER); - } - - public static void setAlarmConfirmationMode(Context context, String alarmConfirmationMode) { - saveString(context, ALARM_CONFIRMATION_MODE, alarmConfirmationMode); - } - - public static boolean isConfirmationClickRequired(Context context) { - String alarmConfirmationMode = sharedPreferences(context).getString(ALARM_CONFIRMATION_MODE, DEFAULT_NO_CONFIRMATION_CLICK_MODE); - Log.d("Nixxx",alarmConfirmationMode); - return (DEFAULT_NO_CONFIRMATION_CLICK_MODE.equals(alarmConfirmationMode) ? false : true); + return sharedPreferences(context).getString(context.getString(R.string.initialTimeKey), context.getString(R.string.initialTimeDefault)); } public static String getShortVibration(Context context) { diff --git a/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java b/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java index a0267c16..3138139d 100644 --- a/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java +++ b/app/src/main/java/org/iilab/pb/trigger/HardwareTriggerReceiver.java @@ -38,8 +38,9 @@ public void onReceive(Context context, Intent intent) { else if(multiClickEvent.canStartVibration()){ Log.d(TAG, "vibration started"); -// PanicAlert panicAlert = getPanicAlert(context); AppUtil.vibrateForHapticFeedback(context); + + } else if (multiClickEvent.isActivated()) { diff --git a/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java b/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java index d117eff8..d5695a8d 100644 --- a/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java +++ b/app/src/main/java/org/iilab/pb/trigger/MultiClickEvent.java @@ -7,6 +7,8 @@ import com.google.gson.Gson; +import org.iilab.pb.common.AppUtil; + import java.io.IOException; import java.util.ArrayList; import java.util.Date; @@ -14,12 +16,13 @@ import java.util.Map; import static org.iilab.pb.common.AppConstants.ALARM_NOT_CONFIRMED_THREE_FAST; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE; import static org.iilab.pb.common.AppConstants.ONE_SECOND; import static org.iilab.pb.common.ApplicationSettings.getAlarmNotConfirmedPattern; +import static org.iilab.pb.common.ApplicationSettings.getConfirmationFeedbackVibrationPattern; 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.isConfirmationClickRequired; public class MultiClickEvent { //This is the guard time @@ -58,38 +61,31 @@ public Context getContext() { } public void registerClick(Long timeWhenButtonClicked) { - if (waitForConfirmation ) { - if(isConfirmationClickRequired(mContext)) { - 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(); - } + 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; - }else{ + } + 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); @@ -99,7 +95,16 @@ public void registerClick(Long timeWhenButtonClicked) { Log.d(TAG, "MultiClickEvent clickCount = " + clickCount + " " + mContext); eventLog.put(Integer.toString(clickCount) + " click", new Date(timeWhenButtonClicked).toString()); if (clickCount >= Integer.parseInt(getInitialClicksForAlertTrigger(mContext))) { - waitForConfirmation = true; + + //if no confirmation click required, activate the alarm + if(ALARM_SENDING_CONFIRMATION_PATTERN_NONE.equals(getConfirmationFeedbackVibrationPattern(mContext))) { + waitForConfirmation=false; + isActivated = true; + AppUtil.vibrateForHapticFeedback(mContext); + }else { + waitForConfirmation = true; + } + eventLog.put("Waiting for confirmation", new Date(timeWhenButtonClicked).toString()); hapticFeedbackVibrationStartTime = timeWhenButtonClicked; return; @@ -107,14 +112,14 @@ public void registerClick(Long timeWhenButtonClicked) { } } - 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)){ + 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); + long[] pattern = {0, 600, 400, 600, 400, 600, 400}; + vibrator.vibrate(pattern, -1); } } @@ -157,8 +162,8 @@ private boolean isPowerClickBecauseOfUser() { 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); + Log.d(TAG, "Initial clicks max time limit is " + initialClicksMaxTimeLimit); + Log.d(TAG, "Initial clicks done with in assigned time limit? " + isInitialClicksWithInLimit); return isInitialClicksWithInLimit; } diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 342419df..5540b243 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -81,7 +81,7 @@ Trigger Pattern Settings Initial Presses - 5 + 7 Number of presses needed to trigger the alarm initialClicks @@ -102,7 +102,7 @@ hapticFeedbackVibrationPattern Alarm Sending Confirmation - 1 + 5 Vibration pattern to inform that the alarm has been activated alertSendingConfirmationVibration diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8cb2722..dcffd2a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,7 +82,7 @@ Trigger Pattern Settings Initial Presses - 5 + 7 Number of presses needed to trigger the alarm initialClicks @@ -103,7 +103,7 @@ hapticFeedbackVibrationPattern Alarm Sending Confirmation - 1 + 5 Vibration pattern to inform that the alarm has been activated alertSendingConfirmationVibration diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e3f22617..8985a4fb 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -8,9 +8,6 @@ android:key="@string/configurePowerButtonTriggerKey" android:summary="@string/configurePowerButtonTriggerSummary" android:title="@string/PowerButtonTriggerTitle" /> - - -