Java Code Examples for android.preference.PreferenceGroup#removePreference()

The following examples show how to use android.preference.PreferenceGroup#removePreference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomInputStyleSettingsFragment.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }

    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 2
Source File: CustomInputStyleSettingsFragment.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onAddCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey();
        mSubtypeEnablerNotificationDialog = createDialog();
        mSubtypeEnablerNotificationDialog.show();
        return;
    }

    // Newly added subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 3
Source File: CookiesFragment.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
private boolean removeCookie(String cookie, boolean preferenceOnly) {
	if (!preferenceOnly) {
		configuration.storeCookie(cookie, null, null);
		configuration.commit();
	}
	CookiePreference preference = (CookiePreference) findPreference(cookie);
	if (preference != null) {
		PreferenceGroup preferenceGroup = getParentGroup(preference);
		preferenceGroup.removePreference(preference);
		cookies.remove(cookie);
		if (preferenceGroup.getPreferenceCount() == 0) {
			getActivity().finish();
			return true;
		}
	}
	return false;
}
 
Example 4
Source File: CustomInputStyleSettingsFragment.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onAddCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey();
        mSubtypeEnablerNotificationDialog = createDialog();
        mSubtypeEnablerNotificationDialog.show();
        return;
    }

    // Newly added subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 5
Source File: AdvancedSettingsFragment.java    From FwdPortForwardingApp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.advanced_preferences);
    advertisementsEnabled = (Preference) findPreference(getString(R.string.pref_disable_ads_key));

    // Remove advertisements option
    PreferenceGroup mCategory = (PreferenceCategory) findPreference("pref_advanced_category");
    mCategory.removePreference(advertisementsEnabled);

    ipChecker = (Preference) findPreference(getString(R.string.pref_ip_checker));
    ipChecker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent ipCheckerActivity = new Intent(getActivity(), IpAddressCheckerActivity.class);
            startActivity(ipCheckerActivity);
            return true;
        }
    });

}
 
Example 6
Source File: CustomInputStyleSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }

    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 7
Source File: CustomInputStyleSettingsFragment.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }

    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 8
Source File: CustomInputStyleSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onAddCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey();
        mSubtypeEnablerNotificationDialog = createDialog();
        mSubtypeEnablerNotificationDialog.show();
        return;
    }

    // Newly added subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 9
Source File: CustomInputStyleSettingsFragment.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }

    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 10
Source File: CustomInputStyleSettingsFragment.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onAddCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey();
        mSubtypeEnablerNotificationDialog = createDialog();
        mSubtypeEnablerNotificationDialog.show();
        return;
    }

    // Newly added subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
 
Example 11
Source File: SettingsActivity.java    From island with Apache License 2.0 5 votes vote down vote up
protected static boolean removeLeafPreference(final PreferenceGroup root, final Preference preference) {
	if (root.removePreference(preference)) return true;
	for (int i = 0; i < root.getPreferenceCount(); i ++) {
		final Preference child = root.getPreference(i);
		if (child instanceof PreferenceGroup && removeLeafPreference((PreferenceGroup) child, preference)) return true;
	}
	return false;
}
 
Example 12
Source File: CustomInputStyleSettingsFragment.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRemoveCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
}
 
Example 13
Source File: TalkBackKeyboardShortcutPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize preference UIs.
 *
 * @param root Root element of preference UIs.
 * @param hiddenShortcutKeys Set of shortcut keys which will be made hidden. Note that
 *     preference is made hidden only when its shortcut is disabled in the key combo model.
 */
private void initPreferenceUIs(PreferenceGroup root, Set<String> hiddenShortcutKeys) {
  if (root == null) {
    return;
  }

  final KeyComboModel keyComboModel = getKeyComboManager().getKeyComboModel();
  final String preferenceKeyForTriggerModifier =
      keyComboModel.getPreferenceKeyForTriggerModifier();

  for (int i = 0; i < root.getPreferenceCount(); i++) {
    final Preference preference = root.getPreference(i);
    final String key = preference.getKey();

    if (key != null
        && preference instanceof KeyboardShortcutDialogPreference
        && !keyComboModel.getKeyComboCodeMap().containsKey(key)) {
      // Disable or hide preference of unavailable key combo on this device.
      if (hiddenShortcutKeys.contains(key)) {
        root.removePreference(preference);
        i--;
      } else {
        preference.setEnabled(false);
      }
    } else if (preference instanceof KeyboardShortcutDialogPreference
        || (key != null && key.equals(getString(R.string.pref_select_keymap_key)))
        || (key != null && key.equals(preferenceKeyForTriggerModifier))) {
      // Set onPreferenceChangeListener.
      preference.setOnPreferenceChangeListener(preferenceChangeListener);
    } else if (preference instanceof PreferenceGroup) {
      initPreferenceUIs((PreferenceGroup) preference, hiddenShortcutKeys);
    }
  }
}
 
Example 14
Source File: CustomInputStyleSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoveCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
}
 
Example 15
Source File: CameraSettingsActivity.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively traverses the tree from the given group as the route and
 * tries to delete the preference. Traversal stops once the preference
 * was found and removed.
 */
private boolean recursiveDelete(PreferenceGroup group, Preference preference)
{
    if (group == null)
    {
        Log.d(TAG, "attempting to delete from null preference group");
        return false;
    }
    if (preference == null)
    {
        Log.d(TAG, "attempting to delete null preference");
        return false;
    }
    if (group.removePreference(preference))
    {
        // Removal was successful.
        return true;
    }

    for (int i = 0; i < group.getPreferenceCount(); ++i)
    {
        Preference pref = group.getPreference(i);
        if (pref instanceof PreferenceGroup)
        {
            if (recursiveDelete((PreferenceGroup) pref, preference))
            {
                return true;
            }
        }
    }
    return false;
}
 
Example 16
Source File: Preferences.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Utils.setLocale(this);
    setTitle(R.string.settings);
    addPreferencesFromResource(R.xml.prefs);

    Preference p = findPreference("more_apps");
    if (p != null) {
        p.setOnPreferenceClickListener(this);
    }
    p = findPreference("reset_data");
    if (p != null) {
        p.setOnPreferenceClickListener(this);
    }

    if (BuildConfig.DEBUG_LOG) {
        p = findPreference("send_logs");
        if (p != null) {
            p.setOnPreferenceClickListener(this);
        }
        p = findPreference("send_devices");
        if (p != null) {
            p.setOnPreferenceClickListener(this);
        }
    } else {
        p = findPreference("debug");
        if (p != null) {
            PreferenceGroup pg = (PreferenceGroup) p;
            pg.removePreference(findPreference("send_logs"));
            pg.removePreference(findPreference("send_devices"));
        }
    }
    onNewIntent(getIntent());
}
 
Example 17
Source File: CustomInputStyleSettingsFragment.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoveCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
}
 
Example 18
Source File: ConfigBase.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
private boolean removePreference(@NonNull PreferenceGroup pg,
                                 @NonNull Preference preference) {
    for (int i = pg.getPreferenceCount() - 1; i >= 0; i--) {
        Preference child = pg.getPreference(i);
        if (child == preference) {
            pg.removePreference(preference);
            return true;
        } else if (child instanceof PreferenceGroup) {
            if (removePreference((PreferenceGroup) child, preference)) return true;
        }
    }
    return false;
}
 
Example 19
Source File: MoreSettings.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings_more_fragment);
    syncPreference(Config.KEY_PRIVACY,
            new MultiSelectListPreferenceSetter(getActivity(), 0,
                    R.string.settings_privacy_mode_disabled));
    syncPreference(Config.KEY_ONLY_WHILE_CHARGING);
    syncPreference(Config.KEY_FEEL_SCREEN_OFF_AFTER_LAST_NOTIFY);
    syncPreference(Config.KEY_DOUBLE_TAP_TO_SLEEP);
    syncPreference(Config.KEY_MEDIA_WIDGET);
    syncPreference(Config.KEY_FEEL_WIDGET_PINNABLE);
    syncPreference(Config.KEY_FEEL_WIDGET_READABLE);
    syncPreference(Config.KEY_CORNER_ACTION_LEFT_TOP, mListPreferenceCornerActionSetter);
    syncPreference(Config.KEY_CORNER_ACTION_LEFT_BOTTOM, mListPreferenceCornerActionSetter);
    syncPreference(Config.KEY_CORNER_ACTION_RIGHT_TOP, mListPreferenceCornerActionSetter);
    syncPreference(Config.KEY_CORNER_ACTION_RIGHT_BOTTOM, mListPreferenceCornerActionSetter);

    mInactiveHoursPreference = findPreference("inactive_hours");
    mTimeoutPreference = findPreference("timeout");
    // Back-up & restore
    mDataRestoreDefaultsPreference = findPreference("data_restore_defaults");
    mDataBackupPreference = findPreference("data_backup");
    mDataRestorePreference = findPreference("data_restore");

    mDataRestoreDefaultsPreference.setOnPreferenceClickListener(this);
    mDataBackupPreference.setOnPreferenceClickListener(this);
    mDataRestorePreference.setOnPreferenceClickListener(this);

    if (!DEBUG) {
        PreferenceGroup pg = (PreferenceGroup) findPreference("data_category");
        pg.removePreference(mDataBackupPreference);
        pg.removePreference(mDataRestorePreference);
    }
}
 
Example 20
Source File: DictionarySettingsFragment.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
static void removeAnyDictSettings(final PreferenceGroup prefGroup) {
    for (int i = prefGroup.getPreferenceCount() - 1; i >= 0; --i) {
        prefGroup.removePreference(prefGroup.getPreference(i));
    }
}