Jorim Jaggi | be565df | 2014-04-28 17:51:23 +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 | |
| 19 | import android.content.Context; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 20 | import android.util.AttributeSet; |
Jorim Jaggi | 00ebdfe | 2014-05-02 17:29:56 +0200 | [diff] [blame] | 21 | import android.view.MotionEvent; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 22 | import android.view.View; |
| 23 | import android.widget.FrameLayout; |
| 24 | |
| 25 | /** |
| 26 | * An abstract view for expandable views. |
| 27 | */ |
| 28 | public abstract class ExpandableView extends FrameLayout { |
| 29 | |
| 30 | private OnHeightChangedListener mOnHeightChangedListener; |
| 31 | protected int mActualHeight; |
| 32 | protected int mClipTopAmount; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 33 | private boolean mActualHeightInitialized; |
| 34 | |
| 35 | public ExpandableView(Context context, AttributeSet attrs) { |
| 36 | super(context, attrs); |
| 37 | } |
| 38 | |
| 39 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 40 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 41 | super.onLayout(changed, left, top, right, bottom); |
| 42 | if (!mActualHeightInitialized && mActualHeight == 0) { |
| 43 | mActualHeight = getHeight(); |
| 44 | } |
| 45 | mActualHeightInitialized = true; |
| 46 | } |
| 47 | |
Jorim Jaggi | 00ebdfe | 2014-05-02 17:29:56 +0200 | [diff] [blame] | 48 | @Override |
| 49 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 50 | if (filterMotionEvent(ev)) { |
| 51 | return super.dispatchTouchEvent(ev); |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | private boolean filterMotionEvent(MotionEvent event) { |
| 57 | return event.getActionMasked() != MotionEvent.ACTION_DOWN |
| 58 | || event.getY() > mClipTopAmount && event.getY() < mActualHeight; |
| 59 | } |
| 60 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 61 | /** |
| 62 | * Sets the actual height of this notification. This is different than the laid out |
| 63 | * {@link View#getHeight()}, as we want to avoid layouting during scrolling and expanding. |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 64 | * |
| 65 | * @param actualHeight The height of this notification. |
| 66 | * @param notifyListeners Whether the listener should be informed about the change. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 67 | */ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 68 | public void setActualHeight(int actualHeight, boolean notifyListeners) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 69 | mActualHeight = actualHeight; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 70 | if (notifyListeners) { |
| 71 | notifyHeightChanged(); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | public void setActualHeight(int actualHeight) { |
| 76 | setActualHeight(actualHeight, true); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * See {@link #setActualHeight}. |
| 81 | * |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 82 | * @return The current actual height of this notification. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 83 | */ |
| 84 | public int getActualHeight() { |
| 85 | return mActualHeight; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return The maximum height of this notification. |
| 90 | */ |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 91 | public int getMaxHeight() { |
| 92 | return getHeight(); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @return The minimum height of this notification. |
| 97 | */ |
| 98 | public int getMinHeight() { |
| 99 | return getHeight(); |
| 100 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 101 | |
| 102 | /** |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 103 | * Sets the notification as dimmed. The default implementation does nothing. |
| 104 | * |
| 105 | * @param dimmed Whether the notification should be dimmed. |
| 106 | * @param fade Whether an animation should be played to change the state. |
| 107 | */ |
| 108 | public void setDimmed(boolean dimmed, boolean fade) { |
| 109 | } |
| 110 | |
| 111 | /** |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 112 | * @return The desired notification height. |
| 113 | */ |
| 114 | public int getIntrinsicHeight() { |
| 115 | return mActualHeight; |
| 116 | } |
| 117 | |
| 118 | /** |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 119 | * Sets the amount this view should be clipped from the top. This is used when an expanded |
| 120 | * notification is scrolling in the top or bottom stack. |
| 121 | * |
| 122 | * @param clipTopAmount The amount of pixels this view should be clipped from top. |
| 123 | */ |
| 124 | public void setClipTopAmount(int clipTopAmount) { |
| 125 | mClipTopAmount = clipTopAmount; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 128 | public int getClipTopAmount() { |
| 129 | return mClipTopAmount; |
| 130 | } |
| 131 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 132 | public void setOnHeightChangedListener(OnHeightChangedListener listener) { |
| 133 | mOnHeightChangedListener = listener; |
| 134 | } |
| 135 | |
| 136 | /** |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 137 | * @return Whether we can expand this views content. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 138 | */ |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 139 | public boolean isContentExpandable() { |
| 140 | return false; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 143 | public void notifyHeightChanged() { |
| 144 | if (mOnHeightChangedListener != null) { |
| 145 | mOnHeightChangedListener.onHeightChanged(this); |
| 146 | } |
| 147 | } |
| 148 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 149 | /** |
| 150 | * A listener notifying when {@link #getActualHeight} changes. |
| 151 | */ |
| 152 | public interface OnHeightChangedListener { |
| 153 | void onHeightChanged(ExpandableView view); |
| 154 | } |
| 155 | } |