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
);
115 Thread
.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
117 if(savedInstanceState
!= null
) {
118 mDirs
= savedInstanceState
.getStringArray(KEY_DIR_ARRAY
);
119 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
120 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
122 for (String s
: mDirs
)
123 mDirectories
.insert(s
, 0);
124 mCurrentDir
= savedInstanceState
.getParcelable(FileDetailFragment
.EXTRA_FILE
);
127 mLayoutView
= getLayoutInflater().inflate(R
.layout
.files
, null
); // always inflate this at onCreate() ; just once!
129 if (AccountUtils
.accountsAreSetup(this)) {
131 initDelayedTilAccountAvailabe();
133 // PIN CODE request ; best location is to decide, let's try this first
134 //if (savedInstanceState == null) {
135 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
142 setContentView(R
.layout
.no_account_available
);
143 getSupportActionBar().setNavigationMode(ActionBar
.DISPLAY_SHOW_TITLE
);
144 findViewById(R
.id
.setup_account
).setOnClickListener(this);
146 setSupportProgressBarIndeterminateVisibility(false
);
148 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
149 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
150 startActivity(intent
); // although the code is here, the activity won't be created until this.onStart() and this.onResume() are finished;
151 mForcedLoginToCreateFirstAccount
= true
;
154 Log
.i(getClass().toString(), "onCreate() end");
158 public boolean onCreateOptionsMenu(Menu menu
) {
159 MenuInflater inflater
= getSherlock().getMenuInflater();
160 inflater
.inflate(R
.menu
.menu
, menu
);
165 public boolean onOptionsItemSelected(MenuItem item
) {
166 boolean retval
= true
;
167 switch (item
.getItemId()) {
168 case R
.id
.createDirectoryItem
: {
169 showDialog(DIALOG_CREATE_DIR
);
172 case R
.id
.startSync
: {
173 ContentResolver
.cancelSync(null
, "org.owncloud"); // cancel the current synchronizations of any ownCloud account
174 Bundle bundle
= new Bundle();
175 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
176 ContentResolver
.requestSync(
177 AccountUtils
.getCurrentOwnCloudAccount(this),
178 "org.owncloud", bundle
);
181 case R
.id
.action_upload
: {
182 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
183 action
= action
.setType("*/*")
184 .addCategory(Intent
.CATEGORY_OPENABLE
);
185 startActivityForResult(
186 Intent
.createChooser(action
, "Upload file from..."),
190 case R
.id
.action_settings
: {
191 Intent settingsIntent
= new Intent(this, Preferences
.class);
192 startActivity(settingsIntent
);
195 case R
.id
.about_app
: {
196 showDialog(DIALOG_ABOUT_APP
);
199 case android
.R
.id
.home
: {
200 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
212 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
213 int i
= itemPosition
;
221 * Called, when the user selected something for uploading
223 public void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
224 if (requestCode
== ACTION_SELECT_FILE
) {
225 if (resultCode
== RESULT_OK
) {
226 Uri selectedImageUri
= data
.getData();
228 String filemanagerstring
= selectedImageUri
.getPath();
229 String selectedImagePath
= getPath(selectedImageUri
);
232 if (selectedImagePath
!= null
)
233 filepath
= selectedImagePath
;
235 filepath
= filemanagerstring
;
237 if (filepath
== null
) {
238 Log
.e("FileDisplay", "Couldnt resolve path to file");
242 Intent i
= new Intent(this, FileUploader
.class);
243 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
244 AccountUtils
.getCurrentOwnCloudAccount(this));
245 String remotepath
= new String();
246 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
247 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
249 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
250 remotepath
+= OCFile
.PATH_SEPARATOR
;
251 remotepath
+= new File(filepath
).getName();
253 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
254 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
255 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
259 }/* dvelasco: WIP - not working as expected ... yet :)
260 else if (requestCode == ACTION_CREATE_FIRST_ACCOUNT) {
261 if (resultCode != RESULT_OK) {
262 finish(); // the user cancelled the AuthenticatorActivity
268 public void onBackPressed() {
269 if (mDirectories
== null
|| mDirectories
.getCount() <= 1) {
274 mFileList
.onNavigateUp();
275 mCurrentDir
= mFileList
.getCurrentFile();
277 if(mCurrentDir
.getParentId() == 0){
278 ActionBar actionBar
= getSupportActionBar();
279 actionBar
.setDisplayHomeAsUpEnabled(false
);
284 protected void onSaveInstanceState(Bundle outState
) {
285 // responsability of restore is prefered in onCreate() before than in onRestoreInstanceState when there are Fragments involved
286 Log
.i(getClass().toString(), "onSaveInstanceState() start");
287 super.onSaveInstanceState(outState
);
288 if(mDirectories
!= null
&& mDirectories
.getCount() != 0){
289 mDirs
= new String
[mDirectories
.getCount()-1];
290 for (int j
= mDirectories
.getCount() - 2, i
= 0; j
>= 0; --j
, ++i
) {
291 mDirs
[i
] = mDirectories
.getItem(j
);
294 outState
.putStringArray(KEY_DIR_ARRAY
, mDirs
);
295 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
296 Log
.i(getClass().toString(), "onSaveInstanceState() end");
300 protected void onResume() {
301 Log
.i(getClass().toString(), "onResume() start");
304 if (AccountUtils
.accountsAreSetup(this)) {
305 // at least an account exist: normal operation
307 // set the layout only if it couldn't be set in onCreate
308 if (mForcedLoginToCreateFirstAccount
) {
309 initDelayedTilAccountAvailabe();
310 mForcedLoginToCreateFirstAccount
= false
;
313 // Listen for sync messages
314 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
315 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
316 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
318 // Listen for upload messages
319 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
320 mUploadFinishReceiver
= new UploadFinishReceiver();
321 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
323 // Storage manager initialization
324 mStorageManager
= new FileDataStorageManager(
325 AccountUtils
.getCurrentOwnCloudAccount(this),
326 getContentResolver());
328 // File list fragments
329 mFileList
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
332 // Figure out what directory to list.
333 // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)
334 if(getIntent().hasExtra(FileDetailFragment
.EXTRA_FILE
)){
335 mCurrentDir
= (OCFile
) getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
336 if(mCurrentDir
!= null
&& !mCurrentDir
.isDirectory()){
337 mCurrentDir
= mStorageManager
.getFileById(mCurrentDir
.getParentId());
340 // Clear intent extra, so rotating the screen will not return us to this directory
341 getIntent().removeExtra(FileDetailFragment
.EXTRA_FILE
);
344 if (mCurrentDir
== null
)
345 mCurrentDir
= mStorageManager
.getFileByPath("/");
347 // Drop-Down navigation and file list restore
348 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
351 // Given the case we have a file to display:
352 if(mCurrentDir
!= null
){
353 ArrayList
<OCFile
> files
= new ArrayList
<OCFile
>();
354 OCFile currFile
= mCurrentDir
;
355 while(currFile
!= null
){
357 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
361 mDirs
= new String
[files
.size()];
362 for(int i
= files
.size() - 1; i
>= 0; i
--){
363 mDirs
[i
] = files
.get(i
).getFileName();
368 for (String s
: mDirs
)
371 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
375 ActionBar action_bar
= getSupportActionBar();
376 action_bar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
377 action_bar
.setDisplayShowTitleEnabled(false
);
378 action_bar
.setListNavigationCallbacks(mDirectories
, this);
379 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
380 action_bar
.setDisplayHomeAsUpEnabled(true
);
382 action_bar
.setDisplayHomeAsUpEnabled(false
);
386 mFileList
.listDirectory(mCurrentDir
);
388 Log
.i(getClass().toString(), "onResume() end");
392 protected void onPause() {
393 Log
.i(getClass().toString(), "onPause() start");
395 if (mSyncBroadcastReceiver
!= null
) {
396 unregisterReceiver(mSyncBroadcastReceiver
);
397 mSyncBroadcastReceiver
= null
;
399 if (mUploadFinishReceiver
!= null
) {
400 unregisterReceiver(mUploadFinishReceiver
);
401 mUploadFinishReceiver
= null
;
403 getIntent().putExtra(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
404 Log
.i(getClass().toString(), "onPause() end");
408 protected Dialog
onCreateDialog(int id
) {
409 Dialog dialog
= null
;
410 AlertDialog
.Builder builder
;
412 case DIALOG_SETUP_ACCOUNT
:
413 builder
= new AlertDialog
.Builder(this);
414 builder
.setTitle(R
.string
.main_tit_accsetup
);
415 builder
.setMessage(R
.string
.main_wrn_accsetup
);
416 builder
.setCancelable(false
);
417 builder
.setPositiveButton(android
.R
.string
.ok
, this);
418 builder
.setNegativeButton(android
.R
.string
.cancel
, this);
419 dialog
= builder
.create();
421 case DIALOG_ABOUT_APP
: {
422 builder
= new AlertDialog
.Builder(this);
423 builder
.setTitle("About");
426 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
427 builder
.setMessage("ownCloud android client\n\nversion: " + pkg
.versionName
);
428 builder
.setIcon(android
.R
.drawable
.ic_menu_info_details
);
429 dialog
= builder
.create();
430 } catch (NameNotFoundException e
) {
437 case DIALOG_CREATE_DIR
: {
438 builder
= new Builder(this);
439 final EditText dirNameInput
= new EditText(getBaseContext());
440 final Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
441 builder
.setView(dirNameInput
);
442 builder
.setTitle(R
.string
.uploader_info_dirname
);
443 int typed_color
= getResources().getColor(R
.color
.setup_text_typed
);
444 dirNameInput
.setTextColor(typed_color
);
445 builder
.setPositiveButton(android
.R
.string
.ok
,
446 new OnClickListener() {
447 public void onClick(DialogInterface dialog
, int which
) {
448 String directoryName
= dirNameInput
.getText().toString();
449 if (directoryName
.trim().length() == 0) {
454 // Figure out the path where the dir needs to be created
456 if (mCurrentDir
== null
) {
457 // this is just a patch; we should ensure that mCurrentDir never is null
458 if (!mStorageManager
.fileExists(OCFile
.PATH_SEPARATOR
)) {
459 OCFile file
= new OCFile(OCFile
.PATH_SEPARATOR
);
460 mStorageManager
.saveFile(file
);
462 mCurrentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
464 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
467 path
+= directoryName
+ OCFile
.PATH_SEPARATOR
;
468 Thread thread
= new Thread(new DirectoryCreator(path
, a
));
471 // Save new directory in local database
472 OCFile newDir
= new OCFile(path
);
473 newDir
.setMimetype("DIR");
474 newDir
.setParentId(mCurrentDir
.getFileId());
475 mStorageManager
.saveFile(newDir
);
477 // Display the new folder right away
479 mFileList
.listDirectory(mCurrentDir
);
482 builder
.setNegativeButton(R
.string
.common_cancel
,
483 new OnClickListener() {
484 public void onClick(DialogInterface dialog
, int which
) {
488 dialog
= builder
.create();
500 * Responds to the "There are no ownCloud Accounts setup" dialog
501 * TODO: Dialog is 100% useless -> Remove
504 public void onClick(DialogInterface dialog
, int which
) {
505 // In any case - we won't need it anymore
508 case DialogInterface
.BUTTON_POSITIVE
:
509 Intent intent
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
510 intent
.putExtra("authorities",
511 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
512 startActivity(intent
);
514 case DialogInterface
.BUTTON_NEGATIVE
:
521 * Translates a content URI of an image to a physical path
523 * @param uri The URI to resolve
524 * @return The path to the image or null if it could not be found
526 public String
getPath(Uri uri
) {
527 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
528 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
529 if (cursor
!= null
) {
530 int column_index
= cursor
531 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
532 cursor
.moveToFirst();
533 return cursor
.getString(column_index
);
539 * Pushes a directory to the drop down list
540 * @param directory to push
541 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
543 public void pushDirname(OCFile directory
) {
544 if(!directory
.isDirectory()){
545 throw new IllegalArgumentException("Only directories may be pushed!");
547 mDirectories
.insert(directory
.getFileName(), 0);
548 mCurrentDir
= directory
;
552 * Pops a directory name from the drop down list
553 * @return True, unless the stack is empty
555 public boolean popDirname() {
556 mDirectories
.remove(mDirectories
.getItem(0));
557 return !mDirectories
.isEmpty();
560 private class DirectoryCreator
implements Runnable
{
561 private String mTargetPath
;
562 private Account mAccount
;
563 private AccountManager mAm
;
565 public DirectoryCreator(String targetPath
, Account account
) {
566 mTargetPath
= targetPath
;
568 mAm
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
573 WebdavClient wdc
= new WebdavClient(mAccount
, getApplicationContext());
575 String username
= mAccount
.name
.substring(0,
576 mAccount
.name
.lastIndexOf('@'));
577 String password
= mAm
.getPassword(mAccount
);
579 wdc
.setCredentials(username
, password
);
580 wdc
.allowSelfsignedCertificates();
581 wdc
.createDirectory(mTargetPath
);
586 // Custom array adapter to override text colors
587 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
589 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
593 public View
getView(int position
, View convertView
, ViewGroup parent
) {
594 View v
= super.getView(position
, convertView
, parent
);
596 ((TextView
) v
).setTextColor(getResources().getColorStateList(
597 android
.R
.color
.white
));
601 public View
getDropDownView(int position
, View convertView
,
603 View v
= super.getDropDownView(position
, convertView
, parent
);
605 ((TextView
) v
).setTextColor(getResources().getColorStateList(
606 android
.R
.color
.white
));
613 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
615 * {@link BroadcastReceiver} to enable syncing feedback in UI
618 public void onReceive(Context context
, Intent intent
) {
619 boolean inProgress
= intent
.getBooleanExtra(
620 FileSyncService
.IN_PROGRESS
, false
);
621 String account_name
= intent
622 .getStringExtra(FileSyncService
.ACCOUNT_NAME
);
624 Log
.d("FileDisplay", "sync of account " + account_name
625 + " is in_progress: " + inProgress
);
627 if (account_name
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
)) {
629 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
631 boolean fillBlankRoot
= false
;
632 if (mCurrentDir
== null
) {
633 mCurrentDir
= mStorageManager
.getFileByPath("/");
634 fillBlankRoot
= (mCurrentDir
!= null
);
637 if (synchFolderRemotePath
!= null
&& mCurrentDir
!= null
&& (mCurrentDir
.getRemotePath().equals(synchFolderRemotePath
) || fillBlankRoot
) ) {
638 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager()
639 .findFragmentById(R
.id
.fileList
);
640 mCurrentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
641 if (fileListFragment
!= null
) {
642 fileListFragment
.listDirectory(mCurrentDir
);
646 setSupportProgressBarIndeterminateVisibility(inProgress
);
653 private class UploadFinishReceiver
extends BroadcastReceiver
{
655 * Once the file upload has finished -> update view
656 * @author David A. Velasco
657 * {@link BroadcastReceiver} to enable upload feedback in UI
660 public void onReceive(Context context
, Intent intent
) {
661 long parentDirId
= intent
.getLongExtra(FileUploader
.EXTRA_PARENT_DIR_ID
, -1);
662 OCFile parentDir
= mStorageManager
.getFileById(parentDirId
);
664 if (parentDir
!= null
&& (
665 (mCurrentDir
== null
&& parentDir
.getFileName().equals("/")) ||
666 parentDir
.equals(mCurrentDir
))
668 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
669 if (fileListFragment
!= null
) {
670 fileListFragment
.listDirectory();
679 public void onClick(View v
) {
680 if (v
.getId() == R
.id
.setup_account
) {
681 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
682 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
683 startActivity(intent
);
684 mForcedLoginToCreateFirstAccount
= true
;
696 public DataStorageManager
getStorageManager() {
697 return mStorageManager
;
705 public void onDirectoryClick(OCFile directory
) {
706 pushDirname(directory
);
707 ActionBar actionBar
= getSupportActionBar();
708 actionBar
.setDisplayHomeAsUpEnabled(true
);
711 // Resets the FileDetailsFragment on Tablets so that it always displays
712 FileDetailFragment fileDetails
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
713 if (fileDetails
!= null
) {
714 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
715 transaction
.remove(fileDetails
);
716 transaction
.add(R
.id
.file_details_container
, new FileDetailFragment(null
, null
));
717 transaction
.commit();
727 public void onFileClick(OCFile file
) {
729 // If we are on a large device -> update fragment
731 // 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'
732 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
733 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
734 transaction
.setTransition(FragmentTransaction
.TRANSIT_FRAGMENT_FADE
);
735 transaction
.commit();
737 } else { // small or medium screen device -> new Activity
738 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
739 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
740 showDetailsIntent
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
741 startActivity(showDetailsIntent
);
746 * Operations in this method should be preferably performed in onCreate to have a lighter onResume method.
748 * 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
749 * put instead the ugly view that shows the 'Setup' button to restart the login activity.
751 * 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
752 * FragmentList view empty).
754 * 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)
756 private void initDelayedTilAccountAvailabe() {
757 setContentView(mLayoutView
);
758 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
759 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
760 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
761 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
762 transaction
.commit();
764 setSupportProgressBarIndeterminateVisibility(false
);
769 * Launch an intent to request the PIN code to the user before letting him use the app
771 private void requestPinCode() {
772 boolean pinStart
= false
;
773 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
774 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
776 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
777 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");