Search in sources :

Example 26 with PreferenceGroup

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

the class PrivateVolumeSettings method update.

private void update() {
    if (!isVolumeValid()) {
        getActivity().finish();
        return;
    }
    setTitle();
    // Valid options may have changed
    getFragmentManager().invalidateOptionsMenu();
    final Context context = getActivity();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    addPreference(screen, mSummary);
    List<UserInfo> allUsers = mUserManager.getUsers();
    final int userCount = allUsers.size();
    final boolean showHeaders = userCount > 1;
    final boolean showShared = (mSharedVolume != null) && mSharedVolume.isMountedReadable();
    mItemPoolIndex = 0;
    mHeaderPoolIndex = 0;
    int addedUserCount = 0;
    // Add current user and its profiles first
    for (int userIndex = 0; userIndex < userCount; ++userIndex) {
        final UserInfo userInfo = allUsers.get(userIndex);
        if (Utils.isProfileOf(mCurrentUser, userInfo)) {
            final PreferenceGroup details = showHeaders ? addCategory(screen, userInfo.name) : screen;
            addDetailItems(details, showShared, userInfo.id);
            ++addedUserCount;
        }
    }
    // Add rest of users
    if (userCount - addedUserCount > 0) {
        PreferenceGroup otherUsers = addCategory(screen, getText(R.string.storage_other_users));
        for (int userIndex = 0; userIndex < userCount; ++userIndex) {
            final UserInfo userInfo = allUsers.get(userIndex);
            if (!Utils.isProfileOf(mCurrentUser, userInfo)) {
                addItem(otherUsers, /* titleRes */
                0, userInfo.name, userInfo.id);
            }
        }
    }
    addItem(screen, R.string.storage_detail_cached, null, UserHandle.USER_NULL);
    if (showShared) {
        addPreference(screen, mExplore);
    }
    final long freeBytes = mVolume.getPath().getFreeSpace();
    final long usedBytes = mTotalSize - freeBytes;
    if (LOGV)
        Log.v(TAG, "update() freeBytes: " + freeBytes + " usedBytes: " + usedBytes);
    final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
    mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
    mSummary.setSummary(getString(R.string.storage_volume_used, Formatter.formatFileSize(context, mTotalSize)));
    mSummary.setPercent(usedBytes, mTotalSize);
    mMeasure.forceMeasure();
    mNeedsUpdate = false;
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) UserInfo(android.content.pm.UserInfo) PreferenceGroup(android.support.v7.preference.PreferenceGroup) BytesResult(android.text.format.Formatter.BytesResult)

Example 27 with PreferenceGroup

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

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 28 with PreferenceGroup

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

the class EncryptionAndCredential method createPreferenceHierarchy.

/**
 * Important!
 *
 * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
 * logic or adding/removing preferences here.
 */
private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.encryption_and_credential);
    root = getPreferenceScreen();
    // Add options for device encryption
    mIsAdmin = mUm.isAdminUser();
    if (mIsAdmin) {
        if (LockPatternUtils.isDeviceEncryptionEnabled()) {
            // The device is currently encrypted.
            addPreferencesFromResource(R.xml.security_settings_encrypted);
        } else {
            // This device supports encryption but isn't encrypted.
            addPreferencesFromResource(R.xml.security_settings_unencrypted);
        }
    }
    // Credential storage
    // needs to be initialized for onResume()
    mKeyStore = KeyStore.getInstance();
    if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) {
        RestrictedPreference userCredentials = (RestrictedPreference) root.findPreference(KEY_USER_CREDENTIALS);
        userCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
        credentialStorageType.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        RestrictedPreference installCredentials = (RestrictedPreference) root.findPreference(KEY_CREDENTIALS_INSTALL);
        installCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        mResetCredentials = (RestrictedPreference) root.findPreference(KEY_RESET_CREDENTIALS);
        mResetCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        final int storageSummaryRes = mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware : R.string.credential_storage_type_software;
        credentialStorageType.setSummary(storageSummaryRes);
    } else {
        PreferenceGroup credentialsManager = (PreferenceGroup) root.findPreference(KEY_CREDENTIALS_MANAGER);
        credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
        credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
        credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
        credentialsManager.removePreference(root.findPreference(KEY_USER_CREDENTIALS));
    }
    return root;
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 29 with PreferenceGroup

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

the class TrustAgentSettings method updateAgents.

private void updateAgents() {
    final Context context = getActivity();
    if (mAvailableAgents == null) {
        mAvailableAgents = findAvailableTrustAgents();
    }
    if (mLockPatternUtils == null) {
        mLockPatternUtils = new LockPatternUtils(getActivity());
    }
    loadActiveAgents();
    PreferenceGroup category = (PreferenceGroup) getPreferenceScreen().findPreference("trust_agents");
    category.removeAll();
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(context, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId());
    final int count = mAvailableAgents.size();
    for (int i = 0; i < count; i++) {
        AgentInfo agent = mAvailableAgents.valueAt(i);
        final RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
        preference.useAdminDisabledSummary(true);
        agent.preference = preference;
        preference.setPersistent(false);
        preference.setTitle(agent.label);
        preference.setIcon(agent.icon);
        preference.setPersistent(false);
        preference.setOnPreferenceChangeListener(this);
        preference.setChecked(mActiveAgents.contains(agent.component));
        if (admin != null && mDpm.getTrustAgentConfiguration(null, agent.component) == null) {
            preference.setChecked(false);
            preference.setDisabledByAdmin(admin);
        }
        category.addPreference(agent.preference);
    }
}
Also used : Context(android.content.Context) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) LockPatternUtils(com.android.internal.widget.LockPatternUtils) PreferenceGroup(android.support.v7.preference.PreferenceGroup) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 30 with PreferenceGroup

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

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)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)140 Preference (android.support.v7.preference.Preference)114 Context (android.content.Context)67 Test (org.junit.Test)54 PreferenceManager (android.support.v7.preference.PreferenceManager)50 ArrayList (java.util.ArrayList)50 UserInfo (android.content.pm.UserInfo)48 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)42 Account (android.accounts.Account)36 AuthenticatorDescription (android.accounts.AuthenticatorDescription)36 UserHandle (android.os.UserHandle)36 Intent (android.content.Intent)27 SwitchPreference (android.support.v14.preference.SwitchPreference)21 PreferenceCategory (android.support.v7.preference.PreferenceCategory)20 PackageManager (android.content.pm.PackageManager)16 ResolveInfo (android.content.pm.ResolveInfo)16 TelephonyManager (android.telephony.TelephonyManager)16 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)15 Activity (android.app.Activity)14