2022-10-02 23:06:56 +02:00
|
|
|
package android.widget;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2024-02-18 08:30:32 +01:00
|
|
|
import android.content.res.TypedArray;
|
2023-09-19 23:22:21 +02:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2023-06-22 11:45:46 +02:00
|
|
|
import android.util.AttributeSet;
|
2022-10-02 23:06:56 +02:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
public class ProgressBar extends View {
|
2023-11-12 12:01:02 +01:00
|
|
|
|
2024-03-10 17:33:37 +01:00
|
|
|
protected int max = 100;
|
|
|
|
protected int progress = 0;
|
2023-11-12 12:01:02 +01:00
|
|
|
|
2024-02-17 15:20:11 +01:00
|
|
|
public ProgressBar(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
2024-03-12 18:19:43 +01:00
|
|
|
haveCustomMeasure = false;
|
2024-02-18 08:30:32 +01:00
|
|
|
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ProgressBar, defStyle, 0);
|
|
|
|
setIndeterminate(a.getBoolean(com.android.internal.R.styleable.ProgressBar_indeterminate, false));
|
|
|
|
a.recycle();
|
2024-02-17 15:20:11 +01:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:04 +02:00
|
|
|
public ProgressBar(Context context, AttributeSet attrs) {
|
2024-02-17 15:20:11 +01:00
|
|
|
this(context, attrs, 0);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ProgressBar(Context context) {
|
2024-02-17 15:20:11 +01:00
|
|
|
this(context, null, 0);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
2023-11-12 12:01:02 +01:00
|
|
|
@Override
|
|
|
|
protected native long native_constructor(Context context, AttributeSet attrs);
|
2024-03-10 17:33:37 +01:00
|
|
|
protected native void native_setProgress(long widget, float fraction);
|
2023-11-12 12:01:02 +01:00
|
|
|
|
2024-02-18 08:30:32 +01:00
|
|
|
public native void setIndeterminate(boolean indeterminate);
|
2023-09-19 23:22:21 +02:00
|
|
|
|
|
|
|
public Drawable getProgressDrawable() {
|
|
|
|
return new Drawable() {
|
|
|
|
@Override
|
|
|
|
public void draw(Canvas canvas) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("Unimplemented method 'draw'");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public Drawable getIndeterminateDrawable() {
|
|
|
|
return new Drawable() {
|
|
|
|
@Override
|
|
|
|
public void draw(Canvas canvas) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("Unimplemented method 'draw'");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
2023-11-12 12:01:02 +01:00
|
|
|
public void setMax(int max) {
|
|
|
|
this.max = max;
|
|
|
|
native_setProgress(widget, progress / (float)max);
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
public int getMax() {
|
2023-11-12 12:01:02 +01:00
|
|
|
return max;
|
2023-09-21 22:49:36 +02:00
|
|
|
}
|
|
|
|
|
2023-11-12 12:01:02 +01:00
|
|
|
public void setProgress(int progress) {
|
|
|
|
this.progress = progress;
|
|
|
|
native_setProgress(widget, progress / (float)max);
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
public void setSecondaryProgress(int secondaryProgress) {}
|
|
|
|
|
|
|
|
public int getProgress() {
|
2023-11-12 12:01:02 +01:00
|
|
|
return progress;
|
2023-09-21 22:49:36 +02:00
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|