alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 1 | package com.savoirfairelinux.sflphone.views;
|
| 2 |
|
| 3 | import android.content.Context;
|
| 4 | import android.util.AttributeSet;
|
Alexandre Lision | febae14 | 2013-07-18 09:58:52 -0400 | [diff] [blame] | 5 | import android.view.View.MeasureSpec;
|
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 6 | import android.widget.GridView;
|
| 7 |
|
Alexandre Lision | febae14 | 2013-07-18 09:58:52 -0400 | [diff] [blame] | 8 |
|
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 9 | public class TACGridView extends GridView {
|
| 10 |
|
| 11 | public TACGridView(Context context, AttributeSet attrs, int defStyle) {
|
| 12 | super(context, attrs, defStyle);
|
| 13 |
|
| 14 | }
|
| 15 |
|
| 16 | public TACGridView(Context context, AttributeSet attrs) {
|
| 17 | super(context, attrs);
|
| 18 | }
|
| 19 |
|
| 20 | public TACGridView(Context context) {
|
| 21 | super(context);
|
| 22 | }
|
| 23 |
|
| 24 | boolean expanded = false;
|
| 25 |
|
| 26 | public boolean isExpanded() {
|
| 27 | return expanded;
|
| 28 | }
|
| 29 |
|
| 30 | public void setExpanded(boolean expanded) {
|
| 31 | this.expanded = expanded;
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
| 36 | if (isExpanded()) {
|
| 37 | // Calculate entire height by providing a very large height hint.
|
| 38 | // But do not use the highest 2 bits of this integer; those are
|
| 39 | // reserved for the MeasureSpec mode.
|
| 40 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
|
| 41 | super.onMeasure(widthMeasureSpec, expandSpec);
|
| 42 |
|
| 43 | android.view.ViewGroup.LayoutParams params = getLayoutParams();
|
| 44 | params.height = getMeasuredHeight();
|
| 45 | } else {
|
| 46 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | }
|