@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_floating_action_settings); setUpSwitch( R.string.key_floating_action_enabled, new OnSwitchChangeListener() { @Override public void onChange(SwitchPreference sw, boolean enabled) { FTD.Settings settings = new FTD.Settings(sw.getSharedPreferences()); MyApp.updateService( sw.getContext(), settings.pressure.enabled, settings.size.enabled, enabled, settings.showNotification); } }); openActivity(R.string.key_floating_action_list, FloatingActionActivity.class); showListSummary( R.string.key_floating_action_color, new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int color = Color.parseColor((String) newValue); GradientDrawable drawable = new GradientDrawable(); drawable.setColor(color); int size = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size); drawable.setSize(size, size); preference.setIcon(drawable); restartService(preference.getContext(), preference.getSharedPreferences()); return true; } }); showTextSummary( R.string.key_floating_action_alpha, new OnTextChangeListener() { @Override public boolean onChange(EditTextPreference edit, String text) { restartService(edit.getContext(), edit.getSharedPreferences()); return true; } }); setUpSwitch( R.string.key_use_local_fab, new OnSwitchChangeListener() { @Override public void onChange(SwitchPreference sw, boolean enabled) { restartService(sw.getContext(), sw.getSharedPreferences()); } }); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_BLACKLIST: if (resultCode == RESULT_OK) { Set<String> blacklist = (Set<String>) data.getSerializableExtra(AppSelectActivity.EXTRA_SELECTED_HASH_SET); getPreferenceManager() .getSharedPreferences() .edit() .putStringSet(mPrefKey, blacklist) .apply(); } break; default: super.onActivityResult(requestCode, resultCode, data); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_header_settings); changeScreen(R.string.key_header_general, GeneralSettingsFragment.class); changeScreen(R.string.key_header_pressure, PressureSettingsFragment.class); changeScreen(R.string.key_header_size, SizeSettingsFragment.class); changeScreen(R.string.key_header_floating_action, FloatingActionSettingsFragment.class); updateState(R.string.key_header_pressure, R.string.key_pressure_enabled); updateState(R.string.key_header_size, R.string.key_size_enabled); updateState(R.string.key_header_floating_action, R.string.key_floating_action_enabled); // Information Preference about = findPreference(R.string.key_about); about.setSummary(getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_ACTION: if (resultCode == RESULT_OK) { ActionInfo.Record record = (ActionInfo.Record) data.getSerializableExtra(ActionPickerActivity.EXTRA_ACTION_RECORD); MyApp.logD("picked intent: " + record.intentUri); // save Preference pref = findPreference(mPrefKey); pref.getSharedPreferences() .edit() .putString(mPrefKey, record.toStringForPreference()) .apply(); updateActionSummary(pref, record); } break; default: super.onActivityResult(requestCode, resultCode, data); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_general_settings); showTextSummary(R.string.key_detection_area, R.string.unit_detection_area); openActivityForResult( R.string.key_blacklist, AppSelectActivity.class, REQUEST_BLACKLIST, new ExtraPutter() { @Override public void putExtras(Preference preference, Intent activityIntent) { mPrefKey = preference.getKey(); Set<String> blacklist = preference .getSharedPreferences() .getStringSet(mPrefKey, Collections.<String>emptySet()); AppSelectActivity.putExtras(activityIntent, preference.getTitle(), blacklist); } }); setUpSwitch( R.string.key_show_notification, new OnSwitchChangeListener() { @Override public void onChange(SwitchPreference sw, boolean enabled) { FTD.Settings settings = new FTD.Settings(sw.getSharedPreferences()); MyApp.updateService( sw.getContext(), settings.pressure.enabled, settings.size.enabled, settings.floatingActionEnabled, enabled); } }); showTextSummary(R.string.key_detection_sensitivity); showTextSummary(R.string.key_detection_window, R.string.unit_detection_window); }