Java Code Examples for android.graphics.drawable.ClipDrawable#HORIZONTAL

The following examples show how to use android.graphics.drawable.ClipDrawable#HORIZONTAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultHeaderTransformer.java    From KlyphMessenger with MIT License 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 2
Source File: DefaultHeaderTransformer.java    From Bitocle with Apache License 2.0 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 3
Source File: FixedRatingBar.java    From proteus with Apache License 2.0 5 votes vote down vote up
/**
 * Taken from AOSP !!
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
public Drawable getTiledDrawable(Drawable drawable, boolean clip) {

  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] = getTiledDrawable(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) {

    final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
    if (sampleTile == null) {
      sampleTile = tileBitmap;
    }
    final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());

    final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
      Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
    shapeDrawable.getPaint().setShader(bitmapShader);

    return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
      ClipDrawable.HORIZONTAL) : shapeDrawable;
  }

  return drawable;
}
 
Example 4
Source File: DefaultHeaderTransformer.java    From Bitocle with Apache License 2.0 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 5
Source File: ProgressBarWrapper.java    From Man-Man with GNU General Public License v3.0 5 votes vote down vote up
private ProgressBar createProgressBar() {
    ProgressBar pb = (ProgressBar) View.inflate(mActivity, R.layout.actionbar_progressbar, null);
    ShapeDrawable shape = new ShapeDrawable();
    shape.setShape(new RectShape());
    shape.getPaint().setColor(Color.parseColor("#FF33B5E5"));
    ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);
    pb.setProgressDrawable(clipDrawable);
    return pb;
}
 
Example 6
Source File: ProgressBarParser.java    From proteus with Apache License 2.0 5 votes vote down vote up
Drawable getLayerDrawable(int progress, int background) {
  ShapeDrawable shape = new ShapeDrawable();
  shape.getPaint().setStyle(Paint.Style.FILL);
  shape.getPaint().setColor(background);

  ShapeDrawable shapeD = new ShapeDrawable();
  shapeD.getPaint().setStyle(Paint.Style.FILL);
  shapeD.getPaint().setColor(progress);
  ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL);

  return new LayerDrawable(new Drawable[]{shape, clipDrawable});
}
 
Example 7
Source File: ZProgressBar.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
private void createDrawable(){
    Drawable[] layers = new Drawable[2];
    Drawable background = makeBackground();
    Drawable progress = makeProgress();
    ClipDrawable clip = new ClipDrawable(progress
            , Gravity.LEFT, ClipDrawable.HORIZONTAL);
    layers[0] = background;
    layers[1] = clip;
    LayerDrawable layer = new LayerDrawable(layers);
    layer.setId(0, android.R.id.background);
    layer.setId(1, android.R.id.progress);
    setProgressDrawable(layer);
}
 
Example 8
Source File: DefaultHeaderTransformer.java    From AndroidPullMenu with Apache License 2.0 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 9
Source File: RatingBar.java    From Kore with Apache License 2.0 5 votes vote down vote up
private FrameLayout createStar(Context context, AttributeSet attrs, int defStyle) {
    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));

    AppCompatImageView ivStarBackground = new AppCompatImageView(context, attrs, defStyle);
    ivStarBackground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarBackground.setImageResource(iconResourceId);
    ivStarBackground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarBackground, ColorStateList.valueOf(backgroundColor));
    frameLayout.addView(ivStarBackground);

    ClipDrawable clipDrawable = new ClipDrawable(
            ContextCompat.getDrawable(context, iconResourceId),
            Gravity.START,
            ClipDrawable.HORIZONTAL);

    AppCompatImageView ivStarForeground = new AppCompatImageView(context, attrs, defStyle);
    ivStarForeground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarForeground.setImageDrawable(clipDrawable);
    ivStarForeground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarForeground, ColorStateList.valueOf(foregroundColor));
    frameLayout.addView(ivStarForeground);

    clipDrawables.add((ClipDrawable) ivStarForeground.getDrawable());

    return frameLayout;
}
 
Example 10
Source File: RefreshNowProgressIndicator.java    From RefreshNow with Apache License 2.0 5 votes vote down vote up
public IndicatorConfig build() {
	final LineDrawable line = new LineDrawable();
	line.setColor(progressColor);
	line.setStrokeWidth(progressStrokeWidth);
	final ClipDrawable progressDrawable = new ClipDrawable(line, Gravity.CENTER_VERTICAL,
			ClipDrawable.HORIZONTAL);
	return new IndicatorConfig(changeProgressDrawable ? progressDrawable : null,
			changeIndeterminateDrawable ? indeterminateDrawableBuilder.build() : null);
}
 
Example 11
Source File: LoadingImageView.java    From LoadingImageView with MIT License 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 12
Source File: FlatSeekBar.java    From GreenDamFileExploere with Apache License 2.0 4 votes vote down vote up
private void init(AttributeSet attrs) {

		if (attributes == null)
			attributes = new Attributes(this, getResources());

		if (attrs != null) {
			TypedArray a = getContext().obtainStyledAttributes(attrs,
					R.styleable.fl_FlatSeekBar);

			// getting common attributes
			int customTheme = a.getResourceId(
					R.styleable.fl_FlatSeekBar_fl_theme,
					Attributes.DEFAULT_THEME);
			attributes.setThemeSilent(customTheme, getResources());

			attributes.setSize(a.getDimensionPixelSize(
					R.styleable.fl_FlatSeekBar_fl_size,
					Attributes.DEFAULT_SIZE_PX));

			a.recycle();
		}

		// setting thumb
		PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
		thumb.setCornerRadius(attributes.getSize() * 9 / 8);
		thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
		thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
		setThumb(thumb);

		// progress
		PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
		progress.setCornerRadius(attributes.getSize());
		progress.setIntrinsicHeight(attributes.getSize());
		progress.setIntrinsicWidth(attributes.getSize());
		progress.setDither(true);
		ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT,
				ClipDrawable.HORIZONTAL);

		// secondary progress
		PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
		secondary.setCornerRadius(attributes.getSize());
		secondary.setIntrinsicHeight(attributes.getSize());
		ClipDrawable secondaryProgressClip = new ClipDrawable(secondary,
				Gravity.LEFT, ClipDrawable.HORIZONTAL);

		// background
		PaintDrawable background = new PaintDrawable(attributes.getColor(3));
		background.setCornerRadius(attributes.getSize());
		background.setIntrinsicHeight(attributes.getSize());

		// applying drawable
		LayerDrawable ld = (LayerDrawable) getProgressDrawable();
		ld.setDrawableByLayerId(android.R.id.background, background);
		ld.setDrawableByLayerId(android.R.id.progress, progressClip);
		ld.setDrawableByLayerId(android.R.id.secondaryProgress,
				secondaryProgressClip);
	}
 
Example 13
Source File: PlaybackControlsPresenter.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public void setProgressColor(ViewHolder vh, int color) {
    Drawable drawable = new ClipDrawable(new ColorDrawable(color),
            Gravity.LEFT, ClipDrawable.HORIZONTAL);
    ((LayerDrawable) vh.mProgressBar.getProgressDrawable())
            .setDrawableByLayerId(android.R.id.progress, drawable);
}
 
Example 14
Source File: IcsProgressBar.java    From Libraries-for-Android-Developers with MIT License 4 votes vote down vote up
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable, boolean clip) {

    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 StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = in.getStateCount();
        for (int i = 0; i < numStates; i++) {
            out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
        }
        return out;

    }*/ else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());

        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);

        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
Example 15
Source File: IcsProgressBar.java    From zen4android with MIT License 4 votes vote down vote up
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable, boolean clip) {

    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 StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = in.getStateCount();
        for (int i = 0; i < numStates; i++) {
            out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
        }
        return out;

    }*/ else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());

        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);

        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
Example 16
Source File: SkinCompatProgressBarHelper.java    From Android-skin-support with MIT License 4 votes vote down vote up
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
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) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
Example 17
Source File: MProgressBarDialog.java    From MNProgressHUD with Apache License 2.0 4 votes vote down vote up
private void configView() {
    try {
        //设置动画
        if (mBuilder != null && mBuilder.animationID != 0 && mDialog.getWindow() != null) {
            mDialog.getWindow().setWindowAnimations(mBuilder.animationID);
        }
    } catch (Exception e) {

    }
    dialog_window_background.setBackgroundColor(mBuilder.backgroundWindowColor);
    tvShow.setTextColor(mBuilder.textColor);

    GradientDrawable myGrad = (GradientDrawable) dialog_view_bg.getBackground();
    myGrad.setColor(mBuilder.backgroundViewColor);
    myGrad.setStroke(MSizeUtils.dp2px(mContext, mBuilder.strokeWidth), mBuilder.strokeColor);
    myGrad.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.cornerRadius));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        dialog_view_bg.setBackground(myGrad);
    } else {
        dialog_view_bg.setBackgroundDrawable(myGrad);
    }

    //horizontalProgressBar 配置
    //背景
    GradientDrawable progressBarBackgroundDrawable = new GradientDrawable();
    progressBarBackgroundDrawable.setColor(mBuilder.progressbarBackgroundColor);
    progressBarBackgroundDrawable.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.progressCornerRadius));
    //二级进度条
    GradientDrawable secondProgressDrawable = new GradientDrawable();
    secondProgressDrawable.setColor(mBuilder.progressbarBackgroundColor);
    secondProgressDrawable.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.progressCornerRadius));
    ClipDrawable hProgressBar02 = new ClipDrawable(secondProgressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    //一级进度条
    GradientDrawable progressDrawable = new GradientDrawable();
    progressDrawable.setColor(mBuilder.progressColor);
    progressDrawable.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.progressCornerRadius));
    ClipDrawable hProgressBar03 = new ClipDrawable(progressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    //组合
    Drawable[] layers = {progressBarBackgroundDrawable, hProgressBar02, hProgressBar03};
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setId(0, android.R.id.background);
    layerDrawable.setId(1, android.R.id.secondaryProgress);
    layerDrawable.setId(2, android.R.id.progress);
    horizontalProgressBar.setProgressDrawable(layerDrawable);

    ViewGroup.LayoutParams layoutParams = horizontalProgressBar.getLayoutParams();
    layoutParams.height = MSizeUtils.dp2px(mContext, mBuilder.horizontalProgressBarHeight);
    horizontalProgressBar.setLayoutParams(layoutParams);

    //circularProgressBar 配置
    circularProgressBar.setBackgroundColor(mBuilder.progressbarBackgroundColor);
    circularProgressBar.setColor(mBuilder.progressColor);
    circularProgressBar.setProgressBarWidth(MSizeUtils.dp2px(mContext, mBuilder.circleProgressBarWidth));
    circularProgressBar.setBackgroundProgressBarWidth(MSizeUtils.dp2px(mContext, mBuilder.circleProgressBarBackgroundWidth));
}
 
Example 18
Source File: SkinCompatProgressBarHelper.java    From AndroidSkinAnimator with MIT License 4 votes vote down vote up
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
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) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
Example 19
Source File: IcsProgressBar.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable, boolean clip) {

    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 StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = in.getStateCount();
        for (int i = 0; i < numStates; i++) {
            out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
        }
        return out;

    }*/ else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());

        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);

        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
Example 20
Source File: PartialView.java    From SSForms with GNU General Public License v3.0 4 votes vote down vote up
public void setFilledDrawable(Drawable drawable) {
    @SuppressLint("RtlHardcoded") ClipDrawable clipDrawable = new ClipDrawable(drawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    mFilledView.setImageDrawable(clipDrawable);
}