OSDN Git Service

Trimming: clean up strings and prevent too short or no trimming.
authorTeng-Hui Zhu <ztenghui@google.com>
Sat, 29 Sep 2012 20:32:01 +0000 (13:32 -0700)
committerTeng-Hui Zhu <ztenghui@google.com>
Sat, 29 Sep 2012 22:01:05 +0000 (15:01 -0700)
Also view the result if the activity is not stopped.
bug:7093055

Change-Id: If244d567a4be9da22542398f6b7c22a081786339

res/values/strings.xml
src/com/android/gallery3d/app/TrimVideo.java

index 7323a7d..61b45a2 100644 (file)
 
     <!-- Label for album grid button -->
     <string name="switch_photo_grid">Grid</string>
+
+    <!-- The tilte of a dialog showing trimming in progress. [CHAR LIMIT=20] -->
+    <string name="trimming">Trimming</string>
+
+    <!-- The content of a dialog showing trimming in progress. [CHAR LIMIT=30] -->
+    <string name="please_wait">Please wait</string>
+
+    <!-- Toast after the trimming is done. [CHAR LIMIT=50] -->
+    <string name="save_into">Save trimmed video into</string>
+
+    <!-- Toast if the trimmed video is too short to trim. [CHAR LIMIT=80] -->
+    <string name="trim_too_short">Can not trim : target video is too short</string>
+
+    <!-- Toast if the trimmed video is the same as the original one. [CHAR LIMIT=80] -->
+    <string name="trim_too_long">Did not trim : the same length as origin</string>
 </resources>
index ed66b4e..cb5b171 100644 (file)
@@ -31,7 +31,6 @@ import android.os.Environment;
 import android.os.Handler;
 import android.provider.MediaStore.Video;
 import android.provider.MediaStore.Video.VideoColumns;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.Window;
@@ -258,6 +257,21 @@ public class TrimVideo extends Activity implements
     }
 
     private void trimVideo() {
+        int delta = mTrimEndTime - mTrimStartTime;
+        // Considering that we only trim at sync frame, we don't want to trim
+        // when the time interval is too short or too close to the origin.
+        if (delta < 100 ) {
+            Toast.makeText(getApplicationContext(),
+                getString(R.string.trim_too_short),
+                Toast.LENGTH_SHORT).show();
+            return;
+        }
+        if (Math.abs(mVideoView.getDuration() - delta) < 100) {
+            Toast.makeText(getApplicationContext(),
+                getString(R.string.trim_too_long),
+                Toast.LENGTH_SHORT).show();
+            return;
+        }
         // Use the default save directory if the source directory cannot be
         // saved.
         mSaveDirectory = getSaveDirectory();
@@ -281,6 +295,8 @@ public class TrimVideo extends Activity implements
             public void run() {
                 try {
                     TrimVideoUtils.startTrim(mSrcFile, mDstFile, mTrimStartTime, mTrimEndTime);
+                    // Update the database for adding a new video file.
+                    insertContent(mDstFile);
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
@@ -288,16 +304,19 @@ public class TrimVideo extends Activity implements
                 mHandler.post(new Runnable() {
                     @Override
                     public void run() {
+                        Toast.makeText(getApplicationContext(),
+                            getString(R.string.save_into) + " " + saveFolderName,
+                            Toast.LENGTH_SHORT)
+                            .show();
                         // TODO: change trimming into a service to avoid
                         // this progressDialog and add notification properly.
                         if (mProgress != null) {
                             mProgress.dismiss();
-                            // Update the database for adding a new video file.
-                            insertContent(mDstFile);
-                            Toast.makeText(getApplicationContext(),
-                                    "Saved into " + saveFolderName, Toast.LENGTH_SHORT)
-                                    .show();
                             mProgress = null;
+                            // Show the result only when the activity not stopped.
+                            Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
+                            intent.setDataAndTypeAndNormalize(Uri.fromFile(mDstFile), "video/*");
+                            startActivity(intent);
                         }
                     }
                 });
@@ -309,8 +328,8 @@ public class TrimVideo extends Activity implements
         // create a background thread to trim the video.
         // and show the progress.
         mProgress = new ProgressDialog(this);
-        mProgress.setTitle("Trimming");
-        mProgress.setMessage("please wait");
+        mProgress.setTitle(getString(R.string.trimming));
+        mProgress.setMessage(getString(R.string.please_wait));
         // TODO: make this cancelable.
         mProgress.setCancelable(false);
         mProgress.setCanceledOnTouchOutside(false);