Example usage for android.view Gravity END

List of usage examples for android.view Gravity END

Introduction

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

Prototype

int END

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

Click Source Link

Document

Push object to x-axis position at the end of its container, not changing its size.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@SuppressLint("RtlHardcoded")
public static int getGravityEnd() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        return Gravity.END;
    }/* w  w w.j a  v  a  2s  .  c o  m*/
    return Gravity.RIGHT;
}

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;//from w  w w . j  ava2s  .c o  m

    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;
    }
}

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 ww  .j av  a 2  s  . c  o m
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Layout.Alignment getLayoutAlignment(TextView textView) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return Layout.Alignment.ALIGN_NORMAL;
    }/*from w w w .  ja va2  s  .  c o  m*/

    Layout.Alignment alignment;
    switch (textView.getTextAlignment()) {
    case TextView.TEXT_ALIGNMENT_GRAVITY:
        switch (textView.getGravity() & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
        case Gravity.START:
            alignment = Layout.Alignment.ALIGN_NORMAL;
            break;
        case Gravity.END:
            alignment = Layout.Alignment.ALIGN_OPPOSITE;
            break;
        case Gravity.LEFT:
            alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL)
                    ? Layout.Alignment.ALIGN_OPPOSITE
                    : Layout.Alignment.ALIGN_NORMAL;
            break;
        case Gravity.RIGHT:
            alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL)
                    ? Layout.Alignment.ALIGN_NORMAL
                    : Layout.Alignment.ALIGN_OPPOSITE;
            break;
        case Gravity.CENTER_HORIZONTAL:
            alignment = Layout.Alignment.ALIGN_CENTER;
            break;
        default:
            alignment = Layout.Alignment.ALIGN_NORMAL;
            break;
        }
        break;
    case TextView.TEXT_ALIGNMENT_TEXT_START:
        alignment = Layout.Alignment.ALIGN_NORMAL;
        break;
    case TextView.TEXT_ALIGNMENT_TEXT_END:
        alignment = Layout.Alignment.ALIGN_OPPOSITE;
        break;
    case TextView.TEXT_ALIGNMENT_CENTER:
        alignment = Layout.Alignment.ALIGN_CENTER;
        break;
    case TextView.TEXT_ALIGNMENT_VIEW_START:
        alignment = Layout.Alignment.ALIGN_NORMAL;
        break;
    case TextView.TEXT_ALIGNMENT_VIEW_END:
        alignment = Layout.Alignment.ALIGN_OPPOSITE;
        break;
    case TextView.TEXT_ALIGNMENT_INHERIT:
        //
    default:
        alignment = Layout.Alignment.ALIGN_NORMAL;
        break;
    }
    return alignment;
}

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  .  j  a v  a  2  s.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;
}

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 .  j  a v  a2s  .c o m*/
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    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 = Math.max(0, Math.min(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);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}

From source file:com.yoloo.android.util.ScrimUtil.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./*w ww  .  j a va2s .c  o  m*/
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs,
    // based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

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

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

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

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtils.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);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}

From source file:com.hybris.mobile.lib.ui.layout.DrawerPushLayout.java

/**
 * Init the drawer layout/*from   ww  w  . j  a  va 2  s.c o  m*/
 */
protected void init() {
    setDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerStateChanged(int arg0) {
        }

        @Override
        public void onDrawerSlide(View arg0, float slideOffset) {
            // Calculation of the x coordinates to slide to
            float toX = arg0.getWidth() * slideOffset;

            // If the drawer is positioned on the right, we push the content to the left
            if (isDrawerVisible(Gravity.END)) {
                toX = -toX;
            }

            getChildAt(0).setX(toX);
        }

        @Override
        public void onDrawerOpened(View arg0) {
            if (mDrawerPushLayoutListener != null) {
                mDrawerPushLayoutListener.onDrawerOpened();
            }
        }

        @Override
        public void onDrawerClosed(View arg0) {
            if (mDrawerPushLayoutListener != null) {
                mDrawerPushLayoutListener.onDrawerClosed();
            }
        }
    });
}

From source file:com.example.android.support.transition.widget.ArcMotionUsage.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mRoot = findViewById(R.id.root);/*from w  w  w. j  a va  2  s. c  o m*/
    mTarget = findViewById(R.id.target);
    mTransition = new ChangeBounds();
    mTransition.setPathMotion(new ArcMotion());
    mTransition.setInterpolator(new FastOutSlowInInterpolator());
    mTransition.setDuration(500);
    findViewById(R.id.move).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TransitionManager.beginDelayedTransition(mRoot, mTransition);
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mTarget.getLayoutParams();
            if ((lp.gravity & Gravity.START) == Gravity.START) {
                lp.gravity = Gravity.END | Gravity.BOTTOM;
            } else {
                lp.gravity = Gravity.START | Gravity.TOP;
            }
            mTarget.setLayoutParams(lp);
        }
    });
}

From source file:de.dreier.mytargets.utils.SlideInItemAnimator.java

@Override
public boolean animateAdd(RecyclerView.ViewHolder holder) {
    if (useDefaultAnimator) {
        return super.animateAdd(holder);
    }// w w w  .  ja  va  2  s  .  c  o m
    holder.itemView.setAlpha(0f);
    switch (slideFromEdge) {
    case Gravity.START:
        holder.itemView.setTranslationX(-holder.itemView.getWidth() / 3);
        break;
    case Gravity.TOP:
        holder.itemView.setTranslationY(-holder.itemView.getHeight() / 3);
        break;
    case Gravity.END:
        holder.itemView.setTranslationX(holder.itemView.getWidth() / 3);
        break;
    default: // Gravity.BOTTOM
        holder.itemView.setTranslationY(holder.itemView.getHeight() / 3);
    }
    pendingAdds.add(holder);
    return true;
}