1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package com.mapswithme.maps.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapswithme.maps.R;
import java.util.Objects;
public class ProgressDialogFragment extends DialogFragment
{
private static final String ARG_MESSAGE = "title";
private static final String ARG_CANCELABLE = "cancelable";
private static final String ARG_RETAIN_INSTANCE = "retain_instance";
public ProgressDialogFragment()
{
// Do nothing by default.
}
@NonNull
public static ProgressDialogFragment newInstance(@NonNull String message)
{
return newInstance(message, false, true);
}
@NonNull
public static ProgressDialogFragment newInstance(@NonNull String message, boolean cancelable,
boolean retainInstance)
{
ProgressDialogFragment fr = new ProgressDialogFragment();
fr.setArguments(getArgs(message, cancelable, retainInstance));
return fr;
}
private static Bundle getArgs(@NonNull String title, boolean cancelable, boolean retainInstance)
{
Bundle args = new Bundle();
args.putString(ARG_MESSAGE, title);
args.putBoolean(ARG_CANCELABLE, cancelable);
args.putBoolean(ARG_RETAIN_INSTANCE, retainInstance);
return args;
}
protected void setCancelResult()
{
Fragment targetFragment = getTargetFragment();
if (targetFragment != null)
targetFragment.onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, null);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle args = Objects.requireNonNull(getArguments());
setRetainInstance(args.getBoolean(ARG_RETAIN_INSTANCE, true));
setCancelable(args.getBoolean(ARG_CANCELABLE, false));
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.indeterminated_progress_dialog, container, false);
Bundle args = Objects.requireNonNull(getArguments());
TextView messageView = view.findViewById(R.id.message);
messageView.setText(args.getString(ARG_MESSAGE));
return view;
}
@Override
public void onCancel(DialogInterface dialog)
{
setCancelResult();
}
public boolean isShowing()
{
Dialog dialog = getDialog();
return dialog != null && dialog.isShowing();
}
@Override
public void onDestroyView()
{
if (getDialog() != null && getRetainInstance())
getDialog().setDismissMessage(null);
super.onDestroyView();
}
}
|