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