1 package com.actionbarsherlock.internal.widget;
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;
12 public class FakeDialogPhoneWindow extends LinearLayout {
13 final TypedValue mMinWidthMajor = new TypedValue();
14 final TypedValue mMinWidthMinor = new TypedValue();
16 public FakeDialogPhoneWindow(Context context, AttributeSet attrs) {
17 super(context, attrs);
19 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockTheme);
21 a.getValue(R.styleable.SherlockTheme_windowMinWidthMajor, mMinWidthMajor);
22 a.getValue(R.styleable.SherlockTheme_windowMinWidthMinor, mMinWidthMinor);
27 /* Stolen from PhoneWindow */
29 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
30 final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
31 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
33 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
35 int width = getMeasuredWidth();
36 boolean measure = false;
38 widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);
40 final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;
42 if (tv.type != TypedValue.TYPE_NULL) {
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);
53 widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
58 // TODO: Support height?
61 super.onMeasure(widthMeasureSpec, heightMeasureSpec);