Brian Colonna | 68d257d | 2012-10-30 14:48:55 -0400 | [diff] [blame] | 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; |
Brian Colonna | 68d257d | 2012-10-30 14:48:55 -0400 | [diff] [blame] | 21 | import android.widget.RelativeLayout; |
| 22 | |
| 23 | public 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 Colonna | 68d257d | 2012-10-30 14:48:55 -0400 | [diff] [blame] | 54 | final int minimumWidth = getSuggestedMinimumWidth(); |
| 55 | final int minimumHeight = getSuggestedMinimumHeight(); |
| 56 | int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth); |
| 57 | int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight); |
| 58 | |
Brian Colonna | ddbf138d | 2012-10-30 18:34:39 -0400 | [diff] [blame] | 59 | 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 Colonna | 68d257d | 2012-10-30 14:48:55 -0400 | [diff] [blame] | 66 | } |
| 67 | } |