diff options
author | John Reck <jreck@google.com> | 2013-03-12 12:55:27 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2013-03-12 13:09:01 -0700 |
commit | 2594ea2c0c650c6f0d03ce5575315dfd0787d189 (patch) | |
tree | aee765fd4b241c22212dd4a7d150a847dfd045ea /src/com/android/photos/views | |
parent | 05a480847362eb9dbf57f73c83092e6a67f919f4 (diff) | |
download | android_packages_apps_Snap-2594ea2c0c650c6f0d03ce5575315dfd0787d189.tar.gz android_packages_apps_Snap-2594ea2c0c650c6f0d03ce5575315dfd0787d189.tar.bz2 android_packages_apps_Snap-2594ea2c0c650c6f0d03ce5575315dfd0787d189.zip |
Fix ICS compatibility issues
Change-Id: I43f3236b9da0424fde66d3ad4d46403223fde8bf
Diffstat (limited to 'src/com/android/photos/views')
-rw-r--r-- | src/com/android/photos/views/SquareImageView.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/com/android/photos/views/SquareImageView.java b/src/com/android/photos/views/SquareImageView.java new file mode 100644 index 000000000..14eff1077 --- /dev/null +++ b/src/com/android/photos/views/SquareImageView.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.photos.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ImageView; + + +public class SquareImageView extends ImageView { + + public SquareImageView(Context context) { + super(context); + } + + public SquareImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SquareImageView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) { + int width = MeasureSpec.getSize(widthMeasureSpec); + int height = width; + if (heightMode == MeasureSpec.AT_MOST) { + height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec)); + } + setMeasuredDimension(width, height); + } else { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + } +} |