OSDN Git Service

Video: Fix crash in trimming/muting video in GB.
authorTeng-Hui Zhu <ztenghui@google.com>
Tue, 13 Nov 2012 18:39:38 +0000 (10:39 -0800)
committerTeng-Hui Zhu <ztenghui@google.com>
Fri, 16 Nov 2012 18:09:27 +0000 (10:09 -0800)
Basically switched to use sherlock actionbar and protect various new methods
with API level check.

bug:7546257

Change-Id: Ic16f75126c619578a9e9c2520fa264687d89a2e6

gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
src/com/android/gallery3d/app/MuteVideo.java
src/com/android/gallery3d/app/TrimControllerOverlay.java
src/com/android/gallery3d/app/TrimVideo.java

index c13e81e..e043274 100644 (file)
@@ -173,6 +173,9 @@ public class ApiHelper {
     public static final boolean HAS_ANNOUNCE_FOR_ACCESSIBILITY =
             Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN;
 
+    public static final boolean HAS_OBJECT_ANIMATION =
+            Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB;
+
     public static int getIntFieldIfExists(Class<?> klass, String fieldName,
             Class<?> obj, int defaultVal) {
         try {
index fbb1804..012b682 100644 (file)
@@ -83,8 +83,7 @@ public class MuteVideo {
                             // Show the result only when the activity not
                             // stopped.
                             Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
-                            intent.setDataAndTypeAndNormalize(
-                                    Uri.fromFile(mDstFileInfo.mFile), "video/*");
+                            intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
                             intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
                             mActivity.startActivity(intent);
                         }
index 9127ad1..cae0166 100644 (file)
@@ -23,6 +23,8 @@ import android.content.Context;
 import android.view.MotionEvent;
 import android.view.View;
 
+import com.android.gallery3d.common.ApiHelper;
+
 /**
  * The controller for the Trimming Video.
  */
@@ -41,36 +43,41 @@ public class TrimControllerOverlay extends CommonControllerOverlay  {
         if (mState == State.PLAYING) {
             mPlayPauseReplayView.setVisibility(View.INVISIBLE);
         }
-        mPlayPauseReplayView.setAlpha(1f);
+        if (ApiHelper.HAS_OBJECT_ANIMATION) {
+            mPlayPauseReplayView.setAlpha(1f);
+        }
     }
 
     @Override
     public void showPlaying() {
         super.showPlaying();
+        if (ApiHelper.HAS_OBJECT_ANIMATION) {
+            // Add animation to hide the play button while playing.
+            ObjectAnimator anim = ObjectAnimator.ofFloat(mPlayPauseReplayView, "alpha", 1f, 0f);
+            anim.setDuration(200);
+            anim.start();
+            anim.addListener(new AnimatorListener() {
+                @Override
+                public void onAnimationStart(Animator animation) {
+                }
 
-        // Add animation to hide the play button while playing.
-        ObjectAnimator anim = ObjectAnimator.ofFloat(mPlayPauseReplayView, "alpha", 1f, 0f);
-        anim.setDuration(200);
-        anim.start();
-        anim.addListener(new AnimatorListener() {
-            @Override
-            public void onAnimationStart(Animator animation) {
-            }
-
-            @Override
-            public void onAnimationEnd(Animator animation) {
-                hidePlayButtonIfPlaying();
-            }
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    hidePlayButtonIfPlaying();
+                }
 
-            @Override
-            public void onAnimationCancel(Animator animation) {
-                hidePlayButtonIfPlaying();
-            }
+                @Override
+                public void onAnimationCancel(Animator animation) {
+                    hidePlayButtonIfPlaying();
+                }
 
-            @Override
-            public void onAnimationRepeat(Animator animation) {
-            }
-          });
+                @Override
+                public void onAnimationRepeat(Animator animation) {
+                }
+            });
+        } else {
+            hidePlayButtonIfPlaying();
+        }
     }
 
     @Override
index 9187ee8..7a76be5 100644 (file)
@@ -16,8 +16,6 @@
 
 package com.android.gallery3d.app;
 
-import android.app.ActionBar;
-import android.app.Activity;
 import android.app.ProgressDialog;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -39,6 +37,8 @@ import android.widget.TextView;
 import android.widget.Toast;
 import android.widget.VideoView;
 
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockActivity;
 import com.android.gallery3d.R;
 import com.android.gallery3d.util.BucketNames;
 import com.android.gallery3d.util.SaveVideoFileInfo;
@@ -49,7 +49,7 @@ import java.io.IOException;
 import java.sql.Date;
 import java.text.SimpleDateFormat;
 
-public class TrimVideo extends Activity implements
+public class TrimVideo extends SherlockActivity implements
         MediaPlayer.OnErrorListener,
         MediaPlayer.OnCompletionListener,
         ControllerOverlay.Listener {
@@ -84,7 +84,7 @@ public class TrimVideo extends Activity implements
         requestWindowFeature(Window.FEATURE_ACTION_BAR);
         requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
 
-        ActionBar actionBar = getActionBar();
+        ActionBar actionBar = getSupportActionBar();
         int displayOptions = ActionBar.DISPLAY_SHOW_HOME;
         actionBar.setDisplayOptions(0, displayOptions);
         displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM;
@@ -268,7 +268,7 @@ public class TrimVideo extends Activity implements
                             mProgress = null;
                             // Show the result only when the activity not stopped.
                             Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
-                            intent.setDataAndTypeAndNormalize(Uri.fromFile(mDstFileInfo.mFile), "video/*");
+                            intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
                             intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
                             startActivity(intent);
                             finish();