- @Override
- protected Dialog onCreateDialog(int id) {
- Dialog dialog = null;
- AlertDialog.Builder builder;
- switch (id) {
- case DIALOG_SHORT_WAIT: {
- ProgressDialog working_dialog = new ProgressDialog(this);
- working_dialog.setMessage(getResources().getString(
- R.string.wait_a_moment));
- working_dialog.setIndeterminate(true);
- working_dialog.setCancelable(false);
- dialog = working_dialog;
- break;
- }
- case DIALOG_CHOOSE_UPLOAD_SOURCE: {
-
-
- String[] allTheItems = { getString(R.string.actionbar_upload_files),
- getString(R.string.actionbar_upload_from_apps) };
-
- builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.actionbar_upload);
- builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int item) {
- if (item == 0) {
- // if (!mDualPane) {
- Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
- action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, FileDisplayActivity.this.getAccount());
- startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
- // } else {
- // TODO create and handle new fragment
- // LocalFileListFragment
- // }
- } else if (item == 1) {
- Intent action = new Intent(Intent.ACTION_GET_CONTENT);
- action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
- //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
- }
- startActivityForResult(Intent.createChooser(action, getString(R.string.upload_chooser_title)),
- ACTION_SELECT_CONTENT_FROM_APPS);
- }
- }
- });
- dialog = builder.create();
- break;
- }
- case DIALOG_CERT_NOT_SAVED: {
- builder = new AlertDialog.Builder(this);
- builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
- builder.setCancelable(false);
- builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- };
- });
- dialog = builder.create();
- break;
- }
- default:
- dialog = null;
- }
-
- return dialog;
- }
-
- /**
- * Translates a content URI of an content to a physical path on the disk
- *
- * @param uri The URI to resolve
- * @return The path to the content or null if it could not be found
- */
- public String getPath(Uri uri) {
- final boolean isKitKatOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
-
- // DocumentProvider
- if (isKitKatOrLater && DocumentsContract.isDocumentUri(getApplicationContext(), uri)) {
- // ExternalStorageProvider
- if (UriUtils.isExternalStorageDocument(uri)) {
- final String docId = DocumentsContract.getDocumentId(uri);
- final String[] split = docId.split(":");
- final String type = split[0];
-
- if ("primary".equalsIgnoreCase(type)) {
- return Environment.getExternalStorageDirectory() + "/" + split[1];
- }
- }
- // DownloadsProvider
- else if (UriUtils.isDownloadsDocument(uri)) {
-
- final String id = DocumentsContract.getDocumentId(uri);
- final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
- Long.valueOf(id));
-
- return UriUtils.getDataColumn(getApplicationContext(), contentUri, null, null);
- }
- // MediaProvider
- else if (UriUtils.isMediaDocument(uri)) {
- final String docId = DocumentsContract.getDocumentId(uri);
- final String[] split = docId.split(":");
- final String type = split[0];
-
- Uri contentUri = null;
- if ("image".equals(type)) {
- contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
- } else if ("video".equals(type)) {
- contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
- } else if ("audio".equals(type)) {
- contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
- }
-
- final String selection = "_id=?";
- final String[] selectionArgs = new String[] { split[1] };
-
- return UriUtils.getDataColumn(getApplicationContext(), contentUri, selection, selectionArgs);
- }
- // Documents providers returned as content://...
- else if (UriUtils.isContentDocument(uri)) {
- return uri.toString();
- }
- }
- // MediaStore (and general)
- else if ("content".equalsIgnoreCase(uri.getScheme())) {
-
- // Return the remote address
- if (UriUtils.isGooglePhotosUri(uri))
- return uri.getLastPathSegment();
-
- return UriUtils.getDataColumn(getApplicationContext(), uri, null, null);
- }
- // File
- else if ("file".equalsIgnoreCase(uri.getScheme())) {
- return uri.getPath();
- }
- return null;
- }
-
- /**
- * Pushes a directory to the drop down list
- * @param directory to push
- * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false.
- */
- public void pushDirname(OCFile directory) {
- if(!directory.isFolder()){
- throw new IllegalArgumentException("Only directories may be pushed!");
- }
- mDirectories.insert(directory.getFileName(), 0);
- setFile(directory);
- }
-
- /**
- * Pops a directory name from the drop down list
- * @return True, unless the stack is empty
- */
- public boolean popDirname() {
- mDirectories.remove(mDirectories.getItem(0));
- return !mDirectories.isEmpty();
- }
-
- // Custom array adapter to override text colors
- private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
-
- public CustomArrayAdapter(FileDisplayActivity ctx, int view) {
- super(ctx, view);
- }
-
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = super.getView(position, convertView, parent);
-
- ((TextView) v).setTextColor(getResources().getColorStateList(
- android.R.color.white));
-
- fixRoot((TextView) v );
- return v;
- }
-
- public View getDropDownView(int position, View convertView,
- ViewGroup parent) {
- View v = super.getDropDownView(position, convertView, parent);
-
- ((TextView) v).setTextColor(getResources().getColorStateList(
- android.R.color.white));
-
- fixRoot((TextView) v );
- return v;
- }
-
- private void fixRoot(TextView v) {
- if (v.getText().equals(OCFile.PATH_SEPARATOR)) {
- v.setText(R.string.default_display_name_for_root_folder);
- }
- }
-
- }
-