ExpandableView.java revision eb973565f3efc6417ca35363e4d6c642947775d8
1be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi/* 2be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Copyright (C) 2014 The Android Open Source Project 3be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * 4be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Licensed under the Apache License, Version 2.0 (the "License"); 5be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * you may not use this file except in compliance with the License. 6be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * You may obtain a copy of the License at 7be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * 8be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * http://www.apache.org/licenses/LICENSE-2.0 9be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * 10be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Unless required by applicable law or agreed to in writing, software 11be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * distributed under the License is distributed on an "AS IS" BASIS, 12be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * See the License for the specific language governing permissions and 14be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * limitations under the License 15be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 16be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 17be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggipackage com.android.systemui.statusbar; 18be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 19be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.content.Context; 20be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.util.AttributeSet; 21be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.view.View; 22be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.widget.FrameLayout; 23be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 24be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi/** 25be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * An abstract view for expandable views. 26be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 27be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggipublic abstract class ExpandableView extends FrameLayout { 28be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 29be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi private OnHeightChangedListener mOnHeightChangedListener; 30be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi protected int mActualHeight; 31be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi protected int mClipTopAmount; 32be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi private boolean mActualHeightInitialized; 33be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 34be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi public ExpandableView(Context context, AttributeSet attrs) { 35be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi super(context, attrs); 36be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 37be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 38be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi @Override 39be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 40be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi super.onLayout(changed, left, top, right, bottom); 41be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi if (!mActualHeightInitialized && mActualHeight == 0) { 42be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi mActualHeight = getHeight(); 43be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 44be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi mActualHeightInitialized = true; 45be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 46be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 47be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi /** 48be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Sets the actual height of this notification. This is different than the laid out 49be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * {@link View#getHeight()}, as we want to avoid layouting during scrolling and expanding. 50be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 51be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi public void setActualHeight(int actualHeight) { 52be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi mActualHeight = actualHeight; 539cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi notifyHeightChanged(); 54be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 55be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 56be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi /** 57be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * See {@link #setActualHeight}. 58be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * 599cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi * @return The current actual height of this notification. 60be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 61be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi public int getActualHeight() { 62be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi return mActualHeight; 63be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 64be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 65be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi /** 66be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * @return The maximum height of this notification. 67be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 684222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi public int getMaxHeight() { 694222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi return getHeight(); 704222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi } 714222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi 724222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi /** 734222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi * @return The minimum height of this notification. 744222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi */ 754222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi public int getMinHeight() { 764222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi return getHeight(); 774222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi } 78be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 79be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi /** 809cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi * @return The desired notification height. 819cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi */ 829cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi public int getIntrinsicHeight() { 839cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi return mActualHeight; 849cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi } 859cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi 869cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi /** 87be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Sets the amount this view should be clipped from the top. This is used when an expanded 88be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * notification is scrolling in the top or bottom stack. 89be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * 90be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * @param clipTopAmount The amount of pixels this view should be clipped from top. 91be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 92be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi public void setClipTopAmount(int clipTopAmount) { 93be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi mClipTopAmount = clipTopAmount; 94be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 95be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 96eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public int getClipTopAmount() { 97eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return mClipTopAmount; 98eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 99eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 100be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi public void setOnHeightChangedListener(OnHeightChangedListener listener) { 101be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi mOnHeightChangedListener = listener; 102be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 103be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 104be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi /** 1054222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi * @return Whether we can expand this views content. 106be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 1074222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi public boolean isContentExpandable() { 1084222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi return false; 109be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 110be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi 1119cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi public void notifyHeightChanged() { 1129cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi if (mOnHeightChangedListener != null) { 1139cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi mOnHeightChangedListener.onHeightChanged(this); 1149cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi } 1159cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi } 1169cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi 117be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi /** 118be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * A listener notifying when {@link #getActualHeight} changes. 119be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */ 120be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi public interface OnHeightChangedListener { 121be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi void onHeightChanged(ExpandableView view); 122be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi } 123be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi} 124