Java Code Examples for android.preference.PreferenceGroup

The following are top voted examples for showing how to use android.preference.PreferenceGroup. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lineagex86   File: NotificationLightSettings.java   View source code 6 votes vote down vote up
private void setChildrenStarted(PreferenceGroup group, boolean started) {
    final int count = group.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference pref = group.getPreference(i);
        if (pref instanceof ApplicationLightPreference) {
            ApplicationLightPreference ap = (ApplicationLightPreference) pref;
            if (started) {
                ap.onStart();
            } else {
                ap.onStop();
            }
        } else if (pref instanceof PreferenceGroup) {
            setChildrenStarted((PreferenceGroup) pref, started);
        }
    }
}
 
Example 2
Project: keepass2android   File: InputLanguageSelection.java   View source code 6 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
 
Example 3
Project: order-by-android   File: SettingsActivity.java   View source code 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    //Atribui os valores selecionados
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }
}
 
Example 4
Project: order-by-android   File: SettingsActivity.java   View source code 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    //Atribui os valores selecionados
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }
}
 
Example 5
Project: IO_Classic_WatchFace   File: SettingsFragment.java   View source code 6 votes vote down vote up
/**
 * Gets the list of preferences in a PreferenceScreen
 *
 * @param p    preference to add to the list
 * @param list of preferences in the PreferenceScreen
 * @return a list of all the preferences
 */
private ArrayList<Preference> getPreferenceList(Preference p, ArrayList<Preference> list) {
    if (p instanceof PreferenceCategory || p instanceof PreferenceScreen) {
        PreferenceGroup prefGroup = (PreferenceGroup) p;

        final int prefCount = prefGroup.getPreferenceCount();

        for (int i = 0; i < prefCount; i++) {
            getPreferenceList(prefGroup.getPreference(i), list);
        }
    }

    if (!(p instanceof PreferenceCategory)) {
        list.add(p);
    }

    return list;
}
 
Example 6
Project: simple-keyboard   File: CustomInputStyleSettingsFragment.java   View source code 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
Project: simple-keyboard   File: CustomInputStyleSettingsFragment.java   View source code 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 8
Project: simple-keyboard   File: TwoStatePreferenceHelper.java   View source code 6 votes vote down vote up
private static void replaceAllCheckBoxPreferencesBySwitchPreferences(
        final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference)preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup)preference);
            }
        }
    }
}
 
Example 9
Project: chromium-for-android-56-debug-video   File: AutofillPreferences.java   View source code 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 10
Project: chromium-for-android-56-debug-video   File: AutofillPreferences.java   View source code 6 votes vote down vote up
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 11
Project: AOSP-Kayboard-7.1.2   File: UserDictionaryList.java   View source code 6 votes vote down vote up
/**
 * Creates the entries that allow the user to go into the user dictionary for each locale.
 * @param userDictGroup The group to put the settings in.
 */
protected void createUserDictSettings(final PreferenceGroup userDictGroup) {
    final Activity activity = getActivity();
    userDictGroup.removeAll();
    final TreeSet<String> localeSet =
            UserDictionaryList.getUserDictionaryLocalesSet(activity);

    if (localeSet.size() > 1) {
        // Have an "All languages" entry in the languages list if there are two or more active
        // languages
        localeSet.add("");
    }

    if (localeSet.isEmpty()) {
        userDictGroup.addPreference(createUserDictionaryPreference(null));
    } else {
        for (String locale : localeSet) {
            userDictGroup.addPreference(createUserDictionaryPreference(locale));
        }
    }
}
 
Example 12
Project: AOSP-Kayboard-7.1.2   File: CustomInputStyleSettingsFragment.java   View source code 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 13
Project: AOSP-Kayboard-7.1.2   File: CustomInputStyleSettingsFragment.java   View source code 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 14
Project: AOSP-Kayboard-7.1.2   File: TwoStatePreferenceHelper.java   View source code 6 votes vote down vote up
private static void replaceAllCheckBoxPreferencesBySwitchPreferences(
        final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference)preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup)preference);
            }
        }
    }
}
 
Example 15
Project: AOSP-Kayboard-7.1.2   File: TwoStatePreferenceHelper.java   View source code 6 votes vote down vote up
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
        final PreferenceGroup group) {
    final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
    switchPref.setTitle(checkBox.getTitle());
    switchPref.setKey(checkBox.getKey());
    switchPref.setOrder(checkBox.getOrder());
    switchPref.setPersistent(checkBox.isPersistent());
    switchPref.setEnabled(checkBox.isEnabled());
    switchPref.setChecked(checkBox.isChecked());
    switchPref.setSummary(checkBox.getSummary());
    switchPref.setSummaryOn(checkBox.getSummaryOn());
    switchPref.setSummaryOff(checkBox.getSummaryOff());
    switchPref.setSwitchTextOn(EMPTY_TEXT);
    switchPref.setSwitchTextOff(EMPTY_TEXT);
    group.addPreference(switchPref);
    switchPref.setDependency(checkBox.getDependency());
}
 
Example 16
Project: AOSP-Kayboard-7.1.2   File: DictionarySettingsFragment.java   View source code 6 votes vote down vote up
private WordListPreference findWordListPreference(final String id) {
    final PreferenceGroup prefScreen = getPreferenceScreen();
    if (null == prefScreen) {
        Log.e(TAG, "Could not find the preference group");
        return null;
    }
    for (int i = prefScreen.getPreferenceCount() - 1; i >= 0; --i) {
        final Preference pref = prefScreen.getPreference(i);
        if (pref instanceof WordListPreference) {
            final WordListPreference wlPref = (WordListPreference)pref;
            if (id.equals(wlPref.mWordlistId)) {
                return wlPref;
            }
        }
    }
    Log.e(TAG, "Could not find the preference for a word list id " + id);
    return null;
}
 
Example 17
Project: AOSP-Kayboard-7.1.2   File: DictionarySettingsFragment.java   View source code 6 votes vote down vote up
void refreshInterface() {
    final Activity activity = getActivity();
    if (null == activity) return;
    final PreferenceGroup prefScreen = getPreferenceScreen();
    final Collection<? extends Preference> prefList =
            createInstalledDictSettingsCollection(mClientId);

    activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // TODO: display this somewhere
                // if (0 != lastUpdate) mUpdateNowPreference.setSummary(updateNowSummary);
                refreshNetworkState();

                removeAnyDictSettings(prefScreen);
                int i = 0;
                for (Preference preference : prefList) {
                    preference.setOrder(i++);
                    prefScreen.addPreference(preference);
                }
            }
        });
}
 
Example 18
Project: KeePass2Android   File: InputLanguageSelection.java   View source code 6 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
 
Example 19
Project: MaoMaoRobot   File: Setting.java   View source code 6 votes vote down vote up
private void bind(PreferenceGroup group) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    for (int i = 0; i < group.getPreferenceCount(); i++) {
        Preference p = group.getPreference(i);
        if (p instanceof PreferenceGroup) {
            bind((PreferenceGroup) p);
        } else {
            if (p instanceof CheckBoxPreference) {
                ;
            } else {
                Object val = sp.getAll().get(p.getKey());
                p.setSummary(val == null ? "" : ("" + val));
                p.setOnPreferenceChangeListener(this);
            }
        }
    }
}
 
Example 20
Project: haystack   File: DevelopmentSettings.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 21
Project: AndroidChromium   File: AutofillPreferences.java   View source code 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 22
Project: AndroidChromium   File: AutofillPreferences.java   View source code 6 votes vote down vote up
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 23
Project: Run-With-You   File: SettingPreferenceFragment.java   View source code 6 votes vote down vote up
private void initPreferences() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        ((PreferenceGroup) findPreference(getString(R.string.pref_category_memory_resident))).removePreference(
                findPreference(getString(R.string.pref_memory_resident_white_list)));
    }

    Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e.onNext(mSettingRepository.getTargetStep());
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Integer>() {
        @Override
        public void accept(Integer target) throws Exception {
            findPreference(getString(R.string.pref_target_step)).setSummary(String.format(Locale.getDefault(),
                                                                                          "每日运动目标:%d步",
                                                                                          target));
        }
    });
}
 
Example 24
Project: instalist-android   File: SettingsFragment.java   View source code 6 votes vote down vote up
public void onEvent(final PluginFoundMessage _msg) {
    if (mInflater == null || mViewContainer == null) {
        Log.e(LOG_TAG, "onEvent: Faster than light, onCreateView was not called yet.");
        return;
    }

    PreferenceGroup preferenceGroup = new PreferenceCategory(mViewContainer.getContext());
    preferenceGroup.setTitle(_msg.mName);


    View prefView = preferenceGroup.getView(null, mViewContainer);
    /*prefView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), _msg.mSettingsActivity);
            startActivity(intent);
        }
    });*/
    ViewGroup viewGroup = (ViewGroup) mViewContainer.getChildAt(0);
    viewGroup.addView(prefView, viewGroup.getChildCount());

}
 
Example 25
Project: Hupl   File: GlobalSettingsActivity.java   View source code 6 votes vote down vote up
private List<Preference> getPreferenceList(Preference p, List<Preference> list)
{
    if (p instanceof PreferenceCategory || p instanceof PreferenceScreen)
    {
        PreferenceGroup g = (PreferenceGroup) p;
        int pCount = g.getPreferenceCount();
        for (int i = 0; i < pCount; i++)
        {
            getPreferenceList(g.getPreference(i), list);
        }
    }
    else
    {
        list.add(p);
    }
    return list;
}
 
Example 26
Project: Vafrinn   File: AutofillPreferences.java   View source code 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfiles()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 27
Project: Vafrinn   File: AutofillPreferences.java   View source code 6 votes vote down vote up
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCards()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillCreditCardEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerCardPreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 28
Project: hackerskeyboard   File: InputLanguageSelection.java   View source code 6 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
 
Example 29
Project: hackerskeyboard   File: LatinIMESettings.java   View source code 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    int autoTextSize = AutoText.getSize(getListView());
    if (autoTextSize < 1) {
        ((PreferenceGroup) findPreference(PREDICTION_SETTINGS_KEY))
                .removePreference(mQuickFixes);
    }
    
    Log.i(TAG, "compactModeEnabled=" + LatinIME.sKeyboardSettings.compactModeEnabled);
    if (!LatinIME.sKeyboardSettings.compactModeEnabled) {
        CharSequence[] oldEntries = mKeyboardModePortraitPreference.getEntries();
        CharSequence[] oldValues = mKeyboardModePortraitPreference.getEntryValues();
        
        if (oldEntries.length > 2) {
            CharSequence[] newEntries = new CharSequence[] { oldEntries[0], oldEntries[2] };
            CharSequence[] newValues = new CharSequence[] { oldValues[0], oldValues[2] };
            mKeyboardModePortraitPreference.setEntries(newEntries);
            mKeyboardModePortraitPreference.setEntryValues(newValues);
            mKeyboardModeLandscapePreference.setEntries(newEntries);
            mKeyboardModeLandscapePreference.setEntryValues(newValues);
        }
    }
    
    updateSummaries();
}
 
Example 30
Project: AndroidPreferenceActivity   File: PreferenceFragment.java   View source code 6 votes vote down vote up
/**
 * Restores the default preferences, which are contained by a specific preference group.
 *
 * @param preferenceGroup
 *         The preference group, whose preferences should be restored, as an instance of the
 *         class {@link PreferenceGroup}. The preference group may not be null
 * @param sharedPreferences
 *         The shared preferences, which should be used to restore the preferences, as an
 *         instance of the type {@link SharedPreferences}. The shared preferences may not be
 *         null
 */
private void restoreDefaults(@NonNull final PreferenceGroup preferenceGroup,
                             @NonNull final SharedPreferences sharedPreferences) {
    for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
        Preference preference = preferenceGroup.getPreference(i);

        if (preference instanceof PreferenceGroup) {
            restoreDefaults((PreferenceGroup) preference, sharedPreferences);
        } else if (preference.getKey() != null && !preference.getKey().isEmpty()) {
            Object oldValue = sharedPreferences.getAll().get(preference.getKey());

            if (notifyOnRestoreDefaultValueRequested(preference, oldValue)) {
                sharedPreferences.edit().remove(preference.getKey()).apply();
                preferenceGroup.removePreference(preference);
                preferenceGroup.addPreference(preference);
                Object newValue = sharedPreferences.getAll().get(preference.getKey());
                notifyOnRestoredDefaultValue(preference, oldValue, newValue);
            } else {
                preferenceGroup.removePreference(preference);
                preferenceGroup.addPreference(preference);
            }

        }
    }
}
 
Example 31
Project: latex-it   File: SettingsFragment.java   View source code 6 votes vote down vote up
/**
 * On resume it update every settings.
 */
@Override
public void onResume() {
    super.onResume();
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }

}
 
Example 32
Project: android-nmea-logger   File: SettingsActivity.java   View source code 6 votes vote down vote up
private void hideAdvancedPreferences(PreferenceGroup group) {
    if(mAdvancedSettings.showAll()) {
        return;
    }

    int c = 0;
    while(c < group.getPreferenceCount()) {
        Preference pref = group.getPreference(c);
        if(!mAdvancedSettings.isVisible(group, pref)) {
            group.removePreference(pref);
        } else {
            if(pref instanceof PreferenceGroup) {
                hideAdvancedPreferences((PreferenceGroup)pref);
            }
            c++;
        }
    }
}
 
Example 33
Project: RBTV-Sendeplan   File: SettingsFragment.java   View source code 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();

    // Register self als listener for changes
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);

    // Set initial summary state
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        Preference preference = getPreferenceScreen().getPreference(i);

        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); j++) {
                updatePreferenceSummary(sharedPreferences, preferenceGroup.getPreference(j));
            }
        } else {
            updatePreferenceSummary(sharedPreferences, preference);
        }
    }
}
 
Example 34
Project: Camera2   File: CameraSettingsActivity.java   View source code 6 votes vote down vote up
/**
 * Depending on camera availability on the device, this removes settings
 * for cameras the device doesn't have.
 */
private void setVisibilities() {
    PreferenceGroup resolutions =
            (PreferenceGroup) findPreference(PREF_CATEGORY_RESOLUTION);
    if (mPictureSizesBack == null) {
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_PICTURE_SIZE_BACK));
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_VIDEO_QUALITY_BACK));
    }
    if (mPictureSizesFront == null) {
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_PICTURE_SIZE_FRONT));
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_VIDEO_QUALITY_FRONT));
    }
}
 
Example 35
Project: Camera2   File: CameraSettingsActivity.java   View source code 6 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 36
Project: talkback   File: TalkBackPreferencesActivity.java   View source code 6 votes vote down vote up
private void assignPlayStoreIntentToPreference(int preferenceId, String url) {
    final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
            R.string.pref_category_miscellaneous_key);
    final Preference pref = findPreferenceByResId(preferenceId);
    if (pref == null) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    if (!canHandleIntent(intent)) {
        category.removePreference(pref);
        return;
    }

    pref.setIntent(intent);
}
 
Example 37
Project: talkback   File: TalkBackPreferencesActivity.java   View source code 6 votes vote down vote up
/**
 * Assigns the intent to open text-to-speech settings.
 */
private void assignTtsSettingsIntent() {
    PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
        R.string.pref_category_when_to_speak_key);
    Preference ttsSettingsPreference =
            findPreferenceByResId(R.string.pref_tts_settings_key);

    if (category == null || ttsSettingsPreference == null) {
        return;
    }

    Intent ttsSettingsIntent = new Intent(TalkBackService.INTENT_TTS_SETTINGS);
    ttsSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (!canHandleIntent(ttsSettingsIntent)) {
        // Need to remove preference item if no TTS Settings intent filter in settings app.
        category.removePreference(ttsSettingsPreference);
    }

    ttsSettingsPreference.setIntent(ttsSettingsIntent);
}
 
Example 38
Project: talkback   File: TalkBackPreferencesActivity.java   View source code 6 votes vote down vote up
/**
 * Assigns the appropriate intent to the tutorial preference.
 */
private void assignTutorialIntent() {
    final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
            R.string.pref_category_miscellaneous_key);
    final Preference prefTutorial = findPreferenceByResId(R.string.pref_tutorial_key);

    if ((category == null) || (prefTutorial == null)) {
        return;
    }

    final int touchscreenState = getResources().getConfiguration().touchscreen;
    if (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) {
        category.removePreference(prefTutorial);
        return;
    }

    Activity activity = getActivity();
    if (activity != null) {
        final Intent tutorialIntent = new Intent(
                activity, AccessibilityTutorialActivity.class);
        tutorialIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        tutorialIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        prefTutorial.setIntent(tutorialIntent);
    }
}
 
Example 39
Project: talkback   File: TalkBackPreferencesActivity.java   View source code 6 votes vote down vote up
/**
 * Assigns the appropriate intent to the label manager preference.
 */
private void assignLabelManagerIntent() {
    final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
            R.string.pref_category_touch_exploration_key);
    final Preference prefManageLabels = findPreferenceByResId(
            R.string.pref_manage_labels_key);

    if ((category == null) || (prefManageLabels == null)) {
        return;
    }

    if (Build.VERSION.SDK_INT < LabelManagerSummaryActivity.MIN_API_LEVEL) {
        category.removePreference(prefManageLabels);
        return;
    }

    Activity activity = getActivity();
    if (activity != null) {
        final Intent labelManagerIntent = new Intent(
                activity, LabelManagerSummaryActivity.class);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        prefManageLabels.setIntent(labelManagerIntent);
    }
}
 
Example 40
Project: talkback   File: TalkBackPreferencesActivity.java   View source code 6 votes vote down vote up
/**
 * Assigns the appropriate intent to the keyboard shortcut preference.
 */
private void assignKeyboardShortcutIntent() {
    final PreferenceGroup category =
            (PreferenceGroup) findPreferenceByResId(
                    R.string.pref_category_miscellaneous_key);
    final Preference keyboardShortcutPref = findPreferenceByResId(
            R.string.pref_category_manage_keyboard_shortcut_key);

    if ((category == null) || (keyboardShortcutPref == null)) {
        return;
    }

    if (Build.VERSION.SDK_INT < KeyComboManager.MIN_API_LEVEL) {
        category.removePreference(keyboardShortcutPref);
        return;
    }

    Activity activity = getActivity();
    if (activity != null) {
        final Intent labelManagerIntent = new Intent(activity,
                TalkBackKeyboardShortcutPreferencesActivity.class);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        keyboardShortcutPref.setIntent(labelManagerIntent);
    }
}