blob: e3c124730ae548f18537779acf226f9db12baa8b [file] [log] [blame]
Brian Colonna68d257d2012-10-30 14:48:55 -04001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.internal.widget;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.util.Log;
22import android.view.View;
23import android.widget.RelativeLayout;
24
25public class FaceUnlockView extends RelativeLayout {
26 private static final String TAG = "FaceUnlockView";
27
28 public FaceUnlockView(Context context) {
29 this(context, null);
30 }
31
32 public FaceUnlockView(Context context, AttributeSet attrs) {
33 super(context, attrs);
34 }
35
36 private int resolveMeasured(int measureSpec, int desired)
37 {
38 int result = 0;
39 int specSize = MeasureSpec.getSize(measureSpec);
40 switch (MeasureSpec.getMode(measureSpec)) {
41 case MeasureSpec.UNSPECIFIED:
42 result = desired;
43 break;
44 case MeasureSpec.AT_MOST:
45 result = Math.max(specSize, desired);
46 break;
47 case MeasureSpec.EXACTLY:
48 default:
49 result = specSize;
50 }
51 return result;
52 }
53
54 @Override
55 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Brian Colonna68d257d2012-10-30 14:48:55 -040056 final int minimumWidth = getSuggestedMinimumWidth();
57 final int minimumHeight = getSuggestedMinimumHeight();
58 int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth);
59 int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight);
60
Brian Colonnaddbf138d2012-10-30 18:34:39 -040061 final int chosenSize = Math.min(viewWidth, viewHeight);
62 final int newWidthMeasureSpec =
63 MeasureSpec.makeMeasureSpec(chosenSize, MeasureSpec.AT_MOST);
64 final int newHeightMeasureSpec =
65 MeasureSpec.makeMeasureSpec(chosenSize, MeasureSpec.AT_MOST);
66
67 super.onMeasure(newWidthMeasureSpec, newHeightMeasureSpec);
Brian Colonna68d257d2012-10-30 14:48:55 -040068 }
69}