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