2 * ownCloud Android client application
4 * Copyright (C) 2015 ownCloud Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.dialog
;
22 import android
.app
.Dialog
;
23 import android
.app
.ProgressDialog
;
24 import android
.content
.DialogInterface
;
25 import android
.content
.DialogInterface
.OnKeyListener
;
26 import android
.os
.Bundle
;
27 import android
.support
.v4
.app
.DialogFragment
;
28 import android
.view
.KeyEvent
;
30 import com
.owncloud
.android
.R
;
33 public class IndeterminateProgressDialog
extends DialogFragment
{
35 private static final String ARG_MESSAGE_ID
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_MESSAGE_ID";
36 private static final String ARG_CANCELABLE
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_CANCELABLE";
40 * Public factory method to get dialog instances.
42 * @param messageId Resource id for a message to show in the dialog.
43 * @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
44 * @return New dialog instance, ready to show.
46 public static IndeterminateProgressDialog
newInstance(int messageId
, boolean cancelable
) {
47 IndeterminateProgressDialog fragment
= new IndeterminateProgressDialog();
48 Bundle args
= new Bundle();
49 args
.putInt(ARG_MESSAGE_ID
, messageId
);
50 args
.putBoolean(ARG_CANCELABLE
, cancelable
);
51 fragment
.setArguments(args
);
60 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
61 /// create indeterminate progress dialog
62 final ProgressDialog dialog
= new ProgressDialog(getActivity());
63 dialog
.setIndeterminate(true
);
66 int messageId
= getArguments().getInt(ARG_MESSAGE_ID
, R
.string
.placeholder_sentence
);
67 dialog
.setMessage(getString(messageId
));
69 /// set cancellation behavior
70 boolean cancelable
= getArguments().getBoolean(ARG_CANCELABLE
, false
);
72 dialog
.setCancelable(false
);
73 // disable the back button
74 OnKeyListener keyListener
= new OnKeyListener() {
76 public boolean onKey(DialogInterface dialog
, int keyCode
,
79 if( keyCode
== KeyEvent
.KEYCODE_BACK
){
86 dialog
.setOnKeyListener(keyListener
);