1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.ui
.activity
;
22 import java
.util
.ArrayList
;
24 import android
.accounts
.Account
;
25 import android
.accounts
.AccountManager
;
26 import android
.app
.AlertDialog
;
27 import android
.app
.AlertDialog
.Builder
;
28 import android
.app
.Dialog
;
29 import android
.content
.BroadcastReceiver
;
30 import android
.content
.ContentResolver
;
31 import android
.content
.Context
;
32 import android
.content
.DialogInterface
;
33 import android
.content
.DialogInterface
.OnClickListener
;
34 import android
.content
.Intent
;
35 import android
.content
.IntentFilter
;
36 import android
.content
.SharedPreferences
;
37 import android
.content
.pm
.PackageInfo
;
38 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
39 import android
.database
.Cursor
;
40 import android
.net
.Uri
;
41 import android
.os
.Bundle
;
42 import android
.preference
.PreferenceManager
;
43 import android
.provider
.MediaStore
;
44 import android
.support
.v4
.app
.FragmentTransaction
;
45 import android
.util
.Log
;
46 import android
.view
.View
;
47 import android
.view
.ViewGroup
;
48 import android
.widget
.ArrayAdapter
;
49 import android
.widget
.EditText
;
50 import android
.widget
.TextView
;
52 import com
.actionbarsherlock
.app
.ActionBar
;
53 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
54 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
55 import com
.actionbarsherlock
.view
.Menu
;
56 import com
.actionbarsherlock
.view
.MenuInflater
;
57 import com
.actionbarsherlock
.view
.MenuItem
;
58 import com
.actionbarsherlock
.view
.Window
;
60 import eu
.alefzero
.owncloud
.AccountUtils
;
61 import eu
.alefzero
.owncloud
.CrashHandler
;
62 import eu
.alefzero
.owncloud
.R
;
63 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
64 import eu
.alefzero
.owncloud
.datamodel
.DataStorageManager
;
65 import eu
.alefzero
.owncloud
.datamodel
.FileDataStorageManager
;
66 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
67 import eu
.alefzero
.owncloud
.files
.services
.FileDownloader
;
68 import eu
.alefzero
.owncloud
.files
.services
.FileUploader
;
69 import eu
.alefzero
.owncloud
.syncadapter
.FileSyncService
;
70 import eu
.alefzero
.owncloud
.ui
.fragment
.FileDetailFragment
;
71 import eu
.alefzero
.owncloud
.ui
.fragment
.FileListFragment
;
72 import eu
.alefzero
.webdav
.WebdavClient
;
75 * Displays, what files the user has available in his ownCloud.
77 * @author Bartek Przybylski
81 public class FileDisplayActivity
extends SherlockFragmentActivity
implements
82 FileListFragment
.ContainerActivity
, OnNavigationListener
, OnClickListener
, android
.view
.View
.OnClickListener
{
84 private ArrayAdapter
<String
> mDirectories
;
85 private OCFile mCurrentDir
;
86 private String
[] mDirs
= null
;
88 private DataStorageManager mStorageManager
;
89 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
90 private UploadFinishReceiver mUploadFinishReceiver
;
92 private View mLayoutView
= null
;
93 private FileListFragment mFileList
;
95 private boolean mDualPane
;
97 private boolean mForcedLoginToCreateFirstAccount
= false
;
99 private static final String KEY_DIR_ARRAY
= "DIR_ARRAY";
100 private static final String KEY_CURRENT_DIR
= "DIR";
102 private static final int DIALOG_SETUP_ACCOUNT
= 0;
103 private static final int DIALOG_CREATE_DIR
= 1;
104 private static final int DIALOG_ABOUT_APP
= 2;
106 private static final int ACTION_SELECT_FILE
= 1;
109 public void onCreate(Bundle savedInstanceState
) {
110 Log
.i(getClass().toString(), "onCreate() start");
111 super.onCreate(savedInstanceState
);
113 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
114 setSupportProgressBarIndeterminateVisibility(false
);
116 // Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
118 if(savedInstanceState
!= null
) {
119 mDirs
= savedInstanceState
.getStringArray(KEY_DIR_ARRAY
);
120 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
121 mDirectories
.add("/");
123 for (String s
: mDirs
)
124 mDirectories
.insert(s
, 0);
125 mCurrentDir
= savedInstanceState
.getParcelable(FileDetailFragment
.EXTRA_FILE
);
128 mLayoutView
= getLayoutInflater().inflate(R
.layout
.files
, null
); // always inflate this at onCreate() ; just once!
130 if (AccountUtils
.accountsAreSetup(this)) {
132 initDelayedTilAccountAvailabe();
135 // best location is to decide; let's try this first
136 boolean pinStart
= false
;
137 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
138 pinStart
= appPrefs
.getBoolean("set_passcode", false
);
141 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
142 i
.putExtra("activity", "splash");
148 setContentView(R
.layout
.no_account_available
);
149 getSupportActionBar().setNavigationMode(ActionBar
.DISPLAY_SHOW_TITLE
);
150 findViewById(R
.id
.setup_account
).setOnClickListener(this);
152 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
153 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
154 startActivity(intent
); // although the code is here, the activity won't be created until this.onStart() and this.onResume() are finished;
155 mForcedLoginToCreateFirstAccount
= true
;
158 Log
.i(getClass().toString(), "onCreate() end");
162 public boolean onCreateOptionsMenu(Menu menu
) {
163 MenuInflater inflater
= getSherlock().getMenuInflater();
164 inflater
.inflate(R
.menu
.menu
, menu
);
169 public boolean onOptionsItemSelected(MenuItem item
) {
170 boolean retval
= true
;
171 switch (item
.getItemId()) {
172 case R
.id
.createDirectoryItem
: {
173 showDialog(DIALOG_CREATE_DIR
);
176 case R
.id
.startSync
: {
177 // This could be interesting
178 //ContentResolver.cancelSync(null, "org.owncloud"); // cancel the current synchronizations of any other ownCloud account
179 Bundle bundle
= new Bundle();
180 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
181 ContentResolver
.requestSync(
182 AccountUtils
.getCurrentOwnCloudAccount(this),
183 "org.owncloud", bundle
);
186 case R
.id
.action_upload
: {
187 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
188 action
= action
.setType("*/*")
189 .addCategory(Intent
.CATEGORY_OPENABLE
);
190 startActivityForResult(
191 Intent
.createChooser(action
, "Upload file from..."),
195 case R
.id
.action_settings
: {
196 Intent settingsIntent
= new Intent(this, Preferences
.class);
197 startActivity(settingsIntent
);
200 case R
.id
.about_app
: {
201 showDialog(DIALOG_ABOUT_APP
);
204 case android
.R
.id
.home
: {
205 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
217 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
218 int i
= itemPosition
;
226 * Called, when the user selected something for uploading
228 public void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
229 if (requestCode
== ACTION_SELECT_FILE
) {
230 if (resultCode
== RESULT_OK
) {
231 Uri selectedImageUri
= data
.getData();
233 String filemanagerstring
= selectedImageUri
.getPath();
234 String selectedImagePath
= getPath(selectedImageUri
);
237 if (selectedImagePath
!= null
)
238 filepath
= selectedImagePath
;
240 filepath
= filemanagerstring
;
242 if (filepath
== null
) {
243 Log
.e("FileDisplay", "Couldnt resolve path to file");
247 Intent i
= new Intent(this, FileUploader
.class);
248 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
249 AccountUtils
.getCurrentOwnCloudAccount(this));
250 String remotepath
= new String();
251 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
252 remotepath
+= "/" + mDirectories
.getItem(j
);
254 if (!remotepath
.endsWith("/"))
256 remotepath
+= new File(filepath
).getName();
257 remotepath
= Uri
.encode(remotepath
, "/");
259 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
260 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
261 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
265 }/* dvelasco: WIP - not working as expected ... yet :)
266 else if (requestCode == ACTION_CREATE_FIRST_ACCOUNT) {
267 if (resultCode != RESULT_OK) {
268 finish(); // the user cancelled the AuthenticatorActivity
274 public void onBackPressed() {
275 if (mDirectories
== null
|| mDirectories
.getCount() <= 1) {
280 mFileList
.onNavigateUp();
281 mCurrentDir
= mFileList
.getCurrentFile();
283 if(mCurrentDir
.getParentId() == 0){
284 ActionBar actionBar
= getSupportActionBar();
285 actionBar
.setDisplayHomeAsUpEnabled(false
);
290 protected void onSaveInstanceState(Bundle outState
) {
291 // responsability of restore is prefered in onCreate() before than in onRestoreInstanceState when there are Fragments involved
292 Log
.i(getClass().toString(), "onSaveInstanceState() start");
293 super.onSaveInstanceState(outState
);
294 if(mDirectories
!= null
&& mDirectories
.getCount() != 0){
295 mDirs
= new String
[mDirectories
.getCount()-1];
296 for (int j
= mDirectories
.getCount() - 2, i
= 0; j
>= 0; --j
, ++i
) {
297 mDirs
[i
] = mDirectories
.getItem(j
);
300 outState
.putStringArray(KEY_DIR_ARRAY
, mDirs
);
301 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
302 Log
.i(getClass().toString(), "onSaveInstanceState() end");
306 protected void onResume() {
307 Log
.i(getClass().toString(), "onResume() start");
310 if (AccountUtils
.accountsAreSetup(this)) {
311 // at least an account exist: normal operation
313 // set the layout only if it couldn't be set in onCreate
314 if (mForcedLoginToCreateFirstAccount
) {
315 initDelayedTilAccountAvailabe();
316 mForcedLoginToCreateFirstAccount
= false
;
319 // Listen for sync messages
320 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
321 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
322 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
324 // Listen for upload messages
325 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
326 mUploadFinishReceiver
= new UploadFinishReceiver();
327 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
329 // Storage manager initialization
330 mStorageManager
= new FileDataStorageManager(
331 AccountUtils
.getCurrentOwnCloudAccount(this),
332 getContentResolver());
334 // File list fragments
335 mFileList
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
338 // Figure out what directory to list.
339 // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)
340 if(getIntent().hasExtra(FileDetailFragment
.EXTRA_FILE
)){
341 mCurrentDir
= (OCFile
) getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
342 if(mCurrentDir
!= null
&& !mCurrentDir
.isDirectory()){
343 mCurrentDir
= mStorageManager
.getFileById(mCurrentDir
.getParentId());
346 // Clear intent extra, so rotating the screen will not return us to this directory
347 getIntent().removeExtra(FileDetailFragment
.EXTRA_FILE
);
350 if (mCurrentDir
== null
)
351 mCurrentDir
= mStorageManager
.getFileByPath("/");
353 // Drop-Down navigation and file list restore
354 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
357 // Given the case we have a file to display:
358 if(mCurrentDir
!= null
){
359 ArrayList
<OCFile
> files
= new ArrayList
<OCFile
>();
360 OCFile currFile
= mCurrentDir
;
361 while(currFile
!= null
){
363 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
367 mDirs
= new String
[files
.size()];
368 for(int i
= files
.size() - 1; i
>= 0; i
--){
369 mDirs
[i
] = files
.get(i
).getFileName();
374 for (String s
: mDirs
)
377 mDirectories
.add("/");
381 ActionBar action_bar
= getSupportActionBar();
382 action_bar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
383 action_bar
.setDisplayShowTitleEnabled(false
);
384 action_bar
.setListNavigationCallbacks(mDirectories
, this);
385 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
386 action_bar
.setDisplayHomeAsUpEnabled(true
);
388 action_bar
.setDisplayHomeAsUpEnabled(false
);
392 mFileList
.listDirectory(mCurrentDir
);
394 Log
.i(getClass().toString(), "onResume() end");
398 protected void onPause() {
399 Log
.i(getClass().toString(), "onPause() start");
401 if (mSyncBroadcastReceiver
!= null
) {
402 unregisterReceiver(mSyncBroadcastReceiver
);
403 mSyncBroadcastReceiver
= null
;
405 if (mUploadFinishReceiver
!= null
) {
406 unregisterReceiver(mUploadFinishReceiver
);
407 mUploadFinishReceiver
= null
;
409 getIntent().putExtra(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
410 Log
.i(getClass().toString(), "onPause() end");
414 protected Dialog
onCreateDialog(int id
) {
415 Dialog dialog
= null
;
416 AlertDialog
.Builder builder
;
418 case DIALOG_SETUP_ACCOUNT
:
419 builder
= new AlertDialog
.Builder(this);
420 builder
.setTitle(R
.string
.main_tit_accsetup
);
421 builder
.setMessage(R
.string
.main_wrn_accsetup
);
422 builder
.setCancelable(false
);
423 builder
.setPositiveButton(android
.R
.string
.ok
, this);
424 builder
.setNegativeButton(android
.R
.string
.cancel
, this);
425 dialog
= builder
.create();
427 case DIALOG_ABOUT_APP
: {
428 builder
= new AlertDialog
.Builder(this);
429 builder
.setTitle("About");
432 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
433 builder
.setMessage("ownCloud android client\n\nversion: " + pkg
.versionName
);
434 builder
.setIcon(android
.R
.drawable
.ic_menu_info_details
);
435 dialog
= builder
.create();
436 } catch (NameNotFoundException e
) {
443 case DIALOG_CREATE_DIR
: {
444 builder
= new Builder(this);
445 final EditText dirNameInput
= new EditText(getBaseContext());
446 final Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
447 builder
.setView(dirNameInput
);
448 builder
.setTitle(R
.string
.uploader_info_dirname
);
449 int typed_color
= getResources().getColor(R
.color
.setup_text_typed
);
450 dirNameInput
.setTextColor(typed_color
);
451 builder
.setPositiveButton(android
.R
.string
.ok
,
452 new OnClickListener() {
453 public void onClick(DialogInterface dialog
, int which
) {
454 String directoryName
= dirNameInput
.getText().toString();
455 if (directoryName
.trim().length() == 0) {
460 // Figure out the path where the dir needs to be created
462 if (mCurrentDir
== null
) {
463 // this is just a patch; we should ensure that mCurrentDir never is null
464 if (!mStorageManager
.fileExists("/")) {
465 OCFile file
= new OCFile("/");
466 mStorageManager
.saveFile(file
);
468 mCurrentDir
= mStorageManager
.getFileByPath("/");
470 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
473 path
+= Uri
.encode(directoryName
) + "/";
474 Thread thread
= new Thread(new DirectoryCreator(path
, a
));
477 // Save new directory in local database
478 OCFile newDir
= new OCFile(path
);
479 newDir
.setMimetype("DIR");
480 newDir
.setParentId(mCurrentDir
.getFileId());
481 mStorageManager
.saveFile(newDir
);
483 // Display the new folder right away
485 mFileList
.listDirectory(mCurrentDir
);
488 builder
.setNegativeButton(R
.string
.common_cancel
,
489 new OnClickListener() {
490 public void onClick(DialogInterface dialog
, int which
) {
494 dialog
= builder
.create();
506 * Responds to the "There are no ownCloud Accounts setup" dialog
507 * TODO: Dialog is 100% useless -> Remove
510 public void onClick(DialogInterface dialog
, int which
) {
511 // In any case - we won't need it anymore
514 case DialogInterface
.BUTTON_POSITIVE
:
515 Intent intent
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
516 intent
.putExtra("authorities",
517 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
518 startActivity(intent
);
520 case DialogInterface
.BUTTON_NEGATIVE
:
527 * Translates a content URI of an image to a physical path
529 * @param uri The URI to resolve
530 * @return The path to the image or null if it could not be found
532 public String
getPath(Uri uri
) {
533 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
534 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
535 if (cursor
!= null
) {
536 int column_index
= cursor
537 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
538 cursor
.moveToFirst();
539 return cursor
.getString(column_index
);
545 * Pushes a directory to the drop down list
546 * @param directory to push
547 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
549 public void pushDirname(OCFile directory
) {
550 if(!directory
.isDirectory()){
551 throw new IllegalArgumentException("Only directories may be pushed!");
553 mDirectories
.insert(directory
.getFileName(), 0);
554 mCurrentDir
= directory
;
558 * Pops a directory name from the drop down list
559 * @return True, unless the stack is empty
561 public boolean popDirname() {
562 mDirectories
.remove(mDirectories
.getItem(0));
563 return !mDirectories
.isEmpty();
566 private class DirectoryCreator
implements Runnable
{
567 private String mTargetPath
;
568 private Account mAccount
;
569 private AccountManager mAm
;
571 public DirectoryCreator(String targetPath
, Account account
) {
572 mTargetPath
= targetPath
;
574 mAm
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
579 WebdavClient wdc
= new WebdavClient(mAccount
, getApplicationContext());
581 String username
= mAccount
.name
.substring(0,
582 mAccount
.name
.lastIndexOf('@'));
583 String password
= mAm
.getPassword(mAccount
);
585 wdc
.setCredentials(username
, password
);
586 wdc
.allowSelfsignedCertificates();
587 wdc
.createDirectory(mTargetPath
);
592 // Custom array adapter to override text colors
593 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
595 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
599 public View
getView(int position
, View convertView
, ViewGroup parent
) {
600 View v
= super.getView(position
, convertView
, parent
);
602 ((TextView
) v
).setTextColor(getResources().getColorStateList(
603 android
.R
.color
.white
));
607 public View
getDropDownView(int position
, View convertView
,
609 View v
= super.getDropDownView(position
, convertView
, parent
);
611 ((TextView
) v
).setTextColor(getResources().getColorStateList(
612 android
.R
.color
.white
));
619 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
621 * {@link BroadcastReceiver} to enable syncing feedback in UI
624 public void onReceive(Context context
, Intent intent
) {
625 boolean inProgress
= intent
.getBooleanExtra(
626 FileSyncService
.IN_PROGRESS
, false
);
627 String account_name
= intent
628 .getStringExtra(FileSyncService
.ACCOUNT_NAME
);
630 Log
.d("FileDisplay", "sync of account " + account_name
631 + " is in_progress: " + inProgress
);
633 if (account_name
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
)) {
635 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
637 boolean fillBlankRoot
= false
;
638 if (mCurrentDir
== null
) {
639 mCurrentDir
= mStorageManager
.getFileByPath("/");
640 fillBlankRoot
= (mCurrentDir
!= null
);
643 if (synchFolderRemotePath
!= null
&& mCurrentDir
!= null
&& (mCurrentDir
.getRemotePath().equals(synchFolderRemotePath
) || fillBlankRoot
) ) {
644 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager()
645 .findFragmentById(R
.id
.fileList
);
646 mCurrentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
647 if (fileListFragment
!= null
) {
648 fileListFragment
.listDirectory(mCurrentDir
);
652 setSupportProgressBarIndeterminateVisibility(inProgress
);
659 private class UploadFinishReceiver
extends BroadcastReceiver
{
661 * Once the file upload has finished -> update view
662 * @author David A. Velasco
663 * {@link BroadcastReceiver} to enable upload feedback in UI
666 public void onReceive(Context context
, Intent intent
) {
667 long parentDirId
= intent
.getLongExtra(FileUploader
.EXTRA_PARENT_DIR_ID
, -1);
668 OCFile parentDir
= mStorageManager
.getFileById(parentDirId
);
670 if (parentDir
!= null
&& (
671 (mCurrentDir
== null
&& parentDir
.getFileName().equals("/")) ||
672 parentDir
.equals(mCurrentDir
))
674 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
675 if (fileListFragment
!= null
) {
676 fileListFragment
.listDirectory();
685 public void onClick(View v
) {
686 if (v
.getId() == R
.id
.setup_account
) {
687 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
688 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
689 startActivity(intent
);
690 mForcedLoginToCreateFirstAccount
= true
;
702 public DataStorageManager
getStorageManager() {
703 return mStorageManager
;
711 public void onDirectoryClick(OCFile directory
) {
712 pushDirname(directory
);
713 ActionBar actionBar
= getSupportActionBar();
714 actionBar
.setDisplayHomeAsUpEnabled(true
);
717 // Resets the FileDetailsFragment on Tablets so that it always displays
718 FileDetailFragment fileDetails
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
719 if (fileDetails
!= null
) {
720 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
721 transaction
.remove(fileDetails
);
722 transaction
.add(R
.id
.file_details_container
, new FileDetailFragment(null
, null
));
723 transaction
.commit();
733 public void onFileClick(OCFile file
) {
735 // If we are on a large device -> update fragment
737 // buttons in the details view are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'
738 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
739 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
740 transaction
.setTransition(FragmentTransaction
.TRANSIT_FRAGMENT_FADE
);
741 transaction
.commit();
743 } else { // small or medium screen device -> new Activity
744 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
745 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
746 showDetailsIntent
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
747 startActivity(showDetailsIntent
);
752 * Operations in this method should be preferably performed in onCreate to have a lighter onResume method.
754 * But we need to delay them to onResume for the first start of the application, when no account exists and the login activity must be shown; and
755 * put instead the ugly view that shows the 'Setup' button to restart the login activity.
757 * In other way, if the users cancels or presses BACK in the login page that first time (users can be cruel sometimes) would show a blank view (the
758 * FragmentList view empty).
760 * This is temporal, until we found out how to get a result in this activity after launching the ADD_ACCOUNT Intent with startActivityForResult (not trivial)
762 private void initDelayedTilAccountAvailabe() {
763 setContentView(mLayoutView
);
764 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
765 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
766 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
767 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
768 transaction
.commit();