Merge branch 'master' of https://github.com/owncloud/android into material_toolbar
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / LoadingDialog.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 package com.owncloud.android.ui.dialog;
20
21 import com.owncloud.android.R;
22
23 import android.app.Dialog;
24 import android.graphics.PorterDuff;
25 import android.os.Bundle;
26 import android.support.v4.app.DialogFragment;
27 import android.view.LayoutInflater;
28 import android.view.View;
29 import android.view.ViewGroup;
30 import android.view.Window;
31 import android.widget.ProgressBar;
32 import android.widget.TextView;
33
34 public class LoadingDialog extends DialogFragment {
35
36 private String mMessage;
37
38 public LoadingDialog() {
39 super();
40 }
41
42 @Override
43 public void onCreate(Bundle savedInstanceState) {
44 super.onCreate(savedInstanceState);
45 setRetainInstance(true);
46 setCancelable(false);
47 }
48
49 public LoadingDialog(String message) {
50 this.mMessage = message;
51 }
52
53 @Override
54 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
55 // Create a view by inflating desired layout
56 View v = inflater.inflate(R.layout.loading_dialog, container, false);
57
58 // set value
59 TextView tv = (TextView) v.findViewById(R.id.loadingText);
60 tv.setText(mMessage);
61
62 // set progress wheel color
63 ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.loadingBar);
64 progressBar.getIndeterminateDrawable().setColorFilter(
65 getResources().getColor(R.color.color_accent), PorterDuff.Mode.SRC_IN);
66
67 return v;
68 }
69
70 @Override
71 public Dialog onCreateDialog(Bundle savedInstanceState) {
72 Dialog dialog = super.onCreateDialog(savedInstanceState);
73 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
74 return dialog;
75 }
76
77 @Override
78 public void onDestroyView() {
79 if (getDialog() != null && getRetainInstance())
80 getDialog().setDismissMessage(null);
81 super.onDestroyView();
82 }
83 }