blob: 121e60106740f771ce7a45528a5952dfe308e32a [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;
Brian Colonna68d257d2012-10-30 14:48:55 -040021import android.widget.RelativeLayout;
22
23public class FaceUnlockView extends RelativeLayout {
24 private static final String TAG = "FaceUnlockView";
25
26 public FaceUnlockView(Context context) {
27 this(context, null);
28 }
29
30 public FaceUnlockView(Context context, AttributeSet attrs) {
31 super(context, attrs);
32 }
33
34 private int resolveMeasured(int measureSpec, int desired)
35 {
36 int result = 0;
37 int specSize = MeasureSpec.getSize(measureSpec);
38 switch (MeasureSpec.getMode(measureSpec)) {
39 case MeasureSpec.UNSPECIFIED:
40 result = desired;
41 break;
42 case MeasureSpec.AT_MOST:
43 result = Math.max(specSize, desired);
44 break;
45 case MeasureSpec.EXACTLY:
46 default:
47 result = specSize;
48 }
49 return result;
50 }
51
52 @Override
53 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Brian Colonna68d257d2012-10-30 14:48:55 -040054 final int minimumWidth = getSuggestedMinimumWidth();
55 final int minimumHeight = getSuggestedMinimumHeight();
56 int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth);
57 int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight);
58
Brian Colonnaddbf138d2012-10-30 18:34:39 -040059 final int chosenSize = Math.min(viewWidth, viewHeight);
60 final int newWidthMeasureSpec =
61 MeasureSpec.makeMeasureSpec(chosenSize, MeasureSpec.AT_MOST);
62 final int newHeightMeasureSpec =
63 MeasureSpec.makeMeasureSpec(chosenSize, MeasureSpec.AT_MOST);
64
65 super.onMeasure(newWidthMeasureSpec, newHeightMeasureSpec);
Brian Colonna68d257d2012-10-30 14:48:55 -040066 }
67}