• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.notification.row;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.service.notification.StatusBarNotification;
22 import android.util.AttributeSet;
23 import android.view.View;
24 import android.widget.LinearLayout;
25 import android.widget.TextView;
26 
27 import com.android.internal.logging.MetricsLogger;
28 import com.android.systemui.res.R;
29 
30 /**
31  * This GutsContent shows an explanatory interstitial telling the user they've just revoked this
32  * app's permission to post Promoted/Live notifications.
33  * If the guts are dismissed without further action, the revocation is committed.
34  * If the user hits undo, the permission is not revoked.
35  */
36 public class PromotedPermissionGutsContent extends LinearLayout
37         implements NotificationGuts.GutsContent, View.OnClickListener {
38 
39     private static final String TAG = "SnoozyPromotedGuts";
40 
41     private NotificationGuts mGutsContainer;
42     private StatusBarNotification mSbn;
43 
44     private TextView mUndoButton;
45 
46     private MetricsLogger mMetricsLogger = new MetricsLogger();
47     private OnClickListener mDemoteAction;
48 
PromotedPermissionGutsContent(Context context, AttributeSet attrs)49     public PromotedPermissionGutsContent(Context context, AttributeSet attrs) {
50         super(context, attrs);
51     }
52 
53 
54     @Override
onFinishInflate()55     protected void onFinishInflate() {
56         super.onFinishInflate();
57         mUndoButton = (TextView) findViewById(R.id.undo);
58         mUndoButton.setOnClickListener(this);
59         mUndoButton.setContentDescription(
60                 getContext().getString(R.string.snooze_undo_content_description));
61 
62     }
63 
64     @Override
onAttachedToWindow()65     protected void onAttachedToWindow() {
66         super.onAttachedToWindow();
67         dispatchConfigurationChanged(getResources().getConfiguration());
68     }
69 
70     /**
71      * Update the content description of the snooze view based on the snooze option and whether the
72      * snooze options are expanded or not.
73      * For example, this will be something like "Collapsed\u2029Snooze for 1 hour". The paragraph
74      * separator is added to introduce a break in speech, to match what TalkBack does by default
75      * when you e.g. press on a notification.
76      */
updateContentDescription()77     private void updateContentDescription() {
78         //
79     }
80 
81 
82     @Override
performAccessibilityActionInternal(int action, Bundle arguments)83     public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
84         if (super.performAccessibilityActionInternal(action, arguments)) {
85             return true;
86         }
87         if (action == R.id.action_snooze_undo) {
88             undoDemote(mUndoButton);
89             return true;
90         }
91         return false;
92     }
93 
94     /**
95      * TODO docs
96      * @param sbn
97      */
setStatusBarNotification(StatusBarNotification sbn)98     public void setStatusBarNotification(StatusBarNotification sbn) {
99         mSbn = sbn;
100         TextView demoteExplanation = (TextView) findViewById(R.id.demote_explain);
101         demoteExplanation.setText(mContext.getResources().getString(R.string.demote_explain_text,
102                 mSbn.getPackageName()));
103     }
104 
105     @Override
onClick(View v)106     public void onClick(View v) {
107         if (mGutsContainer != null) {
108             mGutsContainer.resetFalsingCheck();
109         }
110         final int id = v.getId();
111         if (id == R.id.undo) {
112             undoDemote(v);
113         }
114 
115     }
116 
undoDemote(View v)117     private void undoDemote(View v) {
118         // Don't commit the demote action, instead log the undo and dismiss the view.
119         mGutsContainer.closeControls(v, /* save= */ false);
120     }
121 
122     @Override
getActualHeight()123     public int getActualHeight() {
124         return getHeight();
125     }
126 
127     @Override
willBeRemoved()128     public boolean willBeRemoved() {
129         return false;
130     }
131 
132     @Override
getContentView()133     public View getContentView() {
134         return this;
135     }
136 
137     @Override
setGutsParent(NotificationGuts guts)138     public void setGutsParent(NotificationGuts guts) {
139         mGutsContainer = guts;
140     }
141 
142     @Override
handleCloseControls(boolean save, boolean force)143     public boolean handleCloseControls(boolean save, boolean force) {
144         if (!save) {
145             // Undo changes and let the guts handle closing the view
146             return false;
147         } else {
148             // Commit demote action.
149             mDemoteAction.onClick(this);
150             return false;
151         }
152     }
153 
154     @Override
isLeavebehind()155     public boolean isLeavebehind() {
156         return true;
157     }
158 
159     @Override
shouldBeSavedOnClose()160     public boolean shouldBeSavedOnClose() {
161         return true;
162     }
163 
164     @Override
needsFalsingProtection()165     public boolean needsFalsingProtection() {
166         return false;
167     }
168 
setOnDemoteAction(OnClickListener demoteAction)169     public void setOnDemoteAction(OnClickListener demoteAction) {
170         mDemoteAction = demoteAction;
171     }
172 
173 }
174