2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.andrew.apollo.widgets;
14 import android.content.Context;
15 import android.util.AttributeSet;
16 import android.widget.ImageView;
19 * A custom {@link ImageView} that is sized to be a perfect square, otherwise
20 * functions like a typical {@link ImageView}.
22 * @author Andrew Neal (andrewdneal@gmail.com)
24 public class SquareImageView extends LayoutSuppressingImageView {
27 * @param context The {@link Context} to use
28 * @param attrs The attributes of the XML tag that is inflating the view.
30 public SquareImageView(final Context context, final AttributeSet attrs) {
31 super(context, attrs);
39 public void onMeasure(final int widthSpec, final int heightSpec) {
40 super.onMeasure(widthSpec, heightSpec);
41 final int mSize = Math.min(getMeasuredWidth(), getMeasuredHeight());
42 setMeasuredDimension(mSize, mSize);