2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.camera.ui;
19 import android.graphics.Rect;
20 import android.view.View.MeasureSpec;
24 private final GLView mComponent;
25 private int mPreferredWidth;
26 private int mPreferredHeight;
28 public MeasureHelper(GLView component) {
29 mComponent = component;
32 public MeasureHelper setPreferredContentSize(int width, int height) {
33 mPreferredWidth = width;
34 mPreferredHeight = height;
38 public void measure(int widthSpec, int heightSpec) {
39 Rect p = mComponent.getPaddings();
41 getLength(widthSpec, mPreferredWidth + p.left + p.right),
42 getLength(heightSpec, mPreferredHeight + p.top + p.bottom));
45 private static int getLength(int measureSpec, int prefered) {
46 int specLength = MeasureSpec.getSize(measureSpec);
47 switch(MeasureSpec.getMode(measureSpec)) {
48 case MeasureSpec.EXACTLY: return specLength;
49 case MeasureSpec.AT_MOST: return Math.min(prefered, specLength);
50 default: return prefered;
54 protected void setMeasuredSize(int width, int height) {
55 mComponent.setMeasuredSize(width, height);