Merge pull request #955 from owncloud/thumbnailOOM
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / UploadSourceDialogFragment.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20 package com.owncloud.android.ui.dialog;
21
22 import android.accounts.Account;
23 import android.app.AlertDialog;
24 import android.app.Dialog;
25 import android.content.DialogInterface;
26 import android.content.Intent;
27 import android.os.Build;
28 import android.os.Bundle;
29
30 import com.actionbarsherlock.app.SherlockDialogFragment;
31 import com.owncloud.android.R;
32 import com.owncloud.android.lib.common.utils.Log_OC;
33 import com.owncloud.android.ui.activity.FileActivity;
34 import com.owncloud.android.ui.activity.UploadFilesActivity;
35
36
37 /**
38 * Dialog showing two options to allow the user upload files from the filesystem or from other apps.
39 *
40 * Assumes that its parent activity extends {@link FileActivity}
41 */
42 public class UploadSourceDialogFragment extends SherlockDialogFragment {
43
44 private final static String TAG = UploadSourceDialogFragment.class.getSimpleName();
45 private final static String ARG_ACCOUNT = UploadSourceDialogFragment.class.getSimpleName() + ".ARG_ACCOUNT";
46
47 public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
48 public static final int ACTION_SELECT_MULTIPLE_FILES = 2;
49
50 public static UploadSourceDialogFragment newInstance(Account account) {
51 UploadSourceDialogFragment f = new UploadSourceDialogFragment();
52 Bundle args = new Bundle();
53 args.putParcelable(ARG_ACCOUNT, account);
54 f.setArguments(args);
55 return f;
56 }
57
58 public UploadSourceDialogFragment() {
59 super();
60 Log_OC.v(TAG, "constructor");
61 }
62
63 @Override
64 public Dialog onCreateDialog(Bundle savedInstanceState) {
65
66 String[] allTheItems = {
67 getString(R.string.actionbar_upload_files),
68 getString(R.string.actionbar_upload_from_apps)
69 };
70
71 AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
72 builder.setTitle(R.string.actionbar_upload);
73 builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
74 public void onClick(DialogInterface dialog, int item) {
75 if (item == 0) {
76 Intent action = new Intent(getSherlockActivity(), UploadFilesActivity.class);
77 action.putExtra(
78 UploadFilesActivity.EXTRA_ACCOUNT,
79 ((FileActivity)getSherlockActivity()).getAccount()
80 );
81 //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); // this flow seems broken;
82 // Actionbarsherlock, maybe?
83 getSherlockActivity().startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
84
85 } else if (item == 1) {
86 Intent action = new Intent(Intent.ACTION_GET_CONTENT);
87 action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
88 //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
89 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
90 action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
91 }
92 //startActivityForResult( // this flow seems broken;
93 // Actionbarsherlock, maybe?
94 getSherlockActivity().startActivityForResult(
95 Intent.createChooser(action, getString(R.string.upload_chooser_title)),
96 ACTION_SELECT_CONTENT_FROM_APPS
97 );
98 }
99 }
100 });
101 return builder.create();
102 }
103
104 }