1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.dialog
;
21 import android
.app
.Dialog
;
22 import android
.app
.ProgressDialog
;
23 import android
.content
.DialogInterface
;
24 import android
.content
.DialogInterface
.OnKeyListener
;
25 import android
.os
.Bundle
;
26 import android
.view
.KeyEvent
;
28 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
29 import com
.owncloud
.android
.R
;
31 public class IndeterminateProgressDialog
extends SherlockDialogFragment
{
33 private static final String ARG_MESSAGE_ID
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_MESSAGE_ID";
34 private static final String ARG_CANCELABLE
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_CANCELABLE";
38 * Public factory method to get dialog instances.
40 * @param messageId Resource id for a message to show in the dialog.
41 * @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
42 * @return New dialog instance, ready to show.
44 public static IndeterminateProgressDialog
newInstance(int messageId
, boolean cancelable
) {
45 IndeterminateProgressDialog fragment
= new IndeterminateProgressDialog();
46 Bundle args
= new Bundle();
47 args
.putInt(ARG_MESSAGE_ID
, messageId
);
48 args
.putBoolean(ARG_CANCELABLE
, cancelable
);
49 fragment
.setArguments(args
);
58 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
59 /// create indeterminate progress dialog
60 final ProgressDialog dialog
= new ProgressDialog(getActivity());
61 dialog
.setIndeterminate(true
);
64 int messageId
= getArguments().getInt(ARG_MESSAGE_ID
, R
.string
.placeholder_sentence
);
65 dialog
.setMessage(getString(messageId
));
67 /// set cancellation behavior
68 boolean cancelable
= getArguments().getBoolean(ARG_CANCELABLE
, false
);
70 dialog
.setCancelable(false
);
71 // disable the back button
72 OnKeyListener keyListener
= new OnKeyListener() {
74 public boolean onKey(DialogInterface dialog
, int keyCode
,
77 if( keyCode
== KeyEvent
.KEYCODE_BACK
){
84 dialog
.setOnKeyListener(keyListener
);