2023-07-25 14:29:43 +02:00
|
|
|
package android.graphics.drawable;
|
|
|
|
|
2023-12-29 16:55:11 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2023-12-29 23:47:38 +01:00
|
|
|
import java.util.Arrays;
|
2023-12-29 16:55:11 +01:00
|
|
|
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
|
2023-09-12 23:18:47 +02:00
|
|
|
import android.content.res.ColorStateList;
|
2023-08-17 10:46:24 +02:00
|
|
|
import android.content.res.Resources;
|
2023-12-29 16:55:11 +01:00
|
|
|
import android.content.res.XmlResourceParser;
|
2024-02-03 23:40:20 +01:00
|
|
|
import android.content.res.Resources.Theme;
|
2023-08-06 14:27:30 +02:00
|
|
|
import android.graphics.Canvas;
|
2023-08-22 14:41:01 +02:00
|
|
|
import android.graphics.ColorFilter;
|
2023-08-17 10:46:24 +02:00
|
|
|
import android.graphics.PorterDuff;
|
2023-08-06 14:27:30 +02:00
|
|
|
import android.graphics.Rect;
|
2024-02-03 23:40:20 +01:00
|
|
|
import android.util.AttributeSet;
|
2023-12-29 16:55:11 +01:00
|
|
|
import android.util.TypedValue;
|
2023-07-25 14:29:43 +02:00
|
|
|
|
2023-12-29 16:55:11 +01:00
|
|
|
public class Drawable {
|
2023-08-17 10:46:24 +02:00
|
|
|
public static interface Callback {}
|
2023-08-06 14:27:30 +02:00
|
|
|
|
|
|
|
private Rect mBounds = new Rect();
|
2023-08-17 10:46:24 +02:00
|
|
|
private int[] mStateSet = new int[0];
|
2023-12-29 16:55:11 +01:00
|
|
|
public long paintable;
|
|
|
|
|
|
|
|
public Drawable() {}
|
|
|
|
|
|
|
|
public Drawable(long paintable) {
|
|
|
|
this.paintable = paintable;
|
|
|
|
}
|
2023-08-06 14:27:30 +02:00
|
|
|
|
|
|
|
public int getChangingConfigurations() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChangingConfigurations(int bitmap) {}
|
|
|
|
|
|
|
|
public ConstantState getConstantState() {
|
2023-08-17 10:46:24 +02:00
|
|
|
return null;
|
2023-08-06 14:27:30 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 10:46:24 +02:00
|
|
|
public abstract class ConstantState {
|
|
|
|
|
2023-09-01 12:55:04 +02:00
|
|
|
public abstract Drawable newDrawable(Resources res);
|
|
|
|
|
|
|
|
public abstract Drawable newDrawable();
|
2023-08-06 14:27:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setBounds(int left, int top, int right, int bottom) {
|
|
|
|
mBounds.set(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final Rect getBounds() {
|
|
|
|
return mBounds;
|
|
|
|
}
|
|
|
|
|
2023-12-29 16:55:11 +01:00
|
|
|
public void draw(Canvas canvas) {}
|
2023-08-17 10:46:24 +02:00
|
|
|
|
|
|
|
public boolean setState(int[] stateSet) {
|
2023-12-29 23:47:38 +01:00
|
|
|
if (!Arrays.equals(this.mStateSet, stateSet)) {
|
|
|
|
this.mStateSet = stateSet;
|
|
|
|
return onStateChange(stateSet);
|
|
|
|
}
|
2023-08-17 10:46:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getState() {
|
|
|
|
return mStateSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void invalidateSelf() {}
|
|
|
|
|
|
|
|
public void setCallback(Callback callback) {}
|
|
|
|
|
|
|
|
public boolean isVisible() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean setVisible (boolean visible, boolean restart) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearColorFilter() {}
|
|
|
|
|
|
|
|
public final int getLevel() {return 0;}
|
|
|
|
public final boolean setLevel(int level) {return false;}
|
|
|
|
|
|
|
|
public void setBounds(Rect bounds) {}
|
|
|
|
|
|
|
|
public void setColorFilter(int color, PorterDuff.Mode mode) {}
|
2023-08-22 14:41:01 +02:00
|
|
|
public void setColorFilter(ColorFilter filter) {}
|
2023-08-17 10:46:24 +02:00
|
|
|
|
|
|
|
public Drawable mutate() {
|
|
|
|
return this;
|
|
|
|
}
|
2023-08-22 14:41:01 +02:00
|
|
|
|
|
|
|
public int getIntrinsicWidth() {return 0;}
|
|
|
|
public int getIntrinsicHeight() {return 0;}
|
2023-09-12 23:18:47 +02:00
|
|
|
|
|
|
|
public void setTintList (ColorStateList tint) {}
|
2023-11-08 21:40:39 +01:00
|
|
|
|
|
|
|
public void setTint(int tint) {}
|
|
|
|
|
|
|
|
public boolean isStateful() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTintMode(PorterDuff.Mode tintMode) {}
|
2023-12-29 11:09:37 +01:00
|
|
|
|
|
|
|
public boolean isProjected () {return false;}
|
2023-12-29 16:55:11 +01:00
|
|
|
|
|
|
|
public static Drawable createFromXml(Resources resources, XmlResourceParser parser) throws XmlPullParserException, IOException {
|
|
|
|
int type;
|
|
|
|
while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
|
|
|
|
if (type != XmlPullParser.START_TAG)
|
|
|
|
throw new XmlPullParserException("No start tag found");
|
|
|
|
if ("selector".equals(parser.getName())) {
|
|
|
|
StateListDrawable drawable = new StateListDrawable();
|
|
|
|
drawable.inflate(resources, parser, parser, null);
|
|
|
|
return drawable;
|
2023-12-30 17:09:55 +01:00
|
|
|
} else if ("shape".equals(parser.getName())) {
|
|
|
|
return new GradientDrawable();
|
2023-12-30 17:31:56 +01:00
|
|
|
} else if ("bitmap".equals(parser.getName())) {
|
|
|
|
BitmapDrawable drawable = new BitmapDrawable();
|
|
|
|
drawable.inflate(resources, parser, parser, null);
|
|
|
|
return drawable;
|
2023-12-29 16:55:11 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-02-03 23:40:20 +01:00
|
|
|
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-12-29 16:55:11 +01:00
|
|
|
public static Drawable createFromResourceStream(Resources resources, TypedValue value, InputStream is, String file,
|
|
|
|
Object object) {
|
|
|
|
Path path = Paths.get(android.os.Environment.getExternalStorageDirectory().getPath(), file);
|
|
|
|
if (!Files.exists(path)) {
|
|
|
|
try (InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(file)) {
|
|
|
|
if (inputStream != null) {
|
|
|
|
Files.createDirectories(path.getParent());
|
|
|
|
Files.copy(inputStream, path);
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
long paintable = native_paintable_from_path(path.toString());
|
|
|
|
return new Drawable(paintable);
|
|
|
|
}
|
|
|
|
|
2023-12-29 23:47:38 +01:00
|
|
|
protected boolean onStateChange(int[] stateSet) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-30 17:09:55 +01:00
|
|
|
public void setAlpha(int alpha) {}
|
|
|
|
|
|
|
|
public boolean getPadding(Rect padding) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-29 16:55:11 +01:00
|
|
|
protected static native long native_paintable_from_path(String path);
|
2023-07-25 14:29:43 +02:00
|
|
|
}
|