Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 19 | import android.app.INotificationManager; |
| 20 | import android.app.Notification; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 21 | import android.content.Context; |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 22 | import android.content.pm.PackageInfo; |
| 23 | import android.content.pm.PackageManager; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 24 | import android.graphics.Canvas; |
| 25 | import android.graphics.drawable.Drawable; |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 26 | import android.os.RemoteException; |
| 27 | import android.os.ServiceManager; |
| 28 | import android.service.notification.NotificationListenerService; |
| 29 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 31 | import android.view.View; |
Julia Reynolds | 7727ad2 | 2016-01-22 14:38:46 -0500 | [diff] [blame] | 32 | import android.widget.ImageView; |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 33 | import android.widget.LinearLayout; |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 34 | import android.widget.RadioButton; |
| 35 | import android.widget.SeekBar; |
| 36 | import android.widget.TextView; |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 37 | |
Julia Reynolds | b1a235f | 2016-02-09 12:57:02 -0500 | [diff] [blame] | 38 | import com.android.internal.logging.MetricsLogger; |
| 39 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 40 | import com.android.settingslib.Utils; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 41 | import com.android.systemui.R; |
| 42 | |
| 43 | /** |
| 44 | * The guts of a notification revealed when performing a long press. |
| 45 | */ |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 46 | public class NotificationGuts extends LinearLayout { |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 47 | |
| 48 | private Drawable mBackground; |
| 49 | private int mClipTopAmount; |
| 50 | private int mActualHeight; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 51 | private boolean mExposed; |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 52 | private SeekBar mSeekBar; |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 53 | private INotificationManager mINotificationManager; |
Julia Reynolds | b1a235f | 2016-02-09 12:57:02 -0500 | [diff] [blame] | 54 | private int mStartingImportance; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 55 | |
| 56 | public NotificationGuts(Context context, AttributeSet attrs) { |
| 57 | super(context, attrs); |
| 58 | setWillNotDraw(false); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void onDraw(Canvas canvas) { |
| 63 | draw(canvas, mBackground); |
| 64 | } |
| 65 | |
| 66 | private void draw(Canvas canvas, Drawable drawable) { |
| 67 | if (drawable != null) { |
| 68 | drawable.setBounds(0, mClipTopAmount, getWidth(), mActualHeight); |
| 69 | drawable.draw(canvas); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | protected void onFinishInflate() { |
| 75 | super.onFinishInflate(); |
| 76 | mBackground = mContext.getDrawable(R.drawable.notification_guts_bg); |
| 77 | if (mBackground != null) { |
| 78 | mBackground.setCallback(this); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected boolean verifyDrawable(Drawable who) { |
| 84 | return super.verifyDrawable(who) || who == mBackground; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | protected void drawableStateChanged() { |
| 89 | drawableStateChanged(mBackground); |
| 90 | } |
| 91 | |
| 92 | private void drawableStateChanged(Drawable d) { |
| 93 | if (d != null && d.isStateful()) { |
| 94 | d.setState(getDrawableState()); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void drawableHotspotChanged(float x, float y) { |
| 100 | if (mBackground != null) { |
| 101 | mBackground.setHotspot(x, y); |
| 102 | } |
| 103 | } |
| 104 | |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 105 | void bindImportance(final StatusBarNotification sbn, final ExpandableNotificationRow row, |
| 106 | final int importance) { |
Julia Reynolds | b1a235f | 2016-02-09 12:57:02 -0500 | [diff] [blame] | 107 | mStartingImportance = importance; |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 108 | mINotificationManager = INotificationManager.Stub.asInterface( |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 109 | ServiceManager.getService(Context.NOTIFICATION_SERVICE)); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 110 | |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 111 | final TextView importanceSummary = ((TextView) row.findViewById(R.id.summary)); |
| 112 | final TextView importanceTitle = ((TextView) row.findViewById(R.id.title)); |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 113 | mSeekBar = (SeekBar) row.findViewById(R.id.seekbar); |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 114 | boolean systemApp = false; |
| 115 | try { |
| 116 | final PackageManager pm = BaseStatusBar.getPackageManagerForUser( |
| 117 | getContext(), sbn.getUser().getIdentifier()); |
| 118 | final PackageInfo info = |
| 119 | pm.getPackageInfo(sbn.getPackageName(), PackageManager.GET_SIGNATURES); |
| 120 | systemApp = Utils.isSystemPackage(pm, info); |
| 121 | } catch (PackageManager.NameNotFoundException e) { |
| 122 | // unlikely. |
| 123 | } |
Julia Reynolds | 7727ad2 | 2016-01-22 14:38:46 -0500 | [diff] [blame] | 124 | if (systemApp) { |
| 125 | ((ImageView) row.findViewById(R.id.low_importance)).getDrawable().setTint( |
| 126 | mContext.getColor(R.color.notification_guts_disabled_icon_tint)); |
| 127 | } |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 128 | final int minProgress = systemApp ? |
| 129 | NotificationListenerService.Ranking.IMPORTANCE_LOW |
| 130 | : NotificationListenerService.Ranking.IMPORTANCE_NONE; |
| 131 | mSeekBar.setMax(NotificationListenerService.Ranking.IMPORTANCE_MAX); |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 132 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 133 | @Override |
| 134 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 135 | if (progress < minProgress) { |
| 136 | seekBar.setProgress(minProgress); |
| 137 | progress = minProgress; |
| 138 | } |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 139 | updateTitleAndSummary(progress); |
| 140 | if (fromUser) { |
Julia Reynolds | b1a235f | 2016-02-09 12:57:02 -0500 | [diff] [blame] | 141 | MetricsLogger.action(mContext, MetricsEvent.ACTION_MODIFY_IMPORTANCE_SLIDER); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void onStartTrackingTouch(SeekBar seekBar) { |
| 147 | // no-op |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void onStopTrackingTouch(SeekBar seekBar) { |
| 152 | // no-op |
| 153 | } |
| 154 | |
| 155 | private void updateTitleAndSummary(int progress) { |
| 156 | switch (progress) { |
| 157 | case NotificationListenerService.Ranking.IMPORTANCE_NONE: |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 158 | importanceSummary.setText(mContext.getString( |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 159 | R.string.notification_importance_blocked)); |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 160 | importanceTitle.setText(mContext.getString(R.string.blocked_importance)); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 161 | break; |
| 162 | case NotificationListenerService.Ranking.IMPORTANCE_LOW: |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 163 | importanceSummary.setText(mContext.getString( |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 164 | R.string.notification_importance_low)); |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 165 | importanceTitle.setText(mContext.getString(R.string.low_importance)); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 166 | break; |
| 167 | case NotificationListenerService.Ranking.IMPORTANCE_DEFAULT: |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 168 | importanceSummary.setText(mContext.getString( |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 169 | R.string.notification_importance_default)); |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 170 | importanceTitle.setText(mContext.getString(R.string.default_importance)); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 171 | break; |
| 172 | case NotificationListenerService.Ranking.IMPORTANCE_HIGH: |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 173 | importanceSummary.setText(mContext.getString( |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 174 | R.string.notification_importance_high)); |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 175 | importanceTitle.setText(mContext.getString(R.string.high_importance)); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 176 | break; |
| 177 | case NotificationListenerService.Ranking.IMPORTANCE_MAX: |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 178 | importanceSummary.setText(mContext.getString( |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 179 | R.string.notification_importance_max)); |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 180 | importanceTitle.setText(mContext.getString(R.string.max_importance)); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 181 | break; |
| 182 | } |
| 183 | } |
| 184 | }); |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 185 | mSeekBar.setProgress(importance); |
| 186 | } |
| 187 | |
| 188 | void saveImportance(final StatusBarNotification sbn) { |
| 189 | int progress = mSeekBar.getProgress(); |
Julia Reynolds | b1a235f | 2016-02-09 12:57:02 -0500 | [diff] [blame] | 190 | MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, |
| 191 | progress - mStartingImportance); |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 192 | try { |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 193 | mINotificationManager.setImportance(sbn.getPackageName(), sbn.getUid(), progress); |
Julia Reynolds | 0714f62 | 2016-01-07 13:24:09 -0500 | [diff] [blame] | 194 | } catch (RemoteException e) { |
| 195 | // :( |
| 196 | } |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 199 | public void setActualHeight(int actualHeight) { |
| 200 | mActualHeight = actualHeight; |
| 201 | invalidate(); |
| 202 | } |
| 203 | |
| 204 | public int getActualHeight() { |
| 205 | return mActualHeight; |
| 206 | } |
| 207 | |
| 208 | public void setClipTopAmount(int clipTopAmount) { |
| 209 | mClipTopAmount = clipTopAmount; |
| 210 | invalidate(); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public boolean hasOverlappingRendering() { |
| 215 | |
| 216 | // Prevents this view from creating a layer when alpha is animating. |
| 217 | return false; |
| 218 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 219 | |
| 220 | public void setExposed(boolean exposed) { |
| 221 | mExposed = exposed; |
| 222 | } |
| 223 | |
| 224 | public boolean areGutsExposed() { |
| 225 | return mExposed; |
| 226 | } |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 227 | } |