Java Code Examples for android.support.v4.view.GravityCompat#getAbsoluteGravity()

The following examples show how to use android.support.v4.view.GravityCompat#getAbsoluteGravity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KlyphDrawerLayout.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Set a simple drawable used for the left or right shadow.
 * The drawable provided must have a nonzero intrinsic width.
 *
 * @param shadowDrawable Shadow drawable to use at the edge of a drawer
 * @param gravity Which drawer the shadow should apply to
 */
public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
    /*
     * TODO Someone someday might want to set more complex drawables here.
     * They're probably nuts, but we might want to consider registering callbacks,
     * setting states, etc. properly.
     */

    final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
            ViewCompat.getLayoutDirection(this));
    if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
        invalidate();
    }
}
 
Example 2
Source File: DrawerLayout.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Set a simple drawable used for the left or right shadow.
 * The drawable provided must have a nonzero intrinsic width.
 *
 * @param shadowDrawable Shadow drawable to use at the edge of a drawer
 * @param gravity Which drawer the shadow should apply to
 */
public void setDrawerShadow(Drawable shadowDrawable, @EdgeGravity int gravity) {
    /*
     * TODO Someone someday might want to set more complex drawables here.
     * They're probably nuts, but we might want to consider registering callbacks,
     * setting states, etc. properly.
     */

    final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
            ViewCompat.getLayoutDirection(this));
    if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
        invalidate();
    }
}
 
Example 3
Source File: DrawerLayout.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Check the lock mode of the drawer with the given gravity.
 *
 * @param edgeGravity Gravity of the drawer to check
 * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
 *         {@link #LOCK_MODE_LOCKED_OPEN}.
 */
public int getDrawerLockMode(int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(
            edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.LEFT) {
        return mLockModeLeft;
    } else if (absGravity == Gravity.RIGHT) {
        return mLockModeRight;
    }
    return LOCK_MODE_UNLOCKED;
}
 
Example 4
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the title of the drawer with the given gravity.
 *
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to return the title for.
 * @return The title of the drawer, or null if none set.
 * @see #setDrawerTitle(int, CharSequence)
 */
@Nullable
public CharSequence getDrawerTitle(@EdgeGravity int edgeGravity) {
  final int absGravity = GravityCompat.getAbsoluteGravity(
      edgeGravity, ViewCompat.getLayoutDirection(this));
  if (absGravity == Gravity.LEFT) {
    return mTitleLeft;
  } else if (absGravity == Gravity.RIGHT) {
    return mTitleRight;
  }
  return null;
}
 
Example 5
Source File: DrawerLayout.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Open the specified drawer by animating it out of view.
 *
 * @param gravity Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
 *                GravityCompat.START or GravityCompat.END may also be used.
 */
public void openDrawer(int gravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
            ViewCompat.getLayoutDirection(this));
    final View drawerView = findDrawerWithGravity(absGravity);

    if (drawerView == null) {
        throw new IllegalArgumentException("No drawer view found with absolute gravity " +
                gravityToString(absGravity));
    }
    openDrawer(drawerView);
}
 
Example 6
Source File: DrawerLayout.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public void openDrawer(int i1)
{
    int j1 = GravityCompat.getAbsoluteGravity(i1, ViewCompat.getLayoutDirection(this));
    View view = a(j1);
    if (view == null)
    {
        throw new IllegalArgumentException((new StringBuilder()).append("No drawer view found with absolute gravity ").append(b(j1)).toString());
    } else
    {
        openDrawer(view);
        return;
    }
}
 
Example 7
Source File: DrawerLayout.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the lock mode of the drawer with the given gravity.
 *
 * @param edgeGravity Gravity of the drawer to check
 * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
 *         {@link #LOCK_MODE_LOCKED_OPEN}.
 */
public int getDrawerLockMode(int edgeGravity) {
    final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity,
            ViewCompat.getLayoutDirection(this));
    if (absGrav == Gravity.LEFT) {
        return mLockModeLeft;
    } else if (absGrav == Gravity.RIGHT) {
        return mLockModeRight;
    }
    return LOCK_MODE_UNLOCKED;
}
 
Example 8
Source File: DrawerLayout.java    From letv with Apache License 2.0 5 votes vote down vote up
public void setDrawerTitle(int edgeGravity, CharSequence title) {
    int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == 3) {
        this.mTitleLeft = title;
    } else if (absGravity == 5) {
        this.mTitleRight = title;
    }
}
 
Example 9
Source File: DrawerLayout.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * @param gravity the gravity of the child to return. If specified as a
 *            relative value, it will be resolved according to the current
 *            layout direction.
 * @return the drawer with the specified gravity
 */
View findDrawerWithGravity(int gravity) {
    final int absHorizGravity = GravityCompat.getAbsoluteGravity(
            gravity, ViewCompat.getLayoutDirection(this)) & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
        if ((childAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == absHorizGravity) {
            return child;
        }
    }
    return null;
}
 
Example 10
Source File: DrawerLayout.java    From letv with Apache License 2.0 4 votes vote down vote up
int getDrawerViewAbsoluteGravity(View drawerView) {
    return GravityCompat.getAbsoluteGravity(((LayoutParams) drawerView.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(this));
}
 
Example 11
Source File: DrawerLayout.java    From letv with Apache License 2.0 4 votes vote down vote up
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    if (!(widthMode == 1073741824 && heightMode == 1073741824)) {
        if (isInEditMode()) {
            if (widthMode != Integer.MIN_VALUE) {
                if (widthMode == 0) {
                    widthSize = 300;
                }
            }
            if (heightMode != Integer.MIN_VALUE) {
                if (heightMode == 0) {
                    heightSize = 300;
                }
            }
        } else {
            throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY.");
        }
    }
    setMeasuredDimension(widthSize, heightSize);
    boolean applyInsets = this.mLastInsets != null && ViewCompat.getFitsSystemWindows(this);
    int layoutDirection = ViewCompat.getLayoutDirection(this);
    boolean hasDrawerOnLeftEdge = false;
    boolean hasDrawerOnRightEdge = false;
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != 8) {
            MarginLayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (applyInsets) {
                int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);
                if (ViewCompat.getFitsSystemWindows(child)) {
                    IMPL.dispatchChildInsets(child, this.mLastInsets, cgrav);
                } else {
                    IMPL.applyMarginInsets(lp, this.mLastInsets, cgrav);
                }
            }
            if (isContentView(child)) {
                child.measure(MeasureSpec.makeMeasureSpec((widthSize - lp.leftMargin) - lp.rightMargin, 1073741824), MeasureSpec.makeMeasureSpec((heightSize - lp.topMargin) - lp.bottomMargin, 1073741824));
            } else if (isDrawerView(child)) {
                if (SET_DRAWER_SHADOW_FROM_ELEVATION && ViewCompat.getElevation(child) != this.mDrawerElevation) {
                    ViewCompat.setElevation(child, this.mDrawerElevation);
                }
                int childGravity = getDrawerViewAbsoluteGravity(child) & 7;
                boolean isLeftEdgeDrawer = childGravity == 3;
                if (!(isLeftEdgeDrawer && hasDrawerOnLeftEdge) && (isLeftEdgeDrawer || !hasDrawerOnRightEdge)) {
                    if (isLeftEdgeDrawer) {
                        hasDrawerOnLeftEdge = true;
                    } else {
                        hasDrawerOnRightEdge = true;
                    }
                    child.measure(getChildMeasureSpec(widthMeasureSpec, (this.mMinDrawerMargin + lp.leftMargin) + lp.rightMargin, lp.width), getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height));
                } else {
                    throw new IllegalStateException("Child drawer has absolute gravity " + gravityToString(childGravity) + " but this " + TAG + " already has a " + "drawer view along that edge");
                }
            } else {
                throw new IllegalStateException("Child " + child + " at index " + i + " does not have a valid layout_gravity - must be Gravity.LEFT, " + "Gravity.RIGHT or Gravity.NO_GRAVITY");
            }
        }
    }
}
 
Example 12
Source File: FoldingDrawerLayout.java    From Folding-Android with Apache License 2.0 4 votes vote down vote up
boolean isDrawerView2(View child) {
	final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
	final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
			ViewCompat.getLayoutDirection(child));
	return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0;
}
 
Example 13
Source File: DrawerLayout.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
boolean isDrawerView(View child) {
    final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
    final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
            ViewCompat.getLayoutDirection(child));
    return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0;
}
 
Example 14
Source File: MarginDrawerLayout.java    From something.apk with MIT License 4 votes vote down vote up
/**
 * @return the absolute gravity of the child drawerView, resolved according
 *         to the current layout direction
 */
int getDrawerViewAbsoluteGravity(View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
}
 
Example 15
Source File: BottomDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
int getDrawerViewAbsoluteGravity(View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
}
 
Example 16
Source File: KlyphDrawerLayout.java    From Klyph with MIT License 4 votes vote down vote up
int getDrawerViewGravity(View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(drawerView));
}
 
Example 17
Source File: DrawerLayout.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
boolean isDrawerView(View child) {
    final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
    final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
            ViewCompat.getLayoutDirection(child));
    return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0;
}
 
Example 18
Source File: DrawerLayout.java    From adt-leanback-support with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the title of the drawer with the given gravity.
 * <p>
 * When accessibility is turned on, this is the title that will be used to
 * identify the drawer to the active accessibility service.
 *
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to set the title for.
 * @param title The title for the drawer.
 */
public void setDrawerTitle(@EdgeGravity int edgeGravity, CharSequence title) {
    final int absGravity = GravityCompat.getAbsoluteGravity(
            edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.LEFT) {
        mTitleLeft = title;
    } else if (absGravity == Gravity.RIGHT) {
        mTitleRight = title;
    }
}
 
Example 19
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the title of the drawer with the given gravity.
 * <p>
 * When accessibility is turned on, this is the title that will be used to
 * identify the drawer to the active accessibility service.
 *
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to set the title for.
 * @param title The title for the drawer.
 */
public void setDrawerTitle(@EdgeGravity int edgeGravity, CharSequence title) {
    final int absGravity = GravityCompat.getAbsoluteGravity(
            edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.LEFT) {
        mTitleLeft = title;
    } else if (absGravity == Gravity.RIGHT) {
        mTitleRight = title;
    }
}
 
Example 20
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the title of the drawer with the given gravity.
 * <p>
 * When accessibility is turned on, this is the title that will be used to
 * identify the drawer to the active accessibility service.
 *
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to set the title for.
 * @param title The title for the drawer.
 */
public void setDrawerTitle(@EdgeGravity int edgeGravity, CharSequence title) {
  final int absGravity = GravityCompat.getAbsoluteGravity(
      edgeGravity, ViewCompat.getLayoutDirection(this));
  if (absGravity == Gravity.LEFT) {
    mTitleLeft = title;
  } else if (absGravity == Gravity.RIGHT) {
    mTitleRight = title;
  }
}