create changelog entry
[debian/openrocket] / android-libraries / ActionBarSherlock / src / com / actionbarsherlock / internal / widget / FakeDialogPhoneWindow.java
1 package com.actionbarsherlock.internal.widget;
2
3 import static android.view.View.MeasureSpec.EXACTLY;
4 import android.content.Context;
5 import android.content.res.TypedArray;
6 import android.util.AttributeSet;
7 import android.util.DisplayMetrics;
8 import android.util.TypedValue;
9 import android.widget.LinearLayout;
10 import com.actionbarsherlock.R;
11
12 public class FakeDialogPhoneWindow extends LinearLayout {
13     final TypedValue mMinWidthMajor = new TypedValue();
14     final TypedValue mMinWidthMinor = new TypedValue();
15
16     public FakeDialogPhoneWindow(Context context, AttributeSet attrs) {
17         super(context, attrs);
18
19         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockTheme);
20
21         a.getValue(R.styleable.SherlockTheme_windowMinWidthMajor, mMinWidthMajor);
22         a.getValue(R.styleable.SherlockTheme_windowMinWidthMinor, mMinWidthMinor);
23
24         a.recycle();
25     }
26
27     /* Stolen from PhoneWindow */
28     @Override
29     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
30         final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
31         final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
32
33         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
34
35         int width = getMeasuredWidth();
36         boolean measure = false;
37
38         widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);
39
40         final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;
41
42         if (tv.type != TypedValue.TYPE_NULL) {
43             final int min;
44             if (tv.type == TypedValue.TYPE_DIMENSION) {
45                 min = (int)tv.getDimension(metrics);
46             } else if (tv.type == TypedValue.TYPE_FRACTION) {
47                 min = (int)tv.getFraction(metrics.widthPixels, metrics.widthPixels);
48             } else {
49                 min = 0;
50             }
51
52             if (width < min) {
53                 widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
54                 measure = true;
55             }
56         }
57
58         // TODO: Support height?
59
60         if (measure) {
61             super.onMeasure(widthMeasureSpec, heightMeasureSpec);
62         }
63     }
64 }