Search in sources :

Example 16 with PreferenceGroup

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

the class Utils method addAll.

private static void addAll(PreferenceGroup group, List<String> ret) {
    if (group == null)
        return;
    for (int i = 0; i < group.getPreferenceCount(); i++) {
        Preference pref = group.getPreference(i);
        ret.add(pref.getKey());
        if (pref instanceof PreferenceGroup) {
            addAll((PreferenceGroup) pref, ret);
        }
    }
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 17 with PreferenceGroup

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

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

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

the class EnterpriseSetDefaultAppsListPreferenceController method createPreferences.

private void createPreferences(Context prefContext, PreferenceGroup group, EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>> apps) {
    if (group == null) {
        return;
    }
    for (EnterpriseDefaultApps typeOfDefault : EnterpriseDefaultApps.values()) {
        final List<ApplicationInfo> appsForCategory = apps.get(typeOfDefault);
        if (appsForCategory == null || appsForCategory.isEmpty()) {
            continue;
        }
        final Preference preference = new Preference(prefContext);
        preference.setTitle(getTitle(prefContext, typeOfDefault, appsForCategory.size()));
        preference.setSummary(buildSummaryString(prefContext, appsForCategory));
        preference.setOrder(typeOfDefault.ordinal());
        preference.setSelectable(false);
        group.addPreference(preference);
    }
}
Also used : EnterpriseDefaultApps(com.android.settings.applications.EnterpriseDefaultApps) Preference(android.support.v7.preference.Preference) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 19 with PreferenceGroup

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

the class InactiveApps method init.

private void init() {
    PreferenceGroup screen = getPreferenceScreen();
    screen.removeAll();
    screen.setOrderingAsAdded(false);
    final Context context = getActivity();
    final PackageManager pm = context.getPackageManager();
    final UsageStatsManager usm = context.getSystemService(UsageStatsManager.class);
    Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> apps = pm.queryIntentActivities(launcherIntent, 0);
    for (ResolveInfo app : apps) {
        String packageName = app.activityInfo.applicationInfo.packageName;
        Preference p = new Preference(getPrefContext());
        p.setTitle(app.loadLabel(pm));
        p.setIcon(app.loadIcon(pm));
        p.setKey(packageName);
        updateSummary(p);
        p.setOnPreferenceClickListener(this);
        screen.addPreference(p);
    }
}
Also used : Context(android.content.Context) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) UsageStatsManager(android.app.usage.UsageStatsManager) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Intent(android.content.Intent)

Example 20 with PreferenceGroup

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

the class ChannelNotificationSettings method updateDependents.

void updateDependents(boolean banned) {
    PreferenceGroup parent;
    if (mShowLegacyChannelConfig) {
        parent = getPreferenceScreen();
        setVisible(mImportanceToggle, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    } else {
        setVisible(mAdvanced, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
        setVisible(mImportance, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
        setVisible(mAdvanced, mLights, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight());
        setVisible(mVibrate, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
        setVisible(mRingtone, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
        parent = mAdvanced;
    }
    setVisible(parent, mBadge, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    setVisible(parent, mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && mDndVisualEffectsSuppressed));
    setVisible(parent, mVisibilityOverride, isLockScreenSecure() && checkCanBeVisible(NotificationManager.IMPORTANCE_LOW));
    setVisible(mBlockedDesc, mChannel.getImportance() == IMPORTANCE_NONE);
    if (mAppLink != null) {
        setVisible(mAppLink, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    }
    if (mFooter != null) {
        setVisible(mFooter, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    }
}
Also used : PreferenceGroup(android.support.v7.preference.PreferenceGroup)

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