Remove actionbarsherlock , replace it with Android Support Library (v7)
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / IndeterminateProgressDialog.java
1 /**
2 * ownCloud Android client application
3 *
4 * Copyright (C) 2015 ownCloud Inc.
5 *
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.
9 *
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.
14 *
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/>.
17 *
18 */
19
20 package com.owncloud.android.ui.dialog;
21
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;
29
30 import com.owncloud.android.R;
31
32
33 public class IndeterminateProgressDialog extends DialogFragment {
34
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";
37
38
39 /**
40 * Public factory method to get dialog instances.
41 *
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.
45 */
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);
52 return fragment;
53 }
54
55
56 /**
57 * {@inheritDoc}
58 */
59 @Override
60 public Dialog onCreateDialog(Bundle savedInstanceState) {
61 /// create indeterminate progress dialog
62 final ProgressDialog dialog = new ProgressDialog(getActivity());
63 dialog.setIndeterminate(true);
64
65 /// set message
66 int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
67 dialog.setMessage(getString(messageId));
68
69 /// set cancellation behavior
70 boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
71 if (!cancelable) {
72 dialog.setCancelable(false);
73 // disable the back button
74 OnKeyListener keyListener = new OnKeyListener() {
75 @Override
76 public boolean onKey(DialogInterface dialog, int keyCode,
77 KeyEvent event) {
78
79 if( keyCode == KeyEvent.KEYCODE_BACK){
80 return true;
81 }
82 return false;
83 }
84
85 };
86 dialog.setOnKeyListener(keyListener);
87 }
88
89 return dialog;
90 }
91
92 }
93
94