If you think the Android project nxt-remote-controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.gc.materialdesign.views;
//fromwww.java2s.comimport com.gc.materialdesign.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
publicclass ProgressBarDeterminate extends CustomView {
privateint max = 100;
privateint min = 0;
privateint progress = 0;
protected View progressView;
public ProgressBarDeterminate(Context context, AttributeSet attrs) {
super(context, attrs);
setAttributes(attrs);
}
@Override
protectedvoid onInitDefaultValues() {
minWidth = 40;
minHeight = 3;
backgroundColor = Color.parseColor("#1E88E5");
}
// Set atributtes of XML to View
@Override
protectedvoid setAttributes(AttributeSet attrs) {
progressView = new View(getContext());
RelativeLayout.LayoutParams params = new LayoutParams(1, 1);
progressView.setLayoutParams(params);
if (!isInEditMode()) {
progressView.setBackgroundResource(R.drawable.background_progress);
}
addView(progressView);
//super????view??????????setAttr?????????????view???????????null
super.setAttributes(attrs);
min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 100);
progress = attrs.getAttributeIntValue(MATERIALDESIGNXML, "progress", min);
post(new Runnable() {
@Override
publicvoid run() {
RelativeLayout.LayoutParams params = (LayoutParams) progressView.getLayoutParams();
params.height = getHeight();
progressView.setLayoutParams(params);
//setProgress(progress);
}
});
}
// SETTERS
@Override
protectedvoid onDraw(Canvas canvas) {
super.onDraw(canvas);
if (pendindProgress != -1)
setProgress(pendindProgress);
}
publicvoid setMax(int max) {
this.max = max;
}
publicint getMax() {
return max;
}
publicvoid setMin(int min) {
this.min = min;
}
publicint getMin() {
return min;
}
privateint pendindProgress = -1;
publicvoid setProgress(int progress) {
this.progress = progress;
if (getWidth() == 0) {
pendindProgress = progress;
} else {
//this.progress = progress;
if (progress > max)
progress = max;
if (progress < min)
progress = min;
int totalWidth = max - min;
double progressPercent = (double) progress / (double) totalWidth;
int progressWidth = (int) (getWidth() * progressPercent);
RelativeLayout.LayoutParams params = (LayoutParams) progressView.getLayoutParams();
params.width = progressWidth;
params.height = getHeight();
progressView.setLayoutParams(params);
pendindProgress = -1;
}
}
publicint getProgress() {
return progress;
}
// Set color of background
publicvoid setBackgroundColor(int color) {
backgroundColor = color;
if (!isInEditMode()) {
if (isEnabled()) {
beforeBackground = backgroundColor;
}
LayerDrawable layer = (LayerDrawable) progressView.getBackground();
GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
shape.setColor(color);
}
super.setBackgroundColor(makePressColor(128));
}
/**
* Make a dark color to ripple effect
* @return
*/
@Override
protectedint makePressColor(int alpha){
int r = (this.backgroundColor >> 16) & 0xFF;
int g = (this.backgroundColor >> 8) & 0xFF;
int b = (this.backgroundColor >> 0) & 0xFF;
return Color.argb(alpha,r, g, b);
}
}