Example usage for android.preference Preference setEnabled

List of usage examples for android.preference Preference setEnabled

Introduction

In this page you can find the example usage for android.preference Preference setEnabled.

Prototype

public void setEnabled(boolean enabled) 

Source Link

Document

Sets whether this Preference is enabled.

Usage

From source file:paulscode.android.mupen64plusae.util.PrefUtil.java

@SuppressWarnings("deprecation")
public static void enablePreference(PreferenceActivity activity, String key, boolean enabled) {
    Preference preference = activity.findPreference(key);
    if (preference != null)
        preference.setEnabled(enabled);
}

From source file:com.battlelancer.seriesguide.ui.SeriesGuidePreferences.java

protected static void setupSharingSettings(final Context context, Preference traktAutoAddPref,
        Preference getGluePref) {//ww w .ja  v  a2  s  . c om
    if (HexagonTools.isSignedIn(context)) {
        traktAutoAddPref.setEnabled(false);
        traktAutoAddPref.setSummary(R.string.hexagon_warning_trakt);
    }
    // Disconnect GetGlue
    getGluePref.setEnabled(GetGlueSettings.isAuthenticated(context));
    getGluePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            fireTrackerEvent(context, "Disonnect GetGlue");

            GetGlueSettings.clearTokens(context);
            preference.setEnabled(false);
            return true;
        }
    });
}

From source file:dentex.youtube.downloader.YTD.java

public static void updateInit(Activity act, boolean intoSettings, Preference up) {
    int prefSig = settings.getInt("APP_SIGNATURE", 0);
    Utils.logger("d", "prefSig: " + prefSig, DEBUG_TAG);

    if (prefSig == 0) {
        int currentHash = Utils.getSigHash(act);
        if (currentHash == SIG_HASH) {
            Utils.logger("d", "Found YTD signature: update check possile", DEBUG_TAG);
            if (intoSettings)
                up.setEnabled(true);

            if (settings.getBoolean("autoupdate", false)) {
                Utils.logger("i", "autoupdate enabled", DEBUG_TAG);
                autoUpdate();//from   w ww  .jav  a  2 s. co m
            }
        } else {
            Utils.logger("d",
                    "Found different signature: " + currentHash + " (F-Droid?). Update check cancelled.",
                    DEBUG_TAG);
            if (intoSettings) {
                up.setEnabled(false);
                up.setSummary(R.string.update_disabled_summary);
            }
        }
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("APP_SIGNATURE", currentHash);
        if (editor.commit())
            Utils.logger("d", "saving sig pref...", DEBUG_TAG);
    } else {
        if (prefSig == SIG_HASH) {
            Utils.logger("d", "YTD signature in PREFS: update check possile", DEBUG_TAG);
            if (intoSettings)
                up.setEnabled(true);

            if (settings.getBoolean("autoupdate", false)) {
                Utils.logger("i", "autoupdate enabled", DEBUG_TAG);
                autoUpdate();
            }
        } else {
            Utils.logger("d", "diffrent YTD signature in prefs (F-Droid?). Update check cancelled.", DEBUG_TAG);
            if (intoSettings)
                up.setEnabled(false);
        }
    }
}

From source file:com.oakesville.mythling.prefs.PlaybackPrefs.java

private void doCategoryEnablement(boolean isDevice) {
    Preference deviceCatVid = getPreferenceScreen().findPreference(AppSettings.DEVICE_PLAYBACK_CATEGORY_VIDEO);
    deviceCatVid.setEnabled(isDevice);
    Preference deviceCatMus = getPreferenceScreen().findPreference(AppSettings.DEVICE_PLAYBACK_CATEGORY_MUSIC);
    deviceCatMus.setEnabled(isDevice);//from   www.j  a v  a  2s. co m

    Preference frontendCat = getPreferenceScreen().findPreference(AppSettings.FRONTEND_PLAYBACK_CATEGORY);
    frontendCat.setEnabled(!isDevice);
}

From source file:com.battlelancer.seriesguide.ui.SeriesGuidePreferences.java

protected static void setupNotifiationSettings(final Context context, Preference notificationsPref,
        final Preference notificationsFavOnlyPref, final Preference vibratePref, final Preference ringtonePref,
        final Preference notificationsThresholdPref) {
    // allow supporters to enable notifications
    if (Utils.hasAccessToX(context)) {
        notificationsPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override/*w  ww.j a  v  a2s . c o  m*/
            public boolean onPreferenceClick(Preference preference) {
                boolean isChecked = ((CheckBoxPreference) preference).isChecked();
                if (isChecked) {
                    Utils.trackCustomEvent(context, TAG, "Notifications", "Enable");
                } else {
                    Utils.trackCustomEvent(context, TAG, "Notifications", "Disable");
                }

                notificationsThresholdPref.setEnabled(isChecked);
                notificationsFavOnlyPref.setEnabled(isChecked);
                vibratePref.setEnabled(isChecked);
                ringtonePref.setEnabled(isChecked);

                Utils.runNotificationService(context);
                return true;
            }
        });
        notificationsFavOnlyPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                resetAndRunNotificationsService(context);
                return true;
            }
        });
        // disable advanced notification settings if notifications are disabled
        boolean isNotificationsEnabled = NotificationSettings.isNotificationsEnabled(context);
        notificationsThresholdPref.setEnabled(isNotificationsEnabled);
        notificationsFavOnlyPref.setEnabled(isNotificationsEnabled);
        vibratePref.setEnabled(isNotificationsEnabled);
        ringtonePref.setEnabled(isNotificationsEnabled);
    } else {
        notificationsPref.setOnPreferenceChangeListener(sNoOpChangeListener);
        ((CheckBoxPreference) notificationsPref).setChecked(false);
        notificationsPref.setSummary(R.string.onlyx);
        notificationsThresholdPref.setEnabled(false);
        notificationsFavOnlyPref.setEnabled(false);
        vibratePref.setEnabled(false);
        ringtonePref.setEnabled(false);
    }

    setListPreferenceSummary((ListPreference) notificationsThresholdPref);
}

From source file:com.ovrhere.android.careerstack.ui.fragments.SettingsFragment.java

/** Prepares tablet mode; enabling or hiding based on size support. */
private void prepareTabletMode() {
    final String key = getString(R.string.careerstack_pref_KEY_USE_TABLET_LAYOUT);
    final boolean hasTabletMode = getResources().getBoolean(R.bool.careerstack_has_tablet_mode);

    if (!hasTabletMode) {
        //if not supported, remove preference.
        Preference prefTabletMode = getPreferenceManager().findPreference(key);
        prefTabletMode.setEnabled(false);
        getPreferenceScreen().removePreference(prefTabletMode);
    }/*w ww .  j a v a  2s . com*/
}

From source file:com.fhhst.prodroid.gui.SettingsActivity.java

/**
 * Shows the simplified settings UI if the device configuration if the
 * device configuration dictates that a simplified, single-pane UI should be
 * shown./*w ww .  java2s  .c  om*/
 */
@SuppressWarnings("deprecation")
private void setupSimplePreferencesScreen() {
    if (!isSimplePreferences(this)) {
        return;
    }

    // In the simplified UI, fragments are not used at all and we instead
    // use the older PreferenceActivity APIs.

    // Add 'printer' preferences.

    addPreferencesFromResource(R.xml.pref_printer);
    if (getPreferenceScreen() != null) {

        // Add 'notifications' preferences, and a corresponding header.
        PreferenceCategory fakeHeader1 = new PreferenceCategory(this);
        fakeHeader1.setTitle(R.string.pref_header_communication);
        getPreferenceScreen().addPreference(fakeHeader1);
        addPreferencesFromResource(R.xml.pref_communication);

        // Bind the summaries of EditText/List/Dialog/Ringtone preferences to
        // their values. When their values change, their summaries are updated
        // to reflect the new value, per the Android Design guidelines.
        bindPreferenceSummaryToValue(findPreference("pref_comm_baudrateselect"));
        bindPreferenceSummaryToValue(findPreference("pref_comm_databitsselect"));
        bindPreferenceSummaryToValue(findPreference("pref_comm_stopbitsselect"));
        bindPreferenceSummaryToValue(findPreference("pref_comm_paritybitselect"));
        bindPreferenceSummaryToValue(findPreference("pref_comm_webserver_port"));

        bindPreferenceSummaryToValue(findPreference("pref_print_xyfeedrate"));
        bindPreferenceSummaryToValue(findPreference("pref_print_zfeedrate"));
        bindPreferenceSummaryToValue(findPreference("pref_print_efeedrate"));

        Preference button = (Preference) findPreference("pref_comm_dropbx");
        button.setEnabled(false);

    }

}

From source file:net.imatruck.betterweather.settings.BetterWeatherSettingsActivity.java

private void updateShortcutPreferenceState(String key) {
    Preference pref = findPreference(key);
    if (pref instanceof CheckBoxPreference) {
        CheckBoxPreference refreshOnTouchPref = (CheckBoxPreference) pref;

        Preference shortcutPref = findPreference(BetterWeatherExtension.PREF_WEATHER_SHORTCUT);

        if (shortcutPref == null)
            return;

        if (refreshOnTouchPref.isChecked()) {
            shortcutPref.setEnabled(false);
            shortcutPref.setSummary(R.string.shortcut_pref_help_text);
        } else {/*w  w  w .ja  va 2 s  .co  m*/
            shortcutPref.setEnabled(true);
            bindPreferenceSummaryToValue(findPreference(BetterWeatherExtension.PREF_WEATHER_SHORTCUT));
        }
    }
}

From source file:com.syncedsynapse.kore2.ui.SettingsFragment.java

/**
 * Check if the user has bought coffee and locks/unlocks the ui
 */// ww w.j  a  v a2s  .co m
private void checkCoffeeUpgradeAsync() {
    mBillingHelper = new IabHelper(this.getActivity(), BuildConfig.IAP_KEY);
    mBillingHelper.enableDebugLogging(BuildConfig.DEBUG);

    final Context context = this.getActivity();

    mBillingHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Toast.makeText(context,
                        getResources().getString(R.string.error_setting_up_billing, result.getMessage()),
                        Toast.LENGTH_SHORT).show();

                // Lock UI
                mSettings.hasBoughtCoffee = false;
                setupPreferences(mSettings.hasBoughtCoffee);
                mSettings.save();

                // Lock upgrade preference
                Preference coffeePreference = findPreference(Settings.KEY_PREF_COFFEE);
                coffeePreference.setEnabled(false);
                coffeePreference.setSummary(
                        getResources().getString(R.string.error_setting_up_billing, result.getMessage()));

                LogUtils.LOGD(TAG, "Problem setting up In-app Billing: " + result);
                mBillingHelper.dispose();
                mBillingHelper = null;
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mBillingHelper == null)
                return;

            // IAB is fully set up. Query purchased items
            mBillingHelper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {
                @Override
                public void onQueryInventoryFinished(IabResult result, Inventory inv) {
                    // Have we been disposed of in the meantime? If so, quit.
                    if (mBillingHelper == null)
                        return;

                    if (result.isFailure()) {
                        LogUtils.LOGD(TAG, "Failed to query inventory. Result: " + result);
                        return;
                    }

                    Purchase upgradePurchase = inv.getPurchase(COFFEE_SKU);
                    if (upgradePurchase != null)
                        LogUtils.LOGD(TAG, "Purchase " + upgradePurchase.toString());
                    //boolean hasUpgrade = (upgradePurchase != null && verifyDeveloperPayload(upgradePurchase));
                    boolean hasUpgrade = inv.hasPurchase(COFFEE_SKU);
                    LogUtils.LOGD(TAG, "Has purchase " + String.valueOf(hasUpgrade));

                    // update UI accordingly
                    mSettings.hasBoughtCoffee = hasUpgrade;
                    if (isAdded())
                        setupPreferences(mSettings.hasBoughtCoffee);
                    mSettings.save();
                }
            });
        }
    });
}

From source file:se.bitcraze.crazyfliecontrol.PreferencesActivity.java

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(KEY_PREF_RADIO_CHANNEL)) {
        setSummaryInt(key, radioChannelDefaultValue, RADIOCHANNEL_UPPER_LIMIT, "Radio channel");
    }/*w  w  w .  j  a  va 2s.  com*/
    if (key.equals(KEY_PREF_RADIO_DATARATE)) {
        Preference radioDataratePref = findPreference(key);
        String[] stringArray = getResources().getStringArray(R.array.radioDatarateEntries);
        String keyString = sharedPreferences.getString(key, "");
        radioDataratePref.setSummary(stringArray[Integer.parseInt(keyString)]);
    }
    if (key.equals(KEY_PREF_MODE)) {
        Preference modePref = findPreference(key);
        modePref.setSummary(sharedPreferences.getString(key, modeDefaultValue));
    }
    if (key.equals(KEY_PREF_DEADZONE)) {
        Preference deadzonePref = findPreference(key);
        try {
            float deadzone = Float.parseFloat(sharedPreferences.getString(key, deadzoneDefaultValue));
            if (deadzone < 0.0 || deadzone > DEADZONE_UPPER_LIMIT) {
                resetPreference(key, deadzoneDefaultValue,
                        "Deadzone must be a float value between 0.0 and " + DEADZONE_UPPER_LIMIT + ".");
            }
        } catch (NumberFormatException nfe) {
            resetPreference(key, deadzoneDefaultValue,
                    "Deadzone must be a float value between 0.0 and " + DEADZONE_UPPER_LIMIT + ".");
        }
        deadzonePref.setSummary(sharedPreferences.getString(key, ""));
    }

    if (key.equals(KEY_PREF_RIGHT_ANALOG_X_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rightAnalogXAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_RIGHT_ANALOG_Y_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rightAnalogYAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_LEFT_ANALOG_X_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, leftAnalogXAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_LEFT_ANALOG_Y_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, leftAnalogYAxisDefaultValue));
    }

    if (key.equals(KEY_PREF_SPLITAXIS_YAW_BOOL)) {
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
        pref.setChecked(sharedPreferences.getBoolean(key, false));
        findPreference(KEY_PREF_SPLITAXIS_YAW_LEFT_AXIS).setEnabled(sharedPreferences.getBoolean(key, false));
        findPreference(KEY_PREF_SPLITAXIS_YAW_RIGHT_AXIS).setEnabled(sharedPreferences.getBoolean(key, false));
    }

    if (key.equals(KEY_PREF_SPLITAXIS_YAW_LEFT_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, splitAxisLeftAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_SPLITAXIS_YAW_RIGHT_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, splitAxisRightAxisDefaultValue));
    }

    if (key.equals(KEY_PREF_ROLLTRIM) || key.equals(KEY_PREF_PITCHTRIM)) {
        Preference trimPref = findPreference(key);
        try {
            float trim = Float.parseFloat(sharedPreferences.getString(key, trimDefaultValue));
            if (Math.abs(trim) < 0.0 || Math.abs(trim) > TRIM_UPPER_LIMIT) {
                resetPreference(key, trimDefaultValue,
                        "Roll/Pitch trim must be a float value between 0.0 and " + TRIM_UPPER_LIMIT + ".");
            }
        } catch (NumberFormatException nfe) {
            resetPreference(key, trimDefaultValue,
                    "Roll/Pitch trim must be a float value between 0.0 and " + TRIM_UPPER_LIMIT + ".");
        }
        trimPref.setSummary(sharedPreferences.getString(key, ""));
    }
    if (key.equals(KEY_PREF_EMERGENCY_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, emergencyBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_ROLLTRIM_PLUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rollTrimPlusBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_ROLLTRIM_MINUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rollTrimMinusBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_PITCHTRIM_PLUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, pitchTrimPlusBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_PITCHTRIM_MINUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, pitchTrimMinusBtnDefaultValue));
    }

    if (key.equals(KEY_PREF_AFC_BOOL)) {
        Preference afcScreenPref = findPreference(KEY_PREF_AFC_SCREEN);
        afcScreenPref.setEnabled(sharedPreferences.getBoolean(key, false));
        if (!sharedPreferences.getBoolean(key, false)) {
            Toast.makeText(this,
                    "Resetting to default values:\n" + "Max roll/pitch angle: " + maxRollPitchAngleDefaultValue
                            + "\n" + "Max yaw angle: " + maxYawAngleDefaultValue + "\n" + "Max thrust: "
                            + maxThrustDefaultValue + "\n" + "Min thrust: " + minThrustDefaultValue,
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "You have been warned!", Toast.LENGTH_LONG).show();
        }
    }
    if (key.equals(KEY_PREF_MAX_ROLLPITCH_ANGLE)) {
        setSummaryInt(key, maxRollPitchAngleDefaultValue, MAX_ROLLPITCH_ANGLE_UPPER_LIMIT,
                "Max roll/pitch angle");
    }
    if (key.equals(KEY_PREF_MAX_YAW_ANGLE)) {
        setSummaryInt(key, maxYawAngleDefaultValue, MAX_YAW_ANGLE_UPPER_LIMIT, "Max yaw angle");
    }
    if (key.equals(KEY_PREF_MAX_THRUST)) {
        setSummaryInt(key, maxThrustDefaultValue, MAX_THRUST_UPPER_LIMIT, "Max thrust");
    }
    if (key.equals(KEY_PREF_MIN_THRUST)) {
        setSummaryInt(key, minThrustDefaultValue, MIN_THRUST_UPPER_LIMIT, "Min thrust");
    }
    if (key.equals(KEY_PREF_XMODE)) {
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
        pref.setChecked(sharedPreferences.getBoolean(key, false));
    }

    if (key.equals(KEY_PREF_SCREEN_ROTATION_LOCK_BOOL)) {
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
        pref.setChecked(sharedPreferences.getBoolean(key, false));
    }
}