</pre><pre name="code" class="java">public class Themometer extends ImageView {
private Paint mPaint;
private int height, width, circle_radius;
private int COLOR_BROWN = Color.parseColor("#A5937B");
private int COLOR_YELLOW = Color.parseColor("#F7AF1F");
private int COLOR_GRAY = Color.parseColor("#C1CDCD");
private int COLOR_TEXT = Color.parseColor("#49BDCC");
private float temperature = 0f;
private float temp_temperature = 0f;
public void setTemperature(float value) {
Log.e(this.getClass().getSimpleName(), "setTemperature " + value);
if (value < 0f) {
value = 0;
} else if (value > 41.5f) {
value = 41.5f;
}
if (value <= 34f) {
value = new BigDecimal(value).setScale(0, BigDecimal.ROUND_HALF_UP).floatValue();
} else {
value = new BigDecimal(value).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
}
if (temp_temperature > value) {
temp_temperature = 0f;
}
temperature = value;
invalidate();
}
public Themometer(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public Themometer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mPaint = new Paint();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
this.height = getMeasuredHeight();
this.width = getMeasuredWidth();
circle_radius = width / 4;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawBG(canvas);
drawScale(canvas);
drawFG(canvas);
if (temp_temperature < temperature && temp_temperature < 41.5) {
if (temp_temperature < 34) {
BigDecimal b1 = new BigDecimal(Float.toString(temp_temperature));
BigDecimal b2 = new BigDecimal(Float.toString(1f));
temp_temperature = b1.add(b2).floatValue();
} else {
BigDecimal b1 = new BigDecimal(Float.toString(temp_temperature));
BigDecimal b2 = new BigDecimal(Float.toString(0.1f));
temp_temperature = b1.add(b2).floatValue();
}
invalidate();
}
// else if(temp_temperature>temperature && temp_temperature>0){
// if (temp_temperature < 34) {
// BigDecimal b1 = new BigDecimal(Float.toString(temp_temperature));
// BigDecimal b2 = new BigDecimal(Float.toString(1f));
// temp_tem