2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
20 package com
.owncloud
.android
.ui
.dialog
;
22 import android
.accounts
.Account
;
23 import android
.support
.v7
.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 import android
.support
.v4
.app
.DialogFragment
;
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
;
38 * Dialog showing two options to allow the user upload files from the filesystem or from other apps.
40 * Assumes that its parent activity extends {@link FileActivity}
42 public class UploadSourceDialogFragment
extends DialogFragment
{
44 private final static String TAG
= UploadSourceDialogFragment
.class.getSimpleName();
45 private final static String ARG_ACCOUNT
= UploadSourceDialogFragment
.class.getSimpleName() +
48 public static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
49 public static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
51 public static UploadSourceDialogFragment
newInstance(Account account
) {
52 UploadSourceDialogFragment f
= new UploadSourceDialogFragment();
53 Bundle args
= new Bundle();
54 args
.putParcelable(ARG_ACCOUNT
, account
);
59 public UploadSourceDialogFragment() {
61 Log_OC
.v(TAG
, "constructor");
65 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
67 String
[] allTheItems
= {
68 getString(R
.string
.actionbar_upload_files
),
69 getString(R
.string
.actionbar_upload_from_apps
)
72 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity());
73 builder
.setTitle(R
.string
.actionbar_upload
);
74 builder
.setItems(allTheItems
, new DialogInterface
.OnClickListener() {
75 public void onClick(DialogInterface dialog
, int item
) {
77 Intent action
= new Intent(getActivity(), UploadFilesActivity
.class);
79 UploadFilesActivity
.EXTRA_ACCOUNT
,
80 ((FileActivity
)getActivity()).getAccount()
82 //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
83 // this flow seems broken;
84 // Actionbarsherlock, maybe?
85 getActivity().startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
87 } else if (item
== 1) {
88 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
89 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
90 //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
91 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.JELLY_BEAN_MR2
) {
92 action
.putExtra(Intent
.EXTRA_ALLOW_MULTIPLE
, true
);
94 //startActivityForResult( // this flow seems broken;
95 // Actionbarsherlock, maybe?
96 getActivity().startActivityForResult(
97 Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
98 ACTION_SELECT_CONTENT_FROM_APPS
103 return builder
.create();