• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.annotation.ColorInt;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.util.AttributeSet;
23 import android.view.View;
24 
25 import com.android.systemui.R;
26 import com.android.systemui.statusbar.stack.ExpandableViewState;
27 import com.android.systemui.statusbar.stack.StackScrollState;
28 
29 public class DismissView extends StackScrollerDecorView {
30     private final int mClearAllTopPadding;
31     private DismissViewButton mDismissButton;
32 
DismissView(Context context, AttributeSet attrs)33     public DismissView(Context context, AttributeSet attrs) {
34         super(context, attrs);
35         mClearAllTopPadding = context.getResources().getDimensionPixelSize(
36                 R.dimen.clear_all_padding_top);
37     }
38 
39     @Override
findContentView()40     protected View findContentView() {
41         return findViewById(R.id.dismiss_text);
42     }
43 
44     @Override
onFinishInflate()45     protected void onFinishInflate() {
46         super.onFinishInflate();
47         mDismissButton = (DismissViewButton) findContentView();
48     }
49 
setTextColor(@olorInt int color)50     public void setTextColor(@ColorInt int color) {
51         mDismissButton.setTextColor(color);
52     }
53 
setOnButtonClickListener(OnClickListener listener)54     public void setOnButtonClickListener(OnClickListener listener) {
55         mContent.setOnClickListener(listener);
56     }
57 
isOnEmptySpace(float touchX, float touchY)58     public boolean isOnEmptySpace(float touchX, float touchY) {
59         return touchX < mContent.getX()
60                 || touchX > mContent.getX() + mContent.getWidth()
61                 || touchY < mContent.getY()
62                 || touchY > mContent.getY() + mContent.getHeight();
63     }
64 
65     @Override
onConfigurationChanged(Configuration newConfig)66     protected void onConfigurationChanged(Configuration newConfig) {
67         super.onConfigurationChanged(newConfig);
68         mDismissButton.setText(R.string.clear_all_notifications_text);
69         mDismissButton.setContentDescription(
70                 mContext.getString(R.string.accessibility_clear_all));
71     }
72 
isButtonVisible()73     public boolean isButtonVisible() {
74         return mDismissButton.getAlpha() != 0.0f;
75     }
76 
77     @Override
createNewViewState(StackScrollState stackScrollState)78     public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
79         return new DismissViewState();
80     }
81 
82     public class DismissViewState extends ExpandableViewState {
83         @Override
applyToView(View view)84         public void applyToView(View view) {
85             super.applyToView(view);
86             if (view instanceof DismissView) {
87                 DismissView dismissView = (DismissView) view;
88                 boolean visible = this.clipTopAmount < mClearAllTopPadding;
89                 dismissView.performVisibilityAnimation(visible && !dismissView.willBeGone());
90             }
91         }
92     }
93 }
94