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:Main.java

public static void showPopWindow(Context context, View parent, int drawableId) {
    if (drawableId == 0) {
        return;/*from www. j a v a2  s. c  om*/
    }
    if (pop == null) {
        ImageView imageView = null;
        imageView = new ImageView(context);
        imageView.setBackgroundResource(drawableId);
        pop = new PopupWindow(imageView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pop != null) {
                    pop.dismiss();
                    pop = null;
                }
            }
        });
    }
    if (!pop.isShowing()) {
        pop.showAtLocation(parent, Gravity.BOTTOM, 0, 0);

    }
}

From source file:Main.java

/**
 * Toast dialog with string/*from  w w w  .j a  va 2 s .co  m*/
 */
public static void showToast(final String message, final Activity activity) {
    final Toast toast = Toast.makeText(activity, message, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.BOTTOM, 0, 0);
    toast.show();
}

From source file:Main.java

public static void showTip(Context context, int resId, boolean isInter) {
    if (null == showToast) {
        showToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    } else {//from   ww  w.  j  av  a2  s .  c  o  m
        if (isInter) {
            showToast.cancel();
            showToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
        } else {
            showToast.setText(resId);
        }
    }
    showToast.setGravity(Gravity.BOTTOM, 0, 0);
    showToast.show();
}

From source file:Main.java

public static PopupWindow showPopWindow2(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;//w  ww  . j a v a 2 s.  c o m
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    return popupWindow;
}

From source file:Main.java

/**
 * Toast dialog with string/*from w ww  .jav  a2s .  c  o  m*/
 */
public static void showToast(final String message, final Context context) {
    final Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.BOTTOM, 0, 0);
    toast.show();
}

From source file:Main.java

private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) {
    int drawablePadding = view.getCompoundDrawablePadding();
    int ratio = 1;
    float total;//  w ww .  j  a  va2  s  .co m

    switch (gravity) {
    case Gravity.RIGHT:
        ratio = -1;
    case Gravity.LEFT:
        total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth()
                + drawablePadding + view.getPaddingLeft() + view.getPaddingRight();
        canvas.translate(ratio * (view.getWidth() - total) / 2, 0);
        break;
    case Gravity.BOTTOM:
        ratio = -1;
    case Gravity.TOP:
        Paint.FontMetrics fontMetrics0 = view.getPaint().getFontMetrics();
        total = fontMetrics0.descent - fontMetrics0.ascent + drawable.getIntrinsicHeight() + drawablePadding
                + view.getPaddingTop() + view.getPaddingBottom();
        canvas.translate(0, ratio * (view.getHeight() - total) / 2);
        break;
    }
}

From source file:com.commonslibrary.commons.utils.ToastUtils.java

public static void showDefault(Object object, String message) {

    if (null == object || TextUtils.isEmpty(message)) {
        return;//from   w ww  .  j a  v  a2 s .c  o m
    }

    if (object instanceof Context) {
        show((Context) object, message, Gravity.BOTTOM);
    } else if (object instanceof Fragment) {
        show(((Fragment) object).getActivity(), message, Gravity.BOTTOM);
    }

}

From source file:Main.java

/**
 * Display a {@link Toast} letting the user know what an item does when long
 * pressed.//  ww w  .j  a  v a 2 s. c  om
 * 
 * @param view The {@link View} to copy the content description from.
 */
public static void showCheatSheet(final View view) {

    final int[] screenPos = new int[2]; // origin is device display
    final Rect displayFrame = new Rect(); // includes decorations (e.g.
                                          // status bar)
    view.getLocationOnScreen(screenPos);
    view.getWindowVisibleDisplayFrame(displayFrame);

    final Context context = view.getContext();
    final int viewWidth = view.getWidth();
    final int viewHeight = view.getHeight();
    final int viewCenterX = screenPos[0] + viewWidth / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    final int estimatedToastHeight = (int) (48 * context.getResources().getDisplayMetrics().density);

    final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(), Toast.LENGTH_SHORT);
    final boolean showBelow = screenPos[1] < estimatedToastHeight;
    if (showBelow) {
        // Show below
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                screenPos[1] - displayFrame.top + viewHeight);
    } else {
        // Show above
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                displayFrame.bottom - screenPos[1]);
    }
    cheatSheet.show();
}

From source file:com.sinyuk.jianyi.utils.list.SlideInItemAnimator.java

/**
 * Default to sliding in upward.
 */
public SlideInItemAnimator() {
    this(Gravity.BOTTOM, -1); // undefined layout dir; bottom isn't relative
}

From source file:Main.java

/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details./* ww w.ja v  a 2s .  co m*/
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.START:
        x0 = 1;
        x1 = 0;
        break;
    case Gravity.END:
        x0 = 0;
        x1 = 1;
        break;
    default:
        x0 = 0;
        x1 = 0;
        break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        y0 = 1;
        y1 = 0;
        break;
    case Gravity.BOTTOM:
        y0 = 0;
        y1 = 1;
        break;
    default:
        y0 = 0;
        y1 = 0;
        break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    return paintDrawable;
}