11124090a300e96f6d1d5b0c67f3fe314daf32743John Reck/* 21124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * Copyright (C) 2013 The Android Open Source Project 31124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * 41124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 51124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * you may not use this file except in compliance with the License. 61124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * You may obtain a copy of the License at 71124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * 81124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * http://www.apache.org/licenses/LICENSE-2.0 91124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * 101124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * Unless required by applicable law or agreed to in writing, software 111124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * distributed under the License is distributed on an "AS IS" BASIS, 121124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * See the License for the specific language governing permissions and 141124090a300e96f6d1d5b0c67f3fe314daf32743John Reck * limitations under the License. 151124090a300e96f6d1d5b0c67f3fe314daf32743John Reck */ 161124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 171124090a300e96f6d1d5b0c67f3fe314daf32743John Reckpackage com.android.photos.views; 181124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 191124090a300e96f6d1d5b0c67f3fe314daf32743John Reckimport android.content.Context; 201124090a300e96f6d1d5b0c67f3fe314daf32743John Reckimport android.util.AttributeSet; 211124090a300e96f6d1d5b0c67f3fe314daf32743John Reckimport android.widget.ImageView; 221124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 231124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 241124090a300e96f6d1d5b0c67f3fe314daf32743John Reckpublic class SquareImageView extends ImageView { 251124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 261124090a300e96f6d1d5b0c67f3fe314daf32743John Reck public SquareImageView(Context context) { 271124090a300e96f6d1d5b0c67f3fe314daf32743John Reck super(context); 281124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } 291124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 301124090a300e96f6d1d5b0c67f3fe314daf32743John Reck public SquareImageView(Context context, AttributeSet attrs) { 311124090a300e96f6d1d5b0c67f3fe314daf32743John Reck super(context, attrs); 321124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } 331124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 341124090a300e96f6d1d5b0c67f3fe314daf32743John Reck public SquareImageView(Context context, AttributeSet attrs, int defStyle) { 351124090a300e96f6d1d5b0c67f3fe314daf32743John Reck super(context, attrs, defStyle); 361124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } 371124090a300e96f6d1d5b0c67f3fe314daf32743John Reck 381124090a300e96f6d1d5b0c67f3fe314daf32743John Reck @Override 391124090a300e96f6d1d5b0c67f3fe314daf32743John Reck protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 401124090a300e96f6d1d5b0c67f3fe314daf32743John Reck int widthMode = MeasureSpec.getMode(widthMeasureSpec); 411124090a300e96f6d1d5b0c67f3fe314daf32743John Reck int heightMode = MeasureSpec.getMode(heightMeasureSpec); 421124090a300e96f6d1d5b0c67f3fe314daf32743John Reck if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) { 431124090a300e96f6d1d5b0c67f3fe314daf32743John Reck int width = MeasureSpec.getSize(widthMeasureSpec); 441124090a300e96f6d1d5b0c67f3fe314daf32743John Reck int height = width; 451124090a300e96f6d1d5b0c67f3fe314daf32743John Reck if (heightMode == MeasureSpec.AT_MOST) { 461124090a300e96f6d1d5b0c67f3fe314daf32743John Reck height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec)); 471124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } 481124090a300e96f6d1d5b0c67f3fe314daf32743John Reck setMeasuredDimension(width, height); 491124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } else { 501124090a300e96f6d1d5b0c67f3fe314daf32743John Reck super.onMeasure(widthMeasureSpec, heightMeasureSpec); 511124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } 521124090a300e96f6d1d5b0c67f3fe314daf32743John Reck } 531124090a300e96f6d1d5b0c67f3fe314daf32743John Reck} 54