From ab7c6cf8340366466943c88695198bd036e6cdaa Mon Sep 17 00:00:00 2001 From: Mis012 Date: Sat, 16 Mar 2024 18:55:14 +0100 Subject: [PATCH] api-impl: add stubs to make AnimationDrawable and Animation not cause lockups apps may (ab)use AnimationDrawable.run and Animation.setAnimationListener to time transitions between states; even though we don't currently implement the animations, state transitions are still desirable (otherwise the app may lock up) --- .../graphics/drawable/AnimationDrawable.java | 18 ++++++++++++++++-- .../android/hardware/SensorManager.java | 4 ++++ .../android/view/animation/Animation.java | 12 +++++++++++- src/api-impl/android/widget/ImageView.java | 5 ++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/api-impl/android/graphics/drawable/AnimationDrawable.java b/src/api-impl/android/graphics/drawable/AnimationDrawable.java index e418c5f7..daf18c3a 100644 --- a/src/api-impl/android/graphics/drawable/AnimationDrawable.java +++ b/src/api-impl/android/graphics/drawable/AnimationDrawable.java @@ -1,7 +1,21 @@ package android.graphics.drawable; public class AnimationDrawable extends Drawable { - public void addFrame(Drawable drawable, int dummy) {} - public void start() {} + private int num_frames = 0; + + public int getNumberOfFrames() { + return num_frames; + } + + public void addFrame(Drawable drawable, int duration) { + num_frames++; + } + public void start() { + for(int i = 0; i < num_frames; i++) { + run(); + } + } public void stop() {} + + public void run() {} } diff --git a/src/api-impl/android/hardware/SensorManager.java b/src/api-impl/android/hardware/SensorManager.java index 903f3f47..f8a94f80 100644 --- a/src/api-impl/android/hardware/SensorManager.java +++ b/src/api-impl/android/hardware/SensorManager.java @@ -35,6 +35,10 @@ public class SensorManager { } } + public void unregisterListener(final SensorEventListener listener) { + unregisterListener(listener, null); + } + public void unregisterListener(final SensorEventListener listener, Sensor sensor) { System.out.println("STUB: andoroid.hw.SensorManager.unregisterListener"); } diff --git a/src/api-impl/android/view/animation/Animation.java b/src/api-impl/android/view/animation/Animation.java index 852e7a30..1c5fb6d9 100644 --- a/src/api-impl/android/view/animation/Animation.java +++ b/src/api-impl/android/view/animation/Animation.java @@ -2,7 +2,11 @@ package android.view.animation; public class Animation { - public interface AnimationListener {} + public interface AnimationListener { + public void onAnimationEnd(Animation animation); + public void onAnimationRepeat(Animation animation); + public void onAnimationStart(Animation animation); + } public void setDuration(long durationMillis) {} @@ -12,4 +16,10 @@ public class Animation { public void setFillBefore(boolean dummy) {} public void setFillAfter(boolean dummy) {} + + public void setStartOffset(long offset) {} + + public void setAnimationListener(AnimationListener l) { + l.onAnimationEnd(this); // FIXME + } } diff --git a/src/api-impl/android/widget/ImageView.java b/src/api-impl/android/widget/ImageView.java index 9ba05d17..4f177390 100644 --- a/src/api-impl/android/widget/ImageView.java +++ b/src/api-impl/android/widget/ImageView.java @@ -13,7 +13,7 @@ import android.view.View; public class ImageView extends View { - private Bitmap bitmap; + private Bitmap bitmap = null; private ScaleType scaleType = ScaleType.FIT_CENTER; public ImageView(Context context, AttributeSet attrs) { @@ -61,6 +61,9 @@ public class ImageView extends View { } public Drawable getDrawable() { + if(bitmap == null) + return null; + return new BitmapDrawable(getContext().getResources(), bitmap); }