implement DrawableContainer and copy StateListDrawable from AOSP

This commit is contained in:
Julian Winkler
2023-12-29 23:47:38 +01:00
parent 8c7dbf6ceb
commit ca3c17d773
9 changed files with 482 additions and 37 deletions

View File

@@ -1,13 +1,61 @@
package android.graphics.drawable;
import android.graphics.Canvas;
import android.content.res.Resources;
public class DrawableContainer extends Drawable {
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'draw'");
private DrawableContainerState state;
private int curIndex = -1;
protected native long native_constructor();
protected native void native_selectChild(long container, long child);
public DrawableContainer() {
paintable = native_constructor();
}
public boolean selectDrawable(int idx) {
if (idx >= 0 && idx < state.childCount && idx != curIndex && state.drawables[idx] != null) {
curIndex = idx;
native_selectChild(paintable, state.drawables[idx].paintable);
return true;
}
return false;
}
protected void setConstantState(DrawableContainerState state) {
this.state = state;
}
public static class DrawableContainerState {
private Drawable drawables[] = new Drawable[10];
private int childCount = 0;
public DrawableContainerState(DrawableContainerState orig, DrawableContainer owner, Resources res) {
}
public int getCapacity() {
return drawables.length;
}
public int getChildCount() {
return childCount;
}
public int addChild(Drawable dr) {
if (childCount >= drawables.length) {
growArray(drawables.length, drawables.length * 2);
}
drawables[childCount] = dr;
return childCount++;
}
public void growArray(int oldSize, int newSize) {
Drawable[] newDrawables = new Drawable[newSize];
System.arraycopy(drawables, 0, newDrawables, 0, oldSize);
drawables = newDrawables;
}
}
}