diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-04-08 15:29:48 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-04-08 15:37:29 +0100 |
commit | 93b5a19064fab0c0fb4530a44d137d29c39e808f (patch) | |
tree | f09bf9f1232be72157f8713524aaf429f2cee8be | |
parent | a5347efa93cf7bf2cb4ba281e3693d24a2bcc839 (diff) | |
download | mupdf-93b5a19064fab0c0fb4530a44d137d29c39e808f.tar.xz |
Android: Fix operation under Froyo/Gingerbread.
Android resolves references at class load time, so when MuPDFActivity
is loaded, it tries to resolve AnimatorInflater. This fails on a 2.2
system.
The fix is to push the code into 'SafeAnimatorInflater'. When
MuPDFActivity is loaded, SafeAnimatorInflater is resolved, but
it's not actually loaded until it's used. We never use it unless
we have at least honeycomb, hence we never try to resolve the missing
class.
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFActivity.java | 22 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java | 37 |
2 files changed, 38 insertions, 21 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index 63f5b963..37a00f5e 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -3,9 +3,6 @@ package com.artifex.mupdfdemo; import java.io.InputStream; import java.util.concurrent.Executor; -import android.animation.Animator; -import android.animation.AnimatorInflater; -import android.animation.AnimatorSet; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; @@ -805,24 +802,7 @@ public class MuPDFActivity extends Activity int currentApiVersion = android.os.Build.VERSION.SDK_INT; if (currentApiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { - AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.info); - set.setTarget(mInfoView); - set.addListener(new Animator.AnimatorListener() { - public void onAnimationStart(Animator animation) { - mInfoView.setVisibility(View.VISIBLE); - } - - public void onAnimationRepeat(Animator animation) { - } - - public void onAnimationEnd(Animator animation) { - mInfoView.setVisibility(View.INVISIBLE); - } - - public void onAnimationCancel(Animator animation) { - } - }); - set.start(); + SafeAnimatorInflater safe = new SafeAnimatorInflater((Activity)this, R.animator.info, (View)mInfoView); } else { mInfoView.setVisibility(View.VISIBLE); mHandler.postDelayed(new Runnable() { diff --git a/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java b/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java new file mode 100644 index 00000000..7c6a7ebc --- /dev/null +++ b/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java @@ -0,0 +1,37 @@ +package com.artifex.mupdfdemo; + +import android.animation.Animator; +import android.view.View; +import android.view.animation.Animation; +import android.animation.AnimatorInflater; +import android.animation.AnimatorSet; +import android.view.View; +import android.app.Activity; + +public class SafeAnimatorInflater +{ + private View mView; + + public SafeAnimatorInflater(Activity activity, int animation, View view) + { + AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(activity, R.animator.info); + mView = view; + set.setTarget(view); + set.addListener(new Animator.AnimatorListener() { + public void onAnimationStart(Animator animation) { + mView.setVisibility(View.VISIBLE); + } + + public void onAnimationRepeat(Animator animation) { + } + + public void onAnimationEnd(Animator animation) { + mView.setVisibility(View.INVISIBLE); + } + + public void onAnimationCancel(Animator animation) { + } + }); + set.start(); + } +} |