Search in sources :

Example 1 with RecentLocationAccesses

use of com.android.settingslib.location.RecentLocationAccesses in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RecentLocationAccessPreferenceController method updateRecentApps.

private void updateRecentApps() {
    final List<RecentLocationAccesses.Access> recentLocationAccesses = mRecentLocationAccesses.getAppListSorted();
    if (recentLocationAccesses.size() > 0) {
        // Display the top 3 preferences to container in original order.
        int i = 0;
        for (; i < Math.min(recentLocationAccesses.size(), MAXIMUM_APP_COUNT); i++) {
            final RecentLocationAccesses.Access access = recentLocationAccesses.get(i);
            final AppEntityInfo appEntityInfo = new AppEntityInfo.Builder().setIcon(access.icon).setTitle(access.label).setSummary(StringUtil.formatRelativeTime(mContext, System.currentTimeMillis() - access.accessFinishTime, false, RelativeDateTimeFormatter.Style.SHORT)).setOnClickListener((v) -> {
                final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION);
                intent.putExtra(Intent.EXTRA_PERMISSION_NAME, Manifest.permission.ACCESS_FINE_LOCATION);
                intent.putExtra(Intent.EXTRA_PACKAGE_NAME, access.packageName);
                intent.putExtra(Intent.EXTRA_USER, access.userHandle);
                mContext.startActivity(intent);
            }).build();
            mController.setAppEntity(i, appEntityInfo);
        }
        for (; i < MAXIMUM_APP_COUNT; i++) {
            mController.removeAppEntity(i);
        }
    }
    mController.apply();
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) LayoutPreference(com.android.settingslib.widget.LayoutPreference) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) Intent(android.content.Intent) Preference(androidx.preference.Preference) Manifest(android.Manifest) List(java.util.List) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Utils(com.android.settings.Utils) DAYS(java.util.concurrent.TimeUnit.DAYS) StringUtil(com.android.settingslib.utils.StringUtil) View(android.view.View) RecentLocationAccesses(com.android.settingslib.location.RecentLocationAccesses) AppEntityInfo(com.android.settingslib.widget.AppEntityInfo) AppEntitiesHeaderController(com.android.settingslib.widget.AppEntitiesHeaderController) DeviceConfig(android.provider.DeviceConfig) VisibleForTesting(androidx.annotation.VisibleForTesting) R(com.android.settings.R) AppEntityInfo(com.android.settingslib.widget.AppEntityInfo) RecentLocationAccesses(com.android.settingslib.location.RecentLocationAccesses) Intent(android.content.Intent)

Example 2 with RecentLocationAccesses

use of com.android.settingslib.location.RecentLocationAccesses in project android_packages_apps_Settings by omnirom.

the class RecentLocationAccessPreferenceController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    super.displayPreference(screen);
    mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
    final Context prefContext = mCategoryRecentLocationRequests.getContext();
    final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
    final UserManager userManager = UserManager.get(mContext);
    for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted(/* showSystemApps= */
    false)) {
        if (isRequestMatchesProfileType(userManager, access, mType)) {
            recentLocationAccesses.add(access);
            if (recentLocationAccesses.size() == MAX_APPS) {
                break;
            }
        }
    }
    if (recentLocationAccesses.size() > 0) {
        // Add preferences to container in original order (already sorted by recency).
        for (RecentLocationAccesses.Access access : recentLocationAccesses) {
            mCategoryRecentLocationRequests.addPreference(createAppPreference(prefContext, access, 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_accesses);
        banner.setSelectable(false);
        mCategoryRecentLocationRequests.addPreference(banner);
    }
}
Also used : Context(android.content.Context) RecentLocationAccesses(com.android.settingslib.location.RecentLocationAccesses) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) UserManager(android.os.UserManager) ArrayList(java.util.ArrayList)

Example 3 with RecentLocationAccesses

use of com.android.settingslib.location.RecentLocationAccesses in project android_packages_apps_Settings by omnirom.

the class RecentLocationAccessSeeAllPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    mCategoryAllRecentLocationAccess.removeAll();
    mPreference = preference;
    final UserManager userManager = UserManager.get(mContext);
    final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
    for (RecentLocationAccesses.Access access : mRecentLocationAccesses.getAppListSorted(mShowSystem)) {
        if (isRequestMatchesProfileType(userManager, access, mType)) {
            recentLocationAccesses.add(access);
        }
    }
    if (recentLocationAccesses.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);
        mCategoryAllRecentLocationAccess.addPreference(banner);
    } else {
        for (RecentLocationAccesses.Access request : recentLocationAccesses) {
            final Preference appPreference = createAppPreference(preference.getContext(), request, mFragment);
            mCategoryAllRecentLocationAccess.addPreference(appPreference);
        }
    }
}
Also used : RecentLocationAccesses(com.android.settingslib.location.RecentLocationAccesses) RecentLocationAccessPreferenceController.createAppPreference(com.android.settings.location.RecentLocationAccessPreferenceController.createAppPreference) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) RecentLocationAccessPreferenceController.createAppPreference(com.android.settings.location.RecentLocationAccessPreferenceController.createAppPreference) AppPreference(com.android.settingslib.widget.AppPreference) UserManager(android.os.UserManager) ArrayList(java.util.ArrayList)

Aggregations

Preference (androidx.preference.Preference)3 RecentLocationAccesses (com.android.settingslib.location.RecentLocationAccesses)3 Context (android.content.Context)2 UserManager (android.os.UserManager)2 AppPreference (com.android.settingslib.widget.AppPreference)2 ArrayList (java.util.ArrayList)2 Manifest (android.Manifest)1 Intent (android.content.Intent)1 RelativeDateTimeFormatter (android.icu.text.RelativeDateTimeFormatter)1 DeviceConfig (android.provider.DeviceConfig)1 View (android.view.View)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 PreferenceScreen (androidx.preference.PreferenceScreen)1 R (com.android.settings.R)1 Utils (com.android.settings.Utils)1 PreferenceControllerMixin (com.android.settings.core.PreferenceControllerMixin)1 RecentLocationAccessPreferenceController.createAppPreference (com.android.settings.location.RecentLocationAccessPreferenceController.createAppPreference)1 AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)1 StringUtil (com.android.settingslib.utils.StringUtil)1 AppEntitiesHeaderController (com.android.settingslib.widget.AppEntitiesHeaderController)1