Merge "Save the export progress when rotating the phone"
diff --git a/src/com/android/videoeditor/VideoEditorActivity.java b/src/com/android/videoeditor/VideoEditorActivity.java
index 01729c9..8dc1588 100755
--- a/src/com/android/videoeditor/VideoEditorActivity.java
+++ b/src/com/android/videoeditor/VideoEditorActivity.java
@@ -137,6 +137,10 @@
     // Threshold in width dip for showing title in action bar.
     private static final int SHOW_TITLE_THRESHOLD_WIDTH_DIP = 1000;
 
+    // To store the export progress when the activity is destroyed
+    private static final String EXPORT_PROGRESS  = "export_progress";
+    private int mExportProgress;
+
     private final TimelineRelativeLayout.LayoutCallback mLayoutCallback =
         new TimelineRelativeLayout.LayoutCallback() {
 
@@ -390,9 +394,11 @@
             mRestartPreview = savedInstanceState.getBoolean(STATE_PLAYING);
             mCaptureMediaUri = savedInstanceState.getParcelable(STATE_CAPTURE_URI);
             mMediaLayoutSelectedPos = savedInstanceState.getInt(STATE_SELECTED_POS_ID, -1);
+            mExportProgress = savedInstanceState.getInt(EXPORT_PROGRESS);
         } else {
             mRestartPreview = false;
             mMediaLayoutSelectedPos = -1;
+            mExportProgress = 0;
         }
 
         // Compute the activity width
@@ -490,6 +496,7 @@
         outState.putBoolean(STATE_PLAYING, isPreviewPlaying() || mRestartPreview);
         outState.putParcelable(STATE_CAPTURE_URI, mCaptureMediaUri);
         outState.putInt(STATE_SELECTED_POS_ID, mMediaLayout.getSelectedViewPos());
+        outState.putInt(EXPORT_PROGRESS,mExportProgress);
     }
 
     @Override
@@ -631,6 +638,7 @@
 
             case R.id.menu_item_export_movie: {
                 // Present the user with a dialog to choose export options
+                mExportProgress = 0;
                 showDialog(DIALOG_EXPORT_OPTIONS_ID);
                 return true;
             }
@@ -1438,6 +1446,7 @@
     @Override
     protected void onExportProgress(int progress) {
         if (mExportProgressDialog != null) {
+            mExportProgress = progress;
             mExportProgressDialog.setProgress(progress);
         }
     }
@@ -1447,6 +1456,7 @@
         if (mExportProgressDialog != null) {
             mExportProgressDialog.dismiss();
             mExportProgressDialog = null;
+            mExportProgress = 0;
         }
     }
 
@@ -1654,11 +1664,15 @@
         mExportProgressDialog.setCanceledOnTouchOutside(false);
         mExportProgressDialog.show();
         mExportProgressDialog.setProgressNumberFormat("");
+        if (mExportProgress >= 0 && mExportProgress <= 100) {
+            mExportProgressDialog.setProgress(mExportProgress);
+        }
     }
 
     private void cancelExport() {
         ApiService.cancelExportVideoEditor(VideoEditorActivity.this, mProjectPath,
                 mPendingExportFilename);
+        mExportProgress = 0;
         mPendingExportFilename = null;
         mExportProgressDialog = null;
     }