Java Code Examples for android.graphics.drawable.ClipDrawable

The following are top voted examples for showing how to use android.graphics.drawable.ClipDrawable. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Nird2   File: StrengthMeter.java   View source code 6 votes vote down vote up
public StrengthMeter(Context context, AttributeSet attrs) {
	super(context, attrs, android.R.attr.progressBarStyleHorizontal);
	bar = new ShapeDrawable();
	bar.getPaint().setColor(RED);
	ClipDrawable clip = new ClipDrawable(bar, LEFT, HORIZONTAL);
	ShapeDrawable background = new ShapeDrawable();
	Paint p = background.getPaint();
	p.setStyle(FILL);
	p.setColor(getResources().getColor(android.R.color.transparent));
	p.setStyle(STROKE);
	p.setStrokeWidth(1);
	p.setColor(BLACK);
	Drawable[] layers = new Drawable[] { clip, background };
	setProgressDrawable(new LayerDrawable(layers));
	setIndeterminate(false);
}
 
Example 2
Project: Nird2   File: StrengthMeter.java   View source code 6 votes vote down vote up
public StrengthMeter(Context context, AttributeSet attrs) {
	super(context, attrs, android.R.attr.progressBarStyleHorizontal);
	bar = new ShapeDrawable();
	bar.getPaint().setColor(RED);
	ClipDrawable clip = new ClipDrawable(bar, LEFT, HORIZONTAL);
	ShapeDrawable background = new ShapeDrawable();
	Paint p = background.getPaint();
	p.setStyle(FILL);
	p.setColor(getResources().getColor(android.R.color.transparent));
	p.setStyle(STROKE);
	p.setStrokeWidth(1);
	p.setColor(BLACK);
	Drawable[] layers = new Drawable[] { clip, background };
	setProgressDrawable(new LayerDrawable(layers));
	setIndeterminate(false);
}
 
Example 3
Project: ArtOfAndroid   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.tv_transition).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
            drawable.startTransition(3000);
        }
    });

    ScaleDrawable scaleDrawable = (ScaleDrawable) findViewById(R.id.v_scale).getBackground();
    scaleDrawable.setLevel(10);      //lever默认为0,无法显示。level范围为0~10000。level越大,显示的越大

    ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.v_clip).getBackground();
    clipDrawable.setLevel(5000);

    View vCustom = findViewById(R.id.v_custom);
    CustomDrawable customDrawable = new CustomDrawable(getResources().getColor(R.color.colorAccent));
    vCustom.setBackground(customDrawable);
}
 
Example 4
Project: LoadingImageView   File: LoadingImageView.java   View source code 6 votes vote down vote up
private void initMaskBitmap(int maskColor) {
    Drawable drawable = getDrawable();
    if(drawable == null){
        return;
    }
    Bitmap bgd = ((BitmapDrawable) drawable).getBitmap();
    imageWidth = drawable.getIntrinsicWidth();
    imageHeight = drawable.getIntrinsicHeight();

    Bitmap fg = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
    Canvas fgCanvas = new Canvas(fg);
    fgCanvas.drawColor(maskColor);


    Bitmap bitmap = combineImages(bgd, fg);
    maskDrawable = new BitmapDrawable(bitmap);
    clipDrawable = new ClipDrawable(maskDrawable, gravity, orientaion);

    //shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    //paint.setShader(shader);
}
 
Example 5
Project: yelo-android   File: SwipeClearLayout.java   View source code 6 votes vote down vote up
private void setTargetOffsetTopAndBottom(int offset) {
    circle.offsetTopAndBottom(offset);
    currentTargetOffsetTop = circle.getTop();
    int percent = (int) ((currentTargetOffsetTop / distanceToTriggerSync) * 100);
    if (onSwipeListener != null) {
        onSwipeListener.onSwipe(percent, currentTargetOffsetTop);
    }
    ViewCompat.setElevation(circle, percent);
    ImageView imageView = (ImageView) circle;
    ClipDrawable clipDrawable = (ClipDrawable) imageView.getDrawable();

    if (percent < 50) {
        clipDrawable.setLevel(0);
    } else {
        clipDrawable.setLevel((percent - 50) * 2 * 100);
    }
}
 
Example 6
Project: Loop   File: LoadingImageView.java   View source code 6 votes vote down vote up
private void initMaskBitmap(int maskColor) {
    Drawable drawable = getDrawable();
    if(drawable == null){
        return;
    }
    Bitmap bgd = ((BitmapDrawable) drawable).getBitmap();
    imageWidth = drawable.getIntrinsicWidth();
    imageHeight = drawable.getIntrinsicHeight();

    Bitmap fg = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
    Canvas fgCanvas = new Canvas(fg);
    fgCanvas.drawColor(maskColor);


    Bitmap bitmap = combineImages(bgd, fg);
    maskDrawable = new BitmapDrawable(bitmap);
    clipDrawable = new ClipDrawable(maskDrawable, gravity, orientaion);

    //shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    //paint.setShader(shader);
}
 
Example 7
Project: Noyze   File: CmBatteryBar.java   View source code 6 votes vote down vote up
/**
 * Updates the {@link ShapeDrawable} which displays the
 * color of the bar across the screen.
 */
public void setProgressDrawable(Drawable mDrawable, int mNewColor)
{
	if (mDrawable instanceof LayerDrawable &&
		getProgressDrawable() instanceof LayerDrawable)
	{
        final LayerDrawable mDraw = (LayerDrawable) getProgressDrawable();
        final ClipDrawable mShape = (ClipDrawable)
            mDraw.findDrawableByLayerId(android.R.id.progress);

        // Make sure we've got everything.
        if (mShape != null && mProgress != null &&
            mProgress.getPaint() != null)
        {
            mProgress.getPaint().setColor(mNewColor);
            final Rect mBounds = mDraw.getBounds();
            super.setProgressDrawable(mDraw);
            getProgressDrawable().setBounds(mBounds);
            return;
        }
	}
	
	super.setProgressDrawable(mDrawable);
}
 
Example 8
Project: 365browser   File: ClipDrawableProgressBar.java   View source code 6 votes vote down vote up
/**
 * Create the progress bar with a custom height.
 * @param context An Android context.
 * @param height The height in px of the progress bar.
 */
public ClipDrawableProgressBar(Context context, int height) {
    super(context);

    mDesiredVisibility = getVisibility();

    int foregroundColor =
            ApiCompatibilityUtils.getColor(getResources(), R.color.progress_bar_foreground);
    mBackgroundColor =
            ApiCompatibilityUtils.getColor(getResources(), R.color.progress_bar_background);

    mForegroundDrawable = new ColorDrawable(foregroundColor);
    setImageDrawable(
            new ClipDrawable(mForegroundDrawable, Gravity.START, ClipDrawable.HORIZONTAL));
    setBackgroundColor(mBackgroundColor);

    setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height));
}
 
Example 9
Project: itsnat_droid   File: Assert.java   View source code 6 votes vote down vote up
public static void assertEquals(ClipDrawable a,ClipDrawable b)
{
    assertEqualsDrawableWrapper(a, b);

    Rect ar = new Rect(); Rect br = new Rect();
    a.getPadding(ar); b.getPadding(br);
    assertEquals(ar, br);

    Drawable.ConstantState a_state = a.getConstantState();
    Drawable.ConstantState b_state = b.getConstantState();

    Class classClipState = TestUtil.resolveClass(ClipDrawable.class.getName() + "$ClipState");
    assertEquals((Integer) TestUtil.getField(a_state, classClipState, "mOrientation"), (Integer) TestUtil.getField(b_state, classClipState, "mOrientation"));
    assertEquals((Integer) TestUtil.getField(a_state, classClipState, "mGravity"), (Integer) TestUtil.getField(b_state, classClipState, "mGravity"));

    // android:drawable
    if (Build.VERSION.SDK_INT < TestUtil.MARSHMALLOW) // 23
    {
        assertEquals((Drawable) TestUtil.getField(a_state, classClipState, "mDrawable"), (Drawable) TestUtil.getField(b_state, classClipState, "mDrawable"));
    }
}
 
Example 10
Project: android-art-res   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // test transition
        View v = findViewById(R.id.test_transition);
        TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
        drawable.startTransition(1000);

        // test scale
        View testScale = findViewById(R.id.test_scale);
        ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground();
        testScaleDrawable.setLevel(10);

        // test clip
        ImageView testClip = (ImageView) findViewById(R.id.test_clip);
        ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable();
        testClipDrawable.setLevel(8000);
        
        // test custom drawable
        View testCustomDrawable = findViewById(R.id.test_custom_drawable);
        CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e"));
        testCustomDrawable.setBackgroundDrawable(customDrawable);
    }
}
 
Example 11
Project: androidApp   File: ReportView.java   View source code 6 votes vote down vote up
private void setShadow(int drawableId) {
    Drawable original = ContextCompat.getDrawable(TranSappApplication.getAppContext(), drawableId) ;
    Drawable shadow = getClone(original).mutate();
    toGrayScale(shadow);

    Drawable background = getClone(original).mutate();
    background.setColorFilter(
            ContextCompat.getColor(getContext(), R.color.background_white), PorterDuff.Mode.SRC_ATOP);

    Drawable drawableArray[]= new Drawable[]{background, shadow};
    LayerDrawable layerDraw = new LayerDrawable(drawableArray);


    clipDrawable = new ClipDrawable(layerDraw, Gravity.BOTTOM, ClipDrawable.VERTICAL);
    this.shadow.setImageDrawable(clipDrawable);
}
 
Example 12
Project: pure   File: AppMaterial.java   View source code 6 votes vote down vote up
/** RatingBar 星星 */
public static Drawable RATINGBAR_PROGERSS_DRAWABLE() {
    Drawable[] layers = new Drawable[3];
    Drawable darwable1 = getDrawable(IcomoonIcon.ICON_IC_STAR_NORMAL, NUMBER_3_INT,10,10);
    Drawable darwable2 = getDrawable(IcomoonIcon.ICON_IC_STAR_NORMAL, NUMBER_3_INT,10,10);
    Drawable darwable3 = getDrawable(IcomoonIcon.ICON_IC_STAR_SOLID, NUMBER_3_INT,10,10);
    
    
    layers[0] = darwable1;
    layers[1] = new ClipDrawable(darwable2, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    layers[2] = new ClipDrawable(darwable3, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    LayerDrawable drawable = new LayerDrawable(layers);
    drawable.setId(0, android.R.id.background);
    drawable.setId(1, android.R.id.secondaryProgress);
    drawable.setId(2, android.R.id.progress);
    return drawable;
}
 
Example 13
Project: pure   File: MaterialUtils.java   View source code 6 votes vote down vote up
private Drawable buildRatingBarDrawables(Bitmap[] images) {
    final int[] requiredIds = { android.R.id.background, android.R.id.secondaryProgress, android.R.id.progress };
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    Drawable[] pieces = new Drawable[3];
    for (int i = 0; i < 3; i++) {

        ShapeDrawable sd = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));

        BitmapShader bitmapShader = new BitmapShader(images[i], Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        sd.getPaint().setShader(bitmapShader);

        ClipDrawable cd = new ClipDrawable(sd, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        if (i == 0) {
            pieces[i] = sd;
        } else {
            pieces[i] = cd;
        }
    }
    LayerDrawable ld = new LayerDrawable(pieces);
    for (int i = 0; i < 3; i++) {
        ld.setId(i, requiredIds[i]);
    }
    return ld;
}
 
Example 14
Project: briar   File: StrengthMeter.java   View source code 6 votes vote down vote up
public StrengthMeter(Context context) {
	super(context, null, android.R.attr.progressBarStyleHorizontal);
	bar = new ShapeDrawable();
	bar.getPaint().setColor(RED);
	ClipDrawable clip = new ClipDrawable(bar, LEFT, HORIZONTAL);
	ShapeDrawable background = new ShapeDrawable();
	Paint p = background.getPaint();
	p.setStyle(FILL);
	p.setColor(getResources().getColor(android.R.color.transparent));
	p.setStyle(STROKE);
	p.setStrokeWidth(1);
	p.setColor(BLACK);
	Drawable[] layers = new Drawable[] { clip, background };
	setProgressDrawable(new LayerDrawable(layers));
	setIndeterminate(false);
}
 
Example 15
Project: Orpheus   File: ProfilePortraitView.java   View source code 6 votes vote down vote up
void positionStickyHeader() {
    // sticky header
    final int top = mListHeader.getTop();
    final int stickyHeight = mStickyHeader.getMeasuredHeight();
    final int headerHeight = mListHeader.getMeasuredHeight();
    final int delta = headerHeight - stickyHeight;
    final int pos = delta + top;
    // reposition header
    mStickyHeader.setTranslationY(Math.max(pos,0));
    if (pos < 0 && !mIsStuck) {
        mIsStuck = true;
        makeSlideAnimator(5000, 10000, (ClipDrawable)mStickyHeader.getBackground()).start();
    } else if (pos > 0 && mIsStuck) {
        mIsStuck = false;
        makeSlideAnimator(10000, 5000, (ClipDrawable)mStickyHeader.getBackground()).start();
    }
}
 
Example 16
Project: Orpheus   File: PlaylistPortraitView.java   View source code 6 votes vote down vote up
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    // logic here derived from http://antoine-merle.com/blog/2013/10/04/making-that-google-plus-profile-screen/
    if (visibleItemCount == 0) return;
    if (firstVisibleItem == 0 && mList.getChildCount() > 0) {
        // parallax
        mHeroContainer.setTranslationY(-mList.getChildAt(0).getTop() / 2);
    }
    // sticky header
    final int top = mListHeader.getTop();
    final int stickyHeight = mStickyHeader.getMeasuredHeight();
    final int headerHeight = mListHeader.getMeasuredHeight();
    final int delta = headerHeight - stickyHeight;
    final int pos = delta + top;
    // reposition header
    mStickyHeader.setTranslationY(Math.max(pos,0));
    if (pos < 0 && !mIsStuck) {
        mIsStuck = true;
        makeSlideAnimator(5000, 10000, (ClipDrawable)mStickyHeader.getBackground()).start();
    } else if (pos > 0 && mIsStuck) {
        mIsStuck = false;
        makeSlideAnimator(10000,5000, (ClipDrawable)mStickyHeader.getBackground()).start();
    }
}
 
Example 17
Project: appdeck-android   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                        .strokeWidth(strokeWidth)
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 18
Project: Noyze   File: CmBatteryBar.java   View source code 6 votes vote down vote up
/**
 * Updates the {@link ShapeDrawable} which displays the
 * color of the bar across the screen.
 */
public void setProgressDrawable(Drawable mDrawable, int mNewColor)
{
	if (mDrawable instanceof LayerDrawable &&
		getProgressDrawable() instanceof LayerDrawable)
	{
        final LayerDrawable mDraw = (LayerDrawable) getProgressDrawable();
        final ClipDrawable mShape = (ClipDrawable)
            mDraw.findDrawableByLayerId(android.R.id.progress);

        // Make sure we've got everything.
        if (mShape != null && mProgress != null &&
            mProgress.getPaint() != null)
        {
            mProgress.getPaint().setColor(mNewColor);
            final Rect mBounds = mDraw.getBounds();
            super.setProgressDrawable(mDraw);
            getProgressDrawable().setBounds(mBounds);
            return;
        }
	}
	
	super.setProgressDrawable(mDrawable);
}
 
Example 19
Project: Klyph   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                        .width(strokeWidth)
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 20
Project: CodeLessDoMore   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                       
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 21
Project: mpd-control   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                        .strokeWidth(strokeWidth)
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 22
Project: danmaku-project   File: SwitchSeekBar.java   View source code 6 votes vote down vote up
private void init(Context context) {
    setOnSeekBarChangeListener(this);
    scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mChecked = false;
    progressDrawable = (LayerDrawable) getProgressDrawable();
    outDrawables = new Drawable[progressDrawable.getNumberOfLayers()];
    for (int i = 0; i < progressDrawable.getNumberOfLayers(); i++) {
        switch (progressDrawable.getId(i)) {
        case android.R.id.progress:// ���ý����
            proDrawable = (ClipDrawable) progressDrawable.getDrawable(i);
            break;
        default:
            break;
        }
    }
}
 
Example 23
Project: Team11Prototype   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                        .strokeWidth(strokeWidth)
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 24
Project: mpdroid-2014   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                        .width(strokeWidth)
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 25
Project: KlyphMessenger   File: DefaultHeaderTransformer.java   View source code 6 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources()
                .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);

        mHeaderProgressBar.setIndeterminateDrawable(
                new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext())
                        .color(mProgressDrawableColor)
                        .width(strokeWidth)
                        .build());

        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 26
Project: ghostcommander-supath   File: SelZoneDialog.java   View source code 6 votes vote down vote up
private final LayerDrawable createSeekBarDrawable( int fg_color ) {
    LayerDrawable ld = null;
    try {
        Drawable[] list = new Drawable[2];
        final int bg_color = 0xff9d9e9d;
        GradientDrawable bg = Utils.getShadingEx( atRight ? fg_color : bg_color, 0.6f );
        bg.setCornerRadius( 5 );
        list[0] = bg;
        GradientDrawable fg = Utils.getShadingEx( atRight ? bg_color : fg_color, 0.6f );
        fg.setCornerRadius( 5 );
        list[1] = new ClipDrawable( fg, Gravity.LEFT, ClipDrawable.HORIZONTAL );
        ld = new LayerDrawable( list );
        ld.setId( 0, android.R.id.background );
        ld.setId( 1, android.R.id.progress );
    }
    catch( Exception e ) {
        e.printStackTrace();
    }
    return ld;
}
 
Example 27
Project: SimpleRatingBar   File: PartialView.java   View source code 5 votes vote down vote up
public void setFilledDrawable(Drawable drawable) {
    if (drawable.getConstantState() == null) {
        return;
    }

    ClipDrawable clipDrawable = new ClipDrawable(drawable.getConstantState().newDrawable(), Gravity.START, ClipDrawable.HORIZONTAL);
    mFilledView.setImageDrawable(clipDrawable);
}
 
Example 28
Project: SimpleRatingBar   File: PartialView.java   View source code 5 votes vote down vote up
public void setEmptyDrawable(Drawable drawable) {
    if (drawable.getConstantState() == null) {
        return;
    }

    ClipDrawable clipDrawable = new ClipDrawable(drawable.getConstantState().newDrawable(), Gravity.END, ClipDrawable.HORIZONTAL);
    mEmptyView.setImageDrawable(clipDrawable);
}
 
Example 29
Project: tumbviewer   File: DownloadFragment.java   View source code 5 votes vote down vote up
RxDownloadVH(View itemView) {
    super(itemView);
    progressDrawable = (ClipDrawable) itemView.getBackground();
    stateView = (ImageView) itemView.findViewById(R.id.download_state);
    progress = (TextView) itemView.findViewById(R.id.progress);
    urlView = (TextView) itemView.findViewById(R.id.url);
    stateView.setOnClickListener(this);
    itemView.setOnClickListener(this);
}
 
Example 30
Project: phonk   File: PSlider_.java   View source code 5 votes vote down vote up
public PSlider_(AppRunner appRunner) {
    super(appRunner.getAppContext());
    super.setMax(MAX_VALUE);
    // setProgressDrawable(getResources().getDrawable(R.drawable.ui_seekbar_progress));

    mSlider = this;
    // getStyles = new Styler(appRunner, this);

    //Custom background drawable allows you to draw how you want it to look if needed
    // SeekBarBackgroundDrawable backgroundDrawable = new SeekBarBackgroundDrawable(appRunner.getAppContext());
    ColorDrawable progressDrawable = new ColorDrawable(Color.BLUE);
    SeekBarProgressDrawable clipProgressDrawable = new SeekBarProgressDrawable(progressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL, appRunner.getAppContext());

    ColorDrawable progressDrawable2 = new ColorDrawable(Color.GREEN);
    //Custom seek bar slider drawable. Also allows you to modify appearance.
    InsetDrawable insetDrawable = new InsetDrawable(progressDrawable2, 0, 0, 0, 0);

    Drawable[] drawables = new Drawable[]{ insetDrawable, clipProgressDrawable };

    //Create layer drawables with android pre-defined ids
    LayerDrawable layerDrawable = new LayerDrawable(drawables);
    // layerDrawable.setId(0,android.R.id.background);
    // layerDrawable.setId(1,android.R.id.slider);

    //Set to seek bar
    setThumb(null);
    setProgressDrawable(layerDrawable);
}
 
Example 31
Project: libcommon   File: ProgressView.java   View source code 5 votes vote down vote up
protected void refreshDrawable(final Drawable drawable) {
	mDrawable = drawable;
	if (mDrawable == null) {
		mDrawable = new ColorDrawable(mColor);
	}
	int gravity = GRAVITY_FILL_VERTICAL | GRAVITY_LEFT;
	int orientation = ClipDrawable.HORIZONTAL;
	switch (mRotation) {
	case 90:
		gravity = GRAVITY_FILL_HORIZONTAL | GRAVITY_BOTTOM;
		orientation = ClipDrawable.VERTICAL;
		break;
	case 180:
		gravity = GRAVITY_FILL_VERTICAL | GRAVITY_RIGHT;
		orientation = ClipDrawable.HORIZONTAL;
		break;
	case 270:
		gravity = GRAVITY_FILL_HORIZONTAL | GRAVITY_TOP;
		orientation = ClipDrawable.VERTICAL;
		break;
	}
	mClipDrawable = new ClipDrawable(mDrawable, gravity, orientation);
	final Rect outRect = new Rect();
	getDrawingRect(outRect);
	mClipDrawable.setBounds(outRect);
	mClipDrawable.setLevel((int)(mProgress * mScale) + mMin);
	postInvalidate();
}
 
Example 32
Project: solved-hacking-problem   File: bb.java   View source code 5 votes vote down vote up
private Drawable m2538a(Drawable drawable, boolean z) {
    int i = 0;
    Drawable a;
    if (drawable instanceof C0063q) {
        a = ((C0063q) drawable).m469a();
        if (a != null) {
            ((C0063q) drawable).m473a(m2538a(a, z));
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        int numberOfLayers = layerDrawable.getNumberOfLayers();
        Drawable[] drawableArr = new Drawable[numberOfLayers];
        for (int i2 = 0; i2 < numberOfLayers; i2++) {
            int id = layerDrawable.getId(i2);
            Drawable drawable2 = layerDrawable.getDrawable(i2);
            boolean z2 = id == 16908301 || id == 16908303;
            drawableArr[i2] = m2538a(drawable2, z2);
        }
        a = new LayerDrawable(drawableArr);
        while (i < numberOfLayers) {
            a.setId(i, layerDrawable.getId(i));
            i++;
        }
        return a;
    } else if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (this.f1344d == null) {
            this.f1344d = bitmap;
        }
        Drawable shapeDrawable = new ShapeDrawable(m2539b());
        shapeDrawable.getPaint().setShader(new BitmapShader(bitmap, TileMode.REPEAT, TileMode.CLAMP));
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return z ? new ClipDrawable(shapeDrawable, 3, 1) : shapeDrawable;
    }
    return drawable;
}
 
Example 33
Project: solved-hacking-problem   File: bb.java   View source code 5 votes vote down vote up
private Drawable m2538a(Drawable drawable, boolean z) {
    int i = 0;
    Drawable a;
    if (drawable instanceof C0063q) {
        a = ((C0063q) drawable).m469a();
        if (a != null) {
            ((C0063q) drawable).m473a(m2538a(a, z));
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        int numberOfLayers = layerDrawable.getNumberOfLayers();
        Drawable[] drawableArr = new Drawable[numberOfLayers];
        for (int i2 = 0; i2 < numberOfLayers; i2++) {
            int id = layerDrawable.getId(i2);
            Drawable drawable2 = layerDrawable.getDrawable(i2);
            boolean z2 = id == 16908301 || id == 16908303;
            drawableArr[i2] = m2538a(drawable2, z2);
        }
        a = new LayerDrawable(drawableArr);
        while (i < numberOfLayers) {
            a.setId(i, layerDrawable.getId(i));
            i++;
        }
        return a;
    } else if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (this.f1344d == null) {
            this.f1344d = bitmap;
        }
        Drawable shapeDrawable = new ShapeDrawable(m2539b());
        shapeDrawable.getPaint().setShader(new BitmapShader(bitmap, TileMode.REPEAT, TileMode.CLAMP));
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return z ? new ClipDrawable(shapeDrawable, 3, 1) : shapeDrawable;
    }
    return drawable;
}
 
Example 34
Project: EggProgressSDK   File: EggLoadingProgress.java   View source code 5 votes vote down vote up
public void onShowEggLoadingProgressBar(boolean cancelable, int max, int color) {
    mProgress = new ProgressDialog(mContext);
    mProgress.setCancelable(cancelable);
    mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    LayerDrawable layer = (LayerDrawable) ContextCompat.getDrawable(mContext, R.drawable.custom_linear_progress);
    ClipDrawable progress = (ClipDrawable) (layer.findDrawableByLayerId(R.id.progress));
    progress.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    mProgress.setProgressDrawable(layer);
    mProgress.setProgress(0);
    mProgress.setMax(max);
    mProgress.show();
}
 
Example 35
Project: EggProgressSDK   File: EggLoadingProgress.java   View source code 5 votes vote down vote up
public void onShowEggLoadingProgressBar(boolean cancelable, int max, int color, String title, String message) {
    mProgress = new ProgressDialog(mContext);
    if(!title.equals("")) mProgress.setTitle(title);
    if(!message.equals("")) mProgress.setMessage(message);
    mProgress.setCancelable(cancelable);
    mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    LayerDrawable layer = (LayerDrawable) ContextCompat.getDrawable(mContext, R.drawable.custom_linear_progress);
    ClipDrawable progress = (ClipDrawable) (layer.findDrawableByLayerId(R.id.progress));
    progress.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    mProgress.setProgressDrawable(layer);
    mProgress.setProgress(0);
    mProgress.setMax(max);
    mProgress.show();
}
 
Example 36
Project: WhiteRead   File: MMWebView.java   View source code 5 votes vote down vote up
private void initProgress(Context context) {
    if (mProgressbar == null) {
        mProgressbar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
        mProgressbar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 12, 0, 0));
        mProgressbar.setMax(100);
        mProgressbar.setProgress(0);
        mProgressbar.setBackgroundColor(0xffcccccc);
        ClipDrawable d = new ClipDrawable(new ColorDrawable(mProgressColor), Gravity.START, ClipDrawable.HORIZONTAL);
        mProgressbar.setProgressDrawable(d);
    }

    if (indexOfChild(mProgressbar) == -1) {
        addView(mProgressbar);
    }
}
 
Example 37
Project: LoadingImageView   File: LoadingImageView.java   View source code 5 votes vote down vote up
/**
 * 设置方向
 * @param orientation {@link MaskOrientation}
 */
public void setMaskOrientation(int orientation){
    switch (orientation){
        case MaskOrientation.LeftToRight:
            gravity = Gravity.LEFT;
            orientaion = ClipDrawable.HORIZONTAL;
            break;
        case MaskOrientation.RightToLeft:
            gravity = Gravity.RIGHT;
            orientaion = ClipDrawable.HORIZONTAL;
            break;
        case MaskOrientation.TopToBottom:
            gravity = Gravity.TOP;
            orientaion = ClipDrawable.VERTICAL;
            break;
        case MaskOrientation.BottomToTop:
        default:
            gravity = Gravity.BOTTOM;
            orientaion = ClipDrawable.VERTICAL;
            break;
    }
    if(maskDrawable == null){
        return;
    }
    clipDrawable = new ClipDrawable(maskDrawable, gravity, orientaion);
    initAnim();
}
 
Example 38
Project: AndroidPullMenu   File: DefaultHeaderTransformer.java   View source code 5 votes vote down vote up
private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);

        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
 
Example 39
Project: BetterRatingBar   File: BetterRatingBar.java   View source code 5 votes vote down vote up
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        return (clip) ? new ClipDrawable(bitmapDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : bitmapDrawable;
    }

    return drawable;
}
 
Example 40
Project: soulissapp   File: NodeDetailFragment.java   View source code 5 votes vote down vote up
/**
 * Riga grigia cra spazio
 */
private void createHeader() {

    if (collected.getIconResourceId() != 0)
        FontAwesomeUtil.prepareAwesomeFontAweTextView(getActivity(), nodeic, SimpleTagViewUtils.getAwesomeNames(getActivity()).get(collected.getIconResourceId()));


    par.setMax(Constants.MAX_HEALTH);

    // ProgressBar sfumata
    final ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(Constants.roundedCorners, null, null));
    final LinearGradient gradient = new LinearGradient(0, 0, 250, 0, getResources().getColor(color.aa_red),
            getResources().getColor(color.aa_green), android.graphics.Shader.TileMode.CLAMP);
    // pgDrawable.getPaint().setStrokeWidth(3);
    pgDrawable.getPaint().setDither(true);
    pgDrawable.getPaint().setShader(gradient);

    ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.START, ClipDrawable.HORIZONTAL);
    par.setBackgroundResource(android.R.drawable.progress_horizontal);
    par.setProgressDrawable(progress);
    par.setMax(50);
    par.setProgress(20);
    par.setProgress(0); // <-- BUG Android
    par.setMax(Constants.MAX_HEALTH);
    refreshHeader();

    Log.d(Constants.TAG,
            "Setting bar at " + collected.getHealth() + " win width=" + SoulissApp.getDisplayWidth() / 2);
}