reverted back to light colored login
[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 fragment.setStyle(DialogFragment.STYLE_NO_FRAME, R.style.ownCloud_AlertDialog);
49 Bundle args = new Bundle();
50 args.putInt(ARG_MESSAGE_ID, messageId);
51 args.putBoolean(ARG_CANCELABLE, cancelable);
52 fragment.setArguments(args);
53 return fragment;
54 }
55
56
57 /**
58 * {@inheritDoc}
59 */
60 @Override
61 public Dialog onCreateDialog(Bundle savedInstanceState) {
62 /// create indeterminate progress dialog
63 final ProgressDialog dialog = new ProgressDialog(getActivity(), R.style.ProgressDialogTheme);
64 dialog.setIndeterminate(true);
65
66 /// set message
67 int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
68 dialog.setMessage(getString(messageId));
69
70 /// set cancellation behavior
71 boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
72 if (!cancelable) {
73 dialog.setCancelable(false);
74 // disable the back button
75 OnKeyListener keyListener = new OnKeyListener() {
76 @Override
77 public boolean onKey(DialogInterface dialog, int keyCode,
78 KeyEvent event) {
79
80 if( keyCode == KeyEvent.KEYCODE_BACK){
81 return true;
82 }
83 return false;
84 }
85
86 };
87 dialog.setOnKeyListener(keyListener);
88 }
89
90 return dialog;
91 }
92
93 }
94
95