diff --git a/app/src/main/java/org/iilab/pb/HomeActivity.java b/app/src/main/java/org/iilab/pb/HomeActivity.java index 339fa5e5..466c6f74 100644 --- a/app/src/main/java/org/iilab/pb/HomeActivity.java +++ b/app/src/main/java/org/iilab/pb/HomeActivity.java @@ -114,22 +114,21 @@ public void onCreate(Bundle savedInstanceState) { /* We update the device language content if the english mobile_en.json version has increased or * if the language of the device OS was previously not installed*/ - Log.d(TAG, "currentLocalContentVersion is" +currentLocalContentVersion +"and newLocalContentVersion is "+ newLocalContentVersion); + Log.d(TAG, "currentLocalContentVersion is" + currentLocalContentVersion + "and newLocalContentVersion is " + newLocalContentVersion); if ((newLocalContentVersion > currentLocalContentVersion) || (!isLanguageDataExists(getApplicationContext(), selectedLang))) { Log.d(TAG, "Update local data as the english mobile_en.json version has increased"); // to check if the app is installed first time, -1 is the default value - if(currentLocalContentVersion== FRESH_INSTALL_APP_RELEASE_NO){ - setFirstRun(getApplicationContext(),true); + if (currentLocalContentVersion == FRESH_INSTALL_APP_RELEASE_NO) { + setFirstRun(getApplicationContext(), true); setAppUpdated(getApplicationContext(), false); - }else { - setFirstRun(getApplicationContext(),false); + } else { + setFirstRun(getApplicationContext(), false); setAppUpdated(getApplicationContext(), true); } new InitializeLocalData().execute(); addDBLoadedLanguage(getApplicationContext(), selectedLang); - } - else { + } else { Log.d(TAG, "no update of local data needed"); startNextActivity(); } @@ -174,22 +173,25 @@ private void setSupportedLanguages(Page languagesPage) { private void startNextActivity() { Log.d(TAG, "starting next activity"); int wizardState = getWizardState(this); - supportedLangs = getSupportedLanguages(this); - Log.d(TAG, "Checking supported languages " + supportedLangs); - if (null == supportedLangs) { - PBDatabase dbInstance = new PBDatabase(this); - dbInstance.open(); - Page languagesPage = dbInstance.retrievePage(PAGE_SETUP_LANGUAGE, DEFAULT_LANGUAGE_ENG); - setSupportedLanguages(languagesPage); - dbInstance.close(); - } - if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) { - setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG); - } + //TODO remove after testing -// wizardState=WIZARD_FLAG_HOME_READY; +// wizardState = WIZARD_FLAG_HOME_READY; if (wizardState != WIZARD_FLAG_HOME_READY) { Log.d(TAG, "First run TRUE, running WizardActivity with pageId = " + pageId); + + supportedLangs = getSupportedLanguages(this); + Log.d(TAG, "Checking supported languages " + supportedLangs); + if (null == supportedLangs) { + PBDatabase dbInstance = new PBDatabase(this); + dbInstance.open(); + Page languagesPage = dbInstance.retrievePage(PAGE_SETUP_LANGUAGE, DEFAULT_LANGUAGE_ENG); + setSupportedLanguages(languagesPage); + dbInstance.close(); + } + if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) { + setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG); + } + Intent i = new Intent(HomeActivity.this, WizardActivity.class); i.putExtra(PAGE_ID, pageId); startActivity(i); @@ -197,7 +199,7 @@ private void startNextActivity() { Log.d(TAG, "First run FALSE, running CalculatorActivity"); Intent i = new Intent(HomeActivity.this, CalculatorActivity.class); // Make sure the HardwareTriggerService is started - if(isHardwareTriggerServiceEnabled(this)) { + if (isHardwareTriggerServiceEnabled(this)) { startService(new Intent(this, HardwareTriggerService.class)); } startActivity(i); @@ -256,184 +258,7 @@ protected void onPostExecute(Boolean response) { Log.e(TAG, "Exception while dismissing progress dialog " + e.getMessage()); e.printStackTrace(); } - -// setLocalDataInsertion(HomeActivity.this, true); -// setLastUpdatedDBVersion(HomeActivity.this, DATABASE_VERSION); - startNextActivity(); } } - -// private class GetLatestVersion extends AsyncTask { -// -// @Override -// protected void onPreExecute() { -// super.onPreExecute(); -// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Starting...", true, false); -// } -// -// @Override -// protected Boolean doInBackground(Void... params) { -// -// String url = AppConstants.BASE_URL + AppConstants.VERSION_CHECK_URL; -// JsonParser jsonParser = new JsonParser(); -// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, url, null, null, null); -// if (response.getStatus() == 200) { -// try { -// JSONObject responseObj = response.getjObj(); -// latestVersion = responseObj.getInt("version"); -// Log.e("??????", "latest version = " + latestVersion + " last updated version = " + lastUpdatedVersion); -// return true; -// } catch (JSONException e) { -// e.printStackTrace(); -// } -// } -// return false; -// } -// -// @Override -// protected void onPostExecute(Boolean response) { -// super.onPostExecute(response); -// -// if (latestVersion > lastUpdatedVersion) { -// new GetMobileDataUpdate().execute(); -// } else { -// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis()); -// if (pDialog.isShowing()) -// try { -// pDialog.dismiss(); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// startNextActivity(); -// } -// } -// } - - -// private class GetMobileDataUpdate extends AsyncTask { -// -// @Override -// protected void onPreExecute() { -// super.onPreExecute(); -// try { -// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Downloading updates...", true, false); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } -// -// @Override -// protected Boolean doInBackground(Void... params) { -// -// int version = 0; -// for(version = lastUpdatedVersion + 1; version <= latestVersion; version ++){ -// if (selectedLang.equals("en")) { -// mobileDataUrl = AppConstants.BASE_URL + "/api/mobile." + version + ".json"; -// } else { -// mobileDataUrl = AppConstants.BASE_URL + "/api/" + selectedLang + "/" + "mobile." + version + ".json"; -// } -// -// JsonParser jsonParser = new JsonParser(); -// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, mobileDataUrl, null, null, null); -// if (response.getStatus() == 200) { -// Log.d(">>>><<<<", "success in retrieving server-response for url = " + mobileDataUrl); -// try { -// JSONObject responseObj = response.getjObj(); -// JSONObject mobObj = responseObj.getJSONObject(JSON_OBJECT_MOBILE); -// JSONArray dataArray = mobObj.getJSONArray(JSON_ARRAY_DATA); -// insertMobileDataToLocalDB(dataArray); -// } catch (JSONException e) { -// e.printStackTrace(); -// return false; -// } -// } -// } -// -// if(version > latestVersion){ -// return true; -// } else{ -// return false; -// } -// } -// -// @Override -// protected void onPostExecute(Boolean response) { -// super.onPostExecute(response); -// -// if(response){ -// new GetHelpDataUpdate().execute(); -// } -// else{ -// if (pDialog.isShowing()) -// pDialog.dismiss(); -// -// startNextActivity(); -// } -// } -// } - - -// private class GetHelpDataUpdate extends AsyncTask { -// -// @Override -// protected void onPreExecute() { -// super.onPreExecute(); -// try { -// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Downloading help pages...", true, false); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } -// -// @Override -// protected Boolean doInBackground(Void... params) { -// -// JsonParser jsonParser = new JsonParser(); -// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, helpDataUrl, null, null, null); -// if (response.getStatus() == 200) { -// Log.d(">>>><<<<", "success in retrieving server-response for url = " + helpDataUrl); -// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis()); // if we can retrieve a single data, we change it up-to-date -// try { -// JSONObject responseObj = response.getjObj(); -// JSONObject mobObj = responseObj.getJSONObject(JSON_OBJECT_HELP); -// JSONArray dataArray = mobObj.getJSONArray(JSON_ARRAY_DATA); -// insertHelpDataToLocalDB(dataArray); -// setLastUpdatedVersion(HomeActivity.this, latestVersion); -// return true; -// } catch (JSONException e) { -// e.printStackTrace(); -// } -// } -// return false; -// } -// -// @Override -// protected void onPostExecute(Boolean response) { -// super.onPostExecute(response); -// if (pDialog.isShowing()) -// try { -// pDialog.dismiss(); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// startNextActivity(); -// } -// } - - -// private void insertHelpDataToLocalDB(JSONArray dataArray) { -// List pageList = HelpPage.parseHelpPages(dataArray); -// -// PBDatabase dbInstance = new PBDatabase(HomeActivity.this); -// dbInstance.open(); -// -// for (int i = 0; i < pageList.size(); i++) { -// dbInstance.insertOrUpdateHelpPage(pageList.get(i)); -// } -// dbInstance.close(); -// } - - } \ No newline at end of file diff --git a/app/src/main/java/org/iilab/pb/MainActivity.java b/app/src/main/java/org/iilab/pb/MainActivity.java index fda2cf8f..2435d21a 100644 --- a/app/src/main/java/org/iilab/pb/MainActivity.java +++ b/app/src/main/java/org/iilab/pb/MainActivity.java @@ -15,10 +15,9 @@ import android.widget.Toast; import org.iilab.pb.alert.PanicAlert; -import org.iilab.pb.common.AppConstants; -import org.iilab.pb.common.ApplicationSettings; import org.iilab.pb.data.PBDatabase; import org.iilab.pb.fragment.AdvancedSettingsFragment; +import org.iilab.pb.fragment.AdvancedSettingsSubScreenFragment; import org.iilab.pb.fragment.LanguageSettingsFragment; import org.iilab.pb.fragment.MainSetupAlertFragment; import org.iilab.pb.fragment.SetupCodeFragment; @@ -28,12 +27,31 @@ import org.iilab.pb.fragment.WarningFragment; import org.iilab.pb.model.Page; import org.iilab.pb.trigger.HardwareTriggerService; -import static org.iilab.pb.common.AppConstants.*; + +import static org.iilab.pb.common.AppConstants.FROM_MAIN_ACTIVITY; +import static org.iilab.pb.common.AppConstants.IS_BACK_BUTTON_PRESSED; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_ADVANCED_SETTINGS; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_ALERT; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_CODE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_CONTACTS; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_LANGUAGE; +import static org.iilab.pb.common.AppConstants.PAGE_COMPONENT_MESSAGE; +import static org.iilab.pb.common.AppConstants.PAGE_FROM_NOT_IMPLEMENTED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.AppConstants.PAGE_HOME_READY; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_MODAL; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_SIMPLE; +import static org.iilab.pb.common.AppConstants.PAGE_TYPE_WARNING; +import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED; +import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage; +import static org.iilab.pb.common.ApplicationSettings.isAlertActive; +import static org.iilab.pb.common.ApplicationSettings.setWizardState; /** * Created by aoe on 2/15/14. */ -public class MainActivity extends BaseFragmentActivity implements PreferenceFragmentCompat.OnPreferenceStartScreenCallback { +public class MainActivity extends BaseFragmentActivity implements PreferenceFragmentCompat.OnPreferenceStartScreenCallback { TextView tvToastMessage; @@ -43,12 +61,12 @@ public class MainActivity extends BaseFragmentActivity implements PreferenceFrag Boolean flagRiseFromPause = false; private static final String TAG = MainActivity.class.getName(); - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.root_layout); - + tvToastMessage = (TextView) findViewById(R.id.tv_toast); try { @@ -57,18 +75,18 @@ public void onCreate(Bundle savedInstanceState) { pageId = PAGE_HOME_NOT_CONFIGURED; e.printStackTrace(); } - selectedLang = ApplicationSettings.getSelectedLanguage(this); + selectedLang = getSelectedLanguage(this); Log.i(TAG, "pageId = " + pageId); - if(pageId.equals(PAGE_HOME_NOT_CONFIGURED)){ + if (pageId.equals(PAGE_HOME_NOT_CONFIGURED)) { Log.d(TAG, "Restarting the Wizard"); - if((ApplicationSettings.isAlertActive(this))){ + if ((isAlertActive(this))) { new PanicAlert(this).deActivate(); } - ApplicationSettings.setWizardState(MainActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED); + setWizardState(MainActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED); changeAppIcontoPB(); // We're restarting the wizard so we deactivate the HardwareTriggerService @@ -97,7 +115,7 @@ public void onCreate(Bundle savedInstanceState) { if (currentPage == null) { Log.d(TAG, "page = null"); Toast.makeText(this, "Still to be implemented.", Toast.LENGTH_SHORT).show(); - AppConstants.PAGE_FROM_NOT_IMPLEMENTED = true; + PAGE_FROM_NOT_IMPLEMENTED = true; finish(); return; } else { @@ -108,35 +126,33 @@ public void onCreate(Bundle savedInstanceState) { if (currentPage.getType().equals(PAGE_TYPE_SIMPLE)) { tvToastMessage.setVisibility(View.INVISIBLE); - fragment = new SimpleFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - }else if (currentPage.getType().equals(PAGE_TYPE_WARNING)) { - tvToastMessage.setVisibility(View.INVISIBLE); - fragment = new WarningFragment().newInstance(pageId,AppConstants.FROM_MAIN_ACTIVITY); - - } else if (currentPage.getType().equals(PAGE_TYPE_MODAL)){ + fragment = new SimpleFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + } else if (currentPage.getType().equals(PAGE_TYPE_WARNING)) { + tvToastMessage.setVisibility(View.INVISIBLE); + fragment = new WarningFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + + } else if (currentPage.getType().equals(PAGE_TYPE_MODAL)) { tvToastMessage.setVisibility(View.INVISIBLE); Intent i = new Intent(MainActivity.this, MainModalActivity.class); i.putExtra(PAGE_ID, pageId); -// i.putExtra("parent_activity", AppConstants.FROM_MAIN_ACTIVITY); startActivity(i); finish(); return; } else { if (currentPage.getComponent().equals(PAGE_COMPONENT_CONTACTS)) - fragment = new SetupContactsFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + fragment = new SetupContactsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); else if (currentPage.getComponent().equals(PAGE_COMPONENT_MESSAGE)) - fragment = new SetupMessageFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + fragment = new SetupMessageFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); else if (currentPage.getComponent().equals(PAGE_COMPONENT_CODE)) - fragment = new SetupCodeFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + fragment = new SetupCodeFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); else if (currentPage.getComponent().equals(PAGE_COMPONENT_ALERT)) - fragment = new MainSetupAlertFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + fragment = new MainSetupAlertFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); else if (currentPage.getComponent().equals(PAGE_COMPONENT_LANGUAGE)) - fragment = new LanguageSettingsFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + fragment = new LanguageSettingsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); else if (currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { - fragment = new AdvancedSettingsFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); - } - else - fragment = new SimpleFragment().newInstance(pageId, AppConstants.FROM_MAIN_ACTIVITY); + fragment = new AdvancedSettingsFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); + } else + fragment = new SimpleFragment().newInstance(pageId, FROM_MAIN_ACTIVITY); } fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); @@ -146,9 +162,9 @@ else if (currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { private void 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); + getPackageManager().setComponentEnabledSetting( + new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-setup"), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); getPackageManager().setComponentEnabledSetting( new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-calculator"), @@ -166,9 +182,9 @@ protected void onResume() { if this page is resumed from the page still not implemented, then we'll handle it here. If we don't do this check, then the resume procedure falls under Check-3 & execute that code snippet, which is not proper. */ - if (AppConstants.PAGE_FROM_NOT_IMPLEMENTED) { + if (PAGE_FROM_NOT_IMPLEMENTED) { Log.d(TAG, "returning from not-implemented page."); - AppConstants.PAGE_FROM_NOT_IMPLEMENTED = false; + PAGE_FROM_NOT_IMPLEMENTED = false; return; } @@ -177,13 +193,13 @@ protected void onResume() { if this page is resumed by navigating-back from the next page, then we'll handle it here. If we don't do this check, then the resume procedure falls under Check-3 & execute that code snippet, which is not proper. */ - if (AppConstants.IS_BACK_BUTTON_PRESSED) { + if (IS_BACK_BUTTON_PRESSED) { Log.d(TAG, "back button pressed"); - AppConstants.IS_BACK_BUTTON_PRESSED = false; + IS_BACK_BUTTON_PRESSED = false; return; } - + if (flagRiseFromPause) { Intent i = new Intent(MainActivity.this, CalculatorActivity.class); startActivity(i); @@ -196,17 +212,17 @@ protected void onResume() { } return; } - + @Override protected void onPause() { super.onPause(); Log.d(TAG, "flagRiseFromPause = " + true); flagRiseFromPause = true; } - - protected void onStop(){ + + protected void onStop() { super.onStop(); - Log.d(TAG,"onStop"); + Log.d(TAG, "onStop"); } @Override @@ -214,32 +230,48 @@ protected void onStart() { super.onStart(); // if(pageId.equals("home-not-configured")){ // Log.e("??????????????", "home-not-configured"); -// ApplicationSettings.setWizardState(MainActivity.this, AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED); +// ApplicationSettings.setWizardState(MainActivity.this, WIZARD_FLAG_HOME_NOT_CONFIGURED); // Intent i = new Intent(MainActivity.this, WizardActivity.class); // i.putExtra("page_id", "home-not-configured"); // startActivity(i); // } - Log.d(TAG,"onStart"); + Log.d(TAG, "onStart"); } @Override public void onBackPressed() { - if(pageId.equals(PAGE_HOME_READY)){ + Log.d(TAG, " outttt fragment back pressed in " + currentPage.getId()); + if (pageId.equals(PAGE_HOME_READY)) { // don't go back // finish(); // startActivity(AppUtil.behaveAsHomeButton()); - } - else{ + } else if (currentPage.getComponent() != null && currentPage.getComponent().equals(PAGE_COMPONENT_ADVANCED_SETTINGS)) { + Log.d(TAG, " handling fragment back pressed in " + pageId); + if (getSupportFragmentManager().getBackStackEntryCount() > 0) { + getSupportFragmentManager().popBackStack(); + } + else { + super.onBackPressed(); + IS_BACK_BUTTON_PRESSED = true; + } + } else { super.onBackPressed(); - AppConstants.IS_BACK_BUTTON_PRESSED = true; + IS_BACK_BUTTON_PRESSED = true; } } @Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { - Log.d(TAG,"callback called to attach the preference sub screen"); - preferenceFragmentCompat.setPreferenceScreen(preferenceScreen); + Log.d(TAG, "callback called to attach the preference sub screen"); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + AdvancedSettingsSubScreenFragment fragment = AdvancedSettingsSubScreenFragment.newInstance(pageId, FROM_MAIN_ACTIVITY); + Bundle args = new Bundle(); + args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); + fragment.setArguments(args); + ft.replace(R.id.fragment_container, fragment, preferenceScreen.getKey()); + ft.addToBackStack(null); + ft.commit(); return true; } diff --git a/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsSubScreenFragment.java b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsSubScreenFragment.java new file mode 100644 index 00000000..5c3cacda --- /dev/null +++ b/app/src/main/java/org/iilab/pb/fragment/AdvancedSettingsSubScreenFragment.java @@ -0,0 +1,72 @@ +package org.iilab.pb.fragment; + +import android.os.Bundle; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceFragmentCompat; +import android.util.Log; + +import org.iilab.pb.R; + +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_LONG; +import static org.iilab.pb.common.AppConstants.ALARM_SENDING_CONFIRMATION_PATTERN_NONE; +import static org.iilab.pb.common.AppConstants.PAGE_ID; +import static org.iilab.pb.common.AppConstants.PARENT_ACTIVITY; +import static org.iilab.pb.common.ApplicationSettings.isAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.setAlarmConfirmationRequired; +import static org.iilab.pb.common.ApplicationSettings.setConfirmationFeedbackVibrationPattern; + +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(); + args.putString(PAGE_ID, pageId); + args.putInt(PARENT_ACTIVITY, parentActivity); + f.setArguments(args); + return (f); + } + + @Override + 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); + Preference alertConfirmationSettings = (Preference) findPreference(getString(R.string.confirmationSequenceKey)); + if (isAlarmConfirmationRequired(getActivity())) { + enableConfirmationPatterns(true); + } else { + enableConfirmationPatterns(false); + } + alertConfirmationSettings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange(Preference preference, Object selectedValue) { + Log.d(TAG, "Inside of Alarm confirmation settings"); + + if (selectedValue.equals(getString(R.string.confirmationSequenceDefault))) { + // disable Confirmation Wait Time/ Confirmation Wait Vibration + enableConfirmationPatterns(false); + setAlarmConfirmationRequired(getActivity(), false); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_NONE); + Log.d(TAG, "default confirmation press deactivated"); + } else { + // enable Confirmation Wait Time/ Confirmation Wait Vibration + enableConfirmationPatterns(true); + setAlarmConfirmationRequired(getActivity(), true); + setConfirmationFeedbackVibrationPattern(getActivity(), ALARM_SENDING_CONFIRMATION_PATTERN_LONG); + Log.d(TAG, "Confirmation press enabled"); + } + return true; + } + }); + } + + private void enableConfirmationPatterns(boolean flag) { + Preference confirmationWaitTime = (Preference) findPreference(getString(R.string.confirmationWaitTimeKey)); + confirmationWaitTime.setEnabled(flag); + Preference confirmationWaitVibration = (Preference) findPreference(getString(R.string.hapticFeedbackVibrationPatternKey)); + confirmationWaitVibration.setEnabled(flag); + } +} +