Example usage for android.view Gravity BOTTOM

List of usage examples for android.view Gravity BOTTOM

Introduction

In this page you can find the example usage for android.view Gravity BOTTOM.

Prototype

int BOTTOM

To view the source code for android.view Gravity BOTTOM.

Click Source Link

Document

Push object to the bottom of its container, not changing its size.

Usage

From source file:com.mumu.pokemongogo.HeadService.java

private void initGameControlButtons() {
    mDirectionIconList = new ArrayList<>();

    // Up button/*  w ww .j a v a 2 s  . c  o  m*/
    HeadIconView upButton = new HeadIconView(new ImageView(this), mWindowManager, 130, 160);
    upButton.getImageView().setImageResource(R.drawable.ic_arrow_up);
    upButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    upButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.NORTH, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(upButton);

    // Down button
    HeadIconView downButton = new HeadIconView(new ImageView(this), mWindowManager, 130, 0);
    downButton.getImageView().setImageResource(R.drawable.ic_arrow_down);
    downButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    downButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.SOUTH, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(downButton);

    // Left button
    HeadIconView leftButton = new HeadIconView(new ImageView(this), mWindowManager, 50, 80);
    leftButton.getImageView().setImageResource(R.drawable.ic_arrow_left);
    leftButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    leftButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.WEST, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(leftButton);

    // Right button
    HeadIconView rightButton = new HeadIconView(new ImageView(this), mWindowManager, 210, 80);
    rightButton.getImageView().setImageResource(R.drawable.ic_arrow_right);
    rightButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    rightButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.EAST, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(rightButton);

    // North West button
    HeadIconView upLeftButton = new HeadIconView(new ImageView(this), mWindowManager, 50, 160);
    upLeftButton.getImageView().setImageResource(R.drawable.ic_arrow_squart);
    upLeftButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    upLeftButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.NORTHWEST, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(upLeftButton);

    // West South button
    HeadIconView leftDownButton = new HeadIconView(new ImageView(this), mWindowManager, 50, 0);
    leftDownButton.getImageView().setImageResource(R.drawable.ic_arrow_squart);
    leftDownButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    leftDownButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.WESTSOUTH, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(leftDownButton);

    // South East button
    HeadIconView downRightButton = new HeadIconView(new ImageView(this), mWindowManager, 210, 0);
    downRightButton.getImageView().setImageResource(R.drawable.ic_arrow_squart);
    downRightButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    downRightButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.SOUTHEAST, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(downRightButton);

    // East North button
    HeadIconView rightUpButton = new HeadIconView(new ImageView(this), mWindowManager, 210, 160);
    rightUpButton.getImageView().setImageResource(R.drawable.ic_arrow_squart);
    rightUpButton.getImageView()
            .setBackgroundColor(ContextCompat.getColor(mContext, R.color.button_half_transparent));
    rightUpButton.setOnTapListener(new HeadIconView.OnTapListener() {
        @Override
        public void onTap(View view) {
            mFakeLocationManager.setSpeed(mWalkSpeed);
            mFakeLocationManager.walkPace(FakeLocation.EASTNORTH, 1.0);
        }

        @Override
        public void onLongPress(View view) {

        }
    });
    mDirectionIconList.add(rightUpButton);

    // add view and set invisible
    for (HeadIconView icon : mDirectionIconList) {
        icon.setVisibility(View.INVISIBLE);
        icon.setGravity(Gravity.BOTTOM | Gravity.START, false);
        icon.addView();
    }
}

From source file:android.support.design.widget.BaseTransientBottomBar.java

final void showView() {
    if (mView.getParent() == null) {
        final ViewGroup.LayoutParams lp = mView.getLayoutParams();

        if (lp instanceof CoordinatorLayout.LayoutParams) {
            // If our LayoutParams are from a CoordinatorLayout, we'll setup our Behavior
            final CoordinatorLayout.LayoutParams clp = (CoordinatorLayout.LayoutParams) lp;

            final Behavior behavior = new Behavior();
            behavior.setStartAlphaSwipeDistance(0.1f);
            behavior.setEndAlphaSwipeDistance(0.6f);
            behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
            behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
                @Override/* w  ww  .j a v a2 s . c  o  m*/
                public void onDismiss(View view) {
                    view.setVisibility(View.GONE);
                    dispatchDismiss(BaseCallback.DISMISS_EVENT_SWIPE);
                }

                @Override
                public void onDragStateChanged(int state) {
                    switch (state) {
                    case SwipeDismissBehavior.STATE_DRAGGING:
                    case SwipeDismissBehavior.STATE_SETTLING:
                        // If the view is being dragged or settling, pause the timeout
                        SnackbarManager.getInstance().pauseTimeout(mManagerCallback);
                        break;
                    case SwipeDismissBehavior.STATE_IDLE:
                        // If the view has been released and is idle, restore the timeout
                        SnackbarManager.getInstance().restoreTimeoutIfPaused(mManagerCallback);
                        break;
                    }
                }
            });
            clp.setBehavior(behavior);
            // Also set the inset edge so that views can dodge the bar correctly
            clp.insetEdge = Gravity.BOTTOM;
        }

        mTargetParent.addView(mView);
    }

    mView.setOnAttachStateChangeListener(new OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View v) {
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            if (isShownOrQueued()) {
                // If we haven't already been dismissed then this event is coming from a
                // non-user initiated action. Hence we need to make sure that we callback
                // and keep our state up to date. We need to post the call since
                // removeView() will call through to onDetachedFromWindow and thus overflow.
                sHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        onViewHidden(BaseCallback.DISMISS_EVENT_MANUAL);
                    }
                });
            }
        }
    });

    if (ViewCompat.isLaidOut(mView)) {
        if (shouldAnimate()) {
            // If animations are enabled, animate it in
            animateViewIn();
        } else {
            // Else if anims are disabled just call back now
            onViewShown();
        }
    } else {
        // Otherwise, add one of our layout change listeners and show it in when laid out
        mView.setOnLayoutChangeListener(new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View view, int left, int top, int right, int bottom) {
                mView.setOnLayoutChangeListener(null);

                if (shouldAnimate()) {
                    // If animations are enabled, animate it in
                    animateViewIn();
                } else {
                    // Else if anims are disabled just call back now
                    onViewShown();
                }
            }
        });
    }
}

From source file:com.jecelyin.editor.v2.widget.AnyDrawerLayout.java

public AnyDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    final float density = getResources().getDisplayMetrics().density;
    mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f);
    final float minVel = MIN_FLING_VELOCITY * density;

    mLeftCallback = new ViewDragCallback(Gravity.LEFT);
    mRightCallback = new ViewDragCallback(Gravity.RIGHT);
    mBottomCallback = new ViewDragCallback(Gravity.BOTTOM);

    mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback);
    mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    mLeftDragger.setMinVelocity(minVel);
    mLeftCallback.setDragger(mLeftDragger);

    mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback);
    mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    mRightDragger.setMinVelocity(minVel);
    mRightCallback.setDragger(mRightDragger);

    mBottomDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mBottomCallback);
    mBottomDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_BOTTOM);
    mBottomDragger.setMinVelocity(minVel);
    mBottomCallback.setDragger(mBottomDragger);

    // So that we can catch the back button
    setFocusableInTouchMode(true);//from  ww  w.j a  v  a  2s .  c o  m

    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
    if (ViewCompat.getFitsSystemWindows(this)) {
        IMPL.configureApplyInsets(this);
        mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context);
    }

    mDrawerElevation = DRAWER_ELEVATION * density;

    mNonDrawerViews = new ArrayList<View>();
}

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

/**
 * Open the specified drawer by animating it into view.
 *
 * @param gravity Gravity.TOP to move the top drawer or Gravity.BOTTOM for the bottom.
 *//*from   www.j a  v a2  s .c o m*/
void openDrawer(int gravity) {
    if (!isLaidOut()) {
        switch (gravity) {
        case Gravity.TOP:
            mShouldOpenTopDrawerAfterLayout = true;
            break;
        case Gravity.BOTTOM:
            mShouldOpenBottomDrawerAfterLayout = true;
            break;
        default: // fall out
        }
        return;
    }
    openDrawer(findDrawerWithGravity(gravity));
}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = ViewProps.TEXT_ALIGN_VERTICAL)
public void setTextAlignVertical(ReactEditText view, @Nullable String textAlignVertical) {
    if (textAlignVertical == null || "auto".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.NO_GRAVITY);
    } else if ("top".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.TOP);
    } else if ("bottom".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.BOTTOM);
    } else if ("center".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.CENTER_VERTICAL);
    } else {/*from w  w  w.ja  va2 s.c o m*/
        throw new JSApplicationIllegalArgumentException("Invalid textAlignVertical: " + textAlignVertical);
    }
}

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

final void showView() {
    if (mView.getParent() == null) {

        final ViewGroup.LayoutParams lp = mView.getLayoutParams();
        if (lp instanceof CoordinatorLayout.LayoutParams) {
            // If our LayoutParams are from a CoordinatorLayout, we'll setup our Behavior
            final CoordinatorLayout.LayoutParams clp = (CoordinatorLayout.LayoutParams) lp;
            final Behavior behavior = new Behavior();
            behavior.setStartAlphaSwipeDistance(0.1f);
            behavior.setEndAlphaSwipeDistance(0.6f);
            behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
            behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
                @Override/*w w  w. jav a2s  .  c  o  m*/
                public void onDismiss(View view) {
                    view.setVisibility(View.GONE);
                    dispatchDismiss(BaseCallback.DISMISS_EVENT_SWIPE);
                }

                @Override
                public void onDragStateChanged(int state) {
                    switch (state) {
                    case SwipeDismissBehavior.STATE_DRAGGING:
                    case SwipeDismissBehavior.STATE_SETTLING:
                        // If the view is being dragged or settling, pause the timeout
                        SnackbarManager.getInstance().pauseTimeout(mManagerCallback);
                        break;
                    case SwipeDismissBehavior.STATE_IDLE:
                        // If the view has been released and is idle, restore the timeout
                        SnackbarManager.getInstance().restoreTimeoutIfPaused(mManagerCallback);
                        break;
                    }
                }
            });
            clp.setBehavior(behavior);
            // Also set the inset edge so that views can dodge the bar correctly
            clp.insetEdge = Gravity.BOTTOM;
        }
        mTargetParent.addView(mView);
    }

    mView.setOnAttachStateChangeListener(new BaseTransientBottomBar.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View v) {
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            if (isShownOrQueued()) {
                // If we haven't already been dismissed then this event is coming from a
                // non-user initiated action. Hence we need to make sure that we callback
                // and keep our state up to date. We need to post the call since
                // removeView() will call through to onDetachedFromWindow and thus overflow.
                sHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        onViewHidden(BaseCallback.DISMISS_EVENT_MANUAL);
                    }
                });
            }
        }
    });

    if (ViewCompat.isLaidOut(mView)) {
        if (shouldAnimate()) {
            // If animations are enabled, animate it in
            animateViewIn();
        } else {
            // Else if anims are disabled just call back now
            onViewShown();
        }
    } else {
        // Otherwise, add one of our layout change listeners and show it in when laid out
        mView.setOnLayoutChangeListener(new BaseTransientBottomBar.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View view, int left, int top, int right, int bottom) {
                mView.setOnLayoutChangeListener(null);
                if (shouldAnimate()) {
                    // If animations are enabled, animate it in
                    animateViewIn();
                } else {
                    // Else if anims are disabled just call back now
                    onViewShown();
                }
            }
        });
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java

final void showView() {
    if (mView.getParent() == null) {
        final ViewGroup.LayoutParams lp = mView.getLayoutParams();

        if (lp instanceof CoordinatorLayout.LayoutParams) {
            // If our LayoutParams are from a CoordinatorLayout, we'll setup our Behavior
            final CoordinatorLayout.LayoutParams clp = (CoordinatorLayout.LayoutParams) lp;

            final Behavior behavior = new Behavior();
            behavior.setStartAlphaSwipeDistance(0.1f);
            behavior.setEndAlphaSwipeDistance(0.6f);
            behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
            behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
                @Override/*ww w.j a va  2  s .c om*/
                public void onDismiss(View view) {
                    view.setVisibility(View.GONE);
                    dispatchDismiss(BaseCallback.DISMISS_EVENT_SWIPE);
                }

                @Override
                public void onDragStateChanged(int state) {
                    switch (state) {
                    case SwipeDismissBehavior.STATE_DRAGGING:
                    case SwipeDismissBehavior.STATE_SETTLING:
                        // If the view is being dragged or settling, pause the timeout
                        SnackbarManager.getInstance().pauseTimeout(mManagerCallback);
                        break;
                    case SwipeDismissBehavior.STATE_IDLE:
                        // If the view has been released and is idle, restore the timeout
                        SnackbarManager.getInstance().restoreTimeoutIfPaused(mManagerCallback);
                        break;
                    }
                }
            });
            clp.setBehavior(behavior);
            // Also set the inset edge so that views can dodge the bar correctly
            clp.insetEdge = Gravity.BOTTOM;
        }

        mTargetParent.addView(mView);
    }

    mView.setOnAttachStateChangeListener(new BaseTransientBottomBar.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View v) {
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            if (isShownOrQueued()) {
                // If we haven't already been dismissed then this event is coming from a
                // non-user initiated action. Hence we need to make sure that we callback
                // and keep our state up to date. We need to post the call since
                // removeView() will call through to onDetachedFromWindow and thus overflow.
                sHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        onViewHidden(BaseCallback.DISMISS_EVENT_MANUAL);
                    }
                });
            }
        }
    });

    if (ViewCompat.isLaidOut(mView)) {
        if (shouldAnimate()) {
            // If animations are enabled, animate it in
            animateViewIn();
        } else {
            // Else if anims are disabled just call back now
            onViewShown();
        }
    } else {
        // Otherwise, add one of our layout change listeners and show it in when laid out
        mView.setOnLayoutChangeListener(new BaseTransientBottomBar.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View view, int left, int top, int right, int bottom) {
                mView.setOnLayoutChangeListener(null);

                if (shouldAnimate()) {
                    // If animations are enabled, animate it in
                    animateViewIn();
                } else {
                    // Else if anims are disabled just call back now
                    onViewShown();
                }
            }
        });
    }
}

From source file:com.itsronald.widget.ViewPagerIndicator.java

/**
 * Calculate the starting vertical position for the line of indicator dots.
 * @return The first Y coordinate where the indicator dots start.
 *///from w  w  w .  j a  va  2 s  . c  o  m
@Px
private int calculateIndicatorDotTop() {
    final int top;
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
    switch (verticalGravity) {
    default:
    case Gravity.CENTER_VERTICAL:
        top = (getHeight() - getPaddingTop() - getPaddingBottom()) / 2 - getDotRadius();
        break;
    case Gravity.TOP:
        top = getPaddingTop();
        break;
    case Gravity.BOTTOM:
        top = getHeight() - getPaddingBottom() - 2 * getDotRadius();
        break;
    }
    return top;
}

From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

/**
 * 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}.
 *///from   w ww . java  2  s. c o m
public int getDrawerLockMode(int edgeGravity) {
    final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGrav == Gravity.TOP) {
        return mLockModeTop;
    } else if (absGrav == Gravity.BOTTOM) {
        return mLockModeBottom;
    }
    return LOCK_MODE_UNLOCKED;
}

From source file:android.support.v7.widget.LinearLayoutCompat.java

@Override
public int getBaseline() {
    if (mBaselineAlignedChildIndex < 0) {
        return super.getBaseline();
    }/*from   ww  w  .  ja  va2 s.  c om*/

    if (getChildCount() <= mBaselineAlignedChildIndex) {
        throw new RuntimeException(
                "mBaselineAlignedChildIndex of LinearLayout " + "set to an index that is out of bounds.");
    }

    final View child = getChildAt(mBaselineAlignedChildIndex);
    final int childBaseline = child.getBaseline();

    if (childBaseline == -1) {
        if (mBaselineAlignedChildIndex == 0) {
            // this is just the default case, safe to return -1
            return -1;
        }
        // the user picked an index that points to something that doesn't
        // know how to calculate its baseline.
        throw new RuntimeException("mBaselineAlignedChildIndex of LinearLayout "
                + "points to a View that doesn't know how to get its baseline.");
    }

    // TODO: This should try to take into account the virtual offsets
    // (See getNextLocationOffset and getLocationOffset)
    // We should add to childTop:
    // sum([getNextLocationOffset(getChildAt(i)) / i < mBaselineAlignedChildIndex])
    // and also add:
    // getLocationOffset(child)
    int childTop = mBaselineChildTop;

    if (mOrientation == VERTICAL) {
        final int majorGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
        if (majorGravity != Gravity.TOP) {
            switch (majorGravity) {
            case Gravity.BOTTOM:
                childTop = getBottom() - getTop() - getPaddingBottom() - mTotalLength;
                break;

            case Gravity.CENTER_VERTICAL:
                childTop += ((getBottom() - getTop() - getPaddingTop() - getPaddingBottom()) - mTotalLength)
                        / 2;
                break;
            }
        }
    }

    LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
    return childTop + lp.topMargin + childBaseline;
}