Search in sources :

Example 36 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project snackbar by nispok.

the class Snackbar method init.

private MarginLayoutParams init(Context context, Activity targetActivity, ViewGroup parent, boolean usePhoneLayout) {
    SnackbarLayout layout = (SnackbarLayout) LayoutInflater.from(context).inflate(R.layout.sb__template, this, true);
    layout.setOrientation(LinearLayout.VERTICAL);
    Resources res = getResources();
    mColor = mColor != mUndefinedColor ? mColor : res.getColor(R.color.sb__background);
    mOffset = res.getDimensionPixelOffset(R.dimen.sb__offset);
    mUsePhoneLayout = usePhoneLayout;
    float scale = res.getDisplayMetrics().density;
    View divider = layout.findViewById(R.id.sb__divider);
    MarginLayoutParams params;
    if (mUsePhoneLayout) {
        // Phone
        layout.setMinimumHeight(dpToPx(mType.getMinHeight(), scale));
        layout.setMaxHeight(dpToPx(mType.getMaxHeight(), scale));
        layout.setBackgroundColor(mColor);
        params = createMarginLayoutParams(parent, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, mPhonePosition);
        if (mLineColor != null) {
            divider.setBackgroundColor(mLineColor);
        } else {
            divider.setVisibility(View.GONE);
        }
    } else {
        // Tablet/desktop
        // Force single-line
        mType = SnackbarType.SINGLE_LINE;
        layout.setMinimumWidth(res.getDimensionPixelSize(R.dimen.sb__min_width));
        layout.setMaxWidth(mMaxWidthPercentage == null ? res.getDimensionPixelSize(R.dimen.sb__max_width) : DisplayCompat.getWidthFromPercentage(targetActivity, mMaxWidthPercentage));
        layout.setBackgroundResource(R.drawable.sb__bg);
        GradientDrawable bg = (GradientDrawable) layout.getBackground();
        bg.setColor(mColor);
        params = createMarginLayoutParams(parent, FrameLayout.LayoutParams.WRAP_CONTENT, dpToPx(mType.getMaxHeight(), scale), mWidePosition);
        if (mLineColor != null) {
            divider.setBackgroundResource(R.drawable.sb__divider_bg);
            GradientDrawable dbg = (GradientDrawable) divider.getBackground();
            dbg.setColor(mLineColor);
        } else {
            divider.setVisibility(View.GONE);
        }
    }
    if (mDrawable != mUndefinedDrawable)
        setBackgroundDrawable(layout, res.getDrawable(mDrawable));
    snackbarText = (TextView) layout.findViewById(R.id.sb__text);
    snackbarText.setText(mText);
    snackbarText.setTypeface(mTextTypeface);
    if (mTextColor != mUndefinedColor) {
        snackbarText.setTextColor(mTextColor);
    }
    snackbarText.setMaxLines(mType.getMaxLines());
    snackbarAction = (TextView) layout.findViewById(R.id.sb__action);
    if (!TextUtils.isEmpty(mActionLabel)) {
        requestLayout();
        snackbarAction.setText(mActionLabel);
        snackbarAction.setTypeface(mActionTypeface);
        if (mActionColor != mUndefinedColor) {
            snackbarAction.setTextColor(mActionColor);
        }
        snackbarAction.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                if (mActionClickListener != null) {
                    // 2) If we aren't allowing multiple clicks, that this is the first click
                    if (!mIsDismissing && (!mActionClicked || mShouldAllowMultipleActionClicks)) {
                        mActionClickListener.onActionClicked(Snackbar.this);
                        mActionClicked = true;
                    }
                }
                if (mShouldDismissOnActionClicked) {
                    dismiss();
                }
            }
        });
        snackbarAction.setMaxLines(mType.getMaxLines());
    } else {
        snackbarAction.setVisibility(GONE);
    }
    View inner = layout.findViewById(R.id.sb__inner);
    inner.setClickable(true);
    if (mCanSwipeToDismiss && res.getBoolean(R.bool.sb__is_swipeable)) {
        inner.setOnTouchListener(new SwipeDismissTouchListener(this, null, new SwipeDismissTouchListener.DismissCallbacks() {

            @Override
            public boolean canDismiss(Object token) {
                return true;
            }

            @Override
            public void onDismiss(View view, Object token) {
                if (view != null) {
                    if (mActionSwipeListener != null) {
                        mActionSwipeListener.onSwipeToDismiss();
                    }
                    dismiss(false);
                }
            }

            @Override
            public void pauseTimer(boolean shouldPause) {
                if (isIndefiniteDuration()) {
                    return;
                }
                if (shouldPause) {
                    removeCallbacks(mDismissRunnable);
                    mSnackbarFinish = System.currentTimeMillis();
                } else {
                    mTimeRemaining -= (mSnackbarFinish - mSnackbarStart);
                    startTimer(mTimeRemaining);
                }
            }
        }));
    }
    return params;
}
Also used : SwipeDismissTouchListener(com.nispok.snackbar.listeners.SwipeDismissTouchListener) Resources(android.content.res.Resources) SnackbarLayout(com.nispok.snackbar.layouts.SnackbarLayout) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 37 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project superCleanMaster by joyoyao.

the class IconRoundCornerProgressBar method setHeaderColor.

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void setHeaderColor(int color) {
    headerColor = color;
    int radius = this.radius - (padding / 2);
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(headerColor);
    gradient.setCornerRadii(new float[] { radius, radius, 0, 0, 0, 0, radius, radius });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutHeader.setBackgroundDrawable(gradient);
    } else {
        layoutHeader.setBackground(gradient);
    }
    if (!isProgressBarCreated) {
        isHeaderColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 38 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project android_frameworks_base by ResurrectionRemix.

the class MLand method reset.

public void reset() {
    L("reset");
    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.setBackgroundResource(R.drawable.sun);
        final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
        sun.setTranslationX(frand(w, mWidth - w));
        if (mTimeOfDay == DAY) {
            sun.setTranslationY(frand(w, (mHeight * 0.66f)));
            sun.getBackground().setTint(0);
        } else {
            sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
            sun.getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
            sun.getBackground().setTint(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.setBackgroundResource(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.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));
            // buildings move proportional to their distance
            s.v = 0.85f * s.z;
            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) {
        // put it back!
        addView(p);
        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);
        }
    });
}
Also used : TimeAnimator(android.animation.TimeAnimator) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) GradientDrawable(android.graphics.drawable.GradientDrawable) Paint(android.graphics.Paint)

Example 39 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project Atom_Android by Rogrand-Dev.

the class ButtonStyle method init.

private void init() {
    setGravity(Gravity.CENTER);
    gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(normalColor);
    gradientDrawable.setStroke((int) strokeWidth, strokeColor);
    gradientDrawable.setCornerRadius(currCorner);
    setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            setBackgroundDrawable(gradientDrawable);
            return setColor(event.getAction());
        }
    });
    setBackgroundDrawable(gradientDrawable);
}
Also used : View(android.view.View) GradientDrawable(android.graphics.drawable.GradientDrawable) MotionEvent(android.view.MotionEvent)

Example 40 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project LshUtils by SenhLinsh.

the class LshXmlCreater method createRectangleShape.

/**
     * 代码生成矩形
     *
     * @param fillColor   内部填充颜色
     * @param roundRadius 圆角半径
     * @param strokeWidth 边框宽度
     * @param strokeColor 边框颜色
     * @return 矩形对象, 其他参数可自行设定
     */
public static GradientDrawable createRectangleShape(int fillColor, float roundRadius, int strokeWidth, int strokeColor) {
    GradientDrawable gradientDrawable = createRectangleShape(fillColor, roundRadius);
    //边框宽度, 边框颜色
    gradientDrawable.setStroke(strokeWidth, strokeColor);
    return gradientDrawable;
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable)

Aggregations

GradientDrawable (android.graphics.drawable.GradientDrawable)169 Paint (android.graphics.Paint)19 Drawable (android.graphics.drawable.Drawable)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 View (android.view.View)19 SuppressLint (android.annotation.SuppressLint)18 TextView (android.widget.TextView)18 LayerDrawable (android.graphics.drawable.LayerDrawable)16 ImageView (android.widget.ImageView)14 LinearLayout (android.widget.LinearLayout)12 TypedArray (android.content.res.TypedArray)8 FrameLayout (android.widget.FrameLayout)6 TimeAnimator (android.animation.TimeAnimator)5 Typeface (android.graphics.Typeface)5 LayoutInflater (android.view.LayoutInflater)5 ViewGroup (android.view.ViewGroup)5 Attributes (com.cengalabs.flatui.Attributes)5 Resources (android.content.res.Resources)4 TextPaint (android.text.TextPaint)4 Button (android.widget.Button)4