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