blob: 1664a32d1663ef00f5221ddfe2620e543bb3ce1c [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;
20import android.graphics.Canvas;
21import android.graphics.Outline;
22import android.graphics.Rect;
23import android.graphics.drawable.Drawable;
24import android.graphics.drawable.InsetDrawable;
25import android.util.AttributeSet;
26import android.view.View;
27import android.widget.FrameLayout;
28
29/**
30 * An abstract view for expandable views.
31 */
32public abstract class ExpandableView extends FrameLayout {
33
34 private OnHeightChangedListener mOnHeightChangedListener;
35 protected int mActualHeight;
36 protected int mClipTopAmount;
Jorim Jaggibe565df2014-04-28 17:51:23 +020037 private boolean mActualHeightInitialized;
38
39 public ExpandableView(Context context, AttributeSet attrs) {
40 super(context, attrs);
41 }
42
43 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +020044 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 Jaggi9cbadd32014-05-01 20:18:31 +020058 notifyHeightChanged();
Jorim Jaggibe565df2014-04-28 17:51:23 +020059 }
60
61 /**
62 * See {@link #setActualHeight}.
63 *
Jorim Jaggi9cbadd32014-05-01 20:18:31 +020064 * @return The current actual height of this notification.
Jorim Jaggibe565df2014-04-28 17:51:23 +020065 */
66 public int getActualHeight() {
67 return mActualHeight;
68 }
69
70 /**
71 * @return The maximum height of this notification.
72 */
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020073 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 Jaggibe565df2014-04-28 17:51:23 +020083
84 /**
Jorim Jaggi9cbadd32014-05-01 20:18:31 +020085 * @return The desired notification height.
86 */
87 public int getIntrinsicHeight() {
88 return mActualHeight;
89 }
90
91 /**
Jorim Jaggibe565df2014-04-28 17:51:23 +020092 * 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 Jaggibe565df2014-04-28 17:51:23 +020099 }
100
101 public void setOnHeightChangedListener(OnHeightChangedListener listener) {
102 mOnHeightChangedListener = listener;
103 }
104
105 /**
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200106 * @return Whether we can expand this views content.
Jorim Jaggibe565df2014-04-28 17:51:23 +0200107 */
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200108 public boolean isContentExpandable() {
109 return false;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200110 }
111
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200112 public void notifyHeightChanged() {
113 if (mOnHeightChangedListener != null) {
114 mOnHeightChangedListener.onHeightChanged(this);
115 }
116 }
117
Jorim Jaggibe565df2014-04-28 17:51:23 +0200118 /**
119 * A listener notifying when {@link #getActualHeight} changes.
120 */
121 public interface OnHeightChangedListener {
122 void onHeightChanged(ExpandableView view);
123 }
124}