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

Commit

Permalink
#178 Advanced settings changes for new sub screen
Browse files Browse the repository at this point in the history
  • Loading branch information
niccs committed Mar 2, 2016
1 parent a724be4 commit d6ae3a2
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 177 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/iilab/pb/BaseFragmentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/org/iilab/pb/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -234,7 +236,13 @@ public void onBackPressed() {
}



@Override
public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat,
PreferenceScreen preferenceScreen) {
Log.d(TAG,"g----------------------------------------------");
preferenceFragmentCompat.setPreferenceScreen(preferenceScreen);
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
119 changes: 83 additions & 36 deletions app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
// }
// }


}

Loading

0 comments on commit d6ae3a2

Please sign in to comment.