Example usage for android.graphics.drawable GradientDrawable GradientDrawable

List of usage examples for android.graphics.drawable GradientDrawable GradientDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable GradientDrawable.

Prototype

private GradientDrawable(@NonNull GradientState state, @Nullable Resources res) 

Source Link

Document

Creates a new themed GradientDrawable based on the specified constant state.

Usage

From source file:info.bartowski.easteregg.LLand.java

private void reset() {
    L("reset");//from www  . ja va  2 s.c  o m
    final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
    sky.setDither(true);
    setBackground(sky);

    mFlipped = frand() > 0.5f;
    setScaleX(mFlipped ? -1 : 1);

    setScore(0);

    int i = getChildCount();
    while (i-- > 0) {
        final View v = getChildAt(i);
        if (v instanceof GameView) {
            removeViewAt(i);
        }
    }

    mObstaclesInPlay.clear();

    mWidth = getWidth();
    mHeight = getHeight();

    boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
    if (showingSun) {
        final Star sun = new Star(getContext());
        sun.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.sun));
        final int w = getResources().getDimensionPixelSize(R.dimen.lland_sun_size);
        sun.setTranslationX(frand(w, mWidth - w));
        if (mTimeOfDay == DAY) {
            sun.setTranslationY(frand(w, (mHeight * 0.66f)));
            DrawableCompat.setTint(sun.getBackground(), 0);
        } else {
            sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
            DrawableCompat.setTintMode(sun.getBackground(), PorterDuff.Mode.SRC_ATOP);
            DrawableCompat.setTint(sun.getBackground(), 0xC0FF8000);
        }
        addView(sun, new LayoutParams(w, w));
    }
    if (!showingSun) {
        final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
        final float ff = frand();
        if ((dark && ff < 0.75f) || ff < 0.5f) {
            final Star moon = new Star(getContext());
            moon.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.moon));
            moon.getBackground().setAlpha(dark ? 255 : 128);
            moon.setScaleX(frand() > 0.5 ? -1 : 1);
            moon.setRotation(moon.getScaleX() * frand(5, 30));
            final int w = getResources().getDimensionPixelSize(R.dimen.lland_sun_size);
            moon.setTranslationX(frand(w, mWidth - w));
            moon.setTranslationY(frand(w, mHeight - w));
            addView(moon, new LayoutParams(w, w));
        }
    }

    final int mh = mHeight / 6;
    final boolean cloudless = frand() < 0.25;
    final int N = 20;
    for (i = 0; i < N; i++) {
        final float r1 = frand();
        final Scenery s;
        if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
            s = new Star(getContext());
        } else if (r1 < 0.6 && !cloudless) {
            s = new Cloud(getContext());
        } else {
            s = new Building(getContext());

            s.z = (float) i / N;
            ViewCompat.setTranslationZ(s, PARAMS.SCENERY_Z * (1 + s.z));
            s.v = 0.85f * s.z; // buildings move proportional to their distance
            hsv[0] = 175;
            hsv[1] = 0.25f;
            hsv[2] = 1 * s.z;
            s.setBackgroundColor(Color.HSVToColor(hsv));
            s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
        }
        final LayoutParams lp = new LayoutParams(s.w, s.h);
        if (s instanceof Building) {
            lp.gravity = Gravity.BOTTOM;
        } else {
            lp.gravity = Gravity.TOP;
            final float r = frand();
            if (s instanceof Star) {
                lp.topMargin = (int) (r * r * mHeight);
            } else {
                lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
            }
        }

        addView(s, lp);
        s.setTranslationX(frand(-lp.width, mWidth + lp.width));
    }

    mDroid = new Player(getContext());
    mDroid.setX(mWidth / 2);
    mDroid.setY(mHeight / 2);
    addView(mDroid, new LayoutParams(PARAMS.PLAYER_SIZE, PARAMS.PLAYER_SIZE));

    mAnim = new TimeAnimator();
    mAnim.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
            step(t, dt);
        }
    });
}

From source file:com.arsy.maps_library.MapRadar.java

private void setDrawableAndBitmap() {
    mOuterDrawable.setColor(mFillColor);
    mOuterDrawable.setStroke(UiUtil.dpToPx(mStrokeWidth), mStrokeColor);
    mBackgroundImageDescriptor = UiUtil.drawableToBitmapDescriptor(mOuterDrawable);
    GradientDrawable radarDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR, mColors);
    radarDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
    radarDrawable.setShape(GradientDrawable.OVAL);
    radarDrawable.setSize(1200, 1200);/*from  ww  w.  j av  a 2 s .c  om*/
    mBackgroundImageSweepDescriptor = UiUtil.drawableToBitmapDescriptor(radarDrawable);
}

From source file:com.googlecode.eyesfree.widget.RadialMenuView.java

public RadialMenuView(Context context, RadialMenu menu, boolean useNodeProvider) {
    super(context);

    mRootMenu = menu;/*from   w  w w.j  a va  2  s  . c  o  m*/
    mRootMenu.setLayoutListener(mLayoutListener);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    mHandler = new LongPressHandler(context);
    mHandler.setListener(mLongPressListener);

    final SurfaceHolder holder = getHolder();
    holder.setFormat(PixelFormat.TRANSLUCENT);
    holder.addCallback(mSurfaceCallback);

    final Resources res = context.getResources();
    final ViewConfiguration config = ViewConfiguration.get(context);

    mSingleTapRadiusSq = config.getScaledTouchSlop();

    // Dimensions.
    mInnerRadius = res.getDimensionPixelSize(R.dimen.inner_radius);
    mOuterRadius = res.getDimensionPixelSize(R.dimen.outer_radius);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.corner_radius);
    mExtremeRadius = res.getDimensionPixelSize(R.dimen.extreme_radius);
    mSpacing = res.getDimensionPixelOffset(R.dimen.spacing);
    mTextSize = res.getDimensionPixelSize(R.dimen.text_size);
    mTextShadowRadius = res.getDimensionPixelSize(R.dimen.text_shadow_radius);
    mShadowRadius = res.getDimensionPixelSize(R.dimen.shadow_radius);

    // Colors.
    mOuterFillColor = res.getColor(R.color.outer_fill);
    mTextFillColor = res.getColor(R.color.text_fill);
    mCornerFillColor = res.getColor(R.color.corner_fill);
    mCornerTextFillColor = res.getColor(R.color.corner_text_fill);
    mDotFillColor = res.getColor(R.color.dot_fill);
    mDotStrokeColor = res.getColor(R.color.dot_stroke);
    mSelectionColor = res.getColor(R.color.selection_fill);
    mSelectionTextFillColor = res.getColor(R.color.selection_text_fill);
    mSelectionShadowColor = res.getColor(R.color.selection_shadow);
    mCenterFillColor = res.getColor(R.color.center_fill);
    mCenterTextFillColor = res.getColor(R.color.center_text_fill);
    mTextShadowColor = res.getColor(R.color.text_shadow);

    // Gradient colors.
    final int gradientInnerColor = res.getColor(R.color.gradient_inner);
    final int gradientOuterColor = res.getColor(R.color.gradient_outer);
    final int[] colors = new int[] { gradientInnerColor, gradientOuterColor };
    mGradientBackground = new GradientDrawable(Orientation.TOP_BOTTOM, colors);
    mGradientBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT);
    mGradientBackground.setGradientRadius(mExtremeRadius * 2.0f);

    final int subMenuOverlayColor = res.getColor(R.color.submenu_overlay);

    // Lighting filters generated from colors.
    mSubMenuFilter = new PorterDuffColorFilter(subMenuOverlayColor, PorterDuff.Mode.SCREEN);

    mInnerRadiusSq = (mInnerRadius * mInnerRadius);
    mExtremeRadiusSq = (mExtremeRadius * mExtremeRadius);

    mUseNodeProvider = useNodeProvider;

    if (mUseNodeProvider) {
        mTouchExplorer = new RadialMenuHelper(this);
        ViewCompat.setAccessibilityDelegate(this, mTouchExplorer);
    }

    // Corner shapes only need to be invalidated and cached once.
    initializeCachedShapes();
}

From source file:com.android.screenspeak.contextmenu.RadialMenuView.java

public RadialMenuView(Context context, RadialMenu menu, boolean useNodeProvider) {
    super(context);

    mRootMenu = menu;/* w w  w.  j  a  v a2 s.  c  o  m*/
    mRootMenu.setLayoutListener(new RadialMenu.MenuLayoutListener() {
        @Override
        public void onLayoutChanged() {
            invalidate();
        }
    });

    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    mHandler = new LongPressHandler(context);
    mHandler.setListener(new LongPressHandler.LongPressListener() {
        @Override
        public void onLongPress() {
            onItemLongPressed(mFocusedItem);
        }
    });

    final SurfaceHolder holder = getHolder();
    holder.setFormat(PixelFormat.TRANSLUCENT);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            mHolder = holder;
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            mHolder = null;
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            invalidate();
        }
    });

    final Resources res = context.getResources();
    final ViewConfiguration config = ViewConfiguration.get(context);

    mSingleTapRadiusSq = config.getScaledTouchSlop();

    // Dimensions.
    mInnerRadius = res.getDimensionPixelSize(R.dimen.inner_radius);
    mOuterRadius = res.getDimensionPixelSize(R.dimen.outer_radius);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.corner_radius);
    mExtremeRadius = res.getDimensionPixelSize(R.dimen.extreme_radius);
    mSpacing = res.getDimensionPixelOffset(R.dimen.spacing);
    mTextSize = res.getDimensionPixelSize(R.dimen.text_size);
    mTextShadowRadius = res.getDimensionPixelSize(R.dimen.text_shadow_radius);
    mShadowRadius = res.getDimensionPixelSize(R.dimen.shadow_radius);

    // Colors.
    mOuterFillColor = res.getColor(R.color.outer_fill);
    mTextFillColor = res.getColor(R.color.text_fill);
    mCornerFillColor = res.getColor(R.color.corner_fill);
    mCornerTextFillColor = res.getColor(R.color.corner_text_fill);
    mDotFillColor = res.getColor(R.color.dot_fill);
    mDotStrokeColor = res.getColor(R.color.dot_stroke);
    mSelectionColor = res.getColor(R.color.selection_fill);
    mSelectionTextFillColor = res.getColor(R.color.selection_text_fill);
    mSelectionShadowColor = res.getColor(R.color.selection_shadow);
    mCenterFillColor = res.getColor(R.color.center_fill);
    mCenterTextFillColor = res.getColor(R.color.center_text_fill);
    mTextShadowColor = res.getColor(R.color.text_shadow);

    // Gradient colors.
    final int gradientInnerColor = res.getColor(R.color.gradient_inner);
    final int gradientOuterColor = res.getColor(R.color.gradient_outer);
    final int[] colors = new int[] { gradientInnerColor, gradientOuterColor };
    mGradientBackground = new GradientDrawable(Orientation.TOP_BOTTOM, colors);
    mGradientBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT);
    mGradientBackground.setGradientRadius(mExtremeRadius * 2.0f);

    final int subMenuOverlayColor = res.getColor(R.color.submenu_overlay);

    // Lighting filters generated from colors.
    mSubMenuFilter = new PorterDuffColorFilter(subMenuOverlayColor, PorterDuff.Mode.SCREEN);

    mInnerRadiusSq = (mInnerRadius * mInnerRadius);
    mExtremeRadiusSq = (mExtremeRadius * mExtremeRadius);

    mUseNodeProvider = useNodeProvider;

    if (mUseNodeProvider) {
        // Lazily-constructed node provider helper.
        ViewCompat.setAccessibilityDelegate(this, new RadialMenuHelper(this));
    }

    // Corner shapes only need to be invalidated and cached once.
    initializeCachedShapes();
}

From source file:com.miz.utils.ViewUtils.java

/**
 * Update the Toolbar background color and title.
 * @param activity/*  w  w w .  java 2 s .  com*/
 * @param toolbar
 * @param alpha
 * @param title
 * @param color
 */
public static void updateToolbarBackground(Activity activity, Toolbar toolbar, int alpha, String title,
        int color) {
    if (defaultTitleTextColor == -1) {
        int[] textColorAttr = new int[] { R.attr.actionMenuTextColor };
        TypedValue typedValue = new TypedValue();
        int indexOfAttrTextColor = 0;
        TypedArray a = activity.obtainStyledAttributes(typedValue.data, textColorAttr);
        defaultTitleTextColor = a.getColor(indexOfAttrTextColor, -1);
        a.recycle();
    }
    toolbar.setTitle(title);
    toolbar.setTitleTextColor(adjustAlpha(defaultTitleTextColor, alpha));
    int toolbarColor = adjustAlpha(color, alpha);
    if (MizLib.hasJellyBean()) {
        int topColor = darkenColor(color, alpha / 255f);
        topColor = adjustAlpha(topColor, Math.max(125, alpha));
        int[] colors = { topColor, toolbarColor };
        toolbar.setBackground(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors));
    } else {
        toolbar.setBackgroundColor(toolbarColor);
    }
}

From source file:com.dongdong.wheel.WheelView.java

/**
 * Initializes resources/*from  w  w  w. jav  a 2  s  . c  o  m*/
 */
private void initResourcesIfNecessary() {
    if (mItemsPaint == null) {
        mItemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
        //mItemsPaint.density = getResources().getDisplayMetrics().density;
        mItemsPaint.setTextSize(TEXT_SIZE);
    }

    if (mValuePaint == null) {
        mValuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
        //mValuePaint.density = getResources().getDisplayMetrics().density;
        mValuePaint.setTextSize(TEXT_SIZE);
        mValuePaint.setShadowLayer(0.1f, 0, 0.1f, 0xFFC0C0C0);
    }

    if (mCenterDrawable == null) {
        mCenterDrawable = ContextCompat.getDrawable(getContext(), R.drawable.wheel_val);
    }

    if (mTopShadow == null) {
        mTopShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }

    if (mBottomShadow == null) {
        mBottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    setBackgroundResource(R.drawable.wheel_bg);
}

From source file:com.ssn.currency.convertor.WheelView.java

/**
 * Initializes resources//from w  w w . j  a va2s.  co  m
 */
private void initResourcesIfNecessary() {
    if (centerDrawable == null) {
        centerDrawable = getContext().getResources().getDrawable(R.drawable.wheel_val);
    }

    if (topShadow == null) {
        topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }

    if (bottomShadow == null) {
        bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    setBackgroundResource(com.ssn.currency.convertor.R.drawable.wheel_bg);
}

From source file:com.wiipu.bimu.adapter.AreaSelect.WheelView.java

/**
 * Initializes resources//from  w  w  w  . j a  v a2s.c  o  m
 */
private void initResourcesIfNecessary() {
    if (centerDrawable == null) {
        centerDrawable = ContextCompat.getDrawable(getContext(), wheelForeground);
    }

    if (topShadow == null) {
        topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }

    if (bottomShadow == null) {
        bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    setBackgroundResource(wheelBackground);
}

From source file:com.linkloving.dyh08.logic.UI.launch.view.wheelview.WheelView.java

/**
 * Initializes resources//from   w  w w .  java 2 s.co  m
 */
private void initResourcesIfNecessary() {
    if (centerDrawable == null)
        centerDrawable = ResourcesCompat.getDrawable(getResources(), wheelForeground, null);

    if (topShadow == null)
        topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);

    if (bottomShadow == null) {
        bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    setBackgroundResource(wheelBackground);
}

From source file:info.bartowski.easteregg.MLand.java

public void reset() {
    L("reset");/*from  w ww .j  av  a2s.  com*/
    final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
    sky.setDither(true);
    setBackground(sky);

    mFlipped = frand() > 0.5f;
    setScaleX(mFlipped ? -1 : 1);

    int i = getChildCount();
    while (i-- > 0) {
        final View v = getChildAt(i);
        if (v instanceof GameView) {
            removeViewAt(i);
        }
    }

    mObstaclesInPlay.clear();
    mCurrentPipeId = 0;

    mWidth = getWidth();
    mHeight = getHeight();

    boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
    if (showingSun) {
        final Star sun = new Star(getContext());
        sun.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.sun));
        final int w = getResources().getDimensionPixelSize(R.dimen.mland_sun_size);
        sun.setTranslationX(frand(w, mWidth - w));
        if (mTimeOfDay == DAY) {
            sun.setTranslationY(frand(w, (mHeight * 0.66f)));
            DrawableCompat.setTint(sun.getBackground(), 0);
        } else {
            sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
            DrawableCompat.setTintMode(sun.getBackground(), PorterDuff.Mode.SRC_ATOP);
            DrawableCompat.setTint(sun.getBackground(), 0xC0FF8000);

        }
        addView(sun, new LayoutParams(w, w));
    }
    if (!showingSun) {
        final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
        final float ff = frand();
        if ((dark && ff < 0.75f) || ff < 0.5f) {
            final Star moon = new Star(getContext());
            moon.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.moon));
            moon.getBackground().setAlpha(dark ? 255 : 128);
            moon.setScaleX(frand() > 0.5 ? -1 : 1);
            moon.setRotation(moon.getScaleX() * frand(5, 30));
            final int w = getResources().getDimensionPixelSize(R.dimen.mland_sun_size);
            moon.setTranslationX(frand(w, mWidth - w));
            moon.setTranslationY(frand(w, mHeight - w));
            addView(moon, new LayoutParams(w, w));
        }
    }

    final int mh = mHeight / 6;
    final boolean cloudless = frand() < 0.25;
    final int N = 20;
    for (i = 0; i < N; i++) {
        final float r1 = frand();
        final Scenery s;
        if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
            s = new Star(getContext());
        } else if (r1 < 0.6 && !cloudless) {
            s = new Cloud(getContext());
        } else {
            switch (mScene) {
            case SCENE_ZRH:
                s = new Mountain(getContext());
                break;
            case SCENE_TX:
                s = new Cactus(getContext());
                break;
            case SCENE_CITY:
            default:
                s = new Building(getContext());
                break;
            }
            s.z = (float) i / N;
            // no more shadows for these things
            //s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z));
            s.v = 0.85f * s.z; // buildings move proportional to their distance
            if (mScene == SCENE_CITY) {
                s.setBackgroundColor(Color.GRAY);
                s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
            }
            final int c = (int) (255f * s.z);
            final Drawable bg = s.getBackground();
            if (bg != null)
                bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY);
        }
        final LayoutParams lp = new LayoutParams(s.w, s.h);
        if (s instanceof Building) {
            lp.gravity = Gravity.BOTTOM;
        } else {
            lp.gravity = Gravity.TOP;
            final float r = frand();
            if (s instanceof Star) {
                lp.topMargin = (int) (r * r * mHeight);
            } else {
                lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
            }
        }

        addView(s, lp);
        s.setTranslationX(frand(-lp.width, mWidth + lp.width));
    }

    for (Player p : mPlayers) {
        addView(p); // put it back!
        p.reset();
    }

    realignPlayers();

    if (mAnim != null) {
        mAnim.cancel();
    }
    mAnim = new TimeAnimator();
    mAnim.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
            step(t, dt);
        }
    });
}