| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
import android.content.Context; |
| 21 |
import android.os.Build; |
| 22 |
import android.util.AttributeSet; |
| 23 |
import android.widget.ImageView; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class PreferenceImageView extends ImageView { |
| 29 |
|
| 30 |
public PreferenceImageView(Context context) { |
| 31 |
this(context, null); |
| 32 |
} |
| 33 |
|
| 34 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 35 |
public PreferenceImageView(Context context, AttributeSet attrs) { |
| 36 |
this(context, attrs, 0); |
| 37 |
} |
| 38 |
|
| 39 |
public PreferenceImageView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 40 |
this(context, attrs, defStyleAttr, 0); |
| 41 |
} |
| 42 |
|
| 43 |
public PreferenceImageView(Context context, AttributeSet attrs, int defStyleAttr, |
| 44 |
int defStyleRes) { |
| 45 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 50 |
final int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
| 51 |
if (widthMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.UNSPECIFIED) { |
| 52 |
final int widthSize = MeasureSpec.getSize(widthMeasureSpec); |
| 53 |
final int maxWidth = getMaxWidth(); |
| 54 |
if (maxWidth != Integer.MAX_VALUE |
| 55 |
&& (maxWidth < widthSize || widthMode == MeasureSpec.UNSPECIFIED)) { |
| 56 |
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
final int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
| 61 |
if (heightMode == MeasureSpec.AT_MOST || heightMode == MeasureSpec.UNSPECIFIED) { |
| 62 |
final int heightSize = MeasureSpec.getSize(heightMeasureSpec); |
| 63 |
final int maxHeight = getMaxHeight(); |
| 64 |
if (maxHeight != Integer.MAX_VALUE |
| 65 |
&& (maxHeight < heightSize || heightMode == MeasureSpec.UNSPECIFIED)) { |
| 66 |
heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 71 |
} |
| 72 |
} |