From 93b5a19064fab0c0fb4530a44d137d29c39e808f Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 8 Apr 2013 15:29:48 +0100 Subject: 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. --- .../src/com/artifex/mupdfdemo/MuPDFActivity.java | 22 +------------ .../artifex/mupdfdemo/SafeAnimatorInflater.java | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java (limited to 'android') 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(); + } +} -- cgit v1.2.3