LoadingDialog.java 2.6 KB

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