Search in sources :

Example 31 with PreferenceGroup

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

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 : CustomEditTextPreference(com.android.settingslib.CustomEditTextPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) CustomDialogPreference(com.android.settingslib.CustomDialogPreference) Preference(android.support.v7.preference.Preference)

Example 32 with PreferenceGroup

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

the class AccountPreferenceController method updateProfileUi.

private void updateProfileUi(final UserInfo userInfo) {
    if (mParent.getPreferenceManager() == null) {
        return;
    }
    final ProfileData data = mProfiles.get(userInfo.id);
    if (data != null) {
        data.pendingRemoval = false;
        if (userInfo.isEnabled()) {
            // recreate the authentication helper to refresh the list of enabled accounts
            data.authenticatorHelper = new AuthenticatorHelper(mContext, userInfo.getUserHandle(), this);
        }
        return;
    }
    final Context context = mContext;
    final ProfileData profileData = new ProfileData();
    profileData.userInfo = userInfo;
    AccessiblePreferenceCategory preferenceGroup = mHelper.createAccessiblePreferenceCategory(mParent.getPreferenceManager().getContext());
    preferenceGroup.setOrder(mAccountProfileOrder++);
    if (isSingleProfile()) {
        preferenceGroup.setTitle(context.getString(R.string.account_for_section_header, userInfo.name));
        preferenceGroup.setContentDescription(mContext.getString(R.string.account_settings));
    } else if (userInfo.isManagedProfile()) {
        preferenceGroup.setTitle(R.string.category_work);
        String workGroupSummary = getWorkGroupSummary(context, userInfo);
        preferenceGroup.setSummary(workGroupSummary);
        preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_work, workGroupSummary));
        profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
        mHelper.enforceRestrictionOnPreference(profileData.removeWorkProfilePreference, DISALLOW_REMOVE_MANAGED_PROFILE, UserHandle.myUserId());
        profileData.managedProfilePreference = newManagedProfileSettings();
    } else {
        preferenceGroup.setTitle(R.string.category_personal);
        preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_personal));
    }
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen != null) {
        screen.addPreference(preferenceGroup);
    }
    profileData.preferenceGroup = preferenceGroup;
    if (userInfo.isEnabled()) {
        profileData.authenticatorHelper = new AuthenticatorHelper(context, userInfo.getUserHandle(), this);
        profileData.addAccountPreference = newAddAccountPreference(context);
        mHelper.enforceRestrictionOnPreference(profileData.addAccountPreference, DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
    }
    mProfiles.put(userInfo.id, profileData);
    new SearchFeatureProviderImpl().getIndexingManager(mContext).updateFromClassNameResource(UserAndAccountDashboardFragment.class.getName(), true);
}
Also used : Context(android.content.Context) AuthenticatorHelper(com.android.settingslib.accounts.AuthenticatorHelper) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SearchFeatureProviderImpl(com.android.settings.search.SearchFeatureProviderImpl) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory)

Example 33 with PreferenceGroup

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

the class AccountTypePreferenceLoader method updatePreferenceIntents.

/**
 * Recursively filters through the preference list provided by GoogleLoginService.
 *
 * This method removes all the invalid intent from the list, adds account name as extra into the
 * intent, and hack the location settings to start it as a fragment.
 */
public void updatePreferenceIntents(PreferenceGroup prefs, final String acccountType, Account account) {
    final PackageManager pm = mFragment.getActivity().getPackageManager();
    for (int i = 0; i < prefs.getPreferenceCount(); ) {
        Preference pref = prefs.getPreference(i);
        if (pref instanceof PreferenceGroup) {
            updatePreferenceIntents((PreferenceGroup) pref, acccountType, account);
        }
        Intent intent = pref.getIntent();
        if (intent != null) {
            // preference click event here directly.
            if (intent.getAction().equals(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
                // The OnPreferenceClickListener overrides the click event completely. No intent
                // will get fired.
                pref.setOnPreferenceClickListener(new FragmentStarter(LocationSettings.class.getName(), R.string.location_settings_title));
            } else {
                ResolveInfo ri = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY, mUserHandle.getIdentifier());
                if (ri == null) {
                    prefs.removePreference(pref);
                    continue;
                }
                intent.putExtra(ACCOUNT_KEY, account);
                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent prefIntent = preference.getIntent();
                        /*
                                 * Check the intent to see if it resolves to a exported=false
                                 * activity that doesn't share a uid with the authenticator.
                                 *
                                 * Otherwise the intent is considered unsafe in that it will be
                                 * exploiting the fact that settings has system privileges.
                                 */
                        if (isSafeIntent(pm, prefIntent, acccountType)) {
                            mFragment.getActivity().startActivityAsUser(prefIntent, mUserHandle);
                        } else {
                            Log.e(TAG, "Refusing to launch authenticator intent because" + "it exploits Settings permissions: " + prefIntent);
                        }
                        return true;
                    }
                });
            }
        }
        i++;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Intent(android.content.Intent)

Example 34 with PreferenceGroup

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

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

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

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)

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