Example usage for android.graphics.drawable ShapeDrawable ShapeDrawable

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

Introduction

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

Prototype

public ShapeDrawable(Shape s) 

Source Link

Document

Creates a ShapeDrawable with a specified Shape.

Usage

From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java

private static Drawable getRippleMask(@ColorInt int color) {
    float[] outerRadii = new float[8];
    // 3 is the radius of final ripple, instead of 3 we can give required final radius
    Arrays.fill(outerRadii, 3);/*from   w w w.  j  a  v  a  2  s.co  m*/
    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

From source file:silent.kuasapmaterial.libs.MaterialProgressBar.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }/*from   w w w  .ja  v a 2 s .c o m*/
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);

        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = (int) mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);

    if (mCircleBackgroundEnabled) {
        mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
                mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
                mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
                mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    } else {
        mProgressDrawable.updateSizes(mOverallSize);
    }

    if (isShowArrow()) {
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    mProgressDrawable.start();
}

From source file:com.youhei.easytools.view.progressbar.CircleProgressBar.java

@Override
@SuppressWarnings("deprecation")
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }//from  w  ww  .  j a  va2 s  . com
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);

        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
            mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth,
            mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
            mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    if (isShowArrow()) {
        mProgressDrawable.showArrowOnFirstStart(true);
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    if (getVisibility() == VISIBLE) {
        mProgressDrawable.start();
    }
}

From source file:android.wuliqing.com.mylibrary.header.MaterialProgressDrawable.java

private void setUp(final double diameter) {
    PtrLocalDisplay.init(mParent.getContext());
    final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET);
    final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET);
    int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS);
    OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
    mShadow = new ShapeDrawable(oval);
    if (Build.VERSION.SDK_INT >= 11) {
        mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
    }//  w ww .  java 2 s  .  c o  m
    mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}

From source file:cn.xiaocool.hongyunschool.view.MaterialProgressDrawable.java

private void setUp(final double diameter) {
    final int shadowYOffset = DensityUtil.dip2px(mParent.getContext(), Y_OFFSET);
    final int shadowXOffset = DensityUtil.dip2px(mParent.getContext(), X_OFFSET);
    int mShadowRadius = DensityUtil.dip2px(mParent.getContext(), SHADOW_RADIUS);
    OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
    mShadow = new ShapeDrawable(oval);
    if (Build.VERSION.SDK_INT >= 11) {
        mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
    }//from   ww w  .j a v  a  2  s.c  o m
    mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}

From source file:io.puzzlebox.orbit.ui.OrbitFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_orbit, container, false);

    //      requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    //      setContentView(R.layout.main);
    //      getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

    buttonConnectOrbit = (Button) v.findViewById(R.id.buttonConnectOrbit);
    buttonConnectOrbit.setOnClickListener(new View.OnClickListener() {
        @Override//  w ww .  j  ava 2 s. c  o  m
        public void onClick(View v) {
            setOrbitActivate();
        }
    });

    Button buttonTestFlight = (Button) v.findViewById(R.id.buttonTestFlight);
    buttonTestFlight.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            demoMode(v);
        }
    });

    progressBarAttention = (ProgressBar) v.findViewById(R.id.progressBarAttention);
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    ShapeDrawable progressBarAttentionDrawable = new ShapeDrawable(
            new RoundRectShape(roundedCorners, null, null));
    String progressBarAttentionColor = "#FF0000";
    progressBarAttentionDrawable.getPaint().setColor(Color.parseColor(progressBarAttentionColor));
    ClipDrawable progressAttention = new ClipDrawable(progressBarAttentionDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarAttention.setProgressDrawable(progressAttention);
    progressBarAttention
            .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarMeditation = (ProgressBar) v.findViewById(R.id.progressBarMeditation);
    ShapeDrawable progressBarMeditationDrawable = new ShapeDrawable(
            new RoundRectShape(roundedCorners, null, null));
    String progressBarMeditationColor = "#0000FF";
    progressBarMeditationDrawable.getPaint().setColor(Color.parseColor(progressBarMeditationColor));
    ClipDrawable progressMeditation = new ClipDrawable(progressBarMeditationDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarMeditation.setProgressDrawable(progressMeditation);
    progressBarMeditation
            .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarSignal = (ProgressBar) v.findViewById(R.id.progressBarSignal);
    ShapeDrawable progressBarSignalDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String progressBarSignalColor = "#00FF00";
    progressBarSignalDrawable.getPaint().setColor(Color.parseColor(progressBarSignalColor));
    ClipDrawable progressSignal = new ClipDrawable(progressBarSignalDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarSignal.setProgressDrawable(progressSignal);
    progressBarSignal.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
    //      progressBarSignal.setProgress(tgSignal);

    progressBarPower = (ProgressBar) v.findViewById(R.id.progressBarPower);
    ShapeDrawable progressBarPowerDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String progressBarPowerColor = "#FFFF00";
    progressBarPowerDrawable.getPaint().setColor(Color.parseColor(progressBarPowerColor));
    ClipDrawable progressPower = new ClipDrawable(progressBarPowerDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarPower.setProgressDrawable(progressPower);
    progressBarPower.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    seekBarAttention = (SeekBar) v.findViewById(R.id.seekBarAttention);
    seekBarAttention.setOnSeekBarChangeListener(this);
    seekBarMeditation = (SeekBar) v.findViewById(R.id.seekBarMeditation);
    seekBarMeditation.setOnSeekBarChangeListener(this);

    imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus);

    textViewLabelScores = (TextView) v.findViewById(R.id.textViewLabelScores);
    textViewLabelScore = (TextView) v.findViewById(R.id.textViewLabelScore);
    textViewLabelLastScore = (TextView) v.findViewById(R.id.textViewLabelLastScore);
    textViewLabelHighScore = (TextView) v.findViewById(R.id.textViewLabelHighScore);

    viewSpaceScore = (View) v.findViewById(R.id.viewSpaceScore);
    viewSpaceScoreLast = (View) v.findViewById(R.id.viewSpaceScoreLast);
    viewSpaceScoreHigh = (View) v.findViewById(R.id.viewSpaceScoreHigh);

    textViewScore = (TextView) v.findViewById(R.id.textViewScore);
    textViewLastScore = (TextView) v.findViewById(R.id.textViewLastScore);
    textViewHighScore = (TextView) v.findViewById(R.id.textViewHighScore);

    // Hide the "Scores" label by default
    textViewLabelScores.setVisibility(View.GONE);
    viewSpaceScore.setVisibility(View.GONE);

    /**
     * AudioHandler
     */

    if (!OrbitSingleton.getInstance().audioHandler.isAlive()) {

        /**
         * Prepare audio stream
         */

        maximizeAudioVolume(); // Automatically set media volume to maximum

        /** Set the hardware buttons to control the audio output */
        getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);

        /** Preload the flight control WAV file into memory */
        OrbitSingleton.getInstance().soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
        OrbitSingleton.getInstance().soundPool
                .setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                    public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                        OrbitSingleton.getInstance().loaded = true;
                    }
                });
        OrbitSingleton.getInstance().soundID = OrbitSingleton.getInstance().soundPool
                .load(getActivity().getApplicationContext(), OrbitSingleton.getInstance().audioFile, 1);

        OrbitSingleton.getInstance().audioHandler.start();

    }

    if (OrbitSingleton.getInstance().flightActive)
        buttonTestFlight.setText(getResources().getString(R.string.button_stop_test));

    /**
     * Update settings according to default UI
     */

    updateScreenLayout();

    updatePowerThresholds();
    //      updatePower();

    return v;

}

From source file:in.srain.cube.header.MaterialProgressDrawable.java

@SuppressLint("NewApi")
private void setUp(final double diameter) {
    PtrLocalDisplay.init(mParent.getContext());
    final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET);
    final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET);
    int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS);
    OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
    mShadow = new ShapeDrawable(oval);
    if (Build.VERSION.SDK_INT >= 11) {
        mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
    }/*from w  ww .  j  a  va 2s .  c om*/
    mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}

From source file:com.zzmstring.viewset.View.LoadingProgressBar.CircleProgressBar.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }/* ww w .j a v  a2 s. com*/
    if (getBackground() == null) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);

        ShapeDrawable circle;
        if (elevationSupported()) {
            circle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter);
            circle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
            circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = (int) mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        circle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(circle);
    }
    if (getDrawable() == null) {
        MaterialProgressDrawable progressDrawable = new MaterialProgressDrawable(getContext(), this);
        progressDrawable.setBackgroundColor(mBackGroundColor);
        progressDrawable.setArrowScale(1f);
        //            progressDrawable.showArrow(true);
        //            progressDrawable.setStartEndTrim(0, 180);
        progressDrawable.setSizeParameters(mDiameter, mDiameter,
                mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
                mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
                mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
        super.setImageDrawable(progressDrawable);
        progressDrawable.setAlpha(150);
        progressDrawable.start();
    }
}

From source file:com.summer.lib.view.refreshlayout.CircleProgressBar.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }// ww  w. j a  v a 2 s .c om
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);

        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
            mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth,
            mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
            mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    if (isShowArrow()) {
        mProgressDrawable.showArrowOnFirstStart(true);
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    if (getVisibility() == VISIBLE) {
        mProgressDrawable.setStartEndTrim(0, (float) 0.8);
    }
}

From source file:cc.chenghong.vkagetorder.material.CircleProgressBar.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }/*from www . ja v  a  2 s  .co m*/
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);

        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = (int) mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
            mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth,
            mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
            mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    if (isShowArrow()) {
        mProgressDrawable.showArrowOnFirstStart(true);
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    if (getVisibility() == VISIBLE) {
        mProgressDrawable.setStartEndTrim(0, (float) 0.8);
    }
}