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
.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
;
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
;
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 SherlockDialogFragment
{
44 private final static String TAG
= UploadSourceDialogFragment
.class.getSimpleName();
45 private final static String ARG_ACCOUNT
= UploadSourceDialogFragment
.class.getSimpleName() + ".ARG_ACCOUNT";
47 public static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
48 public static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
50 public static UploadSourceDialogFragment
newInstance(Account account
) {
51 UploadSourceDialogFragment f
= new UploadSourceDialogFragment();
52 Bundle args
= new Bundle();
53 args
.putParcelable(ARG_ACCOUNT
, account
);
58 public UploadSourceDialogFragment() {
60 Log_OC
.v(TAG
, "constructor");
64 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
66 String
[] allTheItems
= {
67 getString(R
.string
.actionbar_upload_files
),
68 getString(R
.string
.actionbar_upload_from_apps
)
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
) {
76 Intent action
= new Intent(getSherlockActivity(), UploadFilesActivity
.class);
78 UploadFilesActivity
.EXTRA_ACCOUNT
,
79 ((FileActivity
)getSherlockActivity()).getAccount()
81 //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); // this flow seems broken;
82 // Actionbarsherlock, maybe?
83 getSherlockActivity().startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
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
);
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
101 return builder
.create();