• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package com.android.systemui.volume;
17 
18 import android.animation.LayoutTransition;
19 import android.animation.ValueAnimator;
20 import android.content.Context;
21 import android.provider.Settings.Global;
22 import android.service.notification.ZenModeConfig;
23 import android.transition.AutoTransition;
24 import android.transition.TransitionManager;
25 import android.util.AttributeSet;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.ImageView;
29 import android.widget.LinearLayout;
30 import android.widget.TextView;
31 
32 import com.android.systemui.Prefs;
33 import com.android.systemui.R;
34 import com.android.systemui.statusbar.policy.ZenModeController;
35 
36 import java.util.Objects;
37 
38 /**
39  * Zen mode information (and end button) attached to the bottom of the volume dialog.
40  */
41 public class ZenFooter extends LinearLayout {
42     private static final String TAG = Util.logTag(ZenFooter.class);
43 
44     private final Context mContext;
45     private final ConfigurableTexts mConfigurableTexts;
46 
47     private ImageView mIcon;
48     private TextView mSummaryLine1;
49     private TextView mSummaryLine2;
50     private TextView mEndNowButton;
51     private View mZenIntroduction;
52     private View mZenIntroductionConfirm;
53     private TextView mZenIntroductionMessage;
54     private int mZen = -1;
55     private ZenModeConfig mConfig;
56     private ZenModeController mController;
57 
ZenFooter(Context context, AttributeSet attrs)58     public ZenFooter(Context context, AttributeSet attrs) {
59         super(context, attrs);
60         mContext = context;
61         mConfigurableTexts = new ConfigurableTexts(mContext);
62         final LayoutTransition layoutTransition = new LayoutTransition();
63         layoutTransition.setDuration(new ValueAnimator().getDuration() / 2);
64         setLayoutTransition(layoutTransition);
65     }
66 
67     @Override
onFinishInflate()68     protected void onFinishInflate() {
69         super.onFinishInflate();
70         mIcon = findViewById(R.id.volume_zen_icon);
71         mSummaryLine1 = findViewById(R.id.volume_zen_summary_line_1);
72         mSummaryLine2 = findViewById(R.id.volume_zen_summary_line_2);
73         mEndNowButton = findViewById(R.id.volume_zen_end_now);
74         mZenIntroduction = findViewById(R.id.zen_introduction);
75         mZenIntroductionMessage = findViewById(R.id.zen_introduction_message);
76         mConfigurableTexts.add(mZenIntroductionMessage, R.string.zen_alarms_introduction);
77         mZenIntroductionConfirm = findViewById(R.id.zen_introduction_confirm);
78         mZenIntroductionConfirm.setOnClickListener(new OnClickListener() {
79             @Override
80             public void onClick(View v) {
81                 confirmZenIntroduction();
82             }
83         });
84         Util.setVisOrGone(mZenIntroduction, shouldShowIntroduction());
85         mConfigurableTexts.add(mSummaryLine1);
86         mConfigurableTexts.add(mSummaryLine2);
87         mConfigurableTexts.add(mEndNowButton, R.string.volume_zen_end_now);
88     }
89 
init(final ZenModeController controller)90     public void init(final ZenModeController controller) {
91         mEndNowButton.setOnClickListener(new OnClickListener() {
92             @Override
93             public void onClick(View v) {
94                 setZen(Global.ZEN_MODE_OFF);
95                 controller.setZen(Global.ZEN_MODE_OFF, null, TAG);
96             }
97         });
98         mZen = controller.getZen();
99         mConfig = controller.getConfig();
100         mController = controller;
101         mController.addCallback(mZenCallback);
102         update();
103         updateIntroduction();
104     }
105 
cleanup()106     public void cleanup() {
107         mController.removeCallback(mZenCallback);
108     }
109 
setZen(int zen)110     private void setZen(int zen) {
111         if (mZen == zen) return;
112         mZen = zen;
113         update();
114         post(() -> {
115             updateIntroduction();
116         });
117     }
118 
setConfig(ZenModeConfig config)119     private void setConfig(ZenModeConfig config) {
120         if (Objects.equals(mConfig, config)) return;
121         mConfig = config;
122         update();
123     }
124 
confirmZenIntroduction()125     private void confirmZenIntroduction() {
126         Prefs.putBoolean(mContext, Prefs.Key.DND_CONFIRMED_ALARM_INTRODUCTION, true);
127         updateIntroduction();
128     }
129 
isZenPriority()130     private boolean isZenPriority() {
131         return mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
132     }
133 
isZenAlarms()134     private boolean isZenAlarms() {
135         return mZen == Global.ZEN_MODE_ALARMS;
136     }
137 
isZenNone()138     private boolean isZenNone() {
139         return mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
140     }
141 
update()142     public void update() {
143         mIcon.setImageResource(isZenNone() ? R.drawable.ic_dnd_total_silence : R.drawable.ic_dnd);
144         final String line1 =
145                 isZenPriority() ? mContext.getString(R.string.interruption_level_priority)
146                 : isZenAlarms() ? mContext.getString(R.string.interruption_level_alarms)
147                 : isZenNone() ? mContext.getString(R.string.interruption_level_none)
148                 : null;
149         Util.setText(mSummaryLine1, line1);
150 
151         final CharSequence line2 = ZenModeConfig.getConditionSummary(mContext, mConfig,
152                                 mController.getCurrentUser(), true /*shortVersion*/);
153         Util.setText(mSummaryLine2, line2);
154     }
155 
shouldShowIntroduction()156     public boolean shouldShowIntroduction() {
157         final boolean confirmed =  Prefs.getBoolean(mContext,
158                 Prefs.Key.DND_CONFIRMED_ALARM_INTRODUCTION, false);
159         return !confirmed && isZenAlarms();
160     }
161 
updateIntroduction()162     public void updateIntroduction() {
163         Util.setVisOrGone(mZenIntroduction, shouldShowIntroduction());
164     }
165 
onConfigurationChanged()166     public void onConfigurationChanged() {
167         mConfigurableTexts.update();
168     }
169 
170     private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() {
171         @Override
172         public void onZenChanged(int zen) {
173             setZen(zen);
174         }
175         @Override
176         public void onConfigChanged(ZenModeConfig config) {
177             setConfig(config);
178         }
179     };
180 }
181