OSDN Git Service

layouts, image icons, and layer behavour
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / CenteredLinearLayout.java
1 package com.android.gallery3d.filtershow;
2
3 import android.content.Context;
4 import android.content.res.Resources;
5 import android.content.res.TypedArray;
6 import android.util.AttributeSet;
7 import android.util.TypedValue;
8 import android.view.View.MeasureSpec;
9 import android.widget.LinearLayout;
10
11 import com.android.gallery3d.R;
12
13 public class CenteredLinearLayout extends LinearLayout {
14     private final int mMaxWidth;
15
16     public CenteredLinearLayout(Context context, AttributeSet attrs) {
17         super(context, attrs);
18         TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CenteredLinearLayout);
19         mMaxWidth = a.getDimensionPixelSize(R.styleable.CenteredLinearLayout_max_width, 0);
20     }
21
22     @Override
23     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
24         int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
25         int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
26         Resources r = getContext().getResources();
27         float value = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, parentWidth,
28                 r.getDisplayMetrics());
29         if (mMaxWidth > 0 && parentWidth > mMaxWidth) {
30             int measureMode = MeasureSpec.getMode(widthMeasureSpec);
31             widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode);
32         }
33         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
34     }
35
36 }