2023-09-01 12:55:04 +02:00
|
|
|
package android.graphics.drawable;
|
|
|
|
|
|
2023-12-29 23:47:38 +01:00
|
|
|
import android.content.res.Resources;
|
2024-05-19 15:08:49 +02:00
|
|
|
import android.graphics.Canvas;
|
2023-09-01 12:55:04 +02:00
|
|
|
|
|
|
|
|
public class DrawableContainer extends Drawable {
|
|
|
|
|
|
2023-12-29 23:47:38 +01:00
|
|
|
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);
|
2024-04-03 01:54:30 +02:00
|
|
|
invalidateSelf();
|
2023-12-29 23:47:38 +01:00
|
|
|
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) {
|
|
|
|
|
}
|
2024-04-03 01:54:30 +02:00
|
|
|
|
2023-12-29 23:47:38 +01:00
|
|
|
public int getCapacity() {
|
|
|
|
|
return drawables.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getChildCount() {
|
|
|
|
|
return childCount;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 01:54:30 +02:00
|
|
|
public Drawable getChild(int idx) {
|
|
|
|
|
return drawables[idx];
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 23:47:38 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2023-09-01 12:55:04 +02:00
|
|
|
}
|
2024-04-03 01:54:30 +02:00
|
|
|
|
2024-05-19 15:08:49 +02:00
|
|
|
@Override
|
|
|
|
|
public void draw(Canvas canvas) {
|
2025-03-26 21:01:57 +01:00
|
|
|
if (curIndex != -1)
|
|
|
|
|
state.drawables[curIndex].draw(canvas);
|
2024-05-19 15:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getIntrinsicHeight() {
|
2025-03-26 21:01:57 +01:00
|
|
|
return curIndex != -1 ? state.drawables[curIndex].getIntrinsicHeight() : -1;
|
2024-05-19 15:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getIntrinsicWidth() {
|
2025-03-26 21:01:57 +01:00
|
|
|
return curIndex != -1 ? state.drawables[curIndex].getIntrinsicWidth() : -1;
|
2024-05-19 15:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setBounds(int left, int top, int right, int bottom) {
|
2025-03-26 21:01:57 +01:00
|
|
|
if (curIndex != -1)
|
|
|
|
|
state.drawables[curIndex].setBounds(left, top, right, bottom);
|
2024-05-19 15:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-22 18:02:54 +01:00
|
|
|
public void setEnterFadeDuration(int duration) {}
|
|
|
|
|
|
|
|
|
|
public void setExitFadeDuration(int duration) {}
|
|
|
|
|
|
2023-09-01 12:55:04 +02:00
|
|
|
}
|