|
| 1 | +/* |
| 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 | + |
| 17 | +package com.android.internal.widget; |
| 18 | + |
| 19 | +import android.content.Context; |
| 20 | +import android.util.AttributeSet; |
| 21 | +import android.util.Log; |
| 22 | +import android.view.View; |
| 23 | +import android.widget.RelativeLayout; |
| 24 | + |
| 25 | +public 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) { |
| 56 | + super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 57 | + |
| 58 | + final int minimumWidth = getSuggestedMinimumWidth(); |
| 59 | + final int minimumHeight = getSuggestedMinimumHeight(); |
| 60 | + int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth); |
| 61 | + int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight); |
| 62 | + |
| 63 | + viewWidth = viewHeight = Math.min(viewWidth, viewHeight); |
| 64 | + Log.v(TAG, "FaceUnlockView dimensions: " + viewWidth + "x" + viewHeight); |
| 65 | + setMeasuredDimension(viewWidth, viewHeight); |
| 66 | + } |
| 67 | +} |
0 commit comments