Search in sources :

Example 36 with Preference

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

the class Utils method updatePreferenceToSpecificActivityOrRemove.

/**
     * Finds a matching activity for a preference's intent. If a matching
     * activity is not found, it will remove the preference.
     *
     * @param context The context.
     * @param parentPreferenceGroup The preference group that contains the
     *            preference whose intent is being resolved.
     * @param preferenceKey The key of the preference whose intent is being
     *            resolved.
     * @param flags 0 or one or more of
     *            {@link #UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY}
     *            .
     * @return Whether an activity was found. If false, the preference was
     *         removed.
     */
public static boolean updatePreferenceToSpecificActivityOrRemove(Context context, PreferenceGroup parentPreferenceGroup, String preferenceKey, int flags) {
    Preference preference = parentPreferenceGroup.findPreference(preferenceKey);
    if (preference == null) {
        return false;
    }
    Intent intent = preference.getIntent();
    if (intent != null) {
        // Find the activity that is in the system image
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
        int listSize = list.size();
        for (int i = 0; i < listSize; i++) {
            ResolveInfo resolveInfo = list.get(i);
            if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                // Replace the intent with this specific activity
                preference.setIntent(new Intent().setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
                if ((flags & UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY) != 0) {
                    // Set the preference title to the activity's label
                    preference.setTitle(resolveInfo.loadLabel(pm));
                }
                return true;
            }
        }
    }
    // Did not find a matching activity, so remove the preference
    parentPreferenceGroup.removePreference(preference);
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent)

Example 37 with Preference

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

the class WallpaperTypeSettings method populateWallpaperTypes.

private void populateWallpaperTypes() {
    // Search for activities that satisfy the ACTION_SET_WALLPAPER action
    final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
    final PackageManager pm = getPackageManager();
    final List<ResolveInfo> rList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    final PreferenceScreen parent = getPreferenceScreen();
    parent.setOrderingAsAdded(false);
    // Add Preference items for each of the matching activities
    for (ResolveInfo info : rList) {
        Preference pref = new Preference(getPrefContext());
        pref.setLayoutResource(R.layout.preference_wallpaper_type);
        Intent prefIntent = new Intent(intent);
        prefIntent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
        pref.setIntent(prefIntent);
        CharSequence label = info.loadLabel(pm);
        if (label == null)
            label = info.activityInfo.packageName;
        pref.setTitle(label);
        pref.setIcon(info.loadIcon(pm));
        parent.addPreference(pref);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 38 with Preference

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

the class Status method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mHandler = new MyHandler(this);
    mCM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    addPreferencesFromResource(R.xml.device_info_status);
    mBatteryLevel = findPreference(KEY_BATTERY_LEVEL);
    mBatteryStatus = findPreference(KEY_BATTERY_STATUS);
    mBtAddress = findPreference(KEY_BT_ADDRESS);
    mWifiMacAddress = findPreference(KEY_WIFI_MAC_ADDRESS);
    mWimaxMacAddress = findPreference(KEY_WIMAX_MAC_ADDRESS);
    mIpAddress = findPreference(KEY_IP_ADDRESS);
    mRes = getResources();
    mUnknown = mRes.getString(R.string.device_info_default);
    mUnavailable = mRes.getString(R.string.status_unavailable);
    // Note - missing in zaku build, be careful later...
    mUptime = findPreference("up_time");
    if (!hasBluetooth()) {
        getPreferenceScreen().removePreference(mBtAddress);
        mBtAddress = null;
    }
    if (!hasWimax()) {
        getPreferenceScreen().removePreference(mWimaxMacAddress);
        mWimaxMacAddress = null;
    }
    mConnectivityIntentFilter = new IntentFilter();
    for (String intent : CONNECTIVITY_INTENTS) {
        mConnectivityIntentFilter.addAction(intent);
    }
    updateConnectivity();
    String serial = getSerialNumber();
    if (serial != null && !serial.equals("")) {
        setSummaryText(KEY_SERIAL_NUMBER, serial);
    } else {
        removePreferenceFromScreen(KEY_SERIAL_NUMBER);
    }
    //TODO: the bug above will surface in split system user mode.
    if (!UserManager.get(getContext()).isAdminUser() || Utils.isWifiOnly(getContext())) {
        removePreferenceFromScreen(KEY_SIM_STATUS);
        removePreferenceFromScreen(KEY_IMEI_INFO);
    } else {
        int numPhones = TelephonyManager.getDefault().getPhoneCount();
        if (numPhones > 1) {
            PreferenceScreen prefSet = getPreferenceScreen();
            Preference singleSimPref = prefSet.findPreference(KEY_SIM_STATUS);
            SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
            for (int i = 0; i < numPhones; i++) {
                SubscriptionInfo sir = subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(i);
                Preference pref = new Preference(getActivity());
                pref.setOrder(singleSimPref.getOrder());
                pref.setTitle(getString(R.string.sim_card_status_title, i + 1));
                if (sir != null) {
                    pref.setSummary(sir.getDisplayName());
                } else {
                    pref.setSummary(R.string.sim_card_summary_empty);
                }
                Intent intent = new Intent(getActivity(), Settings.SimStatusActivity.class);
                intent.putExtra(Settings.EXTRA_SHOW_FRAGMENT_TITLE, getString(R.string.sim_card_status_title, i + 1));
                intent.putExtra(Settings.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
                intent.putExtra(SimStatus.EXTRA_SLOT_ID, i);
                pref.setIntent(intent);
                prefSet.addPreference(pref);
            }
            prefSet.removePreference(singleSimPref);
        }
    }
    if (SystemProperties.getBoolean("ro.alarm_boot", false)) {
        removePreferenceFromScreen(KEY_IMEI_INFO);
    }
}
Also used : IntentFilter(android.content.IntentFilter) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent) SubscriptionManager(android.telephony.SubscriptionManager) Settings(com.android.settings.Settings)

Example 39 with Preference

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

the class PublicVolumeSettings method buildAction.

private Preference buildAction(int titleRes) {
    final Preference pref = new Preference(getPrefContext());
    pref.setTitle(titleRes);
    return pref;
}
Also used : Preference(android.support.v7.preference.Preference)

Example 40 with Preference

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

the class InputMethodAndSubtypeEnabler method addInputMethodSubtypePreferences.

private void addInputMethodSubtypePreferences(final InputMethodInfo imi, final PreferenceScreen root) {
    final Context context = getPrefContext();
    final int subtypeCount = imi.getSubtypeCount();
    if (subtypeCount <= 1) {
        return;
    }
    final String imiId = imi.getId();
    final PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getPrefContext());
    root.addPreference(keyboardSettingsCategory);
    final PackageManager pm = getPackageManager();
    final CharSequence label = imi.loadLabel(pm);
    keyboardSettingsCategory.setTitle(label);
    keyboardSettingsCategory.setKey(imiId);
    // TODO: Use toggle Preference if images are ready.
    final TwoStatePreference autoSelectionPref = new SwitchWithNoTextPreference(getPrefContext());
    mAutoSelectionPrefsMap.put(imiId, autoSelectionPref);
    keyboardSettingsCategory.addPreference(autoSelectionPref);
    autoSelectionPref.setOnPreferenceChangeListener(this);
    final PreferenceCategory activeInputMethodsCategory = new PreferenceCategory(getPrefContext());
    activeInputMethodsCategory.setTitle(R.string.active_input_method_subtypes);
    root.addPreference(activeInputMethodsCategory);
    CharSequence autoSubtypeLabel = null;
    final ArrayList<Preference> subtypePreferences = new ArrayList<>();
    for (int index = 0; index < subtypeCount; ++index) {
        final InputMethodSubtype subtype = imi.getSubtypeAt(index);
        if (subtype.overridesImplicitlyEnabledSubtype()) {
            if (autoSubtypeLabel == null) {
                autoSubtypeLabel = InputMethodAndSubtypeUtil.getSubtypeLocaleNameAsSentence(subtype, context, imi);
            }
        } else {
            final Preference subtypePref = new InputMethodSubtypePreference(context, subtype, imi);
            subtypePreferences.add(subtypePref);
        }
    }
    Collections.sort(subtypePreferences, new Comparator<Preference>() {

        @Override
        public int compare(final Preference lhs, final Preference rhs) {
            if (lhs instanceof InputMethodSubtypePreference) {
                return ((InputMethodSubtypePreference) lhs).compareTo(rhs, mCollator);
            }
            return lhs.compareTo(rhs);
        }
    });
    final int prefCount = subtypePreferences.size();
    for (int index = 0; index < prefCount; ++index) {
        final Preference pref = subtypePreferences.get(index);
        activeInputMethodsCategory.addPreference(pref);
        pref.setOnPreferenceChangeListener(this);
        InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
    }
    mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences);
    if (TextUtils.isEmpty(autoSubtypeLabel)) {
        autoSelectionPref.setTitle(R.string.use_system_language_to_select_input_method_subtypes);
    } else {
        autoSelectionPref.setTitle(autoSubtypeLabel);
    }
}
Also used : Context(android.content.Context) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) TwoStatePreference(android.support.v7.preference.TwoStatePreference) ArrayList(java.util.ArrayList) PackageManager(android.content.pm.PackageManager) PreferenceCategory(android.support.v7.preference.PreferenceCategory) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference)

Aggregations

Preference (android.support.v7.preference.Preference)122 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 SwitchPreference (android.support.v14.preference.SwitchPreference)33 Intent (android.content.Intent)27 ListPreference (android.support.v7.preference.ListPreference)27 Context (android.content.Context)17 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 ArrayList (java.util.ArrayList)14 PackageManager (android.content.pm.PackageManager)11 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)11 PreferenceGroup (android.support.v7.preference.PreferenceGroup)11 TwoStatePreference (android.support.v7.preference.TwoStatePreference)11 Activity (android.app.Activity)10 View (android.view.View)10 Bundle (android.os.Bundle)9 TextView (android.widget.TextView)8 AlertDialog (android.support.v7.app.AlertDialog)7 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7