<!-- 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>
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;
}
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();
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();
}
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);
}
}
});
// 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);