ExpandableOutlineView.java revision be565dfc1c17b7ddafa9753851b8f82849fd3f42
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.graphics.Outline;
21be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.util.AttributeSet;
22be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.widget.FrameLayout;
23be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
24be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi/**
25be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Like {@link ExpandableView}, but setting an outline for the height and clipping.
26be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */
27be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggipublic abstract class ExpandableOutlineView extends ExpandableView {
28be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
29be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    private final Outline mOutline = new Outline();
30be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
31be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public ExpandableOutlineView(Context context, AttributeSet attrs) {
32be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        super(context, attrs);
33be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
34be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
35be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    @Override
36be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public void setActualHeight(int actualHeight) {
37be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        super.setActualHeight(actualHeight);
38be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        updateOutline();
39be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
40be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
41be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    @Override
42be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public void setClipTopAmount(int clipTopAmount) {
43be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        super.setClipTopAmount(clipTopAmount);
44be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        updateOutline();
45be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
46be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
47be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    @Override
48be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
49be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        super.onLayout(changed, left, top, right, bottom);
50be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        updateOutline();
51be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
52be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
53be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    private void updateOutline() {
54be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mOutline.setRect(0,
55be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi                mClipTopAmount,
56be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi                getWidth(),
57be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi                Math.max(mActualHeight, mClipTopAmount));
58be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        setOutline(mOutline);
59be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
60be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi}
61