Added MediaController user interface to handle audio files in the MediaService
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / IndeterminateProgressDialog.java
1 package com.owncloud.android.ui.dialog;
2
3 import android.app.Dialog;
4 import android.app.ProgressDialog;
5 import android.content.DialogInterface;
6 import android.content.DialogInterface.OnKeyListener;
7 import android.os.Bundle;
8 import android.view.KeyEvent;
9
10 import com.actionbarsherlock.app.SherlockDialogFragment;
11 import com.owncloud.android.R;
12
13 public class IndeterminateProgressDialog extends SherlockDialogFragment {
14
15 private static final String ARG_MESSAGE_ID = IndeterminateProgressDialog.class.getCanonicalName() + ".ARG_MESSAGE_ID";
16 private static final String ARG_CANCELABLE = IndeterminateProgressDialog.class.getCanonicalName() + ".ARG_CANCELABLE";
17
18
19 /**
20 * Public factory method to get dialog instances.
21 *
22 * @param messageId Resource id for a message to show in the dialog.
23 * @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
24 * @return New dialog instance, ready to show.
25 */
26 public static IndeterminateProgressDialog newInstance(int messageId, boolean cancelable) {
27 IndeterminateProgressDialog fragment = new IndeterminateProgressDialog();
28 Bundle args = new Bundle();
29 args.putInt(ARG_MESSAGE_ID, messageId);
30 args.putBoolean(ARG_CANCELABLE, cancelable);
31 fragment.setArguments(args);
32 return fragment;
33 }
34
35
36 /**
37 * {@inheritDoc}
38 */
39 @Override
40 public Dialog onCreateDialog(Bundle savedInstanceState) {
41 /// create indeterminate progress dialog
42 final ProgressDialog dialog = new ProgressDialog(getActivity());
43 dialog.setIndeterminate(true);
44
45 /// set message
46 int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.text_placeholder);
47 dialog.setMessage(getString(messageId));
48
49 /// set cancellation behavior
50 boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
51 if (!cancelable) {
52 dialog.setCancelable(false);
53 // disable the back button
54 OnKeyListener keyListener = new OnKeyListener() {
55 @Override
56 public boolean onKey(DialogInterface dialog, int keyCode,
57 KeyEvent event) {
58
59 if( keyCode == KeyEvent.KEYCODE_BACK){
60 return true;
61 }
62 return false;
63 }
64
65 };
66 dialog.setOnKeyListener(keyListener);
67 }
68
69 return dialog;
70 }
71
72 }
73
74