Search in sources :

Example 11 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class AppConversationListPreferenceController method createConversationPref.

protected Preference createConversationPref(final ConversationChannelWrapper conversation) {
    AppPreference pref = new AppPreference(mContext);
    populateConversationPreference(conversation, pref);
    return pref;
}
Also used : AppPreference(com.android.settingslib.widget.AppPreference)

Example 12 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class PasswordsPreferenceController method addPasswordPreferences.

private void addPasswordPreferences(Context prefContext, @UserIdInt int user, PreferenceGroup group) {
    for (int i = 0; i < mServices.size(); i++) {
        final AutofillServiceInfo service = mServices.get(i);
        final AppPreference pref = new AppPreference(prefContext);
        final ServiceInfo serviceInfo = service.getServiceInfo();
        pref.setTitle(serviceInfo.loadLabel(mPm));
        final Drawable icon = mIconFactory.getBadgedIcon(serviceInfo, serviceInfo.applicationInfo, user);
        pref.setIcon(Utils.getSafeIcon(icon));
        pref.setOnPreferenceClickListener(p -> {
            final Intent intent = new Intent(Intent.ACTION_MAIN).setClassName(serviceInfo.packageName, service.getPasswordsActivity());
            prefContext.startActivityAsUser(intent, UserHandle.of(user));
            return true;
        });
        // Set a placeholder summary to avoid a UI flicker when the value loads.
        pref.setSummary(R.string.autofill_passwords_count_placeholder);
        final MutableLiveData<Integer> passwordCount = new MutableLiveData<>();
        passwordCount.observe(mLifecycleOwner, count -> {
            // TODO(b/169455298): Validate the result.
            final CharSequence summary = mContext.getResources().getQuantityString(R.plurals.autofill_passwords_count, count, count);
            pref.setSummary(summary);
        });
        // TODO(b/169455298): Limit the number of concurrent queries.
        // TODO(b/169455298): Cache the results for some time.
        requestSavedPasswordCount(service, user, passwordCount);
        group.addPreference(pref);
    }
}
Also used : AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AppPreference(com.android.settingslib.widget.AppPreference) AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) Drawable(android.graphics.drawable.Drawable) MutableLiveData(androidx.lifecycle.MutableLiveData) Intent(android.content.Intent)

Example 13 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class RecentLocationRequestPreferenceController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    super.displayPreference(screen);
    mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
    final Context prefContext = mCategoryRecentLocationRequests.getContext();
    final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
    final UserManager userManager = UserManager.get(mContext);
    for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(false)) {
        if (isRequestMatchesProfileType(userManager, request, mType)) {
            recentLocationRequests.add(request);
            if (recentLocationRequests.size() == MAX_APPS) {
                break;
            }
        }
    }
    if (recentLocationRequests.size() > 0) {
        // Add preferences to container in original order (already sorted by recency).
        for (RecentLocationApps.Request request : recentLocationRequests) {
            mCategoryRecentLocationRequests.addPreference(createAppPreference(prefContext, request, mFragment));
        }
    } else {
        // If there's no item to display, add a "No recent apps" item.
        final Preference banner = new AppPreference(prefContext);
        banner.setTitle(R.string.location_no_recent_apps);
        banner.setSelectable(false);
        mCategoryRecentLocationRequests.addPreference(banner);
    }
}
Also used : Context(android.content.Context) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) UserManager(android.os.UserManager) ArrayList(java.util.ArrayList) RecentLocationApps(com.android.settingslib.location.RecentLocationApps)

Example 14 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class RecentLocationRequestSeeAllPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    mCategoryAllRecentLocationRequests.removeAll();
    mPreference = preference;
    final UserManager userManager = UserManager.get(mContext);
    final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
    for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(mShowSystem)) {
        if (isRequestMatchesProfileType(userManager, request, mType)) {
            recentLocationRequests.add(request);
        }
    }
    if (recentLocationRequests.isEmpty()) {
        // If there's no item to display, add a "No recent apps" item.
        final Preference banner = new AppPreference(mContext);
        banner.setTitle(R.string.location_no_recent_apps);
        banner.setSelectable(false);
        mCategoryAllRecentLocationRequests.addPreference(banner);
    } else {
        for (RecentLocationApps.Request request : recentLocationRequests) {
            final Preference appPreference = createAppPreference(preference.getContext(), request, mFragment);
            mCategoryAllRecentLocationRequests.addPreference(appPreference);
        }
    }
}
Also used : RecentLocationRequestPreferenceController.createAppPreference(com.android.settings.location.RecentLocationRequestPreferenceController.createAppPreference) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) RecentLocationRequestPreferenceController.createAppPreference(com.android.settings.location.RecentLocationRequestPreferenceController.createAppPreference) AppPreference(com.android.settingslib.widget.AppPreference) UserManager(android.os.UserManager) ArrayList(java.util.ArrayList) RecentLocationApps(com.android.settingslib.location.RecentLocationApps)

Example 15 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class RecentLocationAccessPreferenceController method createAppPreference.

/**
 * Create a {@link AppPreference}
 */
public static AppPreference createAppPreference(Context prefContext, RecentLocationAccesses.Access access, DashboardFragment fragment) {
    final AppPreference pref = new AppPreference(prefContext);
    pref.setIcon(access.icon);
    pref.setTitle(access.label);
    pref.setSummary(StringUtil.formatRelativeTime(prefContext, System.currentTimeMillis() - access.accessFinishTime, false, RelativeDateTimeFormatter.Style.SHORT));
    pref.setOnPreferenceClickListener(new PackageEntryClickedListener(fragment.getContext(), access.packageName, access.userHandle));
    return pref;
}
Also used : AppPreference(com.android.settingslib.widget.AppPreference)

Aggregations

AppPreference (com.android.settingslib.widget.AppPreference)17 Preference (androidx.preference.Preference)10 ArrayList (java.util.ArrayList)7 UserManager (android.os.UserManager)6 Context (android.content.Context)5 PreferenceScreen (androidx.preference.PreferenceScreen)5 ApplicationInfo (android.content.pm.ApplicationInfo)3 Bundle (android.os.Bundle)3 UserHandle (android.os.UserHandle)3 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)3 ApplicationsState (com.android.settingslib.applications.ApplicationsState)3 PackageItemInfo (android.content.pm.PackageItemInfo)2 ServiceInfo (android.content.pm.ServiceInfo)2 Pair (android.util.Pair)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 OnPreferenceClickListener (androidx.preference.Preference.OnPreferenceClickListener)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 RecentLocationAccesses (com.android.settingslib.location.RecentLocationAccesses)2 RecentLocationApps (com.android.settingslib.location.RecentLocationApps)2 UsageStats (android.app.usage.UsageStats)1