Example usage for android.view Gravity TOP

List of usage examples for android.view Gravity TOP

Introduction

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

Prototype

int TOP

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

Click Source Link

Document

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

Usage

From source file:Main.java

public static void toastMsg(String msg, Context con) {
    Toast toast = Toast.makeText(con.getApplicationContext(), msg, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 80);
    toast.show();/*from  w  w w.j  a v  a  2 s .c om*/
}

From source file:Main.java

public static void longToast(int string, Context ctx) {
    Toast t = new Toast(ctx).makeText(ctx, string, Toast.LENGTH_LONG);
    t.setGravity(Gravity.TOP, 0, dpToPx(55, ctx));
    t.show();/*from w  w w  . j  av  a 2  s . co m*/
}

From source file:Main.java

public static void shortToast(int string, Context ctx) {
    Toast t = new Toast(ctx).makeText(ctx, string, Toast.LENGTH_SHORT);
    t.setGravity(Gravity.TOP, 0, dpToPx(55, ctx));
    t.show();//from w ww  .  ja v a2s . c o m
}

From source file:Main.java

public static void showLongToastTop(Context context, int resId) {
    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 100);
    TextView v = toast.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);// www.j  a  v  a2s  .c  o  m
    toast.show();
}

From source file:Main.java

public static WindowManager.LayoutParams makeLayout(int x, int y, int width, int height) {
    WindowManager.LayoutParams ll_lp;//from w w w  .  j a  v  a2s. c o  m

    //Just a sample layout parameters.
    ll_lp = new WindowManager.LayoutParams();
    ll_lp.format = PixelFormat.OPAQUE;
    ll_lp.height = height;
    ll_lp.width = width;
    ll_lp.gravity = Gravity.LEFT | Gravity.TOP;
    ll_lp.x = x;
    ll_lp.y = y;
    ll_lp.token = null;
    //ll_lp.gravity |= Gravity.CENTER_HORIZONTAL;
    //ll_lp.gravity |= Gravity.CENTER_VERTICAL;
    ll_lp.type = WindowManager.LayoutParams.TYPE_APPLICATION;
    ll_lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

    return ll_lp;
}

From source file:Main.java

static void preDraw(TextView view, Canvas canvas) {
    Drawable[] drawables = view.getCompoundDrawables();
    if (drawables[0] != null) {
        view.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
        onCenterDraw(view, canvas, drawables[0], Gravity.START);
    } else if (drawables[1] != null) {
        view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        onCenterDraw(view, canvas, drawables[1], Gravity.TOP);
    } else if (drawables[2] != null) {
        view.setGravity(Gravity.CENTER_VERTICAL | Gravity.END);
        onCenterDraw(view, canvas, drawables[2], Gravity.END);
    } else if (drawables[3] != null) {
        view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        onCenterDraw(view, canvas, drawables[3], Gravity.BOTTOM);
    }//  w w  w  . j a  v  a2s . c om
}

From source file:Main.java

public static void preDraw(TextView view, Canvas canvas) {
    Drawable[] drawables = view.getCompoundDrawables();
    if (drawables != null) {
        if (drawables[0] != null) {
            view.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            onCenterDraw(view, canvas, drawables[0], Gravity.LEFT);
        } else if (drawables[1] != null) {
            view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
            onCenterDraw(view, canvas, drawables[1], Gravity.TOP);
        } else if (drawables[2] != null) {
            view.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
            onCenterDraw(view, canvas, drawables[2], Gravity.RIGHT);
        } else if (drawables[3] != null) {
            view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
            onCenterDraw(view, canvas, drawables[3], Gravity.BOTTOM);
        }//from  w  ww .  ja  v a  2  s . co  m
    }
}

From source file:Main.java

public final static int[] getPopupPosition(View anchor, int gravity) {
    int[] position = new int[2];

    int windowWidth = anchor.getRootView().getMeasuredWidth();
    int windowHeight = anchor.getRootView().getMeasuredHeight();

    int anchorWidth = anchor.getMeasuredWidth();
    int anchorHeight = anchor.getMeasuredHeight();

    int[] location = new int[2];
    anchor.getLocationInWindow(location);

    if (Gravity.LEFT == (gravity & Gravity.LEFT)) {
        position[0] = location[0];/*from   www  .  jav  a 2  s  .co m*/
    } else if (Gravity.RIGHT == (gravity & Gravity.RIGHT)) {
        position[0] = windowWidth - location[0] - anchorWidth;
    }

    if (Gravity.TOP == (gravity & Gravity.TOP)) {
        position[1] = location[1] + anchorHeight;
    } else if (Gravity.BOTTOM == (gravity & Gravity.BOTTOM)) {
        position[1] = windowHeight - location[1];
    }

    return position;
}

From source file:Main.java

protected static WindowManager.LayoutParams updateLayoutParams(boolean left, int y,
        WindowManager.LayoutParams params) {
    if (left) {//from  w  w w  . j  a  v a 2s.  c  om
        params.gravity = Gravity.LEFT | Gravity.TOP;
    } else {
        params.gravity = Gravity.RIGHT | Gravity.TOP;
    }
    params.y = y;
    return params;
}

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;// ww w.  j  a va  2s  . c om

    switch (gravity) {
    case Gravity.END:
        ratio = -1;
    case Gravity.START:
        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 fontMetrics = view.getPaint().getFontMetrics();
        total = fontMetrics.descent - fontMetrics.ascent + drawable.getIntrinsicHeight() + drawablePadding
                + view.getPaddingTop() + view.getPaddingBottom();
        canvas.translate(0, ratio * (view.getHeight() - total) / 2);
        break;
    }
}