Java Code Examples for android.graphics.drawable.GradientDrawable#Orientation

The following examples show how to use android.graphics.drawable.GradientDrawable#Orientation . 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: Drawables.java    From noDrawable with Apache License 2.0 6 votes vote down vote up
private static GradientDrawable.Orientation mapOrientation(@Orientation int orientation) {
    switch (orientation) {
        case Orientation.BL_TR:
            return GradientDrawable.Orientation.BL_TR;
        case Orientation.BOTTOM_TOP:
            return GradientDrawable.Orientation.BOTTOM_TOP;
        case Orientation.BR_TL:
            return GradientDrawable.Orientation.BR_TL;
        case Orientation.LEFT_RIGHT:
            return GradientDrawable.Orientation.LEFT_RIGHT;
        case Orientation.RIGHT_LEFT:
            return GradientDrawable.Orientation.RIGHT_LEFT;
        case Orientation.TL_BR:
            return GradientDrawable.Orientation.TL_BR;
        case Orientation.TOP_BOTTOM:
            return GradientDrawable.Orientation.TOP_BOTTOM;
        case Orientation.TR_BL:
            return GradientDrawable.Orientation.TR_BL;
    }
    return GradientDrawable.Orientation.TOP_BOTTOM;
}
 
Example 2
Source File: OverlayDrawer.java    From WayHoo with Apache License 2.0 6 votes vote down vote up
@Override
protected GradientDrawable.Orientation getDropShadowOrientation() {
    switch (getPosition()) {
        case TOP:
            return GradientDrawable.Orientation.TOP_BOTTOM;

        case RIGHT:
            return GradientDrawable.Orientation.RIGHT_LEFT;

        case BOTTOM:
            return GradientDrawable.Orientation.BOTTOM_TOP;

        default:
            return GradientDrawable.Orientation.LEFT_RIGHT;
    }
}
 
Example 3
Source File: MenuDrawer.java    From WayHoo with Apache License 2.0 6 votes vote down vote up
protected GradientDrawable.Orientation getDropShadowOrientation() {
    // Gets the orientation for the static and sliding drawer. The overlay drawer provides its own implementation.
    switch (getPosition()) {
        case TOP:
            return GradientDrawable.Orientation.BOTTOM_TOP;

        case RIGHT:
            return GradientDrawable.Orientation.LEFT_RIGHT;

        case BOTTOM:
            return GradientDrawable.Orientation.TOP_BOTTOM;

        default:
            return GradientDrawable.Orientation.RIGHT_LEFT;
    }
}
 
Example 4
Source File: NoInternetDialog.java    From NoInternetDialog with Apache License 2.0 5 votes vote down vote up
private void initBackground() {
    GradientDrawable.Orientation orientation = getOrientation();

    GradientDrawable drawable = new GradientDrawable(orientation, new int[]{bgGradientStart, bgGradientCenter, bgGradientEnd});
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setCornerRadius(dialogRadius);

    switch (bgGradientType) {
        case GRADIENT_RADIAL:
            drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
            break;
        case GRADIENT_SWEEP:
            drawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
            break;
        default:
            drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
            break;
    }

    if (isHalloween) {
        drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
        drawable.setGradientRadius(getContext().getResources().getDimensionPixelSize(R.dimen.dialog_height) / 2);
    } else {
        drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        root.setBackground(drawable);
    } else {
        root.setBackgroundDrawable(drawable);
    }
}
 
Example 5
Source File: GradientAbsoluteLayout.java    From GradientLayout with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Configure the gradient background for this layout.</p>
 * @param startColor The start color for the gradient
 * @param endColor The end color for the gradient
 * @param orientation The orientation for the gradient {@link  android.graphics.drawable.GradientDrawable.Orientation  GradientDrawable.Orientation}
 */
public void setGradientBackgroundConfig(final int startColor, final int endColor, final GradientDrawable.Orientation orientation) {
    this.gradientBackground
            .setStartColor(startColor)
            .setEndColor(endColor)
            .setOrientation(orientation)
            .generate();
}
 
Example 6
Source File: GradientFrameLayout.java    From GradientLayout with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Configure the gradient background for this layout.</p>
 * @param startColor The start color for the gradient
 * @param endColor The end color for the gradient
 * @param orientation The orientation for the gradient {@link  android.graphics.drawable.GradientDrawable.Orientation  GradientDrawable.Orientation}
 */
public void setGradientBackgroundConfig(final int startColor, final int endColor, final GradientDrawable.Orientation orientation) {
    this.gradientBackground
            .setStartColor(startColor)
            .setEndColor(endColor)
            .setOrientation(orientation)
            .generate();
}
 
Example 7
Source File: GradientLinearLayout.java    From GradientLayout with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Configure the gradient background for this layout.</p>
 * @param startColor The start color for the gradient
 * @param endColor The end color for the gradient
 * @param orientation The orientation for the gradient {@link  android.graphics.drawable.GradientDrawable.Orientation  GradientDrawable.Orientation}
 */
public void setGradientBackgroundConfig(final int startColor, final int endColor, final GradientDrawable.Orientation orientation) {
    this.gradientBackground
            .setStartColor(startColor)
            .setEndColor(endColor)
            .setOrientation(orientation)
            .generate();
}
 
Example 8
Source File: ArtistAdapter.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private GradientDrawable.Orientation getGradientDirection() {
    GradientDrawable.Orientation[] orientations = new GradientDrawable.Orientation[]{
            GradientDrawable.Orientation.TL_BR,
            GradientDrawable.Orientation.BL_TR,
            GradientDrawable.Orientation.TR_BL,
            GradientDrawable.Orientation.TOP_BOTTOM,
            GradientDrawable.Orientation.BOTTOM_TOP,
            GradientDrawable.Orientation.LEFT_RIGHT,
            GradientDrawable.Orientation.RIGHT_LEFT,
            GradientDrawable.Orientation.BR_TL
    };
    return orientations[new Random().nextInt(orientations.length)];
}
 
Example 9
Source File: ParallaxBackLayout.java    From ParallaxBackLayout with MIT License 5 votes vote down vote up
/**
 * Sets edge flag.
 *
 * @param edgeFlag the edge flag
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setEdgeFlag(@Edge int edgeFlag) {
    if (mEdgeFlag == edgeFlag)
        return;
    mEdgeFlag = edgeFlag;
    mDragHelper.setEdgeTrackingEnabled(edgeFlag);
    GradientDrawable.Orientation orientation = GradientDrawable.Orientation.LEFT_RIGHT;
    if (edgeFlag == EDGE_LEFT)
        orientation = GradientDrawable.Orientation.RIGHT_LEFT;
    else if (edgeFlag == EDGE_TOP) {
        orientation = GradientDrawable.Orientation.BOTTOM_TOP;
    } else if (edgeFlag == EDGE_RIGHT)
        orientation = GradientDrawable.Orientation.LEFT_RIGHT;
    else if (edgeFlag == EDGE_BOTTOM)
        orientation = GradientDrawable.Orientation.TOP_BOTTOM;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        mShadowLeft = null;
    }
    if (mShadowLeft == null) {
        int colors[] = {0x66000000, 0x11000000, 0x00000000};
        ShadowDrawable drawable = new ShadowDrawable(orientation, colors);
        drawable.setGradientRadius(90);
        drawable.setSize(50, 50);
        mShadowLeft = drawable;
    } else if (mShadowLeft instanceof ShadowDrawable) {
        ((ShadowDrawable) mShadowLeft).setOrientation(orientation);
    }
    applyWindowInset();
}
 
Example 10
Source File: MenuDrawer.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the color of the drop shadow.
 *
 * @param color The color of the drop shadow.
 */
public void setDropShadowColor(int color) {
    GradientDrawable.Orientation orientation = getDropShadowOrientation();

    final int endColor = color & 0x00FFFFFF;
    mDropShadowDrawable = new GradientDrawable(orientation,
            new int[] {
                    color,
                    endColor,
            });
    invalidate();
}
 
Example 11
Source File: ComparableGradientDrawable.java    From litho with Apache License 2.0 4 votes vote down vote up
public ComparableGradientDrawable(GradientDrawable.Orientation orientation, int[] colors) {
  super(orientation, colors);
  this.colors = colors;
}
 
Example 12
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setSelectorBg(View view, int state, int shape, GradientDrawable.Orientation[] orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, int radius) {
	ViewCompat.setBackground(view, getDrawable(state, shape, orientation, bgColor, borderColor, borderWidth, radius));
}
 
Example 13
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setSelectorBg(View view, int state, int shape, GradientDrawable.Orientation orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, int radius) {
	ViewCompat.setBackground(view, getDrawable(state, shape, orientation, bgColor, borderColor, borderWidth, radius));
}
 
Example 14
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setShapeBg(View view, int shape, GradientDrawable.Orientation orientation,
                              int[] bgColor, int borderColor, int borderWidth, int radius) {
	ViewCompat.setBackground(view, getDrawable(shape, orientation, bgColor, borderColor, borderWidth, radius));
}
 
Example 15
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setSelectorBg(View view, int state, int shape, GradientDrawable.Orientation orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(state, shape, orientation, bgColor, borderColor, borderWidth, radius));
}
 
Example 16
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setShapeBg(View view, GradientDrawable.Orientation orientation,
                              int[] bgColor, int borderColor, int borderWidth, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(GradientDrawable.RECTANGLE, orientation, bgColor,
			borderColor, borderWidth, radius));
}
 
Example 17
Source File: RoundEdgeDrawable.java    From UILibrary with MIT License 4 votes vote down vote up
public RoundEdgeDrawable(GradientDrawable.Orientation orientation, int[] colors){
    super(orientation, colors);
    mEdgeMark = 0x0;
}
 
Example 18
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setSelectorBg(View view, int state, int shape, GradientDrawable.Orientation[] orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(state, shape, orientation, bgColor, borderColor, borderWidth, radius));
}
 
Example 19
Source File: ViewBgUtil.java    From SimpleProject with MIT License 3 votes vote down vote up
/**
 * 获取构造的渐变背景 -> 具有相同圆角的场景
 * @param shape
 * @param orientation
 * @param bgColor
 * @param borderColor
 * @param borderWidth
 * @param radius
 * @return
 */
public static Drawable getDrawable(int shape, GradientDrawable.Orientation orientation,
                                   int[] bgColor, int borderColor, int borderWidth, int radius) {
	GradientDrawable drawable = new GradientDrawable(orientation, bgColor);
	drawable.setShape(shape);
	drawable.setStroke(borderWidth, borderColor);
	drawable.setCornerRadius(radius);
	return drawable;
}
 
Example 20
Source File: ViewBgUtil.java    From SimpleProject with MIT License 2 votes vote down vote up
/**
 * 获取构造的渐变背景 -> 与状态相关联的背景【圆角有差异的场景】
 * @param state
 * @param shape
 * @param orientation
 * @param bgColor
 * @param borderColor
 * @param borderWidth
 * @param radius
 * @return
 */
public static Drawable getDrawable(int state, int shape, GradientDrawable.Orientation orientation,
                                   int[][] bgColor, int[] borderColor, int borderWidth, float[] radius) {
	return getDrawable(state, shape, new GradientDrawable.Orientation[] {orientation, orientation},
			bgColor, borderColor, borderWidth, radius);
}