Search in sources :

Example 46 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by SudaMod.

the class ApnSettings method fillList.

private void fillList() {
    final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId() : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    final String mccmnc = mSubscriptionInfo == null ? "" : tm.getSimOperator(subId);
    Log.d(TAG, "mccmnc = " + mccmnc);
    StringBuilder where = new StringBuilder("numeric=\"" + mccmnc + "\" AND NOT (type='ia' AND (apn=\"\" OR apn IS NULL)) AND user_visible!=0");
    if (mHideImsApn) {
        where.append(" AND NOT (type='ims')");
    }
    Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, new String[] { "_id", "name", "apn", "type", "mvno_type", "mvno_match_data" }, where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER);
    if (cursor != null) {
        IccRecords r = null;
        if (mUiccController != null && mSubscriptionInfo != null) {
            r = mUiccController.getIccRecords(SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
        }
        PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
        apnList.removeAll();
        ArrayList<ApnPreference> mnoApnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mvnoApnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mnoMmsApnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mvnoMmsApnList = new ArrayList<ApnPreference>();
        mSelectedKey = getSelectedApnKey();
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String name = cursor.getString(NAME_INDEX);
            String apn = cursor.getString(APN_INDEX);
            String key = cursor.getString(ID_INDEX);
            String type = cursor.getString(TYPES_INDEX);
            String mvnoType = cursor.getString(MVNO_TYPE_INDEX);
            String mvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);
            ApnPreference pref = new ApnPreference(getPrefContext());
            pref.setKey(key);
            pref.setTitle(name);
            pref.setSummary(apn);
            pref.setPersistent(false);
            pref.setOnPreferenceChangeListener(this);
            pref.setSubId(subId);
            boolean selectable = ((type == null) || !type.equals("mms"));
            pref.setSelectable(selectable);
            if (selectable) {
                if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
                    pref.setChecked();
                }
                addApnToList(pref, mnoApnList, mvnoApnList, r, mvnoType, mvnoMatchData);
            } else {
                addApnToList(pref, mnoMmsApnList, mvnoMmsApnList, r, mvnoType, mvnoMatchData);
            }
            cursor.moveToNext();
        }
        cursor.close();
        if (!mvnoApnList.isEmpty()) {
            mnoApnList = mvnoApnList;
            mnoMmsApnList = mvnoMmsApnList;
        // Also save the mvno info
        }
        for (Preference preference : mnoApnList) {
            apnList.addPreference(preference);
        }
        for (Preference preference : mnoMmsApnList) {
            apnList.addPreference(preference);
        }
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) IccRecords(com.android.internal.telephony.uicc.IccRecords) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Cursor(android.database.Cursor)

Example 47 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by SudaMod.

the class ManageDomainUrls method onRebuildComplete.

@Override
public void onRebuildComplete(ArrayList<AppEntry> apps) {
    if (getContext() == null) {
        return;
    }
    final boolean disableWebActions = Global.getInt(getContext().getContentResolver(), Global.ENABLE_EPHEMERAL_FEATURE, 1) == 0;
    if (disableWebActions) {
        mDomainAppList = getPreferenceScreen();
    } else {
        final PreferenceGroup preferenceScreen = getPreferenceScreen();
        if (preferenceScreen.getPreferenceCount() == 0) {
            // add preferences
            final PreferenceCategory webActionCategory = new PreferenceCategory(getPrefContext());
            webActionCategory.setTitle(R.string.web_action_section_title);
            preferenceScreen.addPreference(webActionCategory);
            // toggle to enable / disable Web Actions [aka Instant Apps]
            mWebAction = new SwitchPreference(getPrefContext());
            mWebAction.setTitle(R.string.web_action_enable_title);
            mWebAction.setSummary(R.string.web_action_enable_summary);
            mWebAction.setChecked(Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTANT_APPS_ENABLED, 1) != 0);
            mWebAction.setOnPreferenceChangeListener(this);
            webActionCategory.addPreference(mWebAction);
            // Determine whether we should show the instant apps account chooser setting
            ComponentName instantAppSettingsComponent = getActivity().getPackageManager().getInstantAppResolverSettingsComponent();
            Intent instantAppSettingsIntent = null;
            if (instantAppSettingsComponent != null) {
                instantAppSettingsIntent = new Intent().setComponent(instantAppSettingsComponent);
            }
            if (instantAppSettingsIntent != null) {
                final Intent launchIntent = instantAppSettingsIntent;
                // TODO: Make this button actually launch the account chooser.
                mInstantAppAccountPreference = new Preference(getPrefContext());
                mInstantAppAccountPreference.setTitle(R.string.instant_apps_settings);
                mInstantAppAccountPreference.setOnPreferenceClickListener(pref -> {
                    startActivity(launchIntent);
                    return true;
                });
                webActionCategory.addPreference(mInstantAppAccountPreference);
            }
            // list to manage link handling per app
            mDomainAppList = new PreferenceCategory(getPrefContext());
            mDomainAppList.setTitle(R.string.domain_url_section_title);
            preferenceScreen.addPreference(mDomainAppList);
        }
    }
    rebuildAppList(mDomainAppList, apps);
}
Also used : PreferenceCategory(android.support.v7.preference.PreferenceCategory) SwitchPreference(android.support.v14.preference.SwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 48 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_CMParts by LineageOS.

the class SettingsPreferenceFragment method cacheRemoveAllPrefs.

protected void cacheRemoveAllPrefs(PreferenceGroup group) {
    mPreferenceCache = new ArrayMap<String, Preference>();
    final int N = group.getPreferenceCount();
    for (int i = 0; i < N; i++) {
        Preference p = group.getPreference(i);
        if (TextUtils.isEmpty(p.getKey())) {
            continue;
        }
        mPreferenceCache.put(p.getKey(), p);
    }
}
Also used : Preference(android.support.v7.preference.Preference) LayoutPreference(org.cyanogenmod.cmparts.widget.LayoutPreference) CustomDialogPreference(org.cyanogenmod.cmparts.widget.CustomDialogPreference)

Example 49 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_CMParts by LineageOS.

the class AppGroupConfig method updatePackages.

private void updatePackages() {
    PreferenceScreen prefSet = getPreferenceScreen();
    // Add the General section
    PreferenceGroup generalPrefs = (PreferenceGroup) prefSet.findPreference("general_section");
    if (generalPrefs != null) {
        generalPrefs.removeAll();
        // Name preference
        mNamePreference = new NamePreference(getActivity(), mNotificationGroup.getName());
        mNamePreference.setOnPreferenceChangeListener(this);
        generalPrefs.addPreference(mNamePreference);
    }
    PreferenceGroup applicationsList = (PreferenceGroup) prefSet.findPreference("applications_list");
    if (applicationsList != null) {
        applicationsList.removeAll();
        for (String pkg : mNotificationGroup.getPackages()) {
            Preference pref = new Preference(getActivity());
            try {
                PackageInfo group = mPackageManager.getPackageInfo(pkg, 0);
                pref.setKey(group.packageName);
                pref.setTitle(group.applicationInfo.loadLabel(mPackageManager));
                Drawable icon = group.applicationInfo.loadIcon(mPackageManager);
                pref.setIcon(icon);
                pref.setSelectable(true);
                pref.setPersistent(false);
                applicationsList.addPreference(pref);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 50 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class PowerUsageAdvancedTest method testPrefs_shouldNotBeSelectable.

@Test
public void testPrefs_shouldNotBeSelectable() {
    PreferenceManager pm = new PreferenceManager(mShadowContext);
    when(mPowerUsageAdvanced.getPreferenceManager()).thenReturn(pm);
    PreferenceGroup prefGroup = spy(new PreferenceCategory(mShadowContext));
    when(prefGroup.getPreferenceManager()).thenReturn(pm);
    mPowerUsageAdvanced.refreshPowerUsageDataList(mBatteryStatsHelper, prefGroup);
    assertThat(prefGroup.getPreferenceCount()).isAtLeast(1);
    for (int i = 0, count = prefGroup.getPreferenceCount(); i < count; i++) {
        PowerGaugePreference pref = (PowerGaugePreference) prefGroup.getPreference(i);
        assertThat(pref.isSelectable()).isFalse();
    }
}
Also used : PreferenceCategory(android.support.v7.preference.PreferenceCategory) PreferenceGroup(android.support.v7.preference.PreferenceGroup) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)101 Preference (android.support.v7.preference.Preference)68 PreferenceScreen (android.support.v7.preference.PreferenceScreen)28 Context (android.content.Context)27 Test (org.junit.Test)26 PreferenceManager (android.support.v7.preference.PreferenceManager)22 SwitchPreference (android.support.v14.preference.SwitchPreference)19 ArrayList (java.util.ArrayList)19 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 UserInfo (android.content.pm.UserInfo)16 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)14 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)14 Intent (android.content.Intent)13 Account (android.accounts.Account)12 AuthenticatorDescription (android.accounts.AuthenticatorDescription)12 UserHandle (android.os.UserHandle)12 TelephonyManager (android.telephony.TelephonyManager)12 Activity (android.app.Activity)11 RestrictedPreference (com.android.settingslib.RestrictedPreference)11 RemoteException (android.os.RemoteException)8