aboutsummaryrefslogtreecommitdiffstats
path: root/com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java
diff options
context:
space:
mode:
authorDominik <dominik@dominikschuermann.de>2012-04-20 12:14:21 +0200
committerDominik <dominik@dominikschuermann.de>2012-06-13 19:28:23 +0300
commitda96aacf55d113c9a91b8e760b3ffef88b11f786 (patch)
treeb7e5a7780af54fdb677a147a40e7218ee5bbc123 /com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java
parent784c3156dfaac289ddf5a65567385c3561426401 (diff)
downloadopen-keychain-da96aacf55d113c9a91b8e760b3ffef88b11f786.tar.gz
open-keychain-da96aacf55d113c9a91b8e760b3ffef88b11f786.tar.bz2
open-keychain-da96aacf55d113c9a91b8e760b3ffef88b11f786.zip
ActionBarSherlock 4.0.2
Diffstat (limited to 'com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java')
-rw-r--r--com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java154
1 files changed, 133 insertions, 21 deletions
diff --git a/com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java b/com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java
index 2edda7264..1b4463a59 100644
--- a/com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java
+++ b/com_actionbarsherlock/src/com/actionbarsherlock/internal/widget/IcsLinearLayout.java
@@ -10,7 +10,10 @@ import com.actionbarsherlock.internal.nineoldandroids.widget.NineLinearLayout;
/**
* A simple extension of a regular linear layout that supports the divider API
- * of Android 4.0+.
+ * of Android 4.0+. The dividers are added adjacent to the children by changing
+ * their layout params. If you need to rely on the margins which fall in the
+ * same orientation as the layout you should wrap the child in a simple
+ * {@link android.widget.FrameLayout} so it can receive the margin.
*/
public class IcsLinearLayout extends NineLinearLayout {
private static final int[] LinearLayout = new int[] {
@@ -42,6 +45,7 @@ public class IcsLinearLayout extends NineLinearLayout {
private Drawable mDivider;
private int mDividerWidth;
+ private int mDividerHeight;
private int mShowDividers;
private int mDividerPadding;
@@ -59,6 +63,29 @@ public class IcsLinearLayout extends NineLinearLayout {
}
/**
+ * Set how dividers should be shown between items in this layout
+ *
+ * @param showDividers One or more of {@link #SHOW_DIVIDER_BEGINNING},
+ * {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END},
+ * or {@link #SHOW_DIVIDER_NONE} to show no dividers.
+ */
+ public void setShowDividers(int showDividers) {
+ if (showDividers != mShowDividers) {
+ requestLayout();
+ invalidate(); //XXX This is required if you are toggling a divider off
+ }
+ mShowDividers = showDividers;
+ }
+
+ /**
+ * @return A flag set indicating how dividers should be shown around items.
+ * @see #setShowDividers(int)
+ */
+ public int getShowDividers() {
+ return mShowDividers;
+ }
+
+ /**
* Set a drawable to be used as a divider between items.
* @param divider Drawable that will divide each item.
* @see #setShowDividers(int)
@@ -70,14 +97,40 @@ public class IcsLinearLayout extends NineLinearLayout {
mDivider = divider;
if (divider != null) {
mDividerWidth = divider.getIntrinsicWidth();
+ mDividerHeight = divider.getIntrinsicHeight();
} else {
mDividerWidth = 0;
+ mDividerHeight = 0;
}
setWillNotDraw(divider == null);
requestLayout();
}
/**
+ * Set padding displayed on both ends of dividers.
+ *
+ * @param padding Padding value in pixels that will be applied to each end
+ *
+ * @see #setShowDividers(int)
+ * @see #setDividerDrawable(Drawable)
+ * @see #getDividerPadding()
+ */
+ public void setDividerPadding(int padding) {
+ mDividerPadding = padding;
+ }
+
+ /**
+ * Get the padding size used to inset dividers in pixels
+ *
+ * @see #setShowDividers(int)
+ * @see #setDividerDrawable(Drawable)
+ * @see #setDividerPadding(int)
+ */
+ public int getDividerPadding() {
+ return mDividerPadding;
+ }
+
+ /**
* Get the width of the current divider drawable.
*
* @hide Used internally by framework.
@@ -89,9 +142,27 @@ public class IcsLinearLayout extends NineLinearLayout {
@Override
protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
final int index = indexOfChild(child);
+ final int orientation = getOrientation();
+ final LayoutParams params = (LayoutParams) child.getLayoutParams();
if (hasDividerBeforeChildAt(index)) {
- //Account for the divider by pushing everything left
- ((LayoutParams)child.getLayoutParams()).leftMargin = mDividerWidth;
+ if (orientation == VERTICAL) {
+ //Account for the divider by pushing everything up
+ params.topMargin = mDividerHeight;
+ } else {
+ //Account for the divider by pushing everything left
+ params.leftMargin = mDividerWidth;
+ }
+ }
+
+ final int count = getChildCount();
+ if (index == count - 1) {
+ if (hasDividerBeforeChildAt(count)) {
+ if (orientation == VERTICAL) {
+ params.bottomMargin = mDividerHeight;
+ } else {
+ params.rightMargin = mDividerWidth;
+ }
+ }
}
super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
}
@@ -99,32 +170,73 @@ public class IcsLinearLayout extends NineLinearLayout {
@Override
protected void onDraw(Canvas canvas) {
if (mDivider != null) {
- final int count = getChildCount();
- for (int i = 0; i < count; i++) {
- final View child = getChildAt(i);
- if (child != null && child.getVisibility() != GONE) {
- if (hasDividerBeforeChildAt(i)) {
- final LayoutParams lp = (LayoutParams) child.getLayoutParams();
- final int left = child.getLeft() - lp.leftMargin;
- drawVerticalDivider(canvas, left);
- }
+ if (getOrientation() == VERTICAL) {
+ drawDividersVertical(canvas);
+ } else {
+ drawDividersHorizontal(canvas);
+ }
+ }
+ super.onDraw(canvas);
+ }
+
+ void drawDividersVertical(Canvas canvas) {
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+
+ if (child != null && child.getVisibility() != GONE) {
+ if (hasDividerBeforeChildAt(i)) {
+ final LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ final int top = child.getTop() - lp.topMargin/* - mDividerHeight*/;
+ drawHorizontalDivider(canvas, top);
}
}
+ }
+
+ if (hasDividerBeforeChildAt(count)) {
+ final View child = getChildAt(count - 1);
+ int bottom = 0;
+ if (child == null) {
+ bottom = getHeight() - getPaddingBottom() - mDividerHeight;
+ } else {
+ final LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ bottom = child.getBottom()/* + lp.bottomMargin*/;
+ }
+ drawHorizontalDivider(canvas, bottom);
+ }
+ }
- if (hasDividerBeforeChildAt(count)) {
- final View child = getChildAt(count - 1);
- int right = 0;
- if (child == null) {
- right = getWidth() - getPaddingRight() - mDividerWidth;
- } else {
+ void drawDividersHorizontal(Canvas canvas) {
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+
+ if (child != null && child.getVisibility() != GONE) {
+ if (hasDividerBeforeChildAt(i)) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
- right = child.getRight() + lp.rightMargin;
+ final int left = child.getLeft() - lp.leftMargin/* - mDividerWidth*/;
+ drawVerticalDivider(canvas, left);
}
- drawVerticalDivider(canvas, right);
}
}
- super.onDraw(canvas);
+ if (hasDividerBeforeChildAt(count)) {
+ final View child = getChildAt(count - 1);
+ int right = 0;
+ if (child == null) {
+ right = getWidth() - getPaddingRight() - mDividerWidth;
+ } else {
+ final LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ right = child.getRight()/* + lp.rightMargin*/;
+ }
+ drawVerticalDivider(canvas, right);
+ }
+ }
+
+ void drawHorizontalDivider(Canvas canvas, int top) {
+ mDivider.setBounds(getPaddingLeft() + mDividerPadding, top,
+ getWidth() - getPaddingRight() - mDividerPadding, top + mDividerHeight);
+ mDivider.draw(canvas);
}
void drawVerticalDivider(Canvas canvas, int left) {