protected PreferenceGroup getPreferenceParent(PreferenceGroup prefGroup, Preference pref) { for (int i = 0; i < prefGroup.getPreferenceCount(); ++i) { Preference prefChild = prefGroup.getPreference(i); if (prefChild == pref) { return prefGroup; } if (prefChild instanceof PreferenceGroup) { PreferenceGroup childGroup = (PreferenceGroup) prefChild; PreferenceGroup result = getPreferenceParent(childGroup, pref); if (result != null) { return result; } } } return null; }
@DexAppend @Override public void onCreate(Bundle icicle) { try { PreferenceGroup pg = (PreferenceGroup) findPreference( FakeSignatureGlobalUI.DEBUG_APPLICATIONS_CATEGORY_KEY); if (pg != null) { TwoStatePreference p = createTwoStatePreference(pg.getContext()); p.setKey(FakeSignatureGlobalUI.SETTING_SECURE_KEY); p.setTitle(FakeSignatureGlobalUI.SETTING_TITLE); p.setSummary(FakeSignatureGlobalUI.SETTING_SUMMARY); p.setPersistent(false); mResetTwoStatePrefsAdd(p); mAllPrefs.add(p); //pg.setOrderingAsAdded(true); pg.addPreference(p); mAllowFakeSignatureGlobal = p; } else { Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "cannot find 'applications' preference category"); } } catch (Throwable t) { Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "onCreate exception", t); } }
protected void addEditAccountAction( final IGISApplication application, final Account account, PreferenceGroup actionCategory) { Preference preferenceEdit = new Preference(mStyledContext); preferenceEdit.setTitle(R.string.edit_account); preferenceEdit.setSummary(R.string.edit_account_summary); String url = application.getAccountUrl(account); String login = application.getAccountLogin(account); Intent intent = new Intent(mStyledContext, NGWLoginActivity.class); intent.putExtra(NGWLoginActivity.FOR_NEW_ACCOUNT, false); intent.putExtra(NGWLoginActivity.ACCOUNT_URL_TEXT, url); intent.putExtra(NGWLoginActivity.ACCOUNT_LOGIN_TEXT, login); intent.putExtra(NGWLoginActivity.CHANGE_ACCOUNT_URL, false); intent.putExtra(NGWLoginActivity.CHANGE_ACCOUNT_LOGIN, true); preferenceEdit.setIntent(intent); actionCategory.addPreference(preferenceEdit); }
private void tintPrefIconsRecursive(PreferenceGroup prefGroup, @ColorInt int iconColor) { if (prefGroup != null) { int prefCount = prefGroup.getPreferenceCount(); for (int i = 0; i < prefCount; i++) { Preference pref = prefGroup.getPreference(i); if (pref != null) { pref.setIcon(_cu.tintDrawable(pref.getIcon(), iconColor)); if (pref instanceof PreferenceGroup) { tintPrefIconsRecursive((PreferenceGroup) pref, iconColor); } } } } }
protected void removePreference(@Nullable Preference preference) { if (preference == null) { return; } PreferenceGroup parent = getPreferenceParent(getPreferenceScreen(), preference); if (parent == null) { return; } parent.removePreference(preference); }
protected void fillPreferences(PreferenceGroup screen) { if (mAction != null && mAction.equals(SettingsConstantsUI.ACTION_ACCOUNT)) { addPreferencesFromResource(R.xml.preferences_ngid); fillAccountPreferences(screen); } }
private void removeAdvancePreference(Preference preference) { // these null checks are to fix a crash due to an NPE on 4.4.4 if (preference != null) { PreferenceGroup group = (PreferenceGroup) findPreference("pref_general"); if (group != null) { group.removePreference(preference); } } }
private void initSummary(Preference preference) { if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) { initSummary(preferenceGroup.getPreference(i)); } } else { updatePreferenceSummary(preference); } }
private void initPrefsInfos(Preference pref) { if (pref instanceof PreferenceGroup) { PreferenceGroup prefGroup = (PreferenceGroup) pref; final int currentPreferenceCount = prefGroup.getPreferenceCount(); for (int i = 0; i < currentPreferenceCount; i++) { initPrefsInfos(prefGroup.getPreference(i)); } } else { initClickedListenerIfNeeded(pref); initFilterIfNeeded(pref); updatePrefDefaultValue(pref); updatePrefSummary(pref); } }
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.preference_settings, rootKey); mPreferenceScreen = (PreferenceScreen) findPreference("preference_screen"); initGeneral(); initUi(); mDevPreferenceGroup = (PreferenceGroup) findPreference("preference_group_dev"); if (!mPrefs.devOptionsOpened().getValue()) { mPreferenceScreen.removePreference(mDevPreferenceGroup); } else { initDevOps(); } initAbout(); }
public PreferenceGroupAdapter(PreferenceGroup preferenceGroup) { super(preferenceGroup); try { Field preferenceLayoutsField = android.support.v7.preference.PreferenceGroupAdapter.class.getDeclaredField("mPreferenceLayouts"); preferenceLayoutsField.setAccessible(true); mPreferenceLayouts = (List) preferenceLayoutsField.get(this); getReflectionFields(); } catch (Exception e) { e.printStackTrace(); } }
/** * Traverses a {@code PreferenceGroup} to notify all eligible preferences about the results * of a returning activity. * * @param group The {@code PreferenceGroup} to traverse. * @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ protected void onActivityResult(PreferenceGroup group, int requestCode, int resultCode, Intent data) { final int n = group.getPreferenceCount(); for (int i = 0; i < n; i++) { Preference pref = group.getPreference(i); if (pref instanceof PreferenceActivityResultListener) { ((PreferenceActivityResultListener) pref).onActivityResult(requestCode, resultCode, data); } if (pref instanceof PreferenceGroup) { onActivityResult((PreferenceGroup) pref, requestCode, resultCode, data); } } }
private void initSummary(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummary(pGrp.getPreference(i)); } } else { updatePrefSummary(p); } }
private void initSummary(Preference preference) { if (preference instanceof PreferenceGroup) { PreferenceGroup group = (PreferenceGroup) preference; for (int i = 0; i < group.getPreferenceCount(); i++) { initSummary(group.getPreference(i)); } } else { updatePrefSummary(preference); } }
protected void fillPreferences(PreferenceGroup screen) { if (mAction != null && mAction.equals(SettingsConstantsUI.ACTION_ACCOUNT)) { Account account = getArguments().getParcelable(NGWSettingsActivity.KEY_ACCOUNT); fillAccountPreferences(screen, account); } }
public void fillAccountPreferences( PreferenceGroup screen, final Account account) { final IGISApplication appContext = (IGISApplication) mStyledContext.getApplicationContext(); // add sync settings group PreferenceCategory syncCategory = new PreferenceCategory(mStyledContext); syncCategory.setTitle(R.string.sync); screen.addPreference(syncCategory); // add auto sync property addAutoSyncProperty(appContext, account, syncCategory); // add time for periodic sync addPeriodicSyncTime(appContext, account, syncCategory); // add account layers addAccountLayers(screen, appContext, account); // add actions group PreferenceCategory actionCategory = new PreferenceCategory(mStyledContext); actionCategory.setTitle(R.string.actions); screen.addPreference(actionCategory); // add "Edit account" action addEditAccountAction(appContext, account, actionCategory); // add delete account action addDeleteAccountAction(appContext, account, actionCategory); // TODO: for isMultiPane() change title of Settings fragment, not of Activity // if (mChangeTitle && !NGPreferenceActivity.isMultiPane(mActivity)) { if (mChangeTitle) { ActionBar ab = mActivity.getSupportActionBar(); if (null != ab) { ab.setTitle(account.name); } } }
protected void addAutoSyncProperty( final IGISApplication application, final Account account, PreferenceGroup syncCategory) { final String accountNameHash = "_" + account.name.hashCode(); SharedPreferences sharedPreferences = mStyledContext.getSharedPreferences(Constants.PREFERENCES, Constants.MODE_MULTI_PROCESS); CheckBoxPreference enablePeriodicSync = new CheckBoxPreference(mStyledContext); enablePeriodicSync.setKey(KEY_SYNC); enablePeriodicSync.setPersistent(false); enablePeriodicSync.setTitle(R.string.auto_sync); boolean isAccountSyncEnabled = isAccountSyncEnabled(account, application.getAuthority()); enablePeriodicSync.setChecked(isAccountSyncEnabled); enablePeriodicSync.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange( Preference preference, Object newValue) { boolean isChecked = (boolean) newValue; setAccountSyncEnabled(account, application.getAuthority(), isChecked); return true; } }); long timeStamp = sharedPreferences.getLong( com.nextgis.maplib.util.SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP + accountNameHash, 0); if (isAccountSyncEnabled && timeStamp > 0) { enablePeriodicSync.setSummary(ControlHelper.getSyncTime(mStyledContext, timeStamp)); } else { enablePeriodicSync.setSummary(R.string.auto_sync_summary); } syncCategory.addPreference(enablePeriodicSync); }
private static void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) { // If there's some items to display, sort the items and add them to the container. Collections.sort(prefs, new Comparator<Preference>() { @Override public int compare(Preference lhs, Preference rhs) { return lhs.getTitle().toString().toLowerCase().compareTo(rhs.getTitle().toString().toLowerCase()); } }); for (Preference entry : prefs) { container.addPreference(entry); } }
private void setSummary(Preference preference) { if (preference instanceof ShaderListPreference) { long id = Preferences.WALLPAPER_SHADER.equals(preference.getKey()) ? ShaderEditorApp.preferences.getWallpaperShader() : ShaderEditorApp.preferences.getDefaultNewShader(); preference.setSummary(getShaderSummary(id)); } else if (preference instanceof ListPreference) { preference.setSummary(((ListPreference) preference).getEntry()); } else if (preference instanceof PreferenceGroup) { setSummaries((PreferenceGroup) preference); } }
private void initPreferenceScreen(PreferenceGroup screen, SharedPreferences sharedPreferences) { final int count = screen.getPreferenceCount(); for (int i = 0; i < count; i++) { Preference preference = screen.getPreference(i); if (preference instanceof PreferenceGroup) { initPreferenceScreen((PreferenceGroup) preference, sharedPreferences); } else { handlePreferenceChange(preference, sharedPreferences, preference.getKey()); } } }
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); final PreferenceGroupAdapter adapter = (PreferenceGroupAdapter) parent.getAdapter(); final int adapterCount = adapter.getItemCount(); boolean wasLastPreferenceGroup = false; for (int i = 0, childCount = parent.getChildCount(); i < childCount; i++) { final View child = parent.getChildAt(i); final int adapterPosition = parent.getChildAdapterPosition(child); Preference preference = adapter.getItem(adapterPosition); boolean skipNextAboveDivider = false; if (adapterPosition == 0) { if (mDrawTop) { drawAbove(c, left, right, child); } skipNextAboveDivider = true; } if (preference instanceof PreferenceGroup && !(preference instanceof PreferenceScreen)) { if (mDrawBetweenCategories) { if (!skipNextAboveDivider) { drawAbove(c, left, right, child); skipNextAboveDivider = true; } } wasLastPreferenceGroup = true; } else { if (mDrawBetweenItems && !wasLastPreferenceGroup) { if (!skipNextAboveDivider) { drawAbove(c, left, right, child); skipNextAboveDivider = true; } } wasLastPreferenceGroup = false; } if (adapterPosition == adapterCount - 1) { if (mDrawBottom) { drawBottom(c, left, right, child); } } } }
public void fillAccountPreferences(PreferenceGroup screen) { String notDefined = getString(R.string.not_set); String value = mPreferences.getString(NGIDUtils.PREF_USERNAME, null); screen.findPreference(NGIDUtils.PREF_USERNAME) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); value = mPreferences.getString(NGIDUtils.PREF_EMAIL, null); screen.findPreference(NGIDUtils.PREF_EMAIL) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); value = mPreferences.getString(NGIDUtils.PREF_FIRST_NAME, null); screen.findPreference(NGIDUtils.PREF_FIRST_NAME) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); value = mPreferences.getString(NGIDUtils.PREF_LAST_NAME, null); screen.findPreference(NGIDUtils.PREF_LAST_NAME) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); screen.findPreference("sign_out") .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { mPreferences.edit() .remove(NGIDUtils.PREF_USERNAME) .remove(NGIDUtils.PREF_EMAIL) .remove(NGIDUtils.PREF_FIRST_NAME) .remove(NGIDUtils.PREF_LAST_NAME) .remove(NGIDUtils.PREF_ACCESS_TOKEN) .remove(NGIDUtils.PREF_REFRESH_TOKEN) .apply(); if (!NGPreferenceActivity.isMultiPane(getActivity())) { mActivity.onBackPressed(); mActivity.onBackPressed(); } else { mActivity.invalidatePreferences(); } mActivity.replaceSettingsFragment(null); return false; } }); }
public HighlightablePreferenceGroupAdapter(PreferenceGroup preferenceGroup) { super(preferenceGroup); }
public void fillAccountPreferences(PreferenceGroup screen) { String notDefined = getString(R.string.not_set); String value = mPreferences.getString(NGIDUtils.PREF_USERNAME, null); screen.findPreference(NGIDUtils.PREF_USERNAME) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); value = mPreferences.getString(NGIDUtils.PREF_EMAIL, null); screen.findPreference(NGIDUtils.PREF_EMAIL) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); value = mPreferences.getString(NGIDUtils.PREF_FIRST_NAME, null); screen.findPreference(NGIDUtils.PREF_FIRST_NAME) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); value = mPreferences.getString(NGIDUtils.PREF_LAST_NAME, null); screen.findPreference(NGIDUtils.PREF_LAST_NAME) .setSummary(TextUtils.isEmpty(value) ? notDefined : value); screen.findPreference("sign_out") .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { mPreferences.edit() .remove(NGIDUtils.PREF_USERNAME) .remove(NGIDUtils.PREF_EMAIL) .remove(NGIDUtils.PREF_FIRST_NAME) .remove(NGIDUtils.PREF_LAST_NAME) .remove(NGIDUtils.PREF_ACCESS_TOKEN) .remove(NGIDUtils.PREF_REFRESH_TOKEN) .apply(); File support = getContext().getExternalFilesDir(null); if (support == null) support = new File(getContext().getFilesDir(), SUPPORT); else support = new File(support, SUPPORT); FileUtil.deleteRecursive(support); if (!NGPreferenceActivity.isMultiPane(getActivity())) { mActivity.onBackPressed(); mActivity.onBackPressed(); } else { mActivity.invalidatePreferences(); } mActivity.replaceSettingsFragment(null); return false; } }); }
private void setSummaries(PreferenceGroup screen) { for (int i = screen.getPreferenceCount(); i-- > 0; ) { setSummary(screen.getPreference(i)); } }