[tx-robot] updated from transifex
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / IndeterminateProgressDialog.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.ui.dialog;
19
20 import android.app.Dialog;
21 import android.app.ProgressDialog;
22 import android.content.DialogInterface;
23 import android.content.DialogInterface.OnKeyListener;
24 import android.os.Bundle;
25 import android.view.KeyEvent;
26
27 import com.actionbarsherlock.app.SherlockDialogFragment;
28 import com.owncloud.android.R;
29
30
31 public class IndeterminateProgressDialog extends SherlockDialogFragment {
32
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";
35
36
37 /**
38 * Public factory method to get dialog instances.
39 *
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.
43 */
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);
50 return fragment;
51 }
52
53
54 /**
55 * {@inheritDoc}
56 */
57 @Override
58 public Dialog onCreateDialog(Bundle savedInstanceState) {
59 /// create indeterminate progress dialog
60 final ProgressDialog dialog = new ProgressDialog(getActivity());
61 dialog.setIndeterminate(true);
62
63 /// set message
64 int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
65 dialog.setMessage(getString(messageId));
66
67 /// set cancellation behavior
68 boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
69 if (!cancelable) {
70 dialog.setCancelable(false);
71 // disable the back button
72 OnKeyListener keyListener = new OnKeyListener() {
73 @Override
74 public boolean onKey(DialogInterface dialog, int keyCode,
75 KeyEvent event) {
76
77 if( keyCode == KeyEvent.KEYCODE_BACK){
78 return true;
79 }
80 return false;
81 }
82
83 };
84 dialog.setOnKeyListener(keyListener);
85 }
86
87 return dialog;
88 }
89
90 }
91
92