blob: 232795a5cb911c33eecc01aa87bb67d28dbf674b [file] [log] [blame]
Jorim Jaggibe565df2014-04-28 17:51:23 +02001/*
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
17package com.android.systemui.statusbar;
18
19import android.content.Context;
Jorim Jaggibe565df2014-04-28 17:51:23 +020020import android.util.AttributeSet;
21import android.view.View;
22import android.widget.FrameLayout;
23
24/**
25 * An abstract view for expandable views.
26 */
27public abstract class ExpandableView extends FrameLayout {
28
29 private OnHeightChangedListener mOnHeightChangedListener;
30 protected int mActualHeight;
31 protected int mClipTopAmount;
Jorim Jaggibe565df2014-04-28 17:51:23 +020032 private boolean mActualHeightInitialized;
33
34 public ExpandableView(Context context, AttributeSet attrs) {
35 super(context, attrs);
36 }
37
38 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +020039 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 Jaggi9cbadd32014-05-01 20:18:31 +020053 notifyHeightChanged();
Jorim Jaggibe565df2014-04-28 17:51:23 +020054 }
55
56 /**
57 * See {@link #setActualHeight}.
58 *
Jorim Jaggi9cbadd32014-05-01 20:18:31 +020059 * @return The current actual height of this notification.
Jorim Jaggibe565df2014-04-28 17:51:23 +020060 */
61 public int getActualHeight() {
62 return mActualHeight;
63 }
64
65 /**
66 * @return The maximum height of this notification.
67 */
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020068 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 Jaggibe565df2014-04-28 17:51:23 +020078
79 /**
Jorim Jaggi9cbadd32014-05-01 20:18:31 +020080 * @return The desired notification height.
81 */
82 public int getIntrinsicHeight() {
83 return mActualHeight;
84 }
85
86 /**
Jorim Jaggibe565df2014-04-28 17:51:23 +020087 * 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 Jaggibe565df2014-04-28 17:51:23 +020094 }
95
Selim Cinekeb973562014-05-02 17:07:49 +020096 public int getClipTopAmount() {
97 return mClipTopAmount;
98 }
99
Jorim Jaggibe565df2014-04-28 17:51:23 +0200100 public void setOnHeightChangedListener(OnHeightChangedListener listener) {
101 mOnHeightChangedListener = listener;
102 }
103
104 /**
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200105 * @return Whether we can expand this views content.
Jorim Jaggibe565df2014-04-28 17:51:23 +0200106 */
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200107 public boolean isContentExpandable() {
108 return false;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200109 }
110
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200111 public void notifyHeightChanged() {
112 if (mOnHeightChangedListener != null) {
113 mOnHeightChangedListener.onHeightChanged(this);
114 }
115 }
116
Jorim Jaggibe565df2014-04-28 17:51:23 +0200117 /**
118 * A listener notifying when {@link #getActualHeight} changes.
119 */
120 public interface OnHeightChangedListener {
121 void onHeightChanged(ExpandableView view);
122 }
123}