2 * ownCloud Android client application
4 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
20 package com
.owncloud
.android
.ui
.dialog
;
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 import android
.widget
.ProgressBar
;
31 import com
.owncloud
.android
.R
;
34 public class IndeterminateProgressDialog
extends DialogFragment
{
36 private static final String ARG_MESSAGE_ID
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_MESSAGE_ID";
37 private static final String ARG_CANCELABLE
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_CANCELABLE";
41 * Public factory method to get dialog instances.
43 * @param messageId Resource id for a message to show in the dialog.
44 * @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
45 * @return New dialog instance, ready to show.
47 public static IndeterminateProgressDialog
newInstance(int messageId
, boolean cancelable
) {
48 IndeterminateProgressDialog fragment
= new IndeterminateProgressDialog();
49 fragment
.setStyle(DialogFragment
.STYLE_NO_FRAME
, R
.style
.ownCloud_AlertDialog
);
50 Bundle args
= new Bundle();
51 args
.putInt(ARG_MESSAGE_ID
, messageId
);
52 args
.putBoolean(ARG_CANCELABLE
, cancelable
);
53 fragment
.setArguments(args
);
62 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
63 /// create indeterminate progress dialog
64 final ProgressDialog progressDialog
= new ProgressDialog(getActivity(), R
.style
.ProgressDialogTheme
);
65 progressDialog
.setIndeterminate(true
);
66 progressDialog
.setOnShowListener(new DialogInterface
.OnShowListener() {
68 public void onShow(DialogInterface dialog
) {
69 ProgressBar v
= (ProgressBar
) progressDialog
.findViewById(android
.R
.id
.progress
);
70 v
.getIndeterminateDrawable().setColorFilter(getResources().getColor(R
.color
.color_accent
),
71 android
.graphics
.PorterDuff
.Mode
.MULTIPLY
);
77 int messageId
= getArguments().getInt(ARG_MESSAGE_ID
, R
.string
.placeholder_sentence
);
78 progressDialog
.setMessage(getString(messageId
));
80 /// set cancellation behavior
81 boolean cancelable
= getArguments().getBoolean(ARG_CANCELABLE
, false
);
83 progressDialog
.setCancelable(false
);
84 // disable the back button
85 OnKeyListener keyListener
= new OnKeyListener() {
87 public boolean onKey(DialogInterface dialog
, int keyCode
,
90 if( keyCode
== KeyEvent
.KEYCODE_BACK
) {
97 progressDialog
.setOnKeyListener(keyListener
);
100 return progressDialog
;