| 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.annotation.Nullable; |
| 20 |
import android.content.Context; |
| 21 |
import android.util.AttributeSet; |
| 22 |
import android.widget.FrameLayout; |
| 23 |
import android.widget.RemoteViews; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@RemoteViews.RemoteView |
| 36 |
public class NotificationMaxHeightFrameLayout extends FrameLayout { |
| 37 |
private final int mNotificationMaxHeight; |
| 38 |
|
| 39 |
public NotificationMaxHeightFrameLayout(Context context) { |
| 40 |
this(context, null, 0, 0); |
| 41 |
} |
| 42 |
|
| 43 |
public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs) { |
| 44 |
this(context, attrs, 0, 0); |
| 45 |
} |
| 46 |
|
| 47 |
public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs, |
| 48 |
int defStyleAttr) { |
| 49 |
this(context, attrs, defStyleAttr, 0); |
| 50 |
} |
| 51 |
|
| 52 |
public NotificationMaxHeightFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, |
| 53 |
int defStyleRes) { |
| 54 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 55 |
|
| 56 |
mNotificationMaxHeight = getFontScaledHeight(mContext, |
| 57 |
com.android.internal.R.dimen.notification_min_height); |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 62 |
if (MeasureSpec.getSize(heightMeasureSpec) > mNotificationMaxHeight) { |
| 63 |
final int mode = MeasureSpec.getMode(heightMeasureSpec); |
| 64 |
heightMeasureSpec = MeasureSpec.makeMeasureSpec(mNotificationMaxHeight, mode); |
| 65 |
} |
| 66 |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
private static int getFontScaledHeight(Context context, int dimenId) { |
| 76 |
final int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId); |
| 77 |
final float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity |
| 78 |
/ context.getResources().getDisplayMetrics().density); |
| 79 |
return (int) (dimensionPixelSize * factor); |
| 80 |
} |
| 81 |
} |