OSDN Git Service

6bf45767d0f51be08f6409cd1ba283656fd2b737
[android-x86/packages-apps-Eleven.git] / src / com / andrew / apollo / widgets / SquareImageView.java
1 /*
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.
10  */
11
12 package com.andrew.apollo.widgets;
13
14 import android.content.Context;
15 import android.util.AttributeSet;
16 import android.widget.ImageView;
17
18 /**
19  * A custom {@link ImageView} that is sized to be a perfect square, otherwise
20  * functions like a typical {@link ImageView}.
21  * 
22  * @author Andrew Neal (andrewdneal@gmail.com)
23  */
24 public class SquareImageView extends LayoutSuppressingImageView {
25
26     /**
27      * @param context The {@link Context} to use
28      * @param attrs The attributes of the XML tag that is inflating the view.
29      */
30     public SquareImageView(final Context context, final AttributeSet attrs) {
31         super(context, attrs);
32
33     }
34
35     /**
36      * {@inheritDoc}
37      */
38     @Override
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);
43     }
44
45 }