From d6ae3a2fef60d8b9a3ad55a154a52405e07fc69e Mon Sep 17 00:00:00 2001 From: Neetika Date: Wed, 2 Mar 2016 12:55:35 +1100 Subject: [PATCH] #178 Advanced settings changes for new sub screen --- .../org/iilab/pb/BaseFragmentActivity.java | 4 +- .../main/java/org/iilab/pb/MainActivity.java | 14 +- .../iilab/pb/common/ApplicationSettings.java | 8 +- .../pb/fragment/AdvancedSettingsFragment.java | 119 ++++++++---- app/src/main/res/values-en/strings.xml | 42 ++--- app/src/main/res/values/array.xml | 18 +- app/src/main/res/values/strings.xml | 37 ++-- app/src/main/res/xml/preferences.xml | 171 ++++++++++-------- 8 files changed, 236 insertions(+), 177 deletions(-) diff --git a/app/src/main/java/org/iilab/pb/BaseFragmentActivity.java b/app/src/main/java/org/iilab/pb/BaseFragmentActivity.java index a43d134e..f6706587 100644 --- a/app/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/app/src/main/java/org/iilab/pb/MainActivity.java b/app/src/main/java/org/iilab/pb/MainActivity.java index c899012f..c1cb2769 100644 --- a/app/src/main/java/org/iilab/pb/MainActivity.java +++ b/app/src/main/java/org/iilab/pb/MainActivity.java @@ -7,6 +7,8 @@ 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; @@ -31,7 +33,7 @@ /** * Created by aoe on 2/15/14. */ -public class MainActivity extends BaseFragmentActivity { +public class MainActivity extends BaseFragmentActivity implements PreferenceFragmentCompat.OnPreferenceStartScreenCallback { TextView tvToastMessage; @@ -143,7 +145,7 @@ else if (currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { private void changeAppIcontoPB() { - Log.d(TAG," changeAppIcontoPB"); + 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); @@ -234,7 +236,13 @@ public void onBackPressed() { } - + @Override + public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, + PreferenceScreen preferenceScreen) { + Log.d(TAG,"g----------------------------------------------"); + preferenceFragmentCompat.setPreferenceScreen(preferenceScreen); + return true; + } } 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 a3514df5..a903fa6a 100644 --- a/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java +++ b/app/src/main/java/org/iilab/pb/common/ApplicationSettings.java @@ -223,10 +223,10 @@ public static String getConfirmationWaitVibrationDuration(Context context) { } public static void setConfirmationFeedbackVibrationPattern(Context context, String confirmationFeedbackPattern) { - saveString(context,context.getString(R.string.alertSendingConfirmationVibrationKey),confirmationFeedbackPattern); + saveString(context,context.getString(R.string.feedbackAlarmActivationVibrationKey),confirmationFeedbackPattern); } public static String getConfirmationFeedbackVibrationPattern(Context context) { - return sharedPreferences(context).getString(context.getString(R.string.alertSendingConfirmationVibrationKey), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); + return sharedPreferences(context).getString(context.getString(R.string.feedbackAlarmActivationVibrationKey), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); } public static String getAlarmNotConfirmedPattern(Context context) { @@ -235,8 +235,8 @@ public static String getAlarmNotConfirmedPattern(Context context) { public static String getInitialClicksMaxTimeLimit(Context context) { return sharedPreferences(context).getString(context.getString(R.string.initialTimeKey), context.getString(R.string.initialTimeDefault)); } - public static String getTriggerSettings(Context context) { - return sharedPreferences(context).getString(context.getString(R.string.triggerSettingsKey), context.getString(R.string.initialPressesDefault)); + 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); 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 cedb9bc1..89112e59 100644 --- a/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java +++ b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java @@ -7,6 +7,7 @@ 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.PreferenceCategory; import android.support.v7.preference.PreferenceFragmentCompat; @@ -25,8 +26,7 @@ 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.getInitialClicksForAlertTrigger; -import static org.iilab.pb.common.ApplicationSettings.getTriggerSettings; +import static org.iilab.pb.common.ApplicationSettings.getCustomSettings; import static org.iilab.pb.common.ApplicationSettings.isConfirmationFeedback; import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedback; import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern; @@ -37,6 +37,8 @@ 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(); @@ -51,10 +53,20 @@ 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()))) { - enableAdvancedSettings(true); + + + 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 { - enableAdvancedSettings(false); + customPreference.setChecked(false); + customSettings.setEnabled(false); } if (isConfirmationFeedback(getActivity())) { enableConfirmationFeedback(true); @@ -66,7 +78,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { redoTrainingButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - Log.d(TAG, "Testing redo training redoTrainingBtton"); + 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); @@ -85,24 +97,25 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) { if (selectedValue.equals(getString(R.string.activate_power_button_trigger))) { getActivity().startService(new Intent(getActivity(), HardwareTriggerService.class)); - Log.d(TAG, "Power redoTrainingBtton alarm trigger is enabled"); + Log.d(TAG, "Power redoTraining Button alarm trigger is enabled"); } else { getActivity().stopService(new Intent(getActivity(), HardwareTriggerService.class)); displayNotification(); - Log.d(TAG, "Power redoTrainingBtton alarm trigger is disabled"); + Log.d(TAG, "Power redoTrainingButton alarm trigger is disabled"); } return true; } }); - Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.confirmationSettingsKey)); + + Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.confirmationSequenceKey)); alertConfirmationSettings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object selectedValue) { Log.d(TAG, "Inside of feedback for alarm activation settings"); - if (selectedValue.equals(getString(R.string.confirmationSettingsDefault))) { + if (selectedValue.equals(getString(R.string.confirmationSequenceDefault))) { // disable Confirmation Wait Time/ Confirmation Wait Vibration enableConfirmationFeedback(false); setConfirmationFeedback(getActivity(), false); @@ -116,29 +129,55 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) { return true; } }); - Preference triggerSettingsPef = (Preference) findPreference(getString(R.string.triggerSettingsKey)); - triggerSettingsPef.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + + default7RepeatedPress.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object selectedValue) { - Log.d(TAG, "Inside on preference change of main trigger setting"); + Log.d(TAG, "Inside on preference change of main trigger setting " + selectedValue.getClass()); - if (selectedValue.equals(getString(R.string.default7RepeatedPressValue))) { + if ((Boolean) selectedValue) { + extraConfirmationClick.setChecked(false); + customPreference.setChecked(false); + customSettings.setEnabled(false); setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); - enableAdvancedSettings(false); - enableRedoTraining(true); - Log.d(TAG, "Extra confirmation click required to trigger alarm"); - } else if (selectedValue.equals(getString(R.string.extraConfirmationPressValue))) { - //make the press 5 + Log.d(TAG, "Default 7 presses to trigger alarm without confirmation click"); + } + return true; + } + }); + extraConfirmationClick.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside on preference change of main trigger setting " + selectedValue.getClass()); + + if ((Boolean) selectedValue) { + default7RepeatedPress.setChecked(false); + customPreference.setChecked(false); + customSettings.setEnabled(false); + // make the press 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())); - } else if (selectedValue.equals(getString(R.string.custom_modeValue))) { - enableAdvancedSettings(true); - // enable all the advanced settings - Log.d(TAG, "Power redoTrainingButton alarm trigger is disabled"); + + Log.d(TAG, "Default 5 presses to trigger alarm with confirmation click"); + } + return true; + } + }); + + customPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside on preference change of main trigger setting " + selectedValue.getClass()); + + if ((Boolean) selectedValue) { + default7RepeatedPress.setChecked(false); + extraConfirmationClick.setChecked(false); + customSettings.setEnabled(true); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); +// enableAdvancedSettings(false); +// enableRedoTraining(true); + Log.d(TAG, "Default 7 presses to trigger alarm without confirmation click"); } return true; } @@ -147,28 +186,20 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) { private void enableAdvancedSettings(boolean flag) { PreferenceCategory prefCatTriggerPatternSettings = (PreferenceCategory) findPreference(getString(R.string.triggerPatternSettingsKey)); - PreferenceCategory prefCatTriggerVibrationSettings = (PreferenceCategory) findPreference(getString(R.string.feedbackAlarmActivationKey)); +// PreferenceCategory prefCatTriggerVibrationSettings = (PreferenceCategory) findPreference(getString(R.string.feedbackAlarmActivationKey)); PreferenceCategory prefCatRedoTraining = (PreferenceCategory) findPreference(getString(R.string.redoTrainingPrefCatKey)); PreferenceCategory prefCatPowerButtonTriggerSettings = (PreferenceCategory) findPreference(getString(R.string.configurePowerButtonPrefCatKey)); prefCatTriggerPatternSettings.setEnabled(flag); - prefCatTriggerVibrationSettings.setEnabled(flag); +// prefCatTriggerVibrationSettings.setEnabled(flag); prefCatRedoTraining.setEnabled(flag); prefCatPowerButtonTriggerSettings.setEnabled(flag); } - private void enableRedoTraining(boolean flag) { - PreferenceCategory prefCatRedoTraining = (PreferenceCategory) findPreference(getString(R.string.redoTrainingPrefCatKey)); - prefCatRedoTraining.setEnabled(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)); confirmationWaitVibration.setEnabled(flag); - Preference alertSendingConfirmationPattern = (Preference) findPreference(getString(R.string.alertSendingConfirmationVibrationKey)); - alertSendingConfirmationPattern.setEnabled(flag); - } private void displayNotification() { @@ -203,5 +234,21 @@ private void displayNotification() { // pass the Notification object to the system myNotificationManager.notify(notifyID, mBuilder.build()); } +// +// @Override +// public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, +// String key) { +// Log.d(TAG, "callback called"); +// if (key.equals(R.string.default7RepeatedPressKey)) { +// Log.d(TAG, "callback called"); +// +// Preference connectionPref = findPreference("customSettings"); +// // Set summary to be the user-description for the selected value +// connectionPref.setSummary(sharedPreferences.getString(key, "trying to change this runtime")); +// connectionPref.setDefaultValue(false); +// } +// } + + } diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 9c382fa1..97dbbfe0 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -75,7 +75,6 @@ Change Trigger Pattern Number of first clicks - Guard time duration Number of confirmation clicks 3 1 @@ -93,12 +92,16 @@ initialTime Feedback on Alarm Activation - feedbackAlarmActivation + 5 + Vibration pattern to inform that the alarm has been activated + feedbackAlarmActivationVibration + Confirmation Settings - 1 - Feedback on Alarm Activation confirmationSettings - + Use Confirmation Sequence + confirmationSettings + 1 + Feedback on Alarm Activation Confirmation Wait Time 2 @@ -110,14 +113,7 @@ Vibration pattern during the wait time until the confirmation press hapticFeedbackVibrationPattern - Alarm Sending Confirmation - 5 - Vibration pattern to inform that the alarm has been activated - alertSendingConfirmationVibration - - Feedback on NON Confirmation Alarm - feedbackAlarmActivation - Feedback on NON Confirmation Alarm + Feedback on NON Confirmation Alarm 1 Vibration pattern to inform that the alarm has NOT been activated. This will happen if you make the correct number of initial presses but do NOT confirm. alertNotConfirmed @@ -129,17 +125,21 @@ redoTraining Alarm Trigger Settings - Trigger Settings - Alarm Trigger Settings - triggerSettings + + + - (Default) 7 repeated presses - 5 presses plus confirmation - Custom + (Default) 7 repeated presses + default7Press + 5 presses plus confirmation + extraConfirmation + + Custom + Custom 1 2 - 3 - + customSettings + Custom settings diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index c0f59261..41e2cd60 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -38,12 +38,12 @@ 7 8 - + (Default) Inactive Active - + 1 2 @@ -69,7 +69,7 @@ 1 2 - + Long Vibration Repeated Short Vibrations Three short - pause - Three short @@ -77,7 +77,7 @@ None - + 1 2 3 @@ -93,15 +93,5 @@ 1 2 - - @string/default7RepeatedPress - @string/extraConfirmationPress - @string/custom_mode - - - @string/default7RepeatedPressValue - @string/extraConfirmationPressValue - @string/custom_modeValue - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96e063cb..e1726695 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -94,11 +94,16 @@ initialTime Feedback on Alarm Activation - feedbackAlarmActivation + 5 + Vibration pattern to inform that the alarm has been activated + feedbackAlarmActivationVibration + Confirmation Settings - 1 - Feedback on Alarm Activation confirmationSettings + Use Confirmation Sequence + confirmationSettings + 1 + Feedback on Alarm Activation Confirmation Wait Time 2 @@ -110,13 +115,6 @@ Vibration pattern during the wait time until the confirmation press hapticFeedbackVibrationPattern - Alarm Sending Confirmation - 5 - Vibration pattern to inform that the alarm has been activated - alertSendingConfirmationVibration - - Feedback on NON Confirmation Alarm - feedbackAlarmActivation Feedback on NON Confirmation Alarm 1 Vibration pattern to inform that the alarm has NOT been activated. This will happen if you make the correct number of initial presses but do NOT confirm. @@ -129,14 +127,19 @@ redoTraining Alarm Trigger Settings - Trigger Settings - Alarm Trigger Settings - triggerSettings - - (Default) 7 repeated presses - 5 presses plus confirmation - Custom + + + + + (Default) 7 repeated presses + 5 presses plus confirmation + Custom + Custom 1 2 3 + + customSettings + Custom settings + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 65417cc3..a55190cc 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -1,90 +1,101 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - + - + + + + + + + - - - + \ No newline at end of file