Java Code Examples for android.graphics.drawable.ScaleDrawable#getDrawable()

The following examples show how to use android.graphics.drawable.ScaleDrawable#getDrawable() . 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: PlayActivity.java    From AndroidDemo with MIT License 5 votes vote down vote up
private void setSeekBarBg(){
    try {
        int progressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorPrimary,R.color.colorAccent,this);
        LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable();
        ScaleDrawable scaleDrawable = (ScaleDrawable)layerDrawable.findDrawableByLayerId(android.R.id.progress);
        GradientDrawable drawable = (GradientDrawable) scaleDrawable.getDrawable();
        drawable.setColor(progressColor);
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
Example 2
Source File: PlayActivity.java    From MeetMusic with Apache License 2.0 5 votes vote down vote up
private void setSeekBarBg(){
    try {
        int progressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorPrimary,R.color.colorAccent,this);
        LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable();
        ScaleDrawable scaleDrawable = (ScaleDrawable)layerDrawable.findDrawableByLayerId(android.R.id.progress);
        GradientDrawable drawable = (GradientDrawable) scaleDrawable.getDrawable();
        drawable.setColor(progressColor);
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
Example 3
Source File: ChartProgressBar.java    From ChartProgressBar-Android with Apache License 2.0 4 votes vote down vote up
private FrameLayout getBar(final String title, final int value, final int index) {

		int maxValue = (int) (mMaxValue * 100);

		LinearLayout linearLayout = new LinearLayout(mContext);
		FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
			LayoutParams.MATCH_PARENT,
			LayoutParams.MATCH_PARENT
		);

		params.gravity = Gravity.CENTER;
		linearLayout.setLayoutParams(params);
		linearLayout.setOrientation(LinearLayout.VERTICAL);
		linearLayout.setGravity(Gravity.CENTER);

		//Adding bar
		Bar bar = new Bar(mContext, null, android.R.attr.progressBarStyleHorizontal);
		bar.setProgress(value);
		bar.setVisibility(View.VISIBLE);
		bar.setIndeterminate(false);

		bar.setMax(maxValue);

		bar.setProgressDrawable(ContextCompat.getDrawable(mContext, R.drawable.progress_bar_shape));

		LayoutParams progressParams = new LayoutParams(
			mBarWidth,
			mBarHeight
		);

		progressParams.gravity = Gravity.CENTER;
		bar.setLayoutParams(progressParams);

		BarAnimation anim = new BarAnimation(bar, 0, value);
		anim.setDuration(250);
		bar.startAnimation(anim);

		LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
		layerDrawable.mutate();

		GradientDrawable emptyLayer = (GradientDrawable) layerDrawable.getDrawable(0);
		ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

		emptyLayer.setColor(ContextCompat.getColor(mContext, mEmptyColor));
		emptyLayer.setCornerRadius(mBarRadius);

		GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();

		if (progressLayer != null) {
			progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor));
			progressLayer.setCornerRadius(mBarRadius);
		}


		linearLayout.addView(bar);

		//Adding txt below bar
		TextView txtBar = new TextView(mContext);
		LayoutParams txtParams = new LayoutParams(
			LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT
		);

		txtBar.setTextSize(getSP(mBarTitleTxtSize));
		txtBar.setText(title);
		txtBar.setGravity(Gravity.CENTER);
		txtBar.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor));
		txtBar.setPadding(0, mBarTitleMarginTop, 0, 0);

		txtBar.setLayoutParams(txtParams);

		linearLayout.addView(txtBar);

		FrameLayout rootFrameLayout = new FrameLayout(mContext);
		LinearLayout.LayoutParams rootParams = new LinearLayout.LayoutParams(
			0,
			LayoutParams.MATCH_PARENT,
			1f
		);

		rootParams.gravity = Gravity.CENTER;


		//rootParams.setMargins(0, h, 0, h);
		rootFrameLayout.setLayoutParams(rootParams);


		//Adding bar + title
		rootFrameLayout.addView(linearLayout);

		if (isBarCanBeClick)
			rootFrameLayout.setOnClickListener(barClickListener);

		rootFrameLayout.setTag(index);
		return rootFrameLayout;
	}
 
Example 4
Source File: ChartProgressBar.java    From ChartProgressBar-Android with Apache License 2.0 4 votes vote down vote up
private void clickBarOn(FrameLayout frameLayout) {

		pins.get((int) frameLayout.getTag()).setVisibility(View.VISIBLE);

		isOldBarClicked = true;

		int childCount = frameLayout.getChildCount();

		for (int i = 0; i < childCount; i++) {

			View childView = frameLayout.getChildAt(i);
			if (childView instanceof LinearLayout) {

				LinearLayout linearLayout = (LinearLayout) childView;
				Bar bar = (Bar) linearLayout.getChildAt(0);
				TextView titleTxtView = (TextView) linearLayout.getChildAt(1);

				LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
				layerDrawable.mutate();

				ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

				GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();
				if (mPinBackgroundColor != 0) {
					if (progressLayer != null) {
						progressLayer.setColor(ContextCompat.getColor(mContext, mProgressClickColor));
					}

				} else {
					if (progressLayer != null) {
						progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.holo_green_dark));
					}
				}

				if (mBarTitleSelectedColor > 0) {
					titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleSelectedColor));
				} else {
					titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_green_dark));
				}

			}
		}
	}
 
Example 5
Source File: ChartProgressBar.java    From ChartProgressBar-Android with Apache License 2.0 4 votes vote down vote up
public void disableBar(int index) {

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);

			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				if ((int) rootFrame.getTag() != index)
					continue;

				rootFrame.setEnabled(false);
				rootFrame.setClickable(false);

				View childView = rootFrame.getChildAt(j);
				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {

							Bar bar = (Bar) view;

							LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
							layerDrawable.mutate();

							ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

							GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();

							if (progressLayer != null) {

								if (mProgressDisableColor > 0)
									progressLayer.setColor(ContextCompat.getColor(mContext, mProgressDisableColor));
								else
									progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
							}
						} else {
							TextView titleTxtView = (TextView) view;
							if (mProgressDisableColor > 0)
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, mProgressDisableColor));
							else
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
						}
					}
				}
			}
		}
	}
 
Example 6
Source File: ChartProgressBar.java    From ChartProgressBar-Android with Apache License 2.0 4 votes vote down vote up
public void enableBar(int index) {

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);

			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				if ((int) rootFrame.getTag() != index)
					continue;

				rootFrame.setEnabled(true);
				rootFrame.setClickable(true);

				View childView = rootFrame.getChildAt(j);
				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {

							Bar bar = (Bar) view;

							LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
							layerDrawable.mutate();

							ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

							GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();

							if (progressLayer != null) {

								if (mProgressColor > 0)
									progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor));
								else
									progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
							}
						} else {
							TextView titleTxtView = (TextView) view;
							if (mProgressDisableColor > 0)
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor));
							else
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
						}
					}
				}
			}
		}
	}
 
Example 7
Source File: ChartProgressBar.java    From ChartProgressBar-Android with Apache License 2.0 3 votes vote down vote up
private void clickBarOff(FrameLayout frameLayout) {

		pins.get((int) frameLayout.getTag()).setVisibility(View.INVISIBLE);


		isOldBarClicked = false;

		int childCount = frameLayout.getChildCount();

		for (int i = 0; i < childCount; i++) {

			View childView = frameLayout.getChildAt(i);
			if (childView instanceof LinearLayout) {

				LinearLayout linearLayout = (LinearLayout) childView;
				Bar bar = (Bar) linearLayout.getChildAt(0);
				TextView titleTxtView = (TextView) linearLayout.getChildAt(1);

				LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
				layerDrawable.mutate();

				ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

				GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();
				if (progressLayer != null) {
					progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor));
				}
				titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor));
			}
		}
	}