blob: 871c84beab871ff14bd3ec0f997c539e88f7aa87 [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 Jaggibe565df2014-04-28 17:51:23 +020058 if (mOnHeightChangedListener != null) {
59 mOnHeightChangedListener.onHeightChanged(this);
60 }
61 }
62
63 /**
64 * See {@link #setActualHeight}.
65 *
66 * @return The actual height of this notification.
67 */
68 public int getActualHeight() {
69 return mActualHeight;
70 }
71
72 /**
73 * @return The maximum height of this notification.
74 */
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020075 public int getMaxHeight() {
76 return getHeight();
77 }
78
79 /**
80 * @return The minimum height of this notification.
81 */
82 public int getMinHeight() {
83 return getHeight();
84 }
Jorim Jaggibe565df2014-04-28 17:51:23 +020085
86 /**
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 Jaggibe565df2014-04-28 17:51:23 +020094 }
95
96 public void setOnHeightChangedListener(OnHeightChangedListener listener) {
97 mOnHeightChangedListener = listener;
98 }
99
100 /**
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200101 * @return Whether we can expand this views content.
Jorim Jaggibe565df2014-04-28 17:51:23 +0200102 */
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200103 public boolean isContentExpandable() {
104 return false;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200105 }
106
107 /**
108 * A listener notifying when {@link #getActualHeight} changes.
109 */
110 public interface OnHeightChangedListener {
111 void onHeightChanged(ExpandableView view);
112 }
113}