X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/cbf9ca8beac99dc06678d13c5f80804d56445472..153dbb03425d1469bc8b2391f65869fd0a4b789c:/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 3412af81..f9de1ac2 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -48,6 +48,7 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.OnNavigationListener; @@ -111,14 +112,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - setSupportProgressBarIndeterminateVisibility(false); -// Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext())); + Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext())); if(savedInstanceState != null) { mDirs = savedInstanceState.getStringArray(KEY_DIR_ARRAY); mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); - mDirectories.add("/"); + mDirectories.add(OCFile.PATH_SEPARATOR); if (mDirs != null) for (String s : mDirs) mDirectories.insert(s, 0); @@ -131,24 +131,21 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements initDelayedTilAccountAvailabe(); - // PIN CODE request - // best location is to decide; let's try this first - boolean pinStart = false; - SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - pinStart = appPrefs.getBoolean("set_passcode", false); - - if (pinStart) { - Intent i = new Intent(getApplicationContext(), PinCodeActivity.class); - i.putExtra("activity", "splash"); - startActivity(i); + // PIN CODE request ; best location is to decide, let's try this first + //if (savedInstanceState == null) { + if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) { + requestPinCode(); } + } else { setContentView(R.layout.no_account_available); getSupportActionBar().setNavigationMode(ActionBar.DISPLAY_SHOW_TITLE); findViewById(R.id.setup_account).setOnClickListener(this); - + + setSupportProgressBarIndeterminateVisibility(false); + Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE }); startActivity(intent); // although the code is here, the activity won't be created until this.onStart() and this.onResume() are finished; @@ -174,8 +171,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements break; } case R.id.startSync: { - // This could be interesting - //ContentResolver.cancelSync(null, "org.owncloud"); // cancel the current synchronizations of any other ownCloud account + ContentResolver.cancelSync(null, "org.owncloud"); // cancel the current synchronizations of any ownCloud account Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync( @@ -228,20 +224,29 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ACTION_SELECT_FILE) { if (resultCode == RESULT_OK) { - Uri selectedImageUri = data.getData(); - - String filemanagerstring = selectedImageUri.getPath(); - String selectedImagePath = getPath(selectedImageUri); - String filepath; - - if (selectedImagePath != null) - filepath = selectedImagePath; - else - filepath = filemanagerstring; - - if (filepath == null) { - Log.e("FileDisplay", "Couldnt resolve path to file"); - return; + String filepath = null; + try { + Uri selectedImageUri = data.getData(); + + String filemanagerstring = selectedImageUri.getPath(); + String selectedImagePath = getPath(selectedImageUri); + + if (selectedImagePath != null) + filepath = selectedImagePath; + else + filepath = filemanagerstring; + + } catch (Exception e) { + Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e); + e.printStackTrace(); + + } finally { + if (filepath == null) { + Log.e("FileDisplay", "Couldnt resolve path to file"); + Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG); + t.show(); + return; + } } Intent i = new Intent(this, FileUploader.class); @@ -249,12 +254,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements AccountUtils.getCurrentOwnCloudAccount(this)); String remotepath = new String(); for (int j = mDirectories.getCount() - 2; j >= 0; --j) { - remotepath += "/" + mDirectories.getItem(j); + remotepath += OCFile.PATH_SEPARATOR + mDirectories.getItem(j); } - if (!remotepath.endsWith("/")) - remotepath += "/"; + if (!remotepath.endsWith(OCFile.PATH_SEPARATOR)) + remotepath += OCFile.PATH_SEPARATOR; remotepath += new File(filepath).getName(); - remotepath = Uri.encode(remotepath, "/"); i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath); i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath); @@ -374,7 +378,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements for (String s : mDirs) mDirectories.add(s); } else { - mDirectories.add("/"); + mDirectories.add(OCFile.PATH_SEPARATOR); } // Actionbar setup @@ -461,16 +465,16 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements String path; if (mCurrentDir == null) { // this is just a patch; we should ensure that mCurrentDir never is null - if (!mStorageManager.fileExists("/")) { - OCFile file = new OCFile("/"); + if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) { + OCFile file = new OCFile(OCFile.PATH_SEPARATOR); mStorageManager.saveFile(file); } - mCurrentDir = mStorageManager.getFileByPath("/"); + mCurrentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); } path = FileDisplayActivity.this.mCurrentDir.getRemotePath(); // Create directory - path += Uri.encode(directoryName) + "/"; + path += directoryName + OCFile.PATH_SEPARATOR; Thread thread = new Thread(new DirectoryCreator(path, a)); thread.start(); @@ -640,7 +644,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements fillBlankRoot = (mCurrentDir != null); } - if (synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath) || fillBlankRoot) ) { + if ((synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath))) + || fillBlankRoot ) { FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager() .findFragmentById(R.id.fileList); mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath); @@ -767,7 +772,22 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment transaction.commit(); } + setSupportProgressBarIndeterminateVisibility(false); + } + + /** + * Launch an intent to request the PIN code to the user before letting him use the app + */ + private void requestPinCode() { + boolean pinStart = false; + SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + pinStart = appPrefs.getBoolean("set_pincode", false); + if (pinStart) { + Intent i = new Intent(getApplicationContext(), PinCodeActivity.class); + i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity"); + startActivity(i); + } }