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

Commit

Permalink
#178, modified advances settings
Browse files Browse the repository at this point in the history
  • Loading branch information
niccs committed Feb 1, 2016
1 parent 12db4a5 commit e03ab26
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ApplicationSettings extends Application {
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";

Expand Down Expand Up @@ -249,5 +250,11 @@ public static void setAppUpdated(Context context, boolean isAppUpdated) {
public static boolean isAppUpdated(Context context) {
return sharedPreferences(context).getBoolean(APP_UPDATED, false);
}
public static void setConfirmationFeedback(Context context, Boolean confirmationFeedback) {
saveBoolean(context, CONFIRMATION_FEEDBACK, confirmationFeedback);
}
public static boolean isConfirmationFeedback(Context context) {
return sharedPreferences(context).getBoolean(CONFIRMATION_FEEDBACK, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.iilab.pb.MainActivity;
import org.iilab.pb.R;
import org.iilab.pb.WizardActivity;
import org.iilab.pb.common.ApplicationSettings;
import org.iilab.pb.trigger.HardwareTriggerService;

import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_LONG;
Expand All @@ -26,6 +25,10 @@
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.getTriggerSettings;
import static org.iilab.pb.common.ApplicationSettings.isConfirmationFeedback;
import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedback;
import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern;

public class AdvancedSettingsFragment extends PreferenceFragmentCompat {

Expand All @@ -46,11 +49,16 @@ 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(ApplicationSettings.getTriggerSettings(getActivity()))){
if(getString(R.string.custom_modeValue).equals(getTriggerSettings(getActivity()))){
enableAdvancedSettings(true);
}else{
enableAdvancedSettings(false);
}
if(isConfirmationFeedback(getActivity())){
enableConfirmationFeedback(true);
}else{
enableConfirmationFeedback(false);
}

Preference redoTrainingButton = (Preference) findPreference(getString(R.string.redoTrainingKey));
redoTrainingButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand Down Expand Up @@ -85,7 +93,7 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) {
}
});

Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.feedbackAlarmActivationKey));
Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.confirmationSettingsKey));

alertConfirmationSettings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
Expand All @@ -95,10 +103,12 @@ 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);
Log.d(TAG, "default confirmation press deactivated");
} else {
// enable Confirmation Wait Time/ Confirmation Wait Vibration
enableConfirmationFeedback(true);
setConfirmationFeedback(getActivity(), true);
Log.d(TAG, "Confirmation press enabled");
}
return true;
Expand All @@ -112,12 +122,12 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) {
Log.d(TAG, "Inside on preference change of main trigger setting");

if (selectedValue.equals(getString(R.string.default7RepeatedPressValue))) {
ApplicationSettings.setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE);
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))) {
ApplicationSettings.setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_LONG);
setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_LONG);
enableAdvancedSettings(false);
enableRedoTraining(true);
Log.d(TAG, "Extra confirmation click required to trigger alarm");
Expand All @@ -141,14 +151,16 @@ private void enableAdvancedSettings(boolean flag){
prefCatPowerButtonTriggerSettings.setEnabled(flag);
}
private void enableRedoTraining(boolean flag){
Preference prefCatRedoTraining = (Preference) findPreference(getString(R.string.redoTrainingPrefCatKey));
PreferenceCategory prefCatRedoTraining = (PreferenceCategory) findPreference(getString(R.string.redoTrainingPrefCatKey));
prefCatRedoTraining.setEnabled(flag);
}
private void enableConfirmationFeedback(boolean flag){
PreferenceCategory confirmationWaitTime = (PreferenceCategory) findPreference(getString(R.string.confirmationWaitTimeKey));
Preference confirmationWaitTime = (Preference) findPreference(getString(R.string.confirmationWaitTimeKey));
confirmationWaitTime.setEnabled(flag);
PreferenceCategory confirmationWaitVibration = (PreferenceCategory) findPreference(getString(R.string.hapticFeedbackVibrationPatternKey));
Preference confirmationWaitVibration = (Preference) findPreference(getString(R.string.hapticFeedbackVibrationPatternKey));
confirmationWaitVibration.setEnabled(flag);
Preference alertSendingConfirmationPattern = (Preference) findPreference(getString(R.string.alertSendingConfirmationVibrationKey));
alertSendingConfirmationPattern.setEnabled(flag);

}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
<string name="feedbackAlarmActivationKey">feedbackAlarmActivation</string>
<string name="confirmationSettingsTitle">Confirmation Settings</string>
<string name="confirmationSettingsDefault">1</string>
<string name="confirmationSettingsSummary">Time to wait until the confirmation press</string>
<string name="confirmationSettingsKey">confirmationWaitTime</string>
<string name="confirmationSettingsSummary">Feedback on Alarm Activation</string>
<string name="confirmationSettingsKey">confirmationSettings</string>


<string name="confirmationWaitTimeTitle">Confirmation Wait Time</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
<string name="feedbackAlarmActivationKey">feedbackAlarmActivation</string>
<string name="confirmationSettingsTitle">Confirmation Settings</string>
<string name="confirmationSettingsDefault">1</string>
<string name="confirmationSettingsSummary">Time to wait until the confirmation press</string>
<string name="confirmationSettingsKey">confirmationWaitTime</string>
<string name="confirmationSettingsSummary">Feedback on Alarm Activation</string>
<string name="confirmationSettingsKey">confirmationSettings</string>

<string name="confirmationWaitTimeTitle">Confirmation Wait Time</string>
<string name="confirmationWaitTimeDefault">2</string>
Expand Down

0 comments on commit e03ab26

Please sign in to comment.