| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.app; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.util.AttributeSet; |
| 21 |
import android.view.MotionEvent; |
| 22 |
import android.view.View; |
| 23 |
|
| 24 |
import com.android.internal.widget.ViewPager; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class ResolverViewPager extends ViewPager { |
| 33 |
|
| 34 |
private boolean mSwipingEnabled = true; |
| 35 |
|
| 36 |
public ResolverViewPager(Context context) { |
| 37 |
super(context); |
| 38 |
} |
| 39 |
|
| 40 |
public ResolverViewPager(Context context, AttributeSet attrs) { |
| 41 |
super(context, attrs); |
| 42 |
} |
| 43 |
|
| 44 |
public ResolverViewPager(Context context, AttributeSet attrs, int defStyleAttr) { |
| 45 |
super(context, attrs, defStyleAttr); |
| 46 |
} |
| 47 |
|
| 48 |
public ResolverViewPager(Context context, AttributeSet attrs, |
| 49 |
int defStyleAttr, int defStyleRes) { |
| 50 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 55 |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 56 |
if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.AT_MOST) { |
| 57 |
return; |
| 58 |
} |
| 59 |
widthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY); |
| 60 |
int height = getMeasuredHeight(); |
| 61 |
int maxHeight = 0; |
| 62 |
for (int i = 0; i < getChildCount(); i++) { |
| 63 |
View child = getChildAt(i); |
| 64 |
child.measure(widthMeasureSpec, |
| 65 |
MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); |
| 66 |
if (maxHeight < child.getMeasuredHeight()) { |
| 67 |
maxHeight = child.getMeasuredHeight(); |
| 68 |
} |
| 69 |
} |
| 70 |
if (maxHeight > 0) { |
| 71 |
height = maxHeight; |
| 72 |
} |
| 73 |
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); |
| 74 |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
void setSwipingEnabled(boolean swipingEnabled) { |
| 82 |
mSwipingEnabled = swipingEnabled; |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 87 |
return !isLayoutRtl() && mSwipingEnabled && super.onInterceptTouchEvent(ev); |
| 88 |
} |
| 89 |
} |