ZenFooter.java revision bbde26774fcf7ea65abd92d60f7468478c015053
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 */ 16package com.android.systemui.volume; 17 18import android.animation.LayoutTransition; 19import android.content.Context; 20import android.provider.Settings.Global; 21import android.service.notification.ZenModeConfig; 22import android.util.AttributeSet; 23import android.view.View; 24import android.widget.ImageView; 25import android.widget.LinearLayout; 26import android.widget.TextView; 27 28import com.android.systemui.R; 29import com.android.systemui.statusbar.policy.ZenModeController; 30 31import java.util.Objects; 32 33/** 34 * Zen mode information (and end button) attached to the bottom of the volume dialog. 35 */ 36public class ZenFooter extends LinearLayout { 37 private static final String TAG = Util.logTag(ZenFooter.class); 38 39 private final Context mContext; 40 private final SpTexts mSpTexts; 41 42 private ImageView mIcon; 43 private TextView mSummaryLine1; 44 private TextView mSummaryLine2; 45 private TextView mEndNowButton; 46 private int mZen = -1; 47 private ZenModeConfig mConfig; 48 private ZenModeController mController; 49 50 public ZenFooter(Context context, AttributeSet attrs) { 51 super(context, attrs); 52 mContext = context; 53 mSpTexts = new SpTexts(mContext); 54 setLayoutTransition(new LayoutTransition()); 55 } 56 57 @Override 58 protected void onFinishInflate() { 59 super.onFinishInflate(); 60 mIcon = (ImageView) findViewById(R.id.volume_zen_icon); 61 mSummaryLine1 = (TextView) findViewById(R.id.volume_zen_summary_line_1); 62 mSummaryLine2 = (TextView) findViewById(R.id.volume_zen_summary_line_2); 63 mEndNowButton = (TextView) findViewById(R.id.volume_zen_end_now); 64 mSpTexts.add(mSummaryLine1); 65 mSpTexts.add(mSummaryLine2); 66 mSpTexts.add(mEndNowButton); 67 } 68 69 public void init(final ZenModeController controller) { 70 controller.addCallback(new ZenModeController.Callback() { 71 @Override 72 public void onZenChanged(int zen) { 73 setZen(zen); 74 } 75 @Override 76 public void onConfigChanged(ZenModeConfig config) { 77 setConfig(config); 78 } 79 }); 80 mEndNowButton.setOnClickListener(new OnClickListener() { 81 @Override 82 public void onClick(View v) { 83 controller.setZen(Global.ZEN_MODE_OFF, null, TAG); 84 } 85 }); 86 mZen = controller.getZen(); 87 mConfig = controller.getConfig(); 88 mController = controller; 89 update(); 90 } 91 92 private void setZen(int zen) { 93 if (mZen == zen) return; 94 mZen = zen; 95 update(); 96 } 97 98 private void setConfig(ZenModeConfig config) { 99 if (Objects.equals(mConfig, config)) return; 100 mConfig = config; 101 update(); 102 } 103 104 public boolean isZen() { 105 return isZenPriority() || isZenAlarms() || isZenNone(); 106 } 107 108 private boolean isZenPriority() { 109 return mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; 110 } 111 112 private boolean isZenAlarms() { 113 return mZen == Global.ZEN_MODE_ALARMS; 114 } 115 116 private boolean isZenNone() { 117 return mZen == Global.ZEN_MODE_NO_INTERRUPTIONS; 118 } 119 120 public void update() { 121 mIcon.setImageResource(isZenNone() ? R.drawable.ic_dnd_total_silence : R.drawable.ic_dnd); 122 final String line1 = 123 isZenPriority() ? mContext.getString(R.string.interruption_level_priority) 124 : isZenAlarms() ? mContext.getString(R.string.interruption_level_alarms) 125 : isZenNone() ? mContext.getString(R.string.interruption_level_none) 126 : null; 127 Util.setText(mSummaryLine1, line1); 128 129 final String line2 = ZenModeConfig.getConditionSummary(mContext, mConfig, 130 mController.getCurrentUser(), true /*shortVersion*/); 131 Util.setText(mSummaryLine2, line2); 132 } 133 134 public void onConfigurationChanged() { 135 mSpTexts.update(); 136 } 137 138} 139