From: David A. Velasco Date: Tue, 1 Sep 2015 16:35:51 +0000 (+0200) Subject: Merge branch 'master' into copy X-Git-Tag: oc-android-1.8~22^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e6be60679fd7bc781dbd7a2a2b82d58eb720b746?hp=-c Merge branch 'master' into copy Conflicts FIXED: src/com/owncloud/android/ui/activity/FileDisplayActivity.java src/com/owncloud/android/ui/fragment/OCFileListFragment.java src/com/owncloud/android/ui/preview/FileDownloadFragment.java src/com/owncloud/android/ui/preview/PreviewImageFragment.java src/com/owncloud/android/ui/preview/PreviewMediaFragment.java --- e6be60679fd7bc781dbd7a2a2b82d58eb720b746 diff --combined AndroidManifest.xml index fa3dd706,fc701a94..a072d788 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@@ -1,4 -1,5 +1,4 @@@ - - - + @@@ -159,12 -172,12 +160,12 @@@ - + - + @@@ -174,11 -187,11 +175,11 @@@ android:label="@string/copy_link" android:icon="@drawable/copy_link"/> - - diff --combined build.gradle index 8a2521f2,576eb82d..a0db0184 --- a/build.gradle +++ b/build.gradle @@@ -20,14 -20,14 +20,14 @@@ repositories dependencies { compile name: 'touch-image-view' - compile 'com.android.support:support-v4:19.1.0' + compile 'com.android.support:support-v4:22.2.1' compile project(':owncloud-android-library') compile 'com.jakewharton:disklrucache:2.0.2' - compile 'com.android.support:appcompat-v7:19.1.0' + compile 'com.android.support:appcompat-v7:22.2.1' } android { - compileSdkVersion 19 + compileSdkVersion 22 buildToolsVersion "22.0.1" sourceSets { main { @@@ -58,6 -58,12 +58,6 @@@ abortOnError false } } - - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 - } productFlavors { } diff --combined res/values/strings.xml index ee4e5b3c,cc3587d1..00058946 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -28,6 -28,7 +28,7 @@@ Settings Logs Close + Open General More Accounts @@@ -121,14 -122,14 +122,14 @@@ Synchronization failed, you need to relogin Synchronization of %1$s could not be completed Invalid password for %1$s - Conflicts found - %1$d kept-in-sync files could not be sync\'ed + Conflicts found + %1$d kept-in-sync files could not be sync\'ed Kept-in-sync files failed Contents of %1$d files could not be sync\'ed (%2$d conflicts) Some local files were forgotten %1$d files out of the %2$s folder could not be copied into As of version 1.3.16, files uploaded from this device are copied into the local %1$s folder to prevent data loss when a single file is synced with multiple accounts.\n\nDue to this change, all files uploaded in previous versions of this app were copied into the %2$s folder. However, an error prevented the completion of this operation during account synchronization. You may either leave the file(s) as is and remove the link to %3$s, or move the file(s) into the %1$s folder and retain the link to %4$s.\n\nListed below are the local file(s), and the remote file(s) in %5$s they were linked to. - Folder %1$s does not exist anymore + Folder %1$s does not exist anymore "Move all" "All files were moved" "Some files could not be moved" @@@ -151,20 -152,20 +152,20 @@@ "%1$s (loading)" "%1$s playback finished" No media file found - No account provided - File not in a valid account - Unsupported media codec - Media file could not be read - Media file not correctly encoded - Timed out while trying to play - Media file cannot be streamed - Media file cannot be played with the stock media player - Security error trying to play %1$s - Input error trying to play %1$s - Unexpected error trying to play %1$s - Rewind button - Play or pause button - Fast forward button + No account provided + File not in a valid account + Unsupported media codec + Media file could not be read + Media file not correctly encoded + Timed out while trying to play + Media file cannot be streamed + Media file cannot be played with the stock media player + Security error trying to play %1$s + Input error trying to play %1$s + Unexpected error trying to play %1$s + Rewind button + Play or pause button + Fast forward button Getting authorization… Trying to login… @@@ -207,9 -208,9 +208,9 @@@ "Do you really want to remove %1$s?" "Do you really want to remove %1$s and its contents?" Local only - Local contents only - Remove from server - Remote and local + Local only + From server + Remote & local "Removal succeeded" "Removal failed" Enter a new name @@@ -249,31 -250,31 +250,31 @@@ Location: Validity: From: - To: - Signature: - Algorithm: - The certificate could not be shown. - - No information about the error - + To: + Signature: + Algorithm: + The certificate could not be shown. + - No information about the error + This is a placeholder placeholder.txt PNG Image 389 KB 2012/05/18 12:23 PM 12:23:45 - + Upload pictures via WiFi only Upload videos via WiFi only /InstantUpload File conflict Which files do you want to keep? If you select both versions, the local file will have a number added to its name. Keep both - Use local version - Use server version + local version + server version Image preview This image cannot be shown - + %1$s could not be copied to %2$s local folder Upload Path @@@ -286,24 -287,32 +287,24 @@@ Enter a password You must enter a password - Send + An error occurred while connecting with the server. + An error occurred while waiting for the server, the operation couldn\'t have been done + An error occurred while waiting for the server, the operation couldn\'t have been done + The operation couldn\'t be completed, server is unavailable + - Copy link - Copied to clipboard + You do not have permission %s + to rename this file + to delete this file + to share this file + to unshare this file + to create the file + to upload in this folder + The file is no longer available on the server - Critical error: cannot perform operations - - An error occurred while connecting with the server. - An error occurred while waiting for the server, the operation couldn\'t have been done - An error occurred while waiting for the server, the operation couldn\'t have been done - The operation couldn\'t be completed, server is unavailable - - - - You do not have permission %s - to rename this file - to delete this file - to share this file - to unshare this file - to create the file - to upload in this folder - The file is no longer available on the server - - Accounts - Add account - Secure connection is redirected to an unsecured route. + Accounts + Add account + Secure connection is redirected through an unsecured route. Logs Send History @@@ -317,20 -326,13 +318,20 @@@ Nothing in here. You can add a folder! Choose - Unable to move. Please check whether the file exists - It is not possible to move a folder into a descendant - The file exists already in the destination folder - An error occurred while trying to move this file or folder - to move this file + Unable to move. Please check whether the file exists + It is not possible to move a folder into a descendant + The file exists already in the destination folder + An error occurred while trying to move this file or folder + to move this file + + + Unable to copy. Please check whether the file exists + It is not possible to copy a folder into a descendant + The file exists already in the destination folder + An error occurred while trying to copy this file or folder + to copy this file - Instant Uploads + Instant Uploads Security Upload Video Path diff --combined src/com/owncloud/android/ui/activity/FileActivity.java index e2667e8c,f1508c28..1c21cab4 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@@ -35,18 -35,20 +35,20 @@@ import android.content.res.Configuratio import android.os.Bundle; import android.os.Handler; import android.os.IBinder; - import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; - import android.support.v7.app.ActionBarActivity; + import android.support.v7.app.ActionBarDrawerToggle; + import android.support.v7.app.AppCompatActivity; + import android.util.Log; import android.view.View; import android.widget.AdapterView; - import android.widget.LinearLayout; import android.widget.ListView; + import android.widget.RelativeLayout; + import android.widget.TextView; import android.widget.Toast; import com.owncloud.android.BuildConfig; @@@ -85,7 -87,7 +87,7 @@@ import java.util.ArrayList * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud * {@link Account}s . */ - public class FileActivity extends ActionBarActivity + public class FileActivity extends AppCompatActivity implements OnRemoteOperationListener, ComponentsGetter { public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE"; @@@ -289,7 -291,7 +291,7 @@@ // Sync the toggle state after onRestoreInstanceState has occurred. if (mDrawerToggle != null) { mDrawerToggle.syncState(); - if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { + if (isDrawerOpen()) { getSupportActionBar().setTitle(R.string.app_name); mDrawerToggle.setDrawerIndicatorEnabled(true); } @@@ -304,6 -306,37 +306,37 @@@ } } + @Override + public void onBackPressed() { + if (isDrawerOpen()) { + closeNavDrawer(); + return; + } + super.onBackPressed(); + } + + /** + * checks if the drawer exists and is opened. + * + * @return true if the drawer is open, else false + */ + public boolean isDrawerOpen() { + if(mDrawerLayout != null) { + return mDrawerLayout.isDrawerOpen(GravityCompat.START); + } else { + return false; + } + } + + /** + * closes the navigation drawer. + */ + public void closeNavDrawer() { + if(mDrawerLayout != null) { + mDrawerLayout.closeDrawer(GravityCompat.START); + } + } + protected void initDrawer(){ // constant settings for action bar when navigation drawer is inited getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); @@@ -311,7 -344,7 +344,7 @@@ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Notification Drawer - LinearLayout navigationDrawerLayout = (LinearLayout) findViewById(R.id.left_drawer); + RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer); mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list); // TODO re-enable when "Accounts" is available in Navigation Drawer @@@ -329,6 -362,14 +362,14 @@@ // username.setText(account.name.substring(0, lastAtPos)); // } + // Display username in drawer + Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); + if (account != null) { + TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); + int lastAtPos = account.name.lastIndexOf("@"); + username.setText(account.name.substring(0, lastAtPos)); + } + // load slide menu items mDrawerTitles = getResources().getStringArray(R.array.drawer_items); @@@ -344,7 -385,8 +385,8 @@@ // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], // mDrawerContentDescriptions[0])); // All Files - mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0])); + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0], + R.drawable.ic_folder_open)); // TODO Enable when "On Device" is recovered // On Device @@@ -352,11 -394,12 +394,12 @@@ // mDrawerContentDescriptions[2])); // Settings - mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1])); + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1], + R.drawable.ic_settings)); // Logs if (BuildConfig.DEBUG) { mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], - mDrawerContentDescriptions[2])); + mDrawerContentDescriptions[2],R.drawable.ic_log)); } // setting the nav drawer list adapter @@@ -364,12 -407,8 +407,8 @@@ mDrawerItems); mDrawerList.setAdapter(mNavigationDrawerAdapter); - mDrawerToggle = new ActionBarDrawerToggle( - this, - mDrawerLayout, - R.drawable.ic_drawer, - R.string.app_name, - R.string.drawer_close) { + + mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.string.drawer_open,R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { @@@ -386,13 -425,13 +425,13 @@@ invalidateOptionsMenu(); } }; - - //mDrawerToggle.setDrawerIndicatorEnabled(true); + // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); + mDrawerToggle.setDrawerIndicatorEnabled(false); } /** @@@ -471,7 -510,7 +510,7 @@@ */ private void swapToDefaultAccount() { // default to the most recently used account - Account newAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); + Account newAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); if (newAccount == null) { /// no account available: force account creation createFirstAccount(); @@@ -512,7 -551,11 +551,11 @@@ outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification); outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor()); outState.putBoolean(KEY_TRY_SHARE_AGAIN, mTryShareAgain); - outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString()); + if(getSupportActionBar().getTitle() != null) { + // Null check in case the actionbar is used in ActionBar.NAVIGATION_MODE_LIST + // since it doesn't have a title then + outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString()); + } } @@@ -559,7 -602,7 +602,7 @@@ } /** - * @return 'True' when the Activity is finishing to enforce the setup of a new account. + * @return 'True' when the Activity is finishing to enforce the setup of a new account. */ protected boolean isRedirectingToSetupAccount() { return mRedirectingToSetupAccount; @@@ -709,7 -752,6 +752,7 @@@ } + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { dismissLoadingDialog(); @@@ -815,7 -857,7 +858,7 @@@ /** * Dismiss loading dialog */ - public void dismissLoadingDialog(){ + public void dismissLoadingDialog() { Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG); if (frag != null) { LoadingDialog loading = (LoadingDialog) frag; diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 616c068d,9c1d0661..6c09cbfd --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -26,7 -26,7 +26,7 @@@ import android.accounts.Account import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.annotation.TargetApi; - import android.app.AlertDialog; + import android.support.v7.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; @@@ -48,12 -48,15 +48,15 @@@ import android.provider.OpenableColumns import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; + import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; - import android.view.Window; + import android.widget.ProgressBar; + import android.widget.RelativeLayout; + import android.widget.TextView; import android.widget.Toast; import com.owncloud.android.MainApp; @@@ -74,7 -77,6 +77,7 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.MoveFileOperation; @@@ -121,6 -123,7 +124,7 @@@ public class FileDisplayActivity extend private boolean mDualPane; private View mLeftFragmentContainer; private View mRightFragmentContainer; + private ProgressBar mProgressBar; private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"; private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS"; @@@ -131,7 -134,6 +135,7 @@@ public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1; public static final int ACTION_SELECT_MULTIPLE_FILES = 2; public static final int ACTION_MOVE_FILES = 3; + public static final int ACTION_COPY_FILES = 4; private static final String TAG = FileDisplayActivity.class.getSimpleName(); @@@ -139,7 -141,7 +143,7 @@@ private static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT"; private OCFile mWaitingToPreview; - + private boolean mSyncInProgress = false; private static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT"; @@@ -153,7 -155,6 +157,6 @@@ @Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account // is valid @@@ -163,7 -164,7 +166,7 @@@ Intent initObserversIntent = FileObserverService.makeInitIntent(this); startService(initObserversIntent); } - + /// Load of saved instance state if(savedInstanceState != null) { mWaitingToPreview = (OCFile) savedInstanceState.getParcelable( @@@ -176,16 -177,21 +179,21 @@@ mWaitingToPreview = null; mSyncInProgress = false; mWaitingToSend = null; - } + } /// USER INTERFACE // Inflate and set the layout view setContentView(R.layout.files); - + // Navigation Drawer initDrawer(); + mProgressBar = (ProgressBar) findViewById(R.id.progressBar); + mProgressBar.setIndeterminateDrawable( + ContextCompat.getDrawable(this, + R.drawable.actionbar_progress_indeterminate_horizontal)); + mDualPane = getResources().getBoolean(R.bool.large_land_layout); mLeftFragmentContainer = findViewById(R.id.left_fragment_container); mRightFragmentContainer = findViewById(R.id.right_fragment_container); @@@ -198,8 -204,11 +206,11 @@@ // according to the official // documentation - setSupportProgressBarIndeterminateVisibility(mSyncInProgress - /*|| mRefreshSharesInProgress*/); + // enable ActionBar app icon to behave as action to toggle nav drawer + //getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + mProgressBar.setIndeterminate(mSyncInProgress); // always AFTER setContentView(...) ; to work around bug in its implementation setBackgroundText(); @@@ -211,7 -220,6 +222,6 @@@ protected void onStart() { Log_OC.v(TAG, "onStart() start"); super.onStart(); - getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId()); Log_OC.v(TAG, "onStart() end"); } @@@ -223,8 -231,8 +233,8 @@@ } /** - * Called when the ownCloud {@link Account} associated to the Activity was just updated. - */ + * Called when the ownCloud {@link Account} associated to the Activity was just updated. + */ @Override protected void onAccountSet(boolean stateWasRecovered) { super.onAccountSet(stateWasRecovered); @@@ -253,13 -261,22 +263,22 @@@ } setFile(file); + if (mAccountWasSet) { + RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer); + if (navigationDrawerLayout != null && getAccount() != null) { + TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); + int lastAtPos = getAccount().name.lastIndexOf("@"); + username.setText(getAccount().name.substring(0, lastAtPos)); + } + } + if (!stateWasRecovered) { Log_OC.d(TAG, "Initializing Fragments in onAccountChanged.."); initFragmentsWithFile(); if (file.isFolder()) { startSyncFolderOperation(file, false); } - + } else { updateFragmentsVisibility(!file.isFolder()); updateActionBarTitleAndHomeButton(file.isFolder() ? null : file); @@@ -274,11 -291,11 +293,11 @@@ transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES); transaction.commit(); } - + private void initFragmentsWithFile() { if (getAccount() != null && getFile() != null) { /// First fragment - OCFileListFragment listOfFiles = getListOfFilesFragment(); + OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { listOfFiles.listDirectory(getCurrentDir()); // TODO Enable when "On Device" is recovered @@@ -286,9 -303,9 +305,9 @@@ } else { Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } - + /// Second fragment - OCFile file = getFile(); + OCFile file = getFile(); Fragment secondFragment = chooseInitialSecondFragment(file); if (secondFragment != null) { setSecondFragment(secondFragment); @@@ -313,7 -330,7 +332,7 @@@ private Fragment chooseInitialSecondFragment(OCFile file) { Fragment secondFragment = null; if (file != null && !file.isFolder()) { - if (file.isDown() && PreviewMediaFragment.canBePreviewed(file) + if (file.isDown() && PreviewMediaFragment.canBePreviewed(file) && file.getLastSyncDateForProperties() > 0 // temporal fix ) { int startPlaybackPosition = @@@ -334,10 -351,10 +353,10 @@@ /** * Replaces the second fragment managed by the activity with the received as * a parameter. - * - * Assumes never will be more than two fragments managed at the same time. - * - * @param fragment New second Fragment to set. + *

+ * Assumes never will be more than two fragments managed at the same time. + * + * @param fragment New second Fragment to set. */ private void setSecondFragment(Fragment fragment) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); @@@ -378,7 -395,7 +397,7 @@@ Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag( FileDisplayActivity.TAG_LIST_OF_FILES); if (listOfFiles != null) { - return (OCFileListFragment)listOfFiles; + return (OCFileListFragment) listOfFiles; } Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!"); return null; @@@ -388,7 -405,7 +407,7 @@@ Fragment second = getSupportFragmentManager().findFragmentByTag( FileDisplayActivity.TAG_SECOND_FRAGMENT); if (second != null) { - return (FileFragment)second; + return (FileFragment) second; } return null; } @@@ -600,30 -617,17 +619,30 @@@ requestMultipleUpload(data, resultCode); } else if (requestCode == ACTION_MOVE_FILES && resultCode == RESULT_OK){ + final Intent fData = data; + final int fResultCode = resultCode; + getHandler().postDelayed( + new Runnable() { + @Override + public void run() { + requestMoveOperation(fData, fResultCode); + } + }, + DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS + ); + + } else if (requestCode == ACTION_COPY_FILES && resultCode == RESULT_OK) { final Intent fData = data; - final int fResultCode = resultCode; + final int fResultCode = resultCode; getHandler().postDelayed( - new Runnable() { - @Override - public void run() { - requestMoveOperation(fData, fResultCode); - } - }, - DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS + new Runnable() { + @Override + public void run() { + requestCopyOperation(fData, fResultCode); + } + }, + DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS ); } else { @@@ -731,9 -735,9 +750,9 @@@ /** * Request the operation for moving the file/folder from one path to another - * - * @param data Intent received - * @param resultCode Result code received + * + * @param data Intent received + * @param resultCode Result code received */ private void requestMoveOperation(Intent data, int resultCode) { OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER); @@@ -741,36 -745,27 +760,39 @@@ getFileOperationsHelper().moveFile(folderToMoveAt, targetFile); } + /** + * Request the operation for copying the file/folder from one path to another + * + * @param data Intent received + * @param resultCode Result code received + */ + private void requestCopyOperation(Intent data, int resultCode) { + OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER); + OCFile targetFile = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE); + getFileOperationsHelper().copyFile(folderToMoveAt, targetFile); + } + @Override public void onBackPressed() { - OCFileListFragment listOfFiles = getListOfFilesFragment(); - if (mDualPane || getSecondFragment() == null) { - OCFile currentDir = getCurrentDir(); - if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) { - finish(); - return; + if (!isDrawerOpen()){ + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (mDualPane || getSecondFragment() == null) { + OCFile currentDir = getCurrentDir(); + if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) { + finish(); + return; + } + if (listOfFiles != null) { // should never be null, indeed + listOfFiles.onBrowseUp(); + } } if (listOfFiles != null) { // should never be null, indeed - listOfFiles.onBrowseUp(); + setFile(listOfFiles.getCurrentFile()); } + cleanSecondFragment(); + } else { + super.onBackPressed(); } - if (listOfFiles != null) { // should never be null, indeed - setFile(listOfFiles.getCurrentFile()); - } - cleanSecondFragment(); - } @Override @@@ -787,6 -782,7 +809,6 @@@ Log_OC.v(TAG, "onSaveInstanceState() end"); } - @Override @@@ -823,7 -819,7 +845,7 @@@ downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage()); mDownloadFinishReceiver = new DownloadFinishReceiver(); registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); - + Log_OC.v(TAG, "onResume() end"); } @@@ -844,7 -840,7 +866,7 @@@ unregisterReceiver(mDownloadFinishReceiver); mDownloadFinishReceiver = null; } - + super.onPause(); Log_OC.v(TAG, "onPause() end"); } @@@ -870,10 -866,10 +892,10 @@@ accountName.equals(getAccount().name) && getStorageManager() != null); if (sameAccount) { - + if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { mSyncInProgress = true; - + } else { OCFile currentFile = (getFile() == null) ? null : getStorageManager().getFileByPath(getFile().getRemotePath()); @@@ -890,7 -886,7 +912,7 @@@ Toast.LENGTH_LONG) .show(); browseToRoot(); - + } else { if (currentFile == null && !getFile().isFolder()) { // currently selected file was removed in the server, and now we @@@ -911,7 -907,7 +933,7 @@@ } setFile(currentFile); } - + mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED .equals(event)); @@@ -919,11 -915,11 +941,11 @@@ if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. equals(event) && /// TODO refactor and make common - synchResult != null && !synchResult.isSuccess() && - (synchResult.getCode() == ResultCode.UNAUTHORIZED || - synchResult.isIdPRedirection() || - (synchResult.isException() && synchResult.getException() - instanceof AuthenticatorException))) { + synchResult != null && !synchResult.isSuccess() && + (synchResult.getCode() == ResultCode.UNAUTHORIZED || + synchResult.isIdPRedirection() || + (synchResult.isException() && synchResult.getException() + instanceof AuthenticatorException))) { try { @@@ -957,13 -953,15 +979,15 @@@ } removeStickyBroadcast(intent); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); - setSupportProgressBarIndeterminateVisibility(mSyncInProgress - /*|| mRefreshSharesInProgress*/); + mProgressBar.setIndeterminate(mSyncInProgress); + //mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE); + //setSupportProgressBarIndeterminateVisibility(mSyncInProgress + /*|| mRefreshSharesInProgress*/ //); setBackgroundText(); - + } - + if (synchResult != null) { if (synchResult.getCode().equals( RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) { @@@ -977,7 -975,7 +1001,7 @@@ } } } - + /** * Show a text message on screen view for notifying user if content is * loading or folder is empty @@@ -1002,8 -1000,7 +1026,8 @@@ private class UploadFinishReceiver extends BroadcastReceiver { /** * Once the file upload has finished -> update view - * @author David A. Velasco + * + * @author David A. Velasco * {@link BroadcastReceiver} to enable upload feedback in UI */ @Override @@@ -1013,23 -1010,23 +1037,23 @@@ String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name); OCFile currentDir = getCurrentDir(); - boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && + boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(currentDir.getRemotePath())); - + if (sameAccount && isDescendant) { refreshListOfFilesFragment(); } - + boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false); boolean renamedInUpload = getFile().getRemotePath(). equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH)); - boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) || + boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) || renamedInUpload; FileFragment details = getSecondFragment(); - boolean detailFragmentIsShown = (details != null && + boolean detailFragmentIsShown = (details != null && details instanceof FileDetailFragment); - + if (sameAccount && sameFile && detailFragmentIsShown) { if (uploadWasFine) { setFile(getStorageManager().getFileByPath(uploadedRemotePath)); @@@ -1037,39 -1034,40 +1061,40 @@@ if (renamedInUpload) { String newName = (new File(uploadedRemotePath)).getName(); Toast msg = Toast.makeText( - context, + context, String.format( - getString(R.string.filedetails_renamed_in_upload_msg), - newName), + getString(R.string.filedetails_renamed_in_upload_msg), + newName), Toast.LENGTH_LONG); msg.show(); } if (uploadWasFine || getFile().fileExists()) { - ((FileDetailFragment)details).updateFileDetails(false, true); + ((FileDetailFragment) details).updateFileDetails(false, true); } else { cleanSecondFragment(); } - + // Force the preview if the file is an image if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) { startImagePreview(getFile()); } // TODO what about other kind of previews? } + mProgressBar.setIndeterminate(false); } finally { if (intent != null) { removeStickyBroadcast(intent); } } - + } - + } /** * Class waiting for broadcast events from the {@link FileDownloader} service. - * + * * Updates the UI when a download is started or finished, provided that it is relevant for the * current folder. */ @@@ -1097,7 -1095,7 +1122,7 @@@ intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false) ); } - + if (mWaitingToSend != null) { mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); @@@ -1105,7 -1103,7 +1130,7 @@@ sendDownloadedFile(); } } - + } finally { if (intent != null) { removeStickyBroadcast(intent); @@@ -1136,10 -1134,10 +1161,10 @@@ accountName.equals(getAccount().name)); } } - - + + public void browseToRoot() { - OCFileListFragment listOfFiles = getListOfFilesFragment(); + OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { // should never be null, indeed OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); listOfFiles.listDirectory(root); @@@ -1155,7 -1153,7 +1180,7 @@@ /** * {@inheritDoc} - * + *

* Updates action bar and second fragment, if in dual pane mode. */ @Override @@@ -1167,10 -1165,10 +1192,10 @@@ } /** - * Shows the information of the {@link OCFile} received as a + * Shows the information of the {@link OCFile} received as a * parameter in the second fragment. - * - * @param file {@link OCFile} whose details will be shown + * + * @param file {@link OCFile} whose details will be shown */ @Override public void showDetails(OCFile file) { @@@ -1193,15 -1191,12 +1218,14 @@@ } - @Override protected ServiceConnection newTransferenceServiceConnection() { return new ListServiceConnection(); } - /** Defines callbacks for service binding, passed to bindService() */ + /** + * Defines callbacks for service binding, passed to bindService() + */ private class ListServiceConnection implements ServiceConnection { @Override @@@ -1218,7 -1213,7 +1242,7 @@@ if (!mWaitingToPreview.isDown()) { requestForDownload(); } - } + } } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) { @@@ -1237,7 -1232,7 +1261,7 @@@ } FileFragment secondFragment = getSecondFragment(); if (secondFragment != null && secondFragment instanceof FileDetailFragment) { - FileDetailFragment detailFragment = (FileDetailFragment)secondFragment; + FileDetailFragment detailFragment = (FileDetailFragment) secondFragment; detailFragment.listenForTransferProgress(); detailFragment.updateFileDetails(false, false); } @@@ -1255,7 -1250,7 +1279,7 @@@ mUploaderBinder = null; } } - }; + } @Override public void onSavedCertificate() { @@@ -1279,42 -1274,39 +1303,42 @@@ /** * Updates the view associated to the activity after the finish of some operation over files * in the current account. - * - * @param operation Removal operation performed. - * @param result Result of the removal. + * + * @param operation Removal operation performed. + * @param result Result of the removal. */ @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { super.onRemoteOperationFinish(operation, result); - + if (operation instanceof RemoveFileOperation) { onRemoveFileOperationFinish((RemoveFileOperation) operation, result); } else if (operation instanceof RenameFileOperation) { - onRenameFileOperationFinish((RenameFileOperation)operation, result); + onRenameFileOperationFinish((RenameFileOperation) operation, result); } else if (operation instanceof SynchronizeFileOperation) { - onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); + onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result); } else if (operation instanceof CreateFolderOperation) { - onCreateFolderOperationFinish((CreateFolderOperation)operation, result); - + onCreateFolderOperationFinish((CreateFolderOperation) operation, result); + } else if (operation instanceof CreateShareOperation) { onCreateShareOperationFinish((CreateShareOperation) operation, result); - + } else if (operation instanceof UnshareLinkOperation) { - onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); - + onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result); + } else if (operation instanceof MoveFileOperation) { - onMoveFileOperationFinish((MoveFileOperation)operation, result); + onMoveFileOperationFinish((MoveFileOperation) operation, result); + + } else if (operation instanceof CopyFileOperation) { + onCopyFileOperationFinish((CopyFileOperation) operation, result); } - + } - + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { @@@ -1323,36 -1315,36 +1347,36 @@@ } } - + private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { refreshShowDetails(); refreshListOfFilesFragment(); - + } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { cleanSecondFragment(); refreshListOfFilesFragment(); } } - + private void refreshShowDetails() { FileFragment details = getSecondFragment(); if (details != null) { OCFile file = details.getFile(); if (file != null) { - file = getStorageManager().getFileByPath(file.getRemotePath()); + file = getStorageManager().getFileByPath(file.getRemotePath()); if (details instanceof PreviewMediaFragment) { // Refresh OCFile of the fragment ((PreviewMediaFragment) details).updateFile(file); } else { showDetails(file); - } + } } invalidateOptionsMenu(); - } + } } - + /** * Updates the view associated to the activity after the finish of an operation trying to * remove a file. @@@ -1363,18 -1355,18 +1387,18 @@@ private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { dismissLoadingDialog(); - + Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); - + if (result.isSuccess()) { OCFile removedFile = operation.getFile(); FileFragment second = getSecondFragment(); if (second != null && removedFile.equals(second.getFile())) { if (second instanceof PreviewMediaFragment) { - ((PreviewMediaFragment)second).stopPreview(true); + ((PreviewMediaFragment) second).stopPreview(true); } setFile(getStorageManager().getFileById(removedFile.getParentId())); cleanSecondFragment(); @@@ -1390,14 -1382,14 +1414,14 @@@ } } } - - + + /** - * Updates the view associated to the activity after the finish of an operation trying to move a + * Updates the view associated to the activity after the finish of an operation trying to move a * file. - * - * @param operation Move operation performed. - * @param result Result of the move operation. + * + * @param operation Move operation performed. + * @param result Result of the move operation. */ private void onMoveFileOperationFinish(MoveFileOperation operation, RemoteOperationResult result) { @@@ -1407,41 -1399,17 +1431,41 @@@ } else { dismissLoadingDialog(); try { - Toast msg = Toast.makeText(FileDisplayActivity.this, - ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + Toast msg = Toast.makeText(FileDisplayActivity.this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { - Log_OC.e(TAG, "Error while trying to show fail message " , e); + Log_OC.e(TAG, "Error while trying to show fail message ", e); } } } + /** + * Updates the view associated to the activity after the finish of an operation trying to copy a + * file. + * + * @param operation Copy operation performed. + * @param result Result of the copy operation. + */ + private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) { + if (result.isSuccess()) { + dismissLoadingDialog(); + refreshListOfFilesFragment(); + } else { + dismissLoadingDialog(); + try { + Toast msg = Toast.makeText(FileDisplayActivity.this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log_OC.e(TAG, "Error while trying to show fail message ", e); + } + } + } /** * Updates the view associated to the activity after the finish of an operation trying to rename @@@ -1466,14 -1434,14 +1490,14 @@@ renamedFile.equals(details.getFile())) { ((PreviewMediaFragment) details).updateFile(renamedFile); if (PreviewMediaFragment.canBePreviewed(renamedFile)) { - int position = ((PreviewMediaFragment)details).getPosition(); + int position = ((PreviewMediaFragment) details).getPosition(); startMediaPreview(renamedFile, position, true); } else { getFileOperationsHelper().openFile(renamedFile); } } } - + if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())){ refreshListOfFilesFragment(); } @@@ -1483,7 -1451,7 +1507,7 @@@ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); - + if (result.isSslRecoverableException()) { mLastSslUntrustedServerResult = result; showUntrustedCertDialog(mLastSslUntrustedServerResult); @@@ -1517,18 -1485,18 +1541,18 @@@ } else { dismissLoadingDialog(); try { - Toast msg = Toast.makeText(FileDisplayActivity.this, - ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + Toast msg = Toast.makeText(FileDisplayActivity.this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { - Log_OC.e(TAG, "Error while trying to show fail message " , e); + Log_OC.e(TAG, "Error while trying to show fail message ", e); } } } - + /** * {@inheritDoc} */ @@@ -1539,16 -1507,16 +1563,16 @@@ if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) { if (downloading || uploading) { - ((FileDetailFragment)details).updateFileDetails(file, getAccount()); + ((FileDetailFragment) details).updateFileDetails(file, getAccount()); } else { if (!file.fileExists()) { cleanSecondFragment(); } else { - ((FileDetailFragment)details).updateFileDetails(false, true); + ((FileDetailFragment) details).updateFileDetails(false, true); } } } - + } @@@ -1577,12 -1545,12 +1601,12 @@@ } return null; } - + public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) { - long currentSyncTime = System.currentTimeMillis(); - + long currentSyncTime = System.currentTimeMillis(); + mSyncInProgress = true; - + // perform folder synchronization RemoteOperation synchFolderOp = new RefreshFolderOperation( folder, currentSyncTime, @@@ -1594,14 -1562,13 +1618,13 @@@ getApplicationContext() ); synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null); - - setSupportProgressBarIndeterminateVisibility(true); + mProgressBar.setIndeterminate(true); setBackgroundText(); } /** - * Show untrusted cert dialog + * Show untrusted cert dialog */ public void showUntrustedCertDialog(RemoteOperationResult result) { // Show a dialog with the certificate info @@@ -1611,7 -1578,7 +1634,7 @@@ FragmentTransaction ft = fm.beginTransaction(); dialog.show(ft, DIALOG_UNTRUSTED_CERT); } - + private void requestForDownload(OCFile file) { Account account = getAccount(); if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) { @@@ -1621,43 -1588,43 +1644,43 @@@ startService(i); } } - - private void sendDownloadedFile(){ + + private void sendDownloadedFile() { getFileOperationsHelper().sendDownloadedFile(mWaitingToSend); mWaitingToSend = null; } - + /** * Requests the download of the received {@link OCFile} , updates the UI * to monitor the download progress and prepares the activity to send the file * when the download finishes. - * - * @param file {@link OCFile} to download and preview. + * + * @param file {@link OCFile} to download and preview. */ public void startDownloadForSending(OCFile file) { mWaitingToSend = file; requestForDownload(mWaitingToSend); - boolean hasSecondFragment = (getSecondFragment()!= null); + boolean hasSecondFragment = (getSecondFragment() != null); updateFragmentsVisibility(hasSecondFragment); } - + /** * Opens the image gallery showing the image {@link OCFile} received as parameter. - * - * @param file Image {@link OCFile} to show. + * + * @param file Image {@link OCFile} to show. */ public void startImagePreview(OCFile file) { Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class); showDetailsIntent.putExtra(EXTRA_FILE, file); showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount()); startActivity(showDetailsIntent); - + } /** * Stars the preview of an already down media {@link OCFile}. - * + * * @param file Media {@link OCFile} to preview. * @param startPlaybackPosition Media position where the playback will be started, * in milliseconds. @@@ -1677,8 -1644,8 +1700,8 @@@ * Requests the download of the received {@link OCFile} , updates the UI * to monitor the download progress and prepares the activity to preview * or open the file when the download finishes. - * - * @param file {@link OCFile} to download and preview. + * + * @param file {@link OCFile} to download and preview. */ public void startDownloadForPreview(OCFile file) { Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount()); @@@ -1693,7 -1660,7 +1716,7 @@@ public void cancelTransference(OCFile file) { getFileOperationsHelper().cancelTransference(file); - if (mWaitingToPreview != null && + if (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(file.getRemotePath())) { mWaitingToPreview = null; } @@@ -1726,15 -1693,15 +1749,15 @@@ } } - private void sortByDate(boolean ascending){ + private void sortByDate(boolean ascending) { getListOfFilesFragment().sortByDate(ascending); } - private void sortBySize(boolean ascending){ + private void sortBySize(boolean ascending) { getListOfFilesFragment().sortBySize(ascending); } - private void sortByName(boolean ascending){ + private void sortByName(boolean ascending) { getListOfFilesFragment().sortByName(ascending); } diff --combined src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 24767cf2,937a50d0..24015d08 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@@ -71,8 -71,8 +71,8 @@@ public class ExtendedListFragment exten private ArrayList mTops; private int mHeightCell = 0; - private OnEnforceableRefreshListener mOnRefreshListener = null; - + private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null; + protected AbsListView mCurrentListView; private ExtendedListView mListView; private View mListFooterView; @@@ -338,9 -338,9 +338,9 @@@ } private void onCreateSwipeToRefresh(SwipeRefreshLayout refreshLayout) { - // Colors in animations: background - refreshLayout.setColorScheme(R.color.background_color, R.color.background_color, - R.color.background_color, R.color.background_color); + // Colors in animations + refreshLayout.setColorSchemeResources(R.color.color_accent, R.color.primary, + R.color.primary_dark); refreshLayout.setOnRefreshListener(this); } @@@ -352,7 -352,7 +352,7 @@@ mRefreshEmptyLayout.setRefreshing(false); if (mOnRefreshListener != null) { - mOnRefreshListener.onRefresh(ignoreETag); + mOnRefreshListener.onRefresh(); } } diff --combined src/com/owncloud/android/ui/fragment/FileDetailFragment.java index b5fce44e,68ee6771..24f7248f --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@@ -21,7 -21,10 +21,7 @@@ */ package com.owncloud.android.ui.fragment; -import java.lang.ref.WeakReference; - import android.accounts.Account; -import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; @@@ -43,14 -46,13 +43,14 @@@ import com.owncloud.android.files.servi import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.utils.DisplayUtils; +import java.lang.ref.WeakReference; + /** * This Fragment is used to display the details about a file. @@@ -60,9 -62,9 +60,9 @@@ public class FileDetailFragment extend private int mLayout; private View mView; private Account mAccount; - + public ProgressListener mProgressListener; - + private static final String TAG = FileDetailFragment.class.getSimpleName(); public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT"; public static final String FTAG_RENAME_FILE = "RENAME_FILE_FRAGMENT"; @@@ -101,14 -103,14 +101,14 @@@ mLayout = R.layout.file_details_empty; mProgressListener = null; } - + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } - + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@@ -118,19 -120,20 +118,20 @@@ mAccount = getArguments().getParcelable(ARG_ACCOUNT); if (savedInstanceState != null) { - setFile((OCFile)savedInstanceState.getParcelable(FileActivity.EXTRA_FILE)); + setFile((OCFile) savedInstanceState.getParcelable(FileActivity.EXTRA_FILE)); mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT); } - - if(getFile() != null && mAccount != null) { + + if (getFile() != null && mAccount != null) { mLayout = R.layout.file_details_fragment; } - + mView = inflater.inflate(mLayout, null); if (mLayout == R.layout.file_details_fragment) { mView.findViewById(R.id.fdFavorite).setOnClickListener(this); ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar); + DisplayUtils.colorPreLollipopHorizontalProgressBar(progressBar); mProgressListener = new ProgressListener(progressBar); mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this); } @@@ -151,20 -154,20 +152,20 @@@ super.onStart(); listenForTransferProgress(); } - + @Override public void onStop() { leaveTransferProgress(); super.onStop(); } - + @Override public View getView() { return super.getView() == null ? mView : super.getView(); } - + /** * {@inheritDoc} */ @@@ -172,16 -175,16 +173,16 @@@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.file_actions_menu, menu); - } + } + - /** * {@inheritDoc} */ @Override - public void onPrepareOptionsMenu (Menu menu) { + public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - + if (mContainerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter( getFile(), @@@ -191,7 -194,7 +192,7 @@@ ); mf.filter(menu); } - + // additional restriction for this fragment MenuItem item = menu.findItem(R.id.action_see_details); if (item != null) { @@@ -205,16 -208,9 +206,16 @@@ item.setVisible(false); item.setEnabled(false); } + + // additional restriction for this fragment + item = menu.findItem(R.id.action_copy); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } } - + /** * {@inheritDoc} */ @@@ -245,10 -241,10 +246,10 @@@ } case R.id.action_cancel_download: case R.id.action_cancel_upload: { - ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile()); + ((FileDisplayActivity) mContainerActivity).cancelTransference(getFile()); return true; } - case R.id.action_download_file: + case R.id.action_download_file: case R.id.action_sync_file: { mContainerActivity.getFileOperationsHelper().syncFile(getFile()); return true; @@@ -257,10 -253,9 +258,10 @@@ // Obtain the file if (!getFile().isDown()) { // Download the file Log_OC.d(TAG, getFile().getRemotePath() + " : File must be downloaded"); - ((FileDisplayActivity)mContainerActivity).startDownloadForSending(getFile()); - - } else { + ((FileDisplayActivity) mContainerActivity).startDownloadForSending(getFile()); + + } + else { mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile()); } return true; @@@ -287,7 -282,7 +288,7 @@@ break; } case R.id.fdCancelBtn: { - ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile()); + ((FileDisplayActivity) mContainerActivity).cancelTransference(getFile()); break; } default: @@@ -298,17 -293,17 +299,17 @@@ /** * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced. - * - * @return True when the fragment was created with the empty layout. + * + * @return True when the fragment was created with the empty layout. */ public boolean isEmpty() { return (mLayout == R.layout.file_details_empty || getFile() == null || mAccount == null); } - + /** * Use this method to signal this Activity that it shall update its view. - * + * * @param file : An {@link OCFile} */ public void updateFileDetails(OCFile file, Account ocAccount) { @@@ -319,13 -314,14 +320,13 @@@ /** * Updates the view with all relevant details about that file. + *

+ * TODO Remove parameter when the transferring state of files is kept in database. * - * TODO Remove parameter when the transferring state of files is kept in database. - * - * @param transferring Flag signaling if the file should be considered as downloading or uploading, - * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and - * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false. - * - * @param refresh If 'true', try to refresh the whole file from the database + * @param transferring Flag signaling if the file should be considered as downloading or uploading, + * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and + * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false. + * @param refresh If 'true', try to refresh the whole file from the database */ public void updateFileDetails(boolean transferring, boolean refresh) { if (readyToShow()) { @@@ -334,7 -330,7 +335,7 @@@ setFile(storageManager.getFileByPath(getFile().getRemotePath())); } OCFile file = getFile(); - + // set file details setFilename(file.getFileName()); setFiletype(file.getMimetype(), file.getFileName()); @@@ -353,7 -349,7 +354,7 @@@ (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) ) { setButtonsForTransferring(); - + } else if (file.isDown()) { setButtonsForDown(); @@@ -366,27 -362,25 +367,27 @@@ } getView().invalidate(); } - + /** * Checks if the fragment is ready to show details of a OCFile - * - * @return 'True' when the fragment is ready to show details of a file + * + * @return 'True' when the fragment is ready to show details of a file */ private boolean readyToShow() { - return (getFile() != null && mAccount != null && mLayout == R.layout.file_details_fragment); + return (getFile() != null && mAccount != null && mLayout == R.layout.file_details_fragment); } /** * Updates the filename in view + * * @param filename to set */ private void setFilename(String filename) { TextView tv = (TextView) getView().findViewById(R.id.fdFilename); - if (tv != null) + if (tv != null) { tv.setText(filename); + } } /** @@@ -408,28 -402,25 +409,28 @@@ /** * Updates the file size in view + * * @param filesize in bytes to set */ private void setFilesize(long filesize) { TextView tv = (TextView) getView().findViewById(R.id.fdSize); - if (tv != null) + if (tv != null) { tv.setText(DisplayUtils.bytesToHumanReadable(filesize)); + } } - + /** * Updates the time that the file was last modified + * * @param milliseconds Unix time to set */ - private void setTimeModified(long milliseconds){ + private void setTimeModified(long milliseconds) { TextView tv = (TextView) getView().findViewById(R.id.fdModified); - if(tv != null){ + if (tv != null) { tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds)); } } - + /** * Enables or disables buttons for a file being downloaded */ @@@ -440,24 -431,21 +441,24 @@@ // show the progress bar for the transfer getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE); - TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText); + TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText); progressText.setVisibility(View.VISIBLE); FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); //if (getFile().isDownloading()) { if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) { progressText.setText(R.string.downloader_download_in_progress_ticker); - } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) { - progressText.setText(R.string.uploader_upload_in_progress_ticker); + } + else { + if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) { + progressText.setText(R.string.uploader_upload_in_progress_ticker); + } } } } /** - * Enables or disables buttons for a file locally available + * Enables or disables buttons for a file locally available */ private void setButtonsForDown() { if (!isEmpty()) { @@@ -465,13 -453,13 +466,13 @@@ // hides the progress bar getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE); - TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText); + TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText); progressText.setVisibility(View.GONE); } } /** - * Enables or disables buttons for a file not locally available + * Enables or disables buttons for a file not locally available */ private void setButtonsForRemote() { if (!isEmpty()) { @@@ -479,11 -467,11 +480,11 @@@ // hides the progress bar getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE); - TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText); + TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText); progressText.setVisibility(View.GONE); } } - + public void listenForTransferProgress() { if (mProgressListener != null) { @@@ -497,8 -485,8 +498,8 @@@ } } } - - + + public void leaveTransferProgress() { if (mProgressListener != null) { if (mContainerActivity.getFileDownloaderBinder() != null) { @@@ -513,6 -501,7 +514,6 @@@ } - /** * Helper class responsible for updating the progress bar shown for file uploading or * downloading @@@ -520,11 -509,11 +521,11 @@@ private class ProgressListener implements OnDatatransferProgressListener { int mLastPercent = 0; WeakReference mProgressBar = null; - + ProgressListener(ProgressBar progressBar) { mProgressBar = new WeakReference(progressBar); } - + @Override public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filename) { diff --combined src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 1fdc49d7,5ec5c52c..8d76e3aa --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -22,16 -22,20 +22,18 @@@ */ package com.owncloud.android.ui.fragment; -import java.io.File; - import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.ContextMenu; + import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; + import android.widget.PopupMenu; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; @@@ -46,34 -50,33 +48,35 @@@ import com.owncloud.android.ui.activity import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; + import com.owncloud.android.ui.dialog.FileActionsDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; -import com.owncloud.android.utils.DialogMenuItem; import com.owncloud.android.utils.FileStorageUtils; +import java.io.File; +import java.util.Vector; + /** * A Fragment that lists all files and folders in a given path. - * + * * TODO refactor to get rid of direct dependency on FileDisplayActivity */ - public class OCFileListFragment extends ExtendedListFragment { - + public class OCFileListFragment extends ExtendedListFragment implements FileActionsDialogFragment.FileActionsDialogFragmentListener { + private static final String TAG = OCFileListFragment.class.getSimpleName(); private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment"; - + public final static String ARG_JUST_FOLDERS = MY_PACKAGE + ".JUST_FOLDERS"; public final static String ARG_ALLOW_CONTEXTUAL_ACTIONS = MY_PACKAGE + ".ALLOW_CONTEXTUAL"; - + private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE"; private FileFragment.ContainerActivity mContainerActivity; - + private OCFile mFile = null; private FileListListAdapter mAdapter; private boolean mJustFolders; @@@ -91,21 -94,21 +94,21 @@@ Log_OC.e(TAG, "onAttach"); try { mContainerActivity = (FileFragment.ContainerActivity) activity; - + } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement " + + throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName()); } try { setOnRefreshListener((OnEnforceableRefreshListener) activity); } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement " + + throw new ClassCastException(activity.toString() + " must implement " + SwipeRefreshLayout.OnRefreshListener.class.getSimpleName()); } } - + @Override public void onDetach() { setOnRefreshListener(null); @@@ -137,41 -140,94 +140,94 @@@ mJustFolders, getActivity(), mContainerActivity - ); + ); setListAdapter(mAdapter); - registerForContextMenu(); + registerLongClickListener(); } + private void registerLongClickListener() { + getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + public boolean onItemLongClick(AdapterView arg0, View v, + int index, long arg3) { + showFileAction(index); + return true; + } + }); + } + + + private void showFileAction(int fileIndex) { + Bundle args = getArguments(); + PopupMenu pm = new PopupMenu(getActivity(),null); + Menu menu = pm.getMenu(); + + boolean allowContextualActions = + (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); + + if (allowContextualActions) { + MenuInflater inflater = getActivity().getMenuInflater(); + + inflater.inflate(R.menu.file_actions_menu, menu); + OCFile targetFile = (OCFile) mAdapter.getItem(fileIndex); + + if (mContainerActivity.getStorageManager() != null) { + FileMenuFilter mf = new FileMenuFilter( + targetFile, + mContainerActivity.getStorageManager().getAccount(), + mContainerActivity, + getActivity() + ); + mf.filter(menu); + } + + /// TODO break this direct dependency on FileDisplayActivity... if possible + MenuItem item = menu.findItem(R.id.action_open_file_with); + FileFragment frag = ((FileDisplayActivity)getActivity()).getSecondFragment(); + if (frag != null && frag instanceof FileDetailFragment && + frag.getFile().getFileId() == targetFile.getFileId()) { + item = menu.findItem(R.id.action_see_details); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } + } + + FileActionsDialogFragment dialog = FileActionsDialogFragment.newInstance(menu, fileIndex); + dialog.setTargetFragment(this, 0); + dialog.show(getFragmentManager(), FileActionsDialogFragment.FTAG_FILE_ACTIONS); + } + } + /** * Saves the current listed folder. */ @Override - public void onSaveInstanceState (Bundle outState) { + public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(KEY_FILE, mFile); } - + /** * Call this, when the user presses the up button. - *

- * ++ * * Tries to move up the current folder one level. If the parent folder was removed from the * database, it continues browsing up until finding an existing folders. - * + *

* return Count of folder levels browsed up. */ public int onBrowseUp() { OCFile parentDir = null; int moveCount = 0; - - if(mFile != null){ + + if (mFile != null) { FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); - + String parentPath = null; if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) { parentPath = new File(mFile.getRemotePath()).getParent(); - parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : - parentPath + OCFile.PATH_SEPARATOR; + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : + parentPath + OCFile.PATH_SEPARATOR; parentDir = storageManager.getFileByPath(parentPath); moveCount++; } else { @@@ -179,8 -235,8 +235,8 @@@ } while (parentDir == null) { parentPath = new File(parentPath).getParent(); - parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : - parentPath + OCFile.PATH_SEPARATOR; + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : + parentPath + OCFile.PATH_SEPARATOR; parentDir = storageManager.getFileByPath(parentPath); moveCount++; } // exit is granted because storageManager.getFileByPath("/") never returns null @@@ -190,20 -246,20 +246,20 @@@ listDirectory(mFile /*, MainApp.getOnlyOnDevice()*/); onRefresh(false); - + // restore index and top position restoreIndexAndTopPosition(); - + } // else - should never happen now - + return moveCount; } - + @Override public void onItemClick(AdapterView l, View v, int position, long id) { OCFile file = (OCFile) mAdapter.getItem(position); if (file != null) { - if (file.isFolder()) { + if (file.isFolder()) { // update state and view of this fragment // TODO Enable when "On Device" is recovered ? listDirectory(file/*, MainApp.getOnlyOnDevice()*/); @@@ -211,49 -267,48 +267,48 @@@ mContainerActivity.onBrowsedDownTo(file); // save index and top position saveIndexAndTopPosition(position); - + } else { /// Click on a file if (PreviewImageFragment.canBePreviewed(file)) { // preview image - it handles the download, if needed - ((FileDisplayActivity)mContainerActivity).startImagePreview(file); - + ((FileDisplayActivity) mContainerActivity).startImagePreview(file); + } else if (file.isDown()) { if (PreviewMediaFragment.canBePreviewed(file)) { // media preview - ((FileDisplayActivity)mContainerActivity).startMediaPreview(file, 0, true); + ((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true); } else { mContainerActivity.getFileOperationsHelper().openFile(file); } - + } else { // automatic download, preview on finish - ((FileDisplayActivity)mContainerActivity).startDownloadForPreview(file); + ((FileDisplayActivity) mContainerActivity).startDownloadForPreview(file); } - + } - + } else { Log_OC.d(TAG, "Null object in ListAdapter!!"); } - + } - + /** * {@inheritDoc} */ @Override - public void onCreateContextMenu ( + public void onCreateContextMenu( ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); Bundle args = getArguments(); - boolean allowContextualActions = - (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); + boolean allowContextualActions = + (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); if (allowContextualActions) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.file_actions_menu, menu); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; OCFile targetFile = (OCFile) mAdapter.getItem(info.position); - + if (mContainerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter( targetFile, @@@ -278,15 -333,13 +333,13 @@@ } } - /** - * {@inhericDoc} + * {@inheritDoc} */ @Override - public boolean onContextItemSelected(MenuItem item) { - AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); - mTargetFile = (OCFile) mAdapter.getItem(info.position); - switch (item.getItemId()) { + public boolean onFileActionChosen(int menuId, int filePosition) { + mTargetFile = (OCFile) mAdapter.getItem(filePosition); + switch (menuId) { case R.id.action_share_file: { mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile); return true; @@@ -342,23 -395,30 +395,37 @@@ getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES); return true; } - case R.id.action_favorite_file:{ + case R.id.action_favorite_file: { mContainerActivity.getFileOperationsHelper().toggleFavorite(mTargetFile, true); return true; } - case R.id.action_unfavorite_file:{ + case R.id.action_unfavorite_file: { mContainerActivity.getFileOperationsHelper().toggleFavorite(mTargetFile, false); return true; } + case R.id.action_copy: + Intent action = new Intent(getActivity(), FolderPickerActivity.class); + + // Pass mTargetFile that contains info of selected file/folder + action.putExtra(FolderPickerActivity.EXTRA_FILE, mTargetFile); + getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_COPY_FILES); + return true; default: - return super.onContextItemSelected(item); + return false; + } + } + + /** + * {@inhericDoc} + */ + @Override + public boolean onContextItemSelected (MenuItem item) { + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); + boolean matched = onFileActionChosen(item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).position); + if(!matched) { + return super.onContextItemSelected(item); + } else { + return matched; } } @@@ -366,13 -426,12 +433,13 @@@ /** * Use this to query the {@link OCFile} that is currently * being displayed by this fragment + * * @return The currently viewed OCFile */ - public OCFile getCurrentFile(){ + public OCFile getCurrentFile() { return mFile; } - + /** * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter */ @@@ -386,12 -445,12 +453,12 @@@ // TODO Enable when "On Device" is recovered ? listDirectory(getCurrentFile()/*, MainApp.getOnlyOnDevice()*/); } - + /** * Lists the given directory on the view. When the input parameter is null, * it will either refresh the last known directory. list the root * if there never was a directory. - * + * * @param directory File to be listed */ public void listDirectory(OCFile directory/*, boolean onlyOnDevice*/) { @@@ -399,18 -458,18 +466,18 @@@ if (storageManager != null) { // Check input parameters for null - if(directory == null){ - if(mFile != null){ + if (directory == null) { + if (mFile != null) { directory = mFile; } else { directory = storageManager.getFileByPath("/"); if (directory == null) return; // no files, wait for sync } } - - + + // If that's not a directory -> List its parent - if(!directory.isFolder()){ + if (!directory.isFolder()) { Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString()); directory = storageManager.getFileById(directory.getParentId()); } @@@ -437,9 -496,12 +504,12 @@@ if (file.isFolder()) { foldersCount++; } else { - filesCount++; - if (file.isImage()){ - imagesCount++; + if (!file.isHidden()) { + filesCount++; + + if (file.isImage()) { + imagesCount++; + } } } } @@@ -452,6 -514,7 +522,7 @@@ if (version != null && version.supportsRemoteThumbnails() && imagesCount > 0 && imagesCount == filesCount) { switchToGridView(); + registerLongClickListener(); } else { switchToListView(); } @@@ -498,7 -561,6 +569,6 @@@ return output; } - public void sortByName(boolean descending) { mAdapter.setSortOrder(FileStorageUtils.SORT_NAME, descending); } @@@ -510,6 -572,4 +580,4 @@@ public void sortBySize(boolean descending) { mAdapter.setSortOrder(FileStorageUtils.SORT_SIZE, descending); } - - } diff --combined src/com/owncloud/android/ui/preview/FileDownloadFragment.java index 957d3384,dd78a039..e63b3245 --- a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java @@@ -36,13 -36,9 +36,9 @@@ import android.view.ViewGroup import android.widget.ProgressBar; import android.widget.TextView; - import com.owncloud.android.R; - import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.utils.Log_OC; - import com.owncloud.android.ui.fragment.FileFragment; - - import java.lang.ref.WeakReference; + import com.owncloud.android.utils.DisplayUtils; /** @@@ -63,9 -59,9 +59,9 @@@ public class FileDownloadFragment exten public ProgressListener mProgressListener; private boolean mListening; - + private static final String TAG = FileDownloadFragment.class.getSimpleName(); - + private boolean mIgnoreFirstSavedState; private boolean mError; @@@ -122,31 -118,29 +118,30 @@@ mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST); mAccount = args.getParcelable(ARG_ACCOUNT); } - + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - + if (savedInstanceState != null) { if (!mIgnoreFirstSavedState) { - setFile((OCFile)savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE)); + setFile((OCFile) savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE)); mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT); mError = savedInstanceState.getBoolean(FileDownloadFragment.EXTRA_ERROR); - } else { + } + else { mIgnoreFirstSavedState = false; } } - View view = null; - view = inflater.inflate(R.layout.file_download_fragment, container, false); - mView = view; - - ProgressBar progressBar = (ProgressBar) mView.findViewById(R.id.progressBar); + mView = inflater.inflate(R.layout.file_download_fragment, container, false); + + ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.progressBar); + DisplayUtils.colorPreLollipopHorizontalProgressBar(progressBar); mProgressListener = new ProgressListener(progressBar); - + (mView.findViewById(R.id.cancelBtn)).setOnClickListener(this); (mView.findViewById(R.id.fileDownloadLL)).setOnClickListener(new OnClickListener() { @@@ -158,14 -152,13 +153,14 @@@ if (mError) { setButtonsForRemote(); - } else { + } + else { setButtonsForTransferring(); } - + - return view; + return mView; } - + @Override public void onSaveInstanceState(Bundle outState) { @@@ -180,7 -173,7 +175,7 @@@ super.onStart(); listenForTransferProgress(); } - + @Override public void onResume() { super.onResume(); @@@ -192,19 -185,19 +187,19 @@@ super.onPause(); } - + @Override public void onStop() { leaveTransferProgress(); super.onStop(); } - + @Override public void onDestroy() { super.onDestroy(); } - - + + @Override public View getView() { if (!mListening) { @@@ -213,7 -206,7 +208,7 @@@ return super.getView() == null ? mView : super.getView(); } - + @Override public void onClick(View v) { switch (v.getId()) { @@@ -227,52 -220,53 +222,52 @@@ } } - + /** * Enables or disables buttons for a file being downloaded */ private void setButtonsForTransferring() { getView().findViewById(R.id.cancelBtn).setVisibility(View.VISIBLE); - + // show the progress bar for the transfer getView().findViewById(R.id.progressBar).setVisibility(View.VISIBLE); - TextView progressText = (TextView)getView().findViewById(R.id.progressText); + TextView progressText = (TextView) getView().findViewById(R.id.progressText); progressText.setText(R.string.downloader_download_in_progress_ticker); progressText.setVisibility(View.VISIBLE); - + // hides the error icon getView().findViewById(R.id.errorText).setVisibility(View.GONE); getView().findViewById(R.id.error_image).setVisibility(View.GONE); } - /** - * Enables or disables buttons for a file locally available + * Enables or disables buttons for a file locally available */ private void setButtonsForDown() { getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE); - + // hides the progress bar getView().findViewById(R.id.progressBar).setVisibility(View.GONE); - + // updates the text message - TextView progressText = (TextView)getView().findViewById(R.id.progressText); + TextView progressText = (TextView) getView().findViewById(R.id.progressText); progressText.setText(R.string.common_loading); progressText.setVisibility(View.VISIBLE); - + // hides the error icon getView().findViewById(R.id.errorText).setVisibility(View.GONE); getView().findViewById(R.id.error_image).setVisibility(View.GONE); } - + /** - * Enables or disables buttons for a file not locally available - * + * Enables or disables buttons for a file not locally available + *

* Currently, this is only used when a download was failed */ private void setButtonsForRemote() { getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE); - + // hides the progress bar and message getView().findViewById(R.id.progressBar).setVisibility(View.GONE); getView().findViewById(R.id.progressText).setVisibility(View.GONE); @@@ -281,7 -275,7 +276,7 @@@ getView().findViewById(R.id.errorText).setVisibility(View.VISIBLE); getView().findViewById(R.id.error_image).setVisibility(View.VISIBLE); } - + public void listenForTransferProgress() { if (mProgressListener != null && !mListening) { @@@ -294,8 -288,8 +289,8 @@@ } } } - - + + public void leaveTransferProgress() { if (mProgressListener != null) { if (mContainerActivity.getFileDownloaderBinder() != null) { @@@ -314,11 -308,11 +309,11 @@@ private class ProgressListener implements OnDatatransferProgressListener { int mLastPercent = 0; WeakReference mProgressBar = null; - + ProgressListener(ProgressBar progressBar) { mProgressBar = new WeakReference(progressBar); } - + @Override public void onTransferProgress( long progressRate, long totalTransferredSoFar, long totalToTransfer, String filename @@@ -339,9 -333,8 +334,9 @@@ public void setError(boolean error) { mError = error; - }; - + } + + ; } diff --combined src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 6dd18658,6ce592a7..b6f36823 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@@ -26,6 -26,7 +26,7 @@@ import android.annotation.SuppressLint import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Point; + import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentStatePagerAdapter; @@@ -74,11 -75,11 +75,11 @@@ public class PreviewImageFragment exten private ProgressBar mProgressWheel; public Bitmap mBitmap = null; - + private static final String TAG = PreviewImageFragment.class.getSimpleName(); private boolean mIgnoreFirstSavedState; - + private LoadBitmapTask mLoadBitmapTask = null; @@@ -105,7 -106,7 +106,7 @@@ return frag; } - + /** * Creates an empty fragment for image previews. @@@ -119,8 -120,8 +120,8 @@@ public PreviewImageFragment() { mIgnoreFirstSavedState = false; } - - + + /** * {@inheritDoc} */ @@@ -135,14 -136,14 +136,14 @@@ mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST); setHasOptionsMenu(true); } - + /** * {@inheritDoc} */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.preview_image_fragment, container, false); mImageView = (TouchImageViewCustom) view.findViewById(R.id.image); @@@ -182,7 -183,7 +183,7 @@@ throw new IllegalStateException("There is no local file to preview"); } } - + /** * {@inheritDoc} @@@ -192,7 -193,7 +193,7 @@@ super.onSaveInstanceState(outState); outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile()); } - + @Override public void onStart() { @@@ -200,11 -201,12 +201,12 @@@ if (getFile() != null) { mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); //mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()}); - mLoadBitmapTask.execute(getFile().getStoragePath()); + // mLoadBitmapTask.execute(getFile().getStoragePath()); + mLoadBitmapTask.execute(getFile()); } } - - + + @Override public void onStop() { Log_OC.d(TAG, "onStop starts"); @@@ -214,7 -216,7 +216,7 @@@ } super.onStop(); } - + /** * {@inheritDoc} */ @@@ -230,11 -232,11 +232,11 @@@ @Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - + if (mContainerActivity.getStorageManager() != null) { // Update the file setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId())); - + FileMenuFilter mf = new FileMenuFilter( getFile(), mContainerActivity.getStorageManager().getAccount(), @@@ -243,7 -245,7 +245,7 @@@ ); mf.filter(menu); } - + // additional restriction for this fragment // TODO allow renaming in PreviewImageFragment MenuItem item = menu.findItem(R.id.action_rename_file); @@@ -251,7 -253,7 +253,7 @@@ item.setVisible(false); item.setEnabled(false); } - + // additional restriction for this fragment // TODO allow refresh file in PreviewImageFragment item = menu.findItem(R.id.action_sync_file); @@@ -266,17 -268,11 +268,17 @@@ item.setVisible(false); item.setEnabled(false); } - + + // additional restriction for this fragment + item = menu.findItem(R.id.action_copy); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } + } - - + /** * {@inheritDoc} */ @@@ -324,10 -320,10 +326,10 @@@ return false; } } - + private void seeDetails() { - mContainerActivity.showDetails(getFile()); + mContainerActivity.showDetails(getFile()); } @@@ -354,7 -350,7 +356,7 @@@ super.onDestroy(); } - + /** * Opens the previewed image with an external application. */ @@@ -362,9 -358,9 +364,9 @@@ mContainerActivity.getFileOperationsHelper().openFile(getFile()); finish(); } - + - - private class LoadBitmapTask extends AsyncTask { + + private class LoadBitmapTask extends AsyncTask { /** * Weak reference to the target {@link ImageView} where the bitmap will be loaded into. @@@ -382,7 -378,7 +384,7 @@@ */ private final WeakReference mMessageViewRef; - + /** * Weak reference to the target {@link ProgressBar} shown while the load is in progress. * @@@ -391,17 -387,17 +393,17 @@@ */ private final WeakReference mProgressWheelRef; - + /** - * Error message to show when a load fails + * Error message to show when a load fails */ private int mErrorMessageId; - - + + /** * Constructor. - * - * @param imageView Target {@link ImageView} where the bitmap will be loaded into. + * + * @param imageView Target {@link ImageView} where the bitmap will be loaded into. */ public LoadBitmapTask(ImageViewCustom imageView, TextView messageView, ProgressBar progressWheel) { @@@ -409,13 -405,13 +411,13 @@@ mMessageViewRef = new WeakReference(messageView); mProgressWheelRef = new WeakReference(progressWheel); } - + - @Override - protected Bitmap doInBackground(String... params) { + protected LoadImage doInBackground(OCFile... params) { Bitmap result = null; if (params.length != 1) return null; - String storagePath = params[0]; + OCFile ocFile = params[0]; + String storagePath = ocFile.getStoragePath(); try { int maxDownScale = 3; // could be a parameter passed to doInBackground(...) @@@ -428,7 -424,7 +430,7 @@@ result = BitmapUtils.decodeSampledBitmapFromFile(storagePath, minWidth, minHeight); - if (isCancelled()) return result; + if (isCancelled()) return new LoadImage(result, ocFile); if (result == null) { mErrorMessageId = R.string.preview_image_error_unknown_format; @@@ -460,49 -456,54 +462,56 @@@ } catch (NoSuchFieldError e) { mErrorMessageId = R.string.common_error_unknown; - Log_OC.e(TAG, "Error from access to unexisting field despite protection; file " - + storagePath, e); - + Log_OC.e(TAG, "Error from access to unexisting field despite protection; file " + + storagePath, e); + } catch (Throwable t) { mErrorMessageId = R.string.common_error_unknown; Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t); - + } + - return result; + return new LoadImage(result, ocFile); } - + @Override - protected void onCancelled(Bitmap result) { - if (result != null) { - result.recycle(); + protected void onCancelled(LoadImage result) { + if (result.bitmap != null) { + result.bitmap.recycle(); } } @Override - protected void onPostExecute(Bitmap result) { + protected void onPostExecute(LoadImage result) { hideProgressWheel(); - if (result != null) { + if (result.bitmap != null) { showLoadedImage(result); - } else { + } + else { showErrorMessage(); } - if (result != null && mBitmap != result) { + if (result.bitmap != null && mBitmap != result.bitmap) { // unused bitmap, release it! (just in case) - result.recycle(); + result.bitmap.recycle(); } } - + @SuppressLint("InlinedApi") - private void showLoadedImage(Bitmap result) { + private void showLoadedImage(LoadImage result) { final ImageViewCustom imageView = mImageViewRef.get(); + Bitmap bitmap = result.bitmap; if (imageView != null) { - Log_OC.d(TAG, "Showing image with resolution " + result.getWidth() + "x" + - result.getHeight()); - imageView.setImageBitmap(result); + Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" + + bitmap.getHeight()); + + if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")){ + Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat); + imageView.setBackground(backrepeat); + } + + imageView.setImageBitmap(bitmap); imageView.setVisibility(View.VISIBLE); - mBitmap = result; // needs to be kept for recycling when not useful + mBitmap = bitmap; // needs to be kept for recycling when not useful } final TextView messageView = mMessageViewRef.get(); @@@ -510,7 -511,7 +519,7 @@@ messageView.setVisibility(View.GONE); } // else , silently finish, the fragment was destroyed } - + private void showErrorMessage() { final ImageView imageView = mImageViewRef.get(); if (imageView != null) { @@@ -524,14 -525,14 +533,14 @@@ messageView.setVisibility(View.VISIBLE); } // else , silently finish, the fragment was destroyed } - + private void hideProgressWheel() { final ProgressBar progressWheel = mProgressWheelRef.get(); if (progressWheel != null) { progressWheel.setVisibility(View.GONE); } } - + } /** @@@ -545,7 -546,7 +554,7 @@@ return (file != null && file.isImage()); } - + /** * Finishes the preview */ @@@ -553,9 -554,20 +562,20 @@@ Activity container = getActivity(); container.finish(); } - + public TouchImageViewCustom getImageView() { return mImageView; } + private class LoadImage { + private Bitmap bitmap; + private OCFile ocFile; + + public LoadImage(Bitmap bitmap, OCFile ocFile){ + this.bitmap = bitmap; + this.ocFile = ocFile; + } + + } + } diff --combined src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 02aebd0c,b197a855..0dbb1a32 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@@ -21,7 -21,10 +21,10 @@@ package com.owncloud.android.ui.preview import android.accounts.Account; import android.app.Activity; - import android.app.AlertDialog; + import android.graphics.Bitmap; + import android.graphics.BitmapFactory; + import android.media.MediaMetadataRetriever; + import android.support.v7.app.AlertDialog; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; @@@ -46,6 -49,7 +49,6 @@@ import android.view.View import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.Toast; import android.widget.VideoView; @@@ -64,7 -68,7 +67,7 @@@ import com.owncloud.android.ui.fragment /** * This fragment shows a preview of a downloaded media file (audio or video). - * + * * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will * produce an {@link IllegalStateException}. * @@@ -84,46 -88,46 +87,46 @@@ public class PreviewMediaFragment exten private ImageView mImagePreview; private VideoView mVideoPreview; private int mSavedPlaybackPosition; - + private MediaServiceBinder mMediaServiceBinder = null; private MediaControlView mMediaController = null; private MediaServiceConnection mMediaServiceConnection = null; private VideoHelper mVideoHelper; private boolean mAutoplay; public boolean mPrepared; - + private static final String TAG = PreviewMediaFragment.class.getSimpleName(); - + /** * Creates a fragment to preview a file. - * + *

* When 'fileToDetail' or 'ocAccount' are null - * - * @param fileToDetail An {@link OCFile} to preview in the fragment - * @param ocAccount An ownCloud account; needed to start downloads + * + * @param fileToDetail An {@link OCFile} to preview in the fragment + * @param ocAccount An ownCloud account; needed to start downloads */ public PreviewMediaFragment( - OCFile fileToDetail, - Account ocAccount, - int startPlaybackPosition, + OCFile fileToDetail, + Account ocAccount, + int startPlaybackPosition, boolean autoplay) { - + super(fileToDetail); mAccount = ocAccount; mSavedPlaybackPosition = startPlaybackPosition; mAutoplay = autoplay; } - - + + /** - * Creates an empty fragment for previews. - * - * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically - * (for instance, when the device is turned a aside). - * - * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful - * construction + * Creates an empty fragment for previews. + *

+ * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically + * (for instance, when the device is turned a aside). + *

+ * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful + * construction */ public PreviewMediaFragment() { super(); @@@ -131,8 -135,8 +134,8 @@@ mSavedPlaybackPosition = 0; mAutoplay = true; } - - + + /** * {@inheritDoc} */ @@@ -141,29 -145,29 +144,29 @@@ super.onCreate(savedInstanceState); setHasOptionsMenu(true); } - + /** * {@inheritDoc} */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); Log_OC.e(TAG, "onCreateView"); - + mView = inflater.inflate(R.layout.file_preview, container, false); - - mImagePreview = (ImageView)mView.findViewById(R.id.image_preview); - mVideoPreview = (VideoView)mView.findViewById(R.id.video_preview); + + mImagePreview = (ImageView) mView.findViewById(R.id.image_preview); + mVideoPreview = (VideoView) mView.findViewById(R.id.video_preview); mVideoPreview.setOnTouchListener(this); - - mMediaController = (MediaControlView)mView.findViewById(R.id.media_controller); - + + mMediaController = (MediaControlView) mView.findViewById(R.id.media_controller); + return mView; } - + /** * {@inheritDoc} @@@ -184,32 -188,54 +187,56 @@@ if (!file.isDown()) { throw new IllegalStateException("There is no local file to preview"); } - - } else { - file = (OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE); + + } + else { + file = (OCFile) savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE); setFile(file); mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT); - mSavedPlaybackPosition = + mSavedPlaybackPosition = savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION); mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING); - + } if (file != null && file.isDown()) { if (file.isVideo()) { mVideoPreview.setVisibility(View.VISIBLE); mImagePreview.setVisibility(View.GONE); prepareVideo(); - - } else { + + } + else { mVideoPreview.setVisibility(View.GONE); mImagePreview.setVisibility(View.VISIBLE); + extractAndSetCoverArt(file); } } - + } + /** + * tries to read the cover art from the audio file and sets it as cover art. + * + * @param file audio file with potential cover art + */ + private void extractAndSetCoverArt(OCFile file) { + if (file.isAudio()) { + try { + MediaMetadataRetriever mmr = new MediaMetadataRetriever(); + mmr.setDataSource(file.getStoragePath()); + byte[] data = mmr.getEmbeddedPicture(); + if (data != null) { + Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); + mImagePreview.setImageBitmap(bitmap); //associated cover art in bitmap + } else { + mImagePreview.setImageResource(R.drawable.logo); + } + } catch (Throwable t) { + mImagePreview.setImageResource(R.drawable.logo); + } + } + } + /** * {@inheritDoc} @@@ -218,25 -244,24 +245,25 @@@ public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Log_OC.e(TAG, "onSaveInstanceState"); - + outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, getFile()); outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount); - + if (getFile().isVideo()) { mSavedPlaybackPosition = mVideoPreview.getCurrentPosition(); mAutoplay = mVideoPreview.isPlaying(); - outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mSavedPlaybackPosition); - outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mAutoplay); - } else { + outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION, mSavedPlaybackPosition); + outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING, mAutoplay); + } + else { outState.putInt( - PreviewMediaFragment.EXTRA_PLAY_POSITION , + PreviewMediaFragment.EXTRA_PLAY_POSITION, mMediaServiceBinder.getCurrentPosition()); outState.putBoolean( - PreviewMediaFragment.EXTRA_PLAYING , mMediaServiceBinder.isPlaying()); + PreviewMediaFragment.EXTRA_PLAYING, mMediaServiceBinder.isPlaying()); } } - + @Override public void onStart() { @@@ -245,20 -270,17 +272,20 @@@ OCFile file = getFile(); if (file != null && file.isDown()) { - if (file.isAudio()) { - bindMediaService(); - - } else if (file.isVideo()) { - stopAudio(); - playVideo(); - } + if (file.isAudio()) { + bindMediaService(); + + } + else { + if (file.isVideo()) { + stopAudio(); + playVideo(); + } + } } } - - + + private void stopAudio() { Intent i = new Intent(getActivity(), MediaService.class); i.setAction(MediaService.ACTION_STOP_ALL); @@@ -282,7 -304,7 +309,7 @@@ @Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - + if (mContainerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter( getFile(), @@@ -307,16 -329,9 +334,16 @@@ item.setVisible(false); item.setEnabled(false); } + + // additional restriction for this fragment + item = menu.findItem(R.id.action_copy); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } } - - + + /** * {@inheritDoc} */ @@@ -366,26 -381,26 +393,26 @@@ return false; } } - /** * Update the file of the fragment with file value + * * @param file */ - public void updateFile(OCFile file){ + public void updateFile(OCFile file) { setFile(file); } - + private void sendFile() { stopPreview(false); mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile()); - + } private void seeDetails() { stopPreview(false); - mContainerActivity.showDetails(getFile()); + mContainerActivity.showDetails(getFile()); } @@@ -396,80 -411,77 +423,80 @@@ mVideoPreview.setOnCompletionListener(mVideoHelper); mVideoPreview.setOnErrorListener(mVideoHelper); } - + @SuppressWarnings("static-access") private void playVideo() { // create and prepare control panel for the user mMediaController.setMediaPlayer(mVideoPreview); - + // load the video file in the video player ; // when done, VideoHelper#onPrepared() will be called Uri uri = Uri.parse(getFile().getStoragePath()); mVideoPreview.setVideoPath(uri.encode(getFile().getStoragePath())); } - + private class VideoHelper implements OnCompletionListener, OnPreparedListener, OnErrorListener { - - /** + + /** * Called when the file is ready to be played. - * + *

* Just starts the playback. - * + * * @param vp {@link MediaPlayer} instance performing the playback. */ @Override public void onPrepared(MediaPlayer vp) { Log_OC.e(TAG, "onPrepared"); mVideoPreview.seekTo(mSavedPlaybackPosition); - if (mAutoplay) { + if (mAutoplay) { mVideoPreview.start(); } mMediaController.setEnabled(true); mMediaController.updatePausePlay(); mPrepared = true; } - - + + /** * Called when the file is finished playing. - * + *

* Finishes the activity. - * - * @param mp {@link MediaPlayer} instance performing the playback. + * + * @param mp {@link MediaPlayer} instance performing the playback. */ @Override - public void onCompletion(MediaPlayer mp) { + public void onCompletion(MediaPlayer mp) { Log_OC.e(TAG, "completed"); if (mp != null) { mVideoPreview.seekTo(0); // next lines are necessary to work around undesired video loops if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD) { - mVideoPreview.pause(); - - } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) { - // mVideePreview.pause() is not enough - - mMediaController.setEnabled(false); - mVideoPreview.stopPlayback(); - mAutoplay = false; - mSavedPlaybackPosition = 0; - mVideoPreview.setVideoPath(getFile().getStoragePath()); + mVideoPreview.pause(); + + } + else { + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) { + // mVideePreview.pause() is not enough + + mMediaController.setEnabled(false); + mVideoPreview.stopPlayback(); + mAutoplay = false; + mSavedPlaybackPosition = 0; + mVideoPreview.setVideoPath(getFile().getStoragePath()); + } } } // else : called from onError() mMediaController.updatePausePlay(); } - - + + /** * Called when an error in playback occurs. - * - * @param mp {@link MediaPlayer} instance performing the playback. - * @param what Type of error - * @param extra Extra code specific to the error + * + * @param mp {@link MediaPlayer} instance performing the playback. + * @param what Type of error + * @param extra Extra code specific to the error */ @Override public boolean onError(MediaPlayer mp, int what, int extra) { @@@ -490,28 -502,28 +517,28 @@@ } return true; } - + } - + @Override public void onPause() { Log_OC.e(TAG, "onPause"); super.onPause(); } - + @Override public void onResume() { super.onResume(); Log_OC.e(TAG, "onResume"); } - + @Override public void onDestroy() { Log_OC.e(TAG, "onDestroy"); super.onDestroy(); } - + @Override public void onStop() { Log_OC.e(TAG, "onStop"); @@@ -526,10 -538,10 +553,10 @@@ mMediaServiceConnection = null; mMediaServiceBinder = null; } - + super.onStop(); } - + @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN && v == mVideoPreview) { @@@ -542,7 -554,7 +569,7 @@@ return false; } - + private void startFullScreenVideo() { Intent i = new Intent(getActivity(), PreviewVideoActivity.class); i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount); @@@ -554,30 -566,29 +581,30 @@@ } @Override - public void onConfigurationChanged (Configuration newConfig) { + public void onConfigurationChanged(Configuration newConfig) { Log_OC.e(TAG, "onConfigurationChanged " + this); } - + @Override - public void onActivityResult (int requestCode, int resultCode, Intent data) { + public void onActivityResult(int requestCode, int resultCode, Intent data) { Log_OC.e(TAG, "onActivityResult " + this); super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { mSavedPlaybackPosition = data.getExtras().getInt( PreviewVideoActivity.EXTRA_START_POSITION); - mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY); + mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY); } } - + private void playAudio() { OCFile file = getFile(); if (!mMediaServiceBinder.isPlaying(file)) { Log_OC.d(TAG, "starting playback of " + file.getStoragePath()); mMediaServiceBinder.start(mAccount, file, mAutoplay, mSavedPlaybackPosition); - - } else { + + } + else { if (!mMediaServiceBinder.isPlaying() && mAutoplay) { mMediaServiceBinder.start(); mMediaController.updatePausePlay(); @@@ -614,8 -625,7 +641,8 @@@ Log_OC.d(TAG, "Successfully bound to MediaService, MediaController ready"); - } else { + } + else { Log_OC.e(TAG, "Unexpected response from MediaService while binding"); } } @@@ -637,8 -647,7 +664,8 @@@ Log_OC.e(TAG, "Media service suddenly disconnected"); if (mMediaController != null) { mMediaController.setMediaPlayer(null); - } else { + } + else { Toast.makeText( getActivity(), "No media controller to release when disconnected from media service", @@@ -648,8 -657,9 +675,8 @@@ mMediaServiceConnection = null; } } - } + } - /** * Opens the previewed file with an external application. @@@ -659,33 -669,31 +686,33 @@@ mContainerActivity.getFileOperationsHelper().openFile(getFile()); finish(); } - + /** * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} - * to be previewed. - * - * @param file File to test if can be previewed. - * @return 'True' if the file can be handled by the fragment. + * to be previewed. + * + * @param file File to test if can be previewed. + * @return 'True' if the file can be handled by the fragment. */ public static boolean canBePreviewed(OCFile file) { return (file != null && (file.isAudio() || file.isVideo())); } - + public void stopPreview(boolean stopAudio) { OCFile file = getFile(); if (file.isAudio() && stopAudio) { mMediaServiceBinder.pause(); - - } else if (file.isVideo()) { - mVideoPreview.stopPlayback(); + + } + else { + if (file.isVideo()) { + mVideoPreview.stopPlayback(); + } } } - /** * Finishes the preview */ @@@ -701,12 -709,12 +728,12 @@@ Log_OC.e(TAG, "getting position: " + mSavedPlaybackPosition); return mSavedPlaybackPosition; } - + public boolean isPlaying() { if (mPrepared) { mAutoplay = mVideoPreview.isPlaying(); } return mAutoplay; } - + }