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

Commit

Permalink
#178 changes to handle custon summary dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
niccs committed Mar 21, 2016
1 parent 5908d40 commit abc3088
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 61 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/org/iilab/pb/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ protected void onStart() {

@Override
public void onBackPressed() {
Log.d(TAG, " fragment back pressed in " + currentPage.getId());
Log.d(TAG, " fragment back pressed in " + currentPage.getId()+" "+pageId);
if (pageId.equals(PAGE_HOME_READY)) {
// if (pageId.equals(PAGE_SETUP_ALARM_RETRAINING)){
// don't go back
// finish();
// startActivity(AppUtil.behaveAsHomeButton());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ else if (pageId.equals(PAGE_CLOSE_TRAINING)){
int wizardState = ApplicationSettings.getWizardState(mContext.getApplicationContext());
Log.e(TAG, "wizardState = " + wizardState);
if (wizardState == WIZARD_FLAG_HOME_READY && ApplicationSettings.isHardwareTriggerServiceEnabled(mContext)) {
//after the redo training excercise is done, we need to restrat the hardware trigger service.
//after the redo training exercise is done, we need to restart the hardware trigger service.
mContext.startService(new Intent(mContext, HardwareTriggerService.class));
}
((WizardActivity) mContext).callFinishActivityReceiver();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/iilab/pb/common/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class AppConstants {
public static final String ALARM_5_REPEATED_CLICKS = "5";
public static final String ALARM_7_REPEATED_CLICKS = "7";
public static final String ALARM_CONFIRMATION_REQUIRED = "2";
public static final String ALARM_CONFIRMATION_NOT_REQUIRED = "1";

public static final String DEFAULT_7_REPEATED_PRESS = "7PRESS";
public static final String ALARM_5_PRESS_PLUS_CONFIRMATION = "5PRESS_PLUS_CONFIRMATION";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.iilab.pb.R;

import static org.iilab.pb.common.AppConstants.ALARM_5_PRESS_PLUS_CONFIRMATION;
import static org.iilab.pb.common.AppConstants.ALARM_CONFIRMATION_NOT_REQUIRED;
import static org.iilab.pb.common.AppConstants.ALARM_CONFIRMATION_REQUIRED;
import static org.iilab.pb.common.AppConstants.ALARM_CUSTOM;
import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE;
Expand Down Expand Up @@ -256,8 +257,11 @@ public static boolean isAppUpdated(Context context) {
}
public static void setAlarmConfirmationRequired(Context context, Boolean isConfirmationRequired) {
saveBoolean(context, CONFIRMATION_FEEDBACK, isConfirmationRequired);
if(isConfirmationRequired)
saveString(context, context.getString(R.string.confirmationSequenceKey),ALARM_CONFIRMATION_REQUIRED);
if(isConfirmationRequired) {
saveString(context, context.getString(R.string.confirmationSequenceKey), ALARM_CONFIRMATION_REQUIRED);
}else{
saveString(context, context.getString(R.string.confirmationSequenceKey), ALARM_CONFIRMATION_NOT_REQUIRED);
}
}
public static boolean isAlarmConfirmationRequired(Context context) {
return sharedPreferences(context).getBoolean(CONFIRMATION_FEEDBACK, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
Expand Down Expand Up @@ -35,9 +34,8 @@
import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern;
import static org.iilab.pb.common.ApplicationSettings.setInitialClicksForAlertTrigger;

public class AdvancedSettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
public class AdvancedSettingsFragment extends PreferenceFragmentCompat {
private static final String TAG = AdvancedSettingsFragment.class.getName();
// CheckBoxPreference customPreference = (CheckBoxPreference) findPreference(getString(R.string.customKey));
public static AdvancedSettingsFragment newInstance(String pageId, int parentActivity) {
AdvancedSettingsFragment f = new AdvancedSettingsFragment();
Bundle args = new Bundle();
Expand Down Expand Up @@ -113,6 +111,7 @@ public boolean onPreferenceChange(Preference preference, Object selectedValue) {
customPreference.setChecked(false);
customSettings.setEnabled(false);
setInitialClicksForAlertTrigger(getActivity(), ALARM_7_REPEATED_CLICKS);
setAlarmConfirmationRequired(getActivity(),false);
setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE);
Log.d(TAG, "Default 7 presses to trigger alarm without confirmation click");
}
Expand Down Expand Up @@ -199,35 +198,19 @@ private void displayNotification() {
myNotificationManager.notify(notifyID, mBuilder.build());
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d(TAG, "called for advanced settings");
if (key.equals(R.string.initialPressesKey)) {
Preference initialClicks = findPreference(key);
// Set summary to be the user-description for the selected value
//// x repeated press with confirmation
CheckBoxPreference customPreference = (CheckBoxPreference) findPreference(getString(R.string.customKey));
customPreference.setSummary(sharedPreferences.getString(key, "")+"repeated press");
}
}

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
Log.d(TAG, "on Content changed called for main settings onResume");
Log.d(TAG, "on Resume for AdvancedSettingsFragment is called");
CheckBoxPreference customPreference = (CheckBoxPreference) findPreference(getString(R.string.customKey));
Log.d(TAG, "inside initial clicks " +customPreference);
customPreference.setSummary(getCustomSummary());
}

@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
Log.d(TAG, "on Content changed called for main settings onPause");
Log.d(TAG, "on Pause for AdvancedSettingsFragment is called");
}

private String getCustomSummary(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.iilab.pb.fragment;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.util.Log;
Expand All @@ -17,22 +15,9 @@
import static org.iilab.pb.common.ApplicationSettings.setAlarmConfirmationRequired;
import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern;

public class AdvancedSettingsSubScreenFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener{
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d(TAG,"called for advanced settings sub screen "+ key+" "+R.string.initialPressesKey);
if (key.equals(getString(R.string.initialPressesKey))) {
Preference initialClicks = findPreference(key);
// Set summary to be the user-description for the selected value
//// x repeated press with confirmation
CheckBoxPreference customPreference = (CheckBoxPreference) findPreference(getString(R.string.customKey));
Log.d(TAG, "inside initial clicks " +customPreference);
// customPreference.setSummary(sharedPreferences.getString(key, "")+"repeated press");
}
}
public class AdvancedSettingsSubScreenFragment extends PreferenceFragmentCompat {

private static final String TAG = AdvancedSettingsSubScreenFragment.class.getName();

public static AdvancedSettingsSubScreenFragment newInstance(String pageId, int parentActivity) {
AdvancedSettingsSubScreenFragment f = new AdvancedSettingsSubScreenFragment();
Bundle args = new Bundle();
Expand All @@ -46,7 +31,7 @@ public static AdvancedSettingsSubScreenFragment newInstance(String pageId, int p
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
// Load the preferences from an XML resource
setPreferencesFromResource(R.xml.preferences, rootKey);
Log.d(TAG, "onCreatePreferences of the sub screen "+rootKey);
Log.d(TAG, "onCreatePreferences of the sub screen " + rootKey);
Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.confirmationSequenceKey));
if (isAlarmConfirmationRequired(getActivity())) {
enableConfirmationPatterns(true);
Expand Down Expand Up @@ -84,18 +69,5 @@ private void enableConfirmationPatterns(boolean flag) {
confirmationWaitVibration.setEnabled(flag);
}

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
}

6 changes: 4 additions & 2 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@
<string name="redoTrainingKey">redoTraining</string>

<string name="triggerSettingsHeaderTitle">Alarm Trigger Settings</string>
<string name="default7RepeatedPressTitle">(Default)7 Repeated Presses</string>
<string name="default7RepeatedPressTitle">Default</string>
<string name="default7RepeatedPressSummary">7 Repeated Presses</string>
<string name="default7RepeatedPressKey">default7Press</string>
<string name="extraConfirmationPressTitle">5 presses plus confirmation </string>
<string name="extraConfirmationPressTitle">Extra Confirmation </string>
<string name="extraConfirmationPressSummary">5 presses plus confirmation </string>
<string name="extraConfirmationPressKey">extraConfirmation </string>

<string name="customKey">Custom</string>
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@
<string name="redoTrainingKey">redoTraining</string>

<string name="triggerSettingsHeaderTitle">Alarm Trigger Settings</string>
<string name="default7RepeatedPressTitle">(Default)7 Repeated Presses</string>
<string name="default7RepeatedPressTitle">Default</string>
<string name="default7RepeatedPressSummary">7 Repeated Presses</string>
<string name="default7RepeatedPressKey">default7Press</string>
<string name="extraConfirmationPressTitle">5 presses plus confirmation </string>
<string name="extraConfirmationPressTitle">Extra Confirmation </string>
<string name="extraConfirmationPressSummary">5 presses plus confirmation </string>
<string name="extraConfirmationPressKey">extraConfirmation </string>

<string name="customKey">Custom</string>
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/default7RepeatedPressKey"
android:title="@string/default7RepeatedPressTitle" />
android:title="@string/default7RepeatedPressTitle"
android:summary="@string/default7RepeatedPressSummary"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/extraConfirmationPressKey"
android:title="@string/extraConfirmationPressTitle" />
android:title="@string/extraConfirmationPressTitle"
android:summary="@string/extraConfirmationPressSummary"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/customKey"
Expand Down

0 comments on commit abc3088

Please sign in to comment.