1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.settings.applications; 16 17 import android.app.Activity; 18 import android.content.Context; 19 import android.content.pm.ApplicationInfo; 20 import com.android.settings.R; 21 import com.android.settings.dashboard.SummaryLoader; 22 import com.android.settings.notification.NotificationBackend; 23 24 /** 25 * Extension of ManageApplications with no changes other than having its own 26 * SummaryProvider. 27 */ 28 public class NotificationApps extends ManageApplications { 29 30 private static class SummaryProvider implements SummaryLoader.SummaryProvider { 31 32 private final Context mContext; 33 private final SummaryLoader mLoader; 34 private final NotificationBackend mNotificationBackend; 35 36 private SummaryProvider(Context context, SummaryLoader loader) { 37 mContext = context; 38 mLoader = loader; 39 mNotificationBackend = new NotificationBackend(); 40 } 41 42 @Override 43 public void setListening(boolean listening) { 44 if (listening) { 45 new AppCounter(mContext) { 46 @Override 47 protected void onCountComplete(int num) { 48 updateSummary(num); 49 } 50 51 @Override 52 protected boolean includeInCount(ApplicationInfo info) { 53 return mNotificationBackend.getNotificationsBanned(info.packageName, 54 info.uid); 55 } 56 }.execute(); 57 } 58 } 59 60 private void updateSummary(int count) { 61 if (count == 0) { 62 mLoader.setSummary(this, mContext.getString(R.string.notification_summary_none)); 63 } else { 64 mLoader.setSummary(this, mContext.getResources().getQuantityString( 65 R.plurals.notification_summary, count, count)); 66 } 67 } 68 } 69 70 public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY 71 = new SummaryLoader.SummaryProviderFactory() { 72 @Override 73 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity, 74 SummaryLoader summaryLoader) { 75 return new SummaryProvider(activity, summaryLoader); 76 } 77 }; 78 } 79