Java Code Examples for android.support.v4.view.GravityCompat#END

The following examples show how to use android.support.v4.view.GravityCompat#END . 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: DrawerLayout.java    From letv with Apache License 2.0 6 votes vote down vote up
public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
    if (!SET_DRAWER_SHADOW_FROM_ELEVATION) {
        if ((gravity & GravityCompat.START) == GravityCompat.START) {
            this.mShadowStart = shadowDrawable;
        } else if ((gravity & GravityCompat.END) == GravityCompat.END) {
            this.mShadowEnd = shadowDrawable;
        } else if ((gravity & 3) == 3) {
            this.mShadowLeft = shadowDrawable;
        } else if ((gravity & 5) == 5) {
            this.mShadowRight = shadowDrawable;
        } else {
            return;
        }
        resolveShadowDrawables();
        invalidate();
    }
}
 
Example 2
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 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. For API 21 and above, an elevation will be set on the drawer
 * instead of the drawable provided.
 *
 * <p>Note that for better support for both left-to-right and right-to-left layout
 * directions, a drawable for RTL layout (in additional to the one in LTR layout) can be
 * defined with a resource qualifier "ldrtl" for API 17 and above with the gravity
 * {@link GravityCompat#START}. Alternatively, for API 23 and above, the drawable can
 * auto-mirrored such that the drawable will be mirrored in RTL layout.</p>
 *
 * @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.
     */
    if (SET_DRAWER_SHADOW_FROM_ELEVATION) {
        // No op. Drawer shadow will come from setting an elevation on the drawer.
        return;
    }
    if ((gravity & GravityCompat.START) == GravityCompat.START) {
        mShadowStart = shadowDrawable;
    } else if ((gravity & GravityCompat.END) == GravityCompat.END) {
        mShadowEnd = shadowDrawable;
    } else if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
    } else if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
    } else {
        return;
    }
    resolveShadowDrawables();
    invalidate();
}
 
Example 3
Source File: DrawerLayout.java    From letv with Apache License 2.0 5 votes vote down vote up
public void setDrawerLockMode(int lockMode, int edgeGravity) {
    int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    switch (edgeGravity) {
        case 3:
            this.mLockModeLeft = lockMode;
            break;
        case 5:
            this.mLockModeRight = lockMode;
            break;
        case GravityCompat.START /*8388611*/:
            this.mLockModeStart = lockMode;
            break;
        case GravityCompat.END /*8388613*/:
            this.mLockModeEnd = lockMode;
            break;
    }
    if (lockMode != 0) {
        (absGravity == 3 ? this.mLeftDragger : this.mRightDragger).cancel();
    }
    switch (lockMode) {
        case 1:
            View toClose = findDrawerWithGravity(absGravity);
            if (toClose != null) {
                closeDrawer(toClose);
                return;
            }
            return;
        case 2:
            View toOpen = findDrawerWithGravity(absGravity);
            if (toOpen != null) {
                openDrawer(toOpen);
                return;
            }
            return;
        default:
            return;
    }
}
 
Example 4
Source File: AutoLinearLayout.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
private void updateLeftPositionByGravity(ViewPosition pos, int size, int gravity) {
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case GravityCompat.END:
            pos.left += (size > 0) ? size : 0;
            break;

        case Gravity.CENTER_HORIZONTAL:
            pos.left += ((size > 0) ? size : 0) / 2;
            break;
    }
}
 
Example 5
Source File: DrawerBehavior.java    From DrawerBehavior with Apache License 2.0 5 votes vote down vote up
private static void validateGravity(int gravity) {
  if (gravity != Gravity.LEFT
      && gravity != Gravity.RIGHT
      && gravity != GravityCompat.START
      && gravity != GravityCompat.END) {
    throw new IllegalArgumentException("Only START, END, LEFT, or RIGHT gravity is supported.");
  }
}
 
Example 6
Source File: ImageStateDisplay.java    From empty-state-recyclerview with MIT License 4 votes vote down vote up
@Override
public void onDrawState(EmptyStateRecyclerView rv, Canvas canvas) {
    final int width = rv.getMeasuredWidth();
    final int height = rv.getMeasuredHeight();
    configureImage(width, height);

    final int horizontalGravity = Gravity.getAbsoluteGravity(imageGravity,
            ViewCompat.getLayoutDirection(rv))&Gravity.HORIZONTAL_GRAVITY_MASK;
    final int verticalGravity = imageGravity&Gravity.VERTICAL_GRAVITY_MASK;

    // Account for horizontal gravity
    float dx;
    switch (horizontalGravity) {
        case Gravity.CENTER_HORIZONTAL:
            dx = (width >> 1) - (image.getWidth() >> 1);
            break;
        case GravityCompat.END:
            dx = width - image.getWidth();
            break;
        default:
        case GravityCompat.START:
            dx = 0;
            break;
    }

    // Account for vertical gravity
    float dy;
    switch (verticalGravity) {
        case Gravity.CENTER_VERTICAL:
            dy = (height >> 1) - (image.getHeight() >> 1);
            break;
        case Gravity.BOTTOM:
            dy = height - image.getHeight();
            break;
        default:
        case Gravity.TOP:
            dy = 0;
            break;
    }

    // Account for the set margins
    dx -= getPaddingLeft(); // Left margin
    dx += getPaddingRight(); // Right margin
    dy += getPaddingTop(); // Top margin
    dy -= getPaddingBottom(); // Bottom margin

    // Draw bitmap using locations based on gravity
    canvas.drawBitmap(image, dx, dy, null);
}
 
Example 7
Source File: DrawerLayout.java    From letv with Apache License 2.0 4 votes vote down vote up
public int getDrawerLockMode(int edgeGravity) {
    int layoutDirection = ViewCompat.getLayoutDirection(this);
    switch (edgeGravity) {
        case 3:
            if (this.mLockModeLeft != 3) {
                return this.mLockModeLeft;
            }
            int leftLockMode = layoutDirection == 0 ? this.mLockModeStart : this.mLockModeEnd;
            if (leftLockMode != 3) {
                return leftLockMode;
            }
            break;
        case 5:
            if (this.mLockModeRight != 3) {
                return this.mLockModeRight;
            }
            int rightLockMode = layoutDirection == 0 ? this.mLockModeEnd : this.mLockModeStart;
            if (rightLockMode != 3) {
                return rightLockMode;
            }
            break;
        case GravityCompat.START /*8388611*/:
            if (this.mLockModeStart != 3) {
                return this.mLockModeStart;
            }
            int startLockMode = layoutDirection == 0 ? this.mLockModeLeft : this.mLockModeRight;
            if (startLockMode != 3) {
                return startLockMode;
            }
            break;
        case GravityCompat.END /*8388613*/:
            if (this.mLockModeEnd != 3) {
                return this.mLockModeEnd;
            }
            int endLockMode = layoutDirection == 0 ? this.mLockModeRight : this.mLockModeLeft;
            if (endLockMode != 3) {
                return endLockMode;
            }
            break;
    }
    return 0;
}
 
Example 8
Source File: RecyclerViewBanner.java    From RecyclerViewBanner with Apache License 2.0 4 votes vote down vote up
public RecyclerViewBanner(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerViewBanner);
    mInterval = a.getInt(R.styleable.RecyclerViewBanner_rvb_interval, 3000);
    isShowIndicator = a.getBoolean(R.styleable.RecyclerViewBanner_rvb_showIndicator, true);
    isAutoPlaying = a.getBoolean(R.styleable.RecyclerViewBanner_rvb_autoPlaying, true);
    Drawable sd = a.getDrawable(R.styleable.RecyclerViewBanner_rvb_indicatorSelectedSrc);
    Drawable usd = a.getDrawable(R.styleable.RecyclerViewBanner_rvb_indicatorUnselectedSrc);
    if (sd == null) {
        mSelectedDrawable = generateDefaultDrawable(DEFAULT_SELECTED_COLOR);
    } else {
        if (sd instanceof ColorDrawable) {
            mSelectedDrawable = generateDefaultDrawable(((ColorDrawable) sd).getColor());
        } else {
            mSelectedDrawable = sd;
        }
    }
    if (usd == null) {
        mUnselectedDrawable = generateDefaultDrawable(DEFAULT_UNSELECTED_COLOR);
    } else {
        if (usd instanceof ColorDrawable) {
            mUnselectedDrawable = generateDefaultDrawable(((ColorDrawable) usd).getColor());
        } else {
            mUnselectedDrawable = usd;
        }
    }
    mSize = a.getDimensionPixelSize(R.styleable.RecyclerViewBanner_rvb_indicatorSize, 0);
    mSpace = a.getDimensionPixelSize(R.styleable.RecyclerViewBanner_rvb_indicatorSpace, dp2px(4));
    int margin = a.getDimensionPixelSize(R.styleable.RecyclerViewBanner_rvb_indicatorMargin, dp2px(8));
    int g = a.getInt(R.styleable.RecyclerViewBanner_rvb_indicatorGravity, 1);
    int gravity;
    if (g == 0) {
        gravity = GravityCompat.START;
    } else if (g == 2) {
        gravity = GravityCompat.END;
    } else {
        gravity = Gravity.CENTER;
    }
    a.recycle();

    mRecyclerView = new RecyclerView(context);
    mLinearLayout = new LinearLayout(context);

    new PagerSnapHelper().attachToRecyclerView(mRecyclerView);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
    adapter = new RecyclerAdapter();
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int next = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
            if (next != currentIndex) {
                currentIndex = next;
                if (isShowIndicator && isTouched) {
                    isTouched = false;
                    switchIndicator();
                }
            }
        }
    });
    mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    mLinearLayout.setGravity(Gravity.CENTER);

    LayoutParams vpLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    LayoutParams linearLayoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayoutParams.gravity = Gravity.BOTTOM | gravity;
    linearLayoutParams.setMargins(margin, margin, margin, margin);
    addView(mRecyclerView, vpLayoutParams);
    addView(mLinearLayout, linearLayoutParams);

    // 便于在xml中编辑时观察,运行时不执行
    if (isInEditMode()) {
        for (int i = 0; i < 3; i++) {
            mData.add("");
        }
        createIndicators();
    }
}
 
Example 9
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * Enable or disable interaction with the given drawer.
 *
 * <p>This allows the application to restrict the user's ability to open or close
 * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)},
 * {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
 *
 * <p>Locking a drawer open or closed will implicitly open or close
 * that drawer as appropriate.</p>
 *
 * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
 *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END.
 *                    Expresses which drawer to change the mode for.
 *
 * @see #LOCK_MODE_UNLOCKED
 * @see #LOCK_MODE_LOCKED_CLOSED
 * @see #LOCK_MODE_LOCKED_OPEN
 */
public void setDrawerLockMode(@LockMode int lockMode, @EdgeGravity int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity,
            ViewCompat.getLayoutDirection(this));

    switch (edgeGravity) {
        case Gravity.LEFT:
            mLockModeLeft = lockMode;
            break;
        case Gravity.RIGHT:
            mLockModeRight = lockMode;
            break;
        case GravityCompat.START:
            mLockModeStart = lockMode;
            break;
        case GravityCompat.END:
            mLockModeEnd = lockMode;
            break;
    }

    if (lockMode != LOCK_MODE_UNLOCKED) {
        // Cancel interaction in progress
        final ViewDragHelper helper = absGravity == Gravity.LEFT ? mLeftDragger : mRightDragger;
        helper.cancel();
    }
    switch (lockMode) {
        case LOCK_MODE_LOCKED_OPEN:
            final View toOpen = findDrawerWithGravity(absGravity);
            if (toOpen != null) {
                openDrawer(toOpen);
            }
            break;
        case LOCK_MODE_LOCKED_CLOSED:
            final View toClose = findDrawerWithGravity(absGravity);
            if (toClose != null) {
                closeDrawer(toClose);
            }
            break;
        // default: do nothing
    }
}
 
Example 10
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 4 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}.
 */
@LockMode
public int getDrawerLockMode(@EdgeGravity int edgeGravity) {
    int layoutDirection = ViewCompat.getLayoutDirection(this);

    switch (edgeGravity) {
        case Gravity.LEFT:
            if (mLockModeLeft != LOCK_MODE_UNDEFINED) {
                return mLockModeLeft;
            }
            int leftLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ?
                    mLockModeStart : mLockModeEnd;
            if (leftLockMode != LOCK_MODE_UNDEFINED) {
                return leftLockMode;
            }
            break;
        case Gravity.RIGHT:
            if (mLockModeRight != LOCK_MODE_UNDEFINED) {
                return mLockModeRight;
            }
            int rightLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ?
                    mLockModeEnd : mLockModeStart;
            if (rightLockMode != LOCK_MODE_UNDEFINED) {
                return rightLockMode;
            }
            break;
        case GravityCompat.START:
            if (mLockModeStart != LOCK_MODE_UNDEFINED) {
                return mLockModeStart;
            }
            int startLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ?
                    mLockModeLeft : mLockModeRight;
            if (startLockMode != LOCK_MODE_UNDEFINED) {
                return startLockMode;
            }
            break;
        case GravityCompat.END:
            if (mLockModeEnd != LOCK_MODE_UNDEFINED) {
                return mLockModeEnd;
            }
            int endLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ?
                    mLockModeRight : mLockModeLeft;
            if (endLockMode != LOCK_MODE_UNDEFINED) {
                return endLockMode;
            }
            break;
    }

    return LOCK_MODE_UNLOCKED;
}
 
Example 11
Source File: CoordinatorLayout.java    From ticdesign with Apache License 2.0 2 votes vote down vote up
/**
 * Return the given gravity value or the default if the passed value is NO_GRAVITY.
 * This should be used for children that are positioned relative to a keyline.
 */
private static int resolveKeylineGravity(int gravity) {
    return gravity == Gravity.NO_GRAVITY ? GravityCompat.END | Gravity.TOP : gravity;
}