Search in sources :

Example 1 with OnPreferenceClickListener

use of android.support.v7.preference.Preference.OnPreferenceClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FingerprintSettings method getFingerprintPreferenceForUser.

public static Preference getFingerprintPreferenceForUser(Context context, final int userId) {
    FingerprintManager fpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    if (fpm == null || !fpm.isHardwareDetected()) {
        Log.v(TAG, "No fingerprint hardware detected!!");
        return null;
    }
    Preference fingerprintPreference = new Preference(context);
    fingerprintPreference.setKey(KEY_FINGERPRINT_SETTINGS);
    fingerprintPreference.setTitle(R.string.security_settings_fingerprint_preference_title);
    final List<Fingerprint> items = fpm.getEnrolledFingerprints(userId);
    final int fingerprintCount = items != null ? items.size() : 0;
    final String clazz;
    if (fingerprintCount > 0) {
        fingerprintPreference.setSummary(context.getResources().getQuantityString(R.plurals.security_settings_fingerprint_preference_summary, fingerprintCount, fingerprintCount));
        clazz = FingerprintSettings.class.getName();
    } else {
        fingerprintPreference.setSummary(R.string.security_settings_fingerprint_preference_summary_none);
        clazz = FingerprintEnrollIntroduction.class.getName();
    }
    fingerprintPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            final Context context = preference.getContext();
            final UserManager userManager = UserManager.get(context);
            if (Utils.startQuietModeDialogIfNecessary(context, userManager, userId)) {
                return false;
            }
            Intent intent = new Intent();
            intent.setClassName("com.android.settings", clazz);
            intent.putExtra(Intent.EXTRA_USER_ID, userId);
            context.startActivity(intent);
            return true;
        }
    });
    return fingerprintPreference;
}
Also used : Context(android.content.Context) Fingerprint(android.hardware.fingerprint.Fingerprint) Intent(android.content.Intent) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Fingerprint(android.hardware.fingerprint.Fingerprint) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) Preference(android.support.v7.preference.Preference) FingerprintManager(android.hardware.fingerprint.FingerprintManager) UserManager(android.os.UserManager)

Example 2 with OnPreferenceClickListener

use of android.support.v7.preference.Preference.OnPreferenceClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PowerUsageDetail method addControl.

private void addControl(int pageSummary, int actionTitle, final int action) {
    Preference pref = new Preference(getPrefContext());
    pref.setTitle(actionTitle);
    pref.setLayoutResource(R.layout.horizontal_preference);
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            doAction(action);
            return true;
        }
    });
    mControlsParent.addPreference(pref);
}
Also used : OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) LayoutPreference(com.android.settings.applications.LayoutPreference) Preference(android.support.v7.preference.Preference)

Example 3 with OnPreferenceClickListener

use of android.support.v7.preference.Preference.OnPreferenceClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AdvancedWifiSettings method initPreferences.

private void initPreferences() {
    final Context context = getActivity();
    Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
    intent.setClassName("com.android.certinstaller", "com.android.certinstaller.CertInstallerMain");
    intent.putExtra(Credentials.EXTRA_INSTALL_AS_UID, android.os.Process.WIFI_UID);
    Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
    pref.setIntent(intent);
    SwitchPreference enableHs2 = (SwitchPreference) findPreference(KEY_ENABLE_HS2);
    if (enableHs2 != null && getResources().getBoolean(com.android.internal.R.bool.config_passpoint_setting_on)) {
        enableHs2.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                String key = preference.getKey();
                if (KEY_ENABLE_HS2.equals(key)) {
                    Settings.Global.putInt(getContentResolver(), Settings.Global.WIFI_HOTSPOT2_ENABLED, ((SwitchPreference) preference).isChecked() ? 1 : 0);
                }
                return true;
            }
        });
        enableHs2.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_HOTSPOT2_ENABLED, WIFI_HS2_DISABLED) == WIFI_HS2_ENABLED);
    } else {
        if (enableHs2 != null) {
            getPreferenceScreen().removePreference(enableHs2);
        }
    }
    Intent wifiDirectIntent = new Intent(context, com.android.settings.Settings.WifiP2pSettingsActivity.class);
    Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
    wifiDirectPref.setIntent(wifiDirectIntent);
    // WpsDialog: Create the dialog like WifiSettings does.
    Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
    wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
            wpsFragment.show(getFragmentManager(), KEY_WPS_PUSH);
            return true;
        }
    });
    // WpsDialog: Create the dialog like WifiSettings does.
    Preference wpsPinPref = findPreference(KEY_WPS_PIN);
    wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
            wpsFragment.show(getFragmentManager(), KEY_WPS_PIN);
            return true;
        }
    });
    // Wifi extension requirement
    Preference prioritySettingPref = findPreference(KEY_PRIORITY_SETTINGS);
    if (prioritySettingPref != null) {
        if (!getResources().getBoolean(R.bool.set_wifi_priority)) {
            getPreferenceScreen().removePreference(prioritySettingPref);
        }
    } else {
        Log.d(TAG, "Fail to get priority pref...");
    }
    ListPreference ccodePref = (ListPreference) findPreference(KEY_COUNTRY_CODE);
    if (ccodePref != null) {
        boolean hideWifiRegion = getResources().getBoolean(R.bool.config_hideWifiRegionCode);
        if (hideWifiRegion) {
            removePreference(KEY_COUNTRY_CODE);
        } else {
            ccodePref.setOnPreferenceChangeListener(this);
            String value = mWifiManager.getCountryCode();
            if (value != null) {
                ccodePref.setValue(value);
            } else {
                Log.e(TAG, "Failed to fetch country code");
            }
        }
    }
    mAutoConnectEnablePref = (CheckBoxPreference) findPreference(KEY_AUTO_CONNECT_ENABLE);
    if (mAutoConnectEnablePref != null) {
        if (getResources().getBoolean(R.bool.config_auto_connect_wifi_enabled)) {
            mAutoConnectEnablePref.setChecked(isAutoConnectEnabled());
            mAutoConnectEnablePref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mAutoConnectEnablePref);
        }
    }
    mCellularToWlanPref = (ListPreference) findPreference(KEY_CELLULAR_TO_WLAN);
    if (mCellularToWlanPref != null) {
        if (getResources().getBoolean(R.bool.cell_to_wifi)) {
            int value = getCellularToWlanValue();
            mCellularToWlanPref.setValue(String.valueOf(value));
            updateCellToWlanSummary(mCellularToWlanPref, value);
            mCellularToWlanPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mCellularToWlanPref);
        }
    }
    CheckBoxPreference wlanToCellularHintPref = (CheckBoxPreference) findPreference(KEY_WLAN_TO_CELLULAR_HINT);
    if (wlanToCellularHintPref != null) {
        if (getResources().getBoolean(R.bool.wifi_to_cell)) {
            wlanToCellularHintPref.setChecked(isWlanToCellHintEnable());
            wlanToCellularHintPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(wlanToCellularHintPref);
        }
    }
    CheckBoxPreference notifyConnectedApPref = (CheckBoxPreference) findPreference(KEY_CONNECT_NOTIFY);
    if (notifyConnectedApPref != null) {
        if (getResources().getBoolean(R.bool.connect_to_cmcc_notify)) {
            notifyConnectedApPref.setChecked(ifNotifyConnect());
            notifyConnectedApPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(notifyConnectedApPref);
        }
    }
    mCellularToWlanHintPref = (CheckBoxPreference) findPreference(KEY_CELLULAR_TO_WLAN_HINT);
    if (mCellularToWlanHintPref != null) {
        if (getResources().getBoolean(R.bool.cellular_to_wlan_hint)) {
            mCellularToWlanHintPref.setChecked(isCellularToWlanHintEnable());
            mCellularToWlanHintPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mCellularToWlanHintPref);
        }
    }
}
Also used : Context(android.content.Context) SwitchPreference(android.support.v14.preference.SwitchPreference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) Settings(android.provider.Settings)

Example 4 with OnPreferenceClickListener

use of android.support.v7.preference.Preference.OnPreferenceClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeveloperPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    mViewHolder = holder;
    if (donateLink != null) {
        final OnClickListener openDonate = new OnClickListener() {

            @Override
            public void onClick(View v) {
                Uri donateURL = Uri.parse(donateLink);
                final Intent intent = new Intent(Intent.ACTION_VIEW, donateURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
        };
        donateButton.setOnClickListener(openDonate);
    } else {
        donateButton.setVisibility(View.GONE);
    }
    final OnPreferenceClickListener opengplus = new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (gplusName != null) {
                Uri gplusURL = Uri.parse("https://plus.google.com/+" + gplusName);
                final Intent intent = new Intent(Intent.ACTION_VIEW, gplusURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
            return true;
        }
    };
    // changed to clicking the preference to open gplus
    // it was a hit or miss to click the gplus icon
    this.setOnPreferenceClickListener(opengplus);
    UrlImageViewHelper.setUrlDrawable(this.photoView, getGravatarUrl(devEmail), R.drawable.ic_null, UrlImageViewHelper.CACHE_DURATION_ONE_WEEK);
    if (gplusName == null)
        gplusButton.setVisibility(View.INVISIBLE);
    devName.setText(nameDev);
}
Also used : Preference(android.support.v7.preference.Preference) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 5 with OnPreferenceClickListener

use of android.support.v7.preference.Preference.OnPreferenceClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndLanguageSettings method updateUserDictionaryPreference.

private void updateUserDictionaryPreference(Preference userDictionaryPreference) {
    if (userDictionaryPreference == null) {
        return;
    }
    final Activity activity = getActivity();
    final TreeSet<String> localeSet = UserDictionaryList.getUserDictionaryLocalesSet(activity);
    if (null == localeSet) {
        // The locale list is null if and only if the user dictionary service is
        // not present or disabled. In this case we need to remove the preference.
        getPreferenceScreen().removePreference(userDictionaryPreference);
    } else {
        userDictionaryPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                // Redirect to UserDictionarySettings if the user needs only one
                // language.
                final Bundle extras = new Bundle();
                final Class<? extends Fragment> targetFragment;
                if (localeSet.size() <= 1) {
                    if (!localeSet.isEmpty()) {
                        // If the size of localeList is 0, we don't set the locale
                        // parameter in the extras. This will be interpreted by the
                        // UserDictionarySettings class as meaning
                        // "the current locale". Note that with the current code for
                        // UserDictionaryList#getUserDictionaryLocalesSet()
                        // the locale list always has at least one element, since it
                        // always includes the current locale explicitly.
                        // @see UserDictionaryList.getUserDictionaryLocalesSet().
                        extras.putString("locale", localeSet.first());
                    }
                    targetFragment = UserDictionarySettings.class;
                } else {
                    targetFragment = UserDictionaryList.class;
                }
                startFragment(InputMethodAndLanguageSettings.this, targetFragment.getCanonicalName(), -1, -1, extras);
                return true;
            }
        });
    }
}
Also used : OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) UserDictionarySettings(com.android.settings.UserDictionarySettings) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) Bundle(android.os.Bundle) SettingsActivity(com.android.settings.SettingsActivity) KeyboardLayoutPickerActivity(com.android.settings.Settings.KeyboardLayoutPickerActivity) Activity(android.app.Activity) SettingsPreferenceFragment(com.android.settings.SettingsPreferenceFragment) Fragment(android.app.Fragment)

Aggregations

Preference (android.support.v7.preference.Preference)12 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)10 Intent (android.content.Intent)6 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 Context (android.content.Context)3 SwitchPreference (android.support.v14.preference.SwitchPreference)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 ListPreference (android.support.v7.preference.ListPreference)2 View (android.view.View)2 LayoutPreference (com.android.settings.applications.LayoutPreference)2 Activity (android.app.Activity)1 AutomaticZenRule (android.app.AutomaticZenRule)1 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Fingerprint (android.hardware.fingerprint.Fingerprint)1