Search in sources :

Example 71 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModeAllBypassingAppsPreferenceController method updateNotificationChannelList.

@VisibleForTesting
void updateNotificationChannelList(List<ApplicationsState.AppEntry> apps) {
    if (mPreferenceScreen == null || apps == null) {
        return;
    }
    List<Preference> channelsBypassingDnd = new ArrayList<>();
    for (ApplicationsState.AppEntry entry : apps) {
        String pkg = entry.info.packageName;
        mApplicationsState.ensureIcon(entry);
        for (NotificationChannel channel : mNotificationBackend.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList()) {
            Preference pref = new AppPreference(mPrefContext);
            pref.setKey(pkg + "|" + channel.getId());
            pref.setTitle(BidiFormatter.getInstance().unicodeWrap(entry.label));
            pref.setIcon(entry.icon);
            pref.setSummary(BidiFormatter.getInstance().unicodeWrap(channel.getName()));
            pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Bundle args = new Bundle();
                    args.putString(AppInfoBase.ARG_PACKAGE_NAME, entry.info.packageName);
                    args.putInt(AppInfoBase.ARG_PACKAGE_UID, entry.info.uid);
                    args.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
                    new SubSettingLauncher(mContext).setDestination(ChannelNotificationSettings.class.getName()).setArguments(args).setTitleRes(R.string.notification_channel_title).setResultListener(mHostFragment, 0).setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP).launch();
                    return true;
                }
            });
            channelsBypassingDnd.add(pref);
        }
        mPreferenceScreen.removeAll();
        if (channelsBypassingDnd.size() > 0) {
            for (Preference prefToAdd : channelsBypassingDnd) {
                mPreferenceScreen.addPreference(prefToAdd);
            }
        }
    }
}
Also used : AppPreference(com.android.settingslib.widget.apppreference.AppPreference) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) NotificationChannel(android.app.NotificationChannel) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) Preference(androidx.preference.Preference) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 72 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RecentNotifyingAppsPreferenceController method reloadData.

@VisibleForTesting
void reloadData() {
    mApps = new ArrayList<>();
    mCal = Calendar.getInstance();
    mCal.add(Calendar.DAY_OF_YEAR, -DAYS);
    for (int userId : mUserIds) {
        UsageEvents events = null;
        try {
            events = mUsageStatsManager.queryEventsForUser(mCal.getTimeInMillis(), System.currentTimeMillis(), userId, mContext.getPackageName());
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        if (events != null) {
            ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>();
            UsageEvents.Event event = new UsageEvents.Event();
            while (events.hasNextEvent()) {
                events.getNextEvent(event);
                if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
                    NotifyingApp app = aggregatedStats.get(getKey(userId, event.getPackageName()));
                    if (app == null) {
                        app = new NotifyingApp();
                        aggregatedStats.put(getKey(userId, event.getPackageName()), app);
                        app.setPackage(event.getPackageName());
                        app.setUserId(userId);
                    }
                    if (event.getTimeStamp() > app.getLastNotified()) {
                        app.setLastNotified(event.getTimeStamp());
                    }
                }
            }
            mApps.addAll(aggregatedStats.values());
        }
    }
}
Also used : ArrayMap(android.util.ArrayMap) UsageEvents(android.app.usage.UsageEvents) RemoteException(android.os.RemoteException) NotifyingApp(android.service.notification.NotifyingApp) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 73 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CreateShortcutPreferenceController method createResultIntent.

/**
 * Create {@link Intent} that will be consumed by ShortcutManager, which later generates a
 * launcher widget using this intent.
 */
@VisibleForTesting
Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
    ShortcutInfo info = createShortcutInfo(mContext, shortcutIntent, resolveInfo, label);
    Intent intent = mShortcutManager.createShortcutResultIntent(info);
    if (intent == null) {
        intent = new Intent();
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(mContext, R.mipmap.ic_launcher)).putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent).putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    final ActivityInfo activityInfo = resolveInfo.activityInfo;
    if (activityInfo.icon != 0) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(mContext, activityInfo.applicationInfo, activityInfo.icon, R.layout.shortcut_badge, mContext.getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
    }
    return intent;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) ShortcutInfo(android.content.pm.ShortcutInfo) Intent(android.content.Intent) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 74 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsInitialize method refreshExistingShortcuts.

// Refresh settings shortcuts to have correct intent flags
@VisibleForTesting
void refreshExistingShortcuts(Context context) {
    final ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
    final List<ShortcutInfo> updates = new ArrayList<>();
    for (ShortcutInfo info : pinnedShortcuts) {
        if (info.isImmutable()) {
            continue;
        }
        final Intent shortcutIntent = info.getIntent();
        shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        final ShortcutInfo updatedInfo = new ShortcutInfo.Builder(context, info.getId()).setIntent(shortcutIntent).build();
        updates.add(updatedInfo);
    }
    shortcutManager.updateShortcuts(updates);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 75 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsPreferenceFragment method updateEmptyView.

@VisibleForTesting
void updateEmptyView() {
    if (mEmptyView == null)
        return;
    if (getPreferenceScreen() != null) {
        final View listContainer = getActivity().findViewById(android.R.id.list_container);
        boolean show = (getPreferenceScreen().getPreferenceCount() - (mHeader != null ? 1 : 0) - (mFooterPreferenceMixin.hasFooter() ? 1 : 0)) <= 0 || (listContainer != null && listContainer.getVisibility() != View.VISIBLE);
        mEmptyView.setVisibility(show ? View.VISIBLE : View.GONE);
    } else {
        mEmptyView.setVisibility(View.VISIBLE);
    }
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (androidx.annotation.VisibleForTesting)385 Intent (android.content.Intent)36 ArrayList (java.util.ArrayList)36 Context (android.content.Context)34 Bundle (android.os.Bundle)30 Uri (android.net.Uri)18 View (android.view.View)18 Preference (androidx.preference.Preference)18 TextView (android.widget.TextView)16 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)16 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)16 SuppressLint (android.annotation.SuppressLint)15 Activity (android.app.Activity)14 RemoteException (android.os.RemoteException)14 SubscriptionInfo (android.telephony.SubscriptionInfo)12 ImageView (android.widget.ImageView)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 ComponentName (android.content.ComponentName)11 Drawable (android.graphics.drawable.Drawable)11 SharedPreferences (android.content.SharedPreferences)10