浏览代码

PreviewVideoActivity protected against access to non-exiting account

David A. Velasco 12 年之前
父节点
当前提交
3ecabe3ea7

+ 1 - 1
AndroidManifest.xml

@@ -95,7 +95,7 @@
 		        
         <activity	android:name="com.owncloud.android.ui.preview.PreviewVideoActivity"
 					android:label="@string/app_name"
-					android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
+					android:theme="@style/Theme.ownCloud.Fullscreen" >
 		</activity>        
 
         <service

+ 2 - 2
res/layout/video_layout.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout	xmlns:android="http://schemas.android.com/apk/res/android"
-				android:layout_width="fill_parent"
-				android:layout_height="fill_parent" >
+				android:layout_width="match_parent"
+				android:layout_height="match_parent" >
 
 	<VideoView  android:id="@+id/videoPlayer"
 				android:layout_width="wrap_content"

+ 9 - 3
res/values/styles.xml

@@ -17,7 +17,7 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<resources>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
 	<style name="Animations" />
 
 	<!-- Default ownCloud app style -->
@@ -29,9 +29,15 @@
 	<style name="Theme.ownCloud.noActionBar" parent="style/Theme.Sherlock.Light.NoActionBar">
       <item name="android:actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
       <item name="actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
-  </style>
+    </style>
+	
+	<style name="Theme.ownCloud.Fullscreen" parent="style/Theme.Sherlock.NoActionBar">
+      <item name="android:actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
+      <item name="actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
+      <item name="android:windowFullscreen">true</item>
+    </style>
+	
 	
-
 	<style name="Theme.ownCloud.Widget.ActionBar" parent="style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
     	<item name="android:background">@drawable/main_header_bg</item>
     	<item name="background">@drawable/main_header_bg</item>

+ 8 - 11
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -215,7 +215,7 @@ public class FileDisplayActivity extends FileActivity implements
                 file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);  // never returns null
             }
             setFile(file);
-            
+            mDirectories.clear();
             while(file != null && file.getFileName() != OCFile.PATH_SEPARATOR) {
                 if (file.isDirectory()) {
                     mDirectories.add(file.getFileName());
@@ -248,6 +248,11 @@ public class FileDisplayActivity extends FileActivity implements
             Fragment secondFragment = chooseInitialSecondFragment(file);
             if (secondFragment != null) {
                 setSecondFragment(secondFragment);
+                updateFragmentsVisibility(true);
+                updateNavigationElementsInActionBar(file);
+                
+            } else {
+                cleanSecondFragment();
             }
             
         } else {
@@ -343,8 +348,9 @@ public class FileDisplayActivity extends FileActivity implements
             FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
             tr.remove(second);
             tr.commit();
-            updateFragmentsVisibility(false);
         }
+        updateFragmentsVisibility(false);
+        updateNavigationElementsInActionBar(null);
     }
     
     protected void refeshListOfFilesFragment() {
@@ -569,7 +575,6 @@ public class FileDisplayActivity extends FileActivity implements
             setFile(listOfFiles.getCurrentFile());
         }
         cleanSecondFragment();
-        updateNavigationElementsInActionBar(null);
     }
 
     @Override
@@ -581,13 +586,6 @@ public class FileDisplayActivity extends FileActivity implements
         Log_OC.d(TAG, "onSaveInstanceState() end");
     }
 
-    @Override
-    protected void onStart() {
-        super.onStart();
-        FileFragment second = getSecondFragment();
-        updateFragmentsVisibility(second != null);
-        updateNavigationElementsInActionBar((second == null) ? null : second.getFile());
-    }
     
     @Override
     protected void onResume() {
@@ -921,7 +919,6 @@ public class FileDisplayActivity extends FileActivity implements
     public void onBrowsedDownTo(OCFile directory) {
         pushDirname(directory);
         cleanSecondFragment();
-        updateNavigationElementsInActionBar(null);
     }
     
     /**

+ 0 - 12
src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java

@@ -40,8 +40,6 @@ import com.owncloud.android.ui.fragment.FileFragment;
 //public class PreviewImagePagerAdapter extends PagerAdapter {
 public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
     
-    private static final String TAG = PreviewImagePagerAdapter.class.getSimpleName();
-            
     private Vector<OCFile> mImageFiles;
     private Account mAccount;
     private Set<Object> mObsoleteFragments;
@@ -51,14 +49,6 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
     
     private Map<Integer, FileFragment> mCachedFragments;
 
-    /*
-    private final FragmentManager mFragmentManager;
-    private FragmentTransaction mCurTransaction = null;
-    private ArrayList<Fragment.SavedState> mSavedState = new ArrayList<Fragment.SavedState>();
-    private ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
-    private Fragment mCurrentPrimaryItem = null;
-    */
-
     /**
      * Constructor.
      * 
@@ -188,8 +178,6 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
         return mDownloadErrors.contains(Integer.valueOf(position));
     }
 
-
-    
     /* -*
      * Called when a change in the shown pages is going to start being made.
      * 

+ 3 - 4
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -61,6 +61,7 @@ import com.owncloud.android.operations.OnRemoteOperationListener;
 import com.owncloud.android.operations.RemoteOperation;
 import com.owncloud.android.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
@@ -477,8 +478,8 @@ public class PreviewMediaFragment extends FileFragment implements
     
     private void startFullScreenVideo() {
         Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
-        i.putExtra(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
-        i.putExtra(PreviewVideoActivity.EXTRA_FILE, getFile());
+        i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
+        i.putExtra(FileActivity.EXTRA_FILE, getFile());
         i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
         mVideoPreview.pause();
         i.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPreview.getCurrentPosition());
@@ -661,7 +662,6 @@ public class PreviewMediaFragment extends FileFragment implements
                                                             mStorageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
-            boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
             getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         }
     }
@@ -716,7 +716,6 @@ public class PreviewMediaFragment extends FileFragment implements
     }
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
         getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         
         if (result.isSuccess()) {

+ 39 - 88
src/com/owncloud/android/ui/preview/PreviewVideoActivity.java

@@ -18,7 +18,6 @@
 package com.owncloud.android.ui.preview;
 
 import android.accounts.Account;
-import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -28,15 +27,17 @@ import android.media.MediaPlayer.OnErrorListener;
 import android.media.MediaPlayer.OnPreparedListener;
 import android.net.Uri;
 import android.os.Bundle;
-import android.view.MotionEvent;
 import android.widget.MediaController;
 import android.widget.VideoView;
 
 import com.owncloud.android.AccountUtils;
 import com.owncloud.android.Log_OC;
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.DataStorageManager;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.media.MediaService;
+import com.owncloud.android.ui.activity.FileActivity;
 
 /**
  *  Activity implementing a basic video player.
@@ -48,14 +49,8 @@ import com.owncloud.android.media.MediaService;
  *  
  *  @author David A. Velasco
  */
-public class PreviewVideoActivity extends Activity implements OnCompletionListener, OnPreparedListener, OnErrorListener {
+public class PreviewVideoActivity extends FileActivity implements OnCompletionListener, OnPreparedListener, OnErrorListener {
 
-    /** Key to receive an {@link OCFile} to play as an extra value in an {@link Intent} */
-    public static final String EXTRA_FILE = "FILE";
-    
-    /** Key to receive the ownCloud {@link Account} where the file to play is saved as an extra value in an {@link Intent} */
-    public static final String EXTRA_ACCOUNT = "ACCOUNT";
-    
     /** Key to receive a flag signaling if the video should be started immediately */
     public static final String EXTRA_AUTOPLAY = "AUTOPLAY";
     
@@ -64,8 +59,8 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     
     private static final String TAG = PreviewVideoActivity.class.getSimpleName();
 
-    private OCFile mFile;                       // video file to play
-    private Account mAccount;                   // ownCloud account holding mFile
+    private DataStorageManager mStorageManager;
+    
     private int mSavedPlaybackPosition;         // in the unit time handled by MediaPlayer.getCurrentPosition()
     private boolean mAutoplay;                  // when 'true', the playback starts immediately with the activity
     private VideoView mVideoPlayer;             // view to play the file; both performs and show the playback
@@ -90,14 +85,10 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     
         if (savedInstanceState == null) {
             Bundle extras = getIntent().getExtras();
-            mFile = extras.getParcelable(EXTRA_FILE);
-            mAccount = extras.getParcelable(EXTRA_ACCOUNT);
             mSavedPlaybackPosition = extras.getInt(EXTRA_START_POSITION);
             mAutoplay = extras.getBoolean(EXTRA_AUTOPLAY);
             
         } else {
-            mFile = savedInstanceState.getParcelable(EXTRA_FILE);
-            mAccount = savedInstanceState.getParcelable(EXTRA_ACCOUNT);
             mSavedPlaybackPosition = savedInstanceState.getInt(EXTRA_START_POSITION);
             mAutoplay = savedInstanceState.getBoolean(EXTRA_AUTOPLAY);
         }
@@ -111,29 +102,6 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
           
         // keep the screen on while the playback is performed (prevents screen off by battery save)
         mVideoPlayer.setKeepScreenOn(true);
-        
-        if (mFile != null) {
-            if (mFile.isDown()) {
-                mVideoPlayer.setVideoPath(mFile.getStoragePath());
-                
-            } else if (mAccount != null) {
-                // not working now
-                String url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath();
-                mVideoPlayer.setVideoURI(Uri.parse(url));
-                
-            } else {
-                onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
-            }
-            
-            // create and prepare control panel for the user
-            mMediaController = new MediaController(this);
-            mMediaController.setMediaPlayer(mVideoPlayer);
-            mMediaController.setAnchorView(mVideoPlayer);
-            mVideoPlayer.setMediaController(mMediaController);
-            
-        } else {
-            onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_nothing_to_play);
-        }
     }    
     
     
@@ -144,8 +112,6 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         Log_OC.e(TAG, "ACTIVITY\t\tonSaveInstanceState");
-        outState.putParcelable(PreviewVideoActivity.EXTRA_FILE, mFile);
-        outState.putParcelable(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
         outState.putInt(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPlayer.getCurrentPosition());
         outState.putBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY , mVideoPlayer.isPlaying());
     }
@@ -162,39 +128,6 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     }
 
     
-    @Override
-    public void onResume() {
-        super.onResume();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonResume");
-    }
-
-    
-    @Override
-    public void onStart() {
-        super.onStart();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonStart");
-    }
-    
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-        Log_OC.e(TAG, "ACTIVITY\t\tonDestroy");
-    }
-    
-    @Override
-    public void onStop() {
-        super.onStop();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonStop");
-    }
-    
-    
-    @Override
-    public void onPause() {
-        super.onPause();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonPause");
-    }
-    
-    
     /** 
      * Called when the file is ready to be played.
      * 
@@ -258,25 +191,43 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     }
     
     
-    /**  
-     * Screen touches trigger the appearance of the control panel for a limited time.
-     *
-     * {@inheritDoc}
-     */
     @Override
-    public boolean onTouchEvent (MotionEvent ev){ 
-        /*if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-            if (mMediaController.isShowing()) {
-                mMediaController.hide();
+    protected void onAccountSet(boolean stateWasRecovered) {
+        if (getAccount() != null) {
+            OCFile file = getFile();
+            /// Validate handled file  (first image to preview)
+            if (file == null) {
+                throw new IllegalStateException("Instanced with a NULL OCFile");
+            }
+            if (!file.isVideo()) {
+                throw new IllegalArgumentException("Non-video file passed as argument");
+            }
+            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+            file = mStorageManager.getFileById(file.getFileId()); 
+            if (file != null) {
+                if (file.isDown()) {
+                    mVideoPlayer.setVideoPath(file.getStoragePath());
+                    
+                } else {
+                    // not working now
+                    String url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
+                    mVideoPlayer.setVideoURI(Uri.parse(url));
+                }
+                
+                // create and prepare control panel for the user
+                mMediaController = new MediaController(this);
+                mMediaController.setMediaPlayer(mVideoPlayer);
+                mMediaController.setAnchorView(mVideoPlayer);
+                mVideoPlayer.setMediaController(mMediaController);
+                
             } else {
-                mMediaController.show(MediaService.MEDIA_CONTROL_SHORT_LIFE);
+                finish();
             }
-            return true;        
         } else {
-            return false;
-        }*/
-        return false;
-    }
+            Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
+            finish();
+        }
+   }
 
 
 }