import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
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.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 com.owncloud.android.ui.adapter.NavigationDrawerListAdapter;
import com.owncloud.android.ui.dialog.LoadingDialog;
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter;
import com.owncloud.android.ui.dialog.LoadingDialog;
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
implements OnRemoteOperationListener, ComponentsGetter {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
implements OnRemoteOperationListener, ComponentsGetter {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
"com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
public static final String EXTRA_FROM_NOTIFICATION =
"com.owncloud.android.ui.activity.FROM_NOTIFICATION";
"com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
public static final String EXTRA_FROM_NOTIFICATION =
"com.owncloud.android.ui.activity.FROM_NOTIFICATION";
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
private static final String DIALOG_SHARE_PASSWORD = "DIALOG_SHARE_PASSWORD";
private static final String KEY_TRY_SHARE_AGAIN = "TRY_SHARE_AGAIN";
private static final String KEY_ACTION_BAR_TITLE = "ACTION_BAR_TITLE";
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
private static final String DIALOG_SHARE_PASSWORD = "DIALOG_SHARE_PASSWORD";
private static final String KEY_TRY_SHARE_AGAIN = "TRY_SHARE_AGAIN";
private static final String KEY_ACTION_BAR_TITLE = "ACTION_BAR_TITLE";
/** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
private Account mAccount;
/** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
private Account mAccount;
/** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
* {@link Account} */
private boolean mRedirectingToSetupAccount = false;
/** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
* {@link Account} */
private boolean mRedirectingToSetupAccount = false;
/** Flag to signal if the activity is launched by a notification */
private boolean mFromNotification;
/** Flag to signal if the activity is launched by a notification */
private boolean mFromNotification;
/** Messages handler associated to the main thread and the life cycle of the activity */
private Handler mHandler;
/** Messages handler associated to the main thread and the life cycle of the activity */
private Handler mHandler;
/** Access point to the cached database for the current ownCloud {@link Account} */
private FileDataStorageManager mStorageManager = null;
/** Access point to the cached database for the current ownCloud {@link Account} */
private FileDataStorageManager mStorageManager = null;
protected FileDownloaderBinder mDownloaderBinder = null;
protected FileUploaderBinder mUploaderBinder = null;
private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
protected FileDownloaderBinder mDownloaderBinder = null;
protected FileUploaderBinder mUploaderBinder = null;
private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
// TODO re-enable when "Accounts" is available in Navigation Drawer
// protected boolean mShowAccounts = false;
// TODO re-enable when "Accounts" is available in Navigation Drawer
// protected boolean mShowAccounts = false;
mOperationsServiceConnection = new OperationsServiceConnection();
bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection,
Context.BIND_AUTO_CREATE);
mOperationsServiceConnection = new OperationsServiceConnection();
bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection,
Context.BIND_AUTO_CREATE);
mDownloadServiceConnection = newTransferenceServiceConnection();
if (mDownloadServiceConnection != null) {
bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection,
mDownloadServiceConnection = newTransferenceServiceConnection();
if (mDownloadServiceConnection != null) {
bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection,
- * Since ownCloud {@link Account}s can be managed from the system setting menu,
- * the existence of the {@link Account} associated to the instance must be checked
+ * Since ownCloud {@link Account}s can be managed from the system setting menu,
+ * the existence of the {@link Account} associated to the instance must be checked
@Override
protected void onPause() {
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.removeOperationListener(this);
}
@Override
protected void onPause() {
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.removeOperationListener(this);
}
// Sync the toggle state after onRestoreInstanceState has occurred.
if (mDrawerToggle != null) {
mDrawerToggle.syncState();
// Sync the toggle state after onRestoreInstanceState has occurred.
if (mDrawerToggle != null) {
mDrawerToggle.syncState();
+ @Override
+ public void onBackPressed() {
+ if (isDrawerOpen()) {
+ closeNavDrawer();
+ return;
+ }
+ super.onBackPressed();
+ }
+
+ public boolean isDrawerOpen() {
+ return mDrawerLayout.isDrawerOpen(GravityCompat.START);
+ }
+
+ public void closeNavDrawer() {
+ mDrawerLayout.closeDrawer(GravityCompat.START);
+ }
+
protected void initDrawer(){
// constant settings for action bar when navigation drawer is inited
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
protected void initDrawer(){
// constant settings for action bar when navigation drawer is inited
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list);
// TODO re-enable when "Accounts" is available in Navigation Drawer
mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list);
// TODO re-enable when "Accounts" is available in Navigation Drawer
+ // 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));
+ }
+
// mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
// mDrawerContentDescriptions[0]));
// All Files
// 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));
- mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1]));
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1],
+ R.drawable.ic_settings));
- 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) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
* @param account New {@link Account} to set.
* @param savedAccount When 'true', account was retrieved from a saved instance state.
*/
* @param account New {@link Account} to set.
* @param savedAccount When 'true', account was retrieved from a saved instance state.
*/
- * Tries to swap the current ownCloud {@link Account} for other valid and existing.
- *
- * If no valid ownCloud {@link Account} exists, the the user is requested
+ * Tries to swap the current ownCloud {@link Account} for other valid and existing.
+ *
+ * If no valid ownCloud {@link Account} exists, the the user is requested
* POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
*/
private void swapToDefaultAccount() {
* POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
*/
private void swapToDefaultAccount() {
outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification);
outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor());
outState.putBoolean(KEY_TRY_SHARE_AGAIN, mTryShareAgain);
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());
+ }
/**
* Helper class handling a callback from the {@link AccountManager} after the creation of
* a new ownCloud {@link Account} finished, successfully or not.
/**
* Helper class handling a callback from the {@link AccountManager} after the creation of
* a new ownCloud {@link Account} finished, successfully or not.
* At this moment, only called after the creation of the first account.
*/
public class AccountCreationCallback implements AccountManagerCallback<Bundle> {
* At this moment, only called after the creation of the first account.
*/
public class AccountCreationCallback implements AccountManagerCallback<Bundle> {
}
} catch (OperationCanceledException e) {
Log_OC.d(TAG, "Account creation canceled");
}
} catch (OperationCanceledException e) {
Log_OC.d(TAG, "Account creation canceled");
* Child classes must grant that state depending on the {@link Account} is updated.
*/
protected void onAccountSet(boolean stateWasRecovered) {
if (getAccount() != null) {
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
* Child classes must grant that state depending on the {@link Account} is updated.
*/
protected void onAccountSet(boolean stateWasRecovered) {
if (getAccount() != null) {
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the "
+ "FileActivities ");
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the "
+ "FileActivities ");
result.isIdPRedirection() ||
(result.isException() && result.getException() instanceof AuthenticatorException)
)) {
result.isIdPRedirection() ||
(result.isException() && result.getException() instanceof AuthenticatorException)
)) {
if (result.getCode() == ResultCode.UNAUTHORIZED) {
dismissLoadingDialog();
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
if (result.getCode() == ResultCode.UNAUTHORIZED) {
dismissLoadingDialog();
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
} else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
} else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
} else if (operation instanceof UnshareLinkOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
} else if (operation instanceof UnshareLinkOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
} else if (operation instanceof SynchronizeFolderOperation) {
onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
} else if (operation instanceof SynchronizeFolderOperation) {
onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
updateAccountCredentials.putExtra(
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
updateAccountCredentials.putExtra(
AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(updateAccountCredentials);
}
AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(updateAccountCredentials);
}
private void onCreateShareOperationFinish(CreateShareOperation operation,
RemoteOperationResult result) {
private void onCreateShareOperationFinish(CreateShareOperation operation,
RemoteOperationResult result) {
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
} else {
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
t.show();
} else {
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
t.show();
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
RemoteOperationResult result) {
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
RemoteOperationResult result) {
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, getAccount());
startActivity(i);
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, getAccount());
startActivity(i);
Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
msg.show();
}
Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
msg.show();
}
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
loading.show(ft, DIALOG_WAIT_TAG);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
loading.show(ft, DIALOG_WAIT_TAG);
private void doOnResumeAndBound() {
mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
long waitingForOpId = mFileOperationsHelper.getOpIdWaitingFor();
private void doOnResumeAndBound() {
mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
long waitingForOpId = mFileOperationsHelper.getOpIdWaitingFor();