| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.preference; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.content.res.TypedArray; |
| 21 |
import android.util.AttributeSet; |
| 22 |
import android.view.View; |
| 23 |
import android.widget.FrameLayout; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
@Deprecated |
| 35 |
public class PreferenceFrameLayout extends FrameLayout { |
| 36 |
private static final int DEFAULT_BORDER_TOP = 0; |
| 37 |
private static final int DEFAULT_BORDER_BOTTOM = 0; |
| 38 |
private static final int DEFAULT_BORDER_LEFT = 0; |
| 39 |
private static final int DEFAULT_BORDER_RIGHT = 0; |
| 40 |
private final int mBorderTop; |
| 41 |
private final int mBorderBottom; |
| 42 |
private final int mBorderLeft; |
| 43 |
private final int mBorderRight; |
| 44 |
private boolean mPaddingApplied; |
| 45 |
|
| 46 |
public PreferenceFrameLayout(Context context) { |
| 47 |
this(context, null); |
| 48 |
} |
| 49 |
|
| 50 |
public PreferenceFrameLayout(Context context, AttributeSet attrs) { |
| 51 |
this(context, attrs, com.android.internal.R.attr.preferenceFrameLayoutStyle); |
| 52 |
} |
| 53 |
|
| 54 |
public PreferenceFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { |
| 55 |
this(context, attrs, defStyleAttr, 0); |
| 56 |
} |
| 57 |
|
| 58 |
public PreferenceFrameLayout( |
| 59 |
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 60 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 61 |
final TypedArray a = context.obtainStyledAttributes(attrs, |
| 62 |
com.android.internal.R.styleable.PreferenceFrameLayout, defStyleAttr, defStyleRes); |
| 63 |
|
| 64 |
float density = context.getResources().getDisplayMetrics().density; |
| 65 |
int defaultBorderTop = (int) (density * DEFAULT_BORDER_TOP + 0.5f); |
| 66 |
int defaultBottomPadding = (int) (density * DEFAULT_BORDER_BOTTOM + 0.5f); |
| 67 |
int defaultLeftPadding = (int) (density * DEFAULT_BORDER_LEFT + 0.5f); |
| 68 |
int defaultRightPadding = (int) (density * DEFAULT_BORDER_RIGHT + 0.5f); |
| 69 |
|
| 70 |
mBorderTop = a.getDimensionPixelSize( |
| 71 |
com.android.internal.R.styleable.PreferenceFrameLayout_borderTop, |
| 72 |
defaultBorderTop); |
| 73 |
mBorderBottom = a.getDimensionPixelSize( |
| 74 |
com.android.internal.R.styleable.PreferenceFrameLayout_borderBottom, |
| 75 |
defaultBottomPadding); |
| 76 |
mBorderLeft = a.getDimensionPixelSize( |
| 77 |
com.android.internal.R.styleable.PreferenceFrameLayout_borderLeft, |
| 78 |
defaultLeftPadding); |
| 79 |
mBorderRight = a.getDimensionPixelSize( |
| 80 |
com.android.internal.R.styleable.PreferenceFrameLayout_borderRight, |
| 81 |
defaultRightPadding); |
| 82 |
|
| 83 |
a.recycle(); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
@Override |
| 90 |
public LayoutParams generateLayoutParams(AttributeSet attrs) { |
| 91 |
return new LayoutParams(getContext(), attrs); |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
public void addView(View child) { |
| 96 |
int borderTop = getPaddingTop(); |
| 97 |
int borderBottom = getPaddingBottom(); |
| 98 |
int borderLeft = getPaddingLeft(); |
| 99 |
int borderRight = getPaddingRight(); |
| 100 |
|
| 101 |
android.view.ViewGroup.LayoutParams params = child.getLayoutParams(); |
| 102 |
LayoutParams layoutParams = params instanceof PreferenceFrameLayout.LayoutParams |
| 103 |
? (PreferenceFrameLayout.LayoutParams) child.getLayoutParams() : null; |
| 104 |
|
| 105 |
if (layoutParams != null && layoutParams.removeBorders) { |
| 106 |
if (mPaddingApplied) { |
| 107 |
borderTop -= mBorderTop; |
| 108 |
borderBottom -= mBorderBottom; |
| 109 |
borderLeft -= mBorderLeft; |
| 110 |
borderRight -= mBorderRight; |
| 111 |
mPaddingApplied = false; |
| 112 |
} |
| 113 |
} else { |
| 114 |
|
| 115 |
|
| 116 |
if (!mPaddingApplied) { |
| 117 |
borderTop += mBorderTop; |
| 118 |
borderBottom += mBorderBottom; |
| 119 |
borderLeft += mBorderLeft; |
| 120 |
borderRight += mBorderRight; |
| 121 |
mPaddingApplied = true; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
int previousTop = getPaddingTop(); |
| 126 |
int previousBottom = getPaddingBottom(); |
| 127 |
int previousLeft = getPaddingLeft(); |
| 128 |
int previousRight = getPaddingRight(); |
| 129 |
if (previousTop != borderTop || previousBottom != borderBottom |
| 130 |
|| previousLeft != borderLeft || previousRight != borderRight) { |
| 131 |
setPadding(borderLeft, borderTop, borderRight, borderBottom); |
| 132 |
} |
| 133 |
|
| 134 |
super.addView(child); |
| 135 |
} |
| 136 |
|
| 137 |
public static class LayoutParams extends FrameLayout.LayoutParams { |
| 138 |
public boolean removeBorders = false; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public LayoutParams(Context c, AttributeSet attrs) { |
| 143 |
super(c, attrs); |
| 144 |
|
| 145 |
TypedArray a = c.obtainStyledAttributes(attrs, |
| 146 |
com.android.internal.R.styleable.PreferenceFrameLayout_Layout); |
| 147 |
removeBorders = a.getBoolean( |
| 148 |
com.android.internal.R.styleable.PreferenceFrameLayout_Layout_layout_removeBorders, |
| 149 |
false); |
| 150 |
a.recycle(); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public LayoutParams(int width, int height) { |
| 157 |
super(width, height); |
| 158 |
} |
| 159 |
} |
| 160 |
} |