123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- package epson.common;
- import android.app.Dialog;
- import android.content.DialogInterface;
- import android.os.Bundle;
- import android.support.annotation.NonNull;
- import android.support.annotation.Nullable;
- import android.support.p000v4.app.DialogFragment;
- import android.support.p000v4.app.FragmentManager;
- import android.support.p003v7.app.AlertDialog;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ProgressBar;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import epson.print.C2135R;
- public class DialogProgress extends DialogFragment {
- public static final int MESSAGE_BOTTOM = 1;
- public static final int MESSAGE_ONLY = 2;
- public static final int MESSAGE_RIGHT = 0;
- private static final String TAG_DIALOG = "tag";
- private static final String TAG_MESSAGE = "message";
- private static final String TAG_NEGATIVE_MESSAGE = "negative_dialog_message";
- private static final String TAG_NEUTRAL_MESSAGE = "neutral_dialog_message";
- private static final String TAG_POSITION = "position";
- private static final String TAG_POSITIVE_MESSAGE = "positive_dialog_message";
- private static final String TAG_TITLE_MESSAGE = "title_message";
- private DialogButtonClick mActivity;
- private String mTag;
- public interface DialogButtonClick {
- void onCancelDialog(String str);
- void onNegativeClick(String str);
- void onNeutralClick(String str);
- void onPositiveClick(String str);
- }
- public static DialogProgress newInstance(String str, int i, @Nullable String str2) {
- return newInstance(str, i, str2, (String) null, (String) null, (String) null, (String) null);
- }
- public static DialogProgress newInstance(String str, int i, @Nullable String str2, @Nullable String str3, @Nullable String str4, @Nullable String str5, @Nullable String str6) {
- DialogProgress dialogProgress = new DialogProgress();
- Bundle bundle = new Bundle();
- bundle.putString(TAG_DIALOG, str);
- bundle.putInt("position", i);
- bundle.putString("message", str2);
- bundle.putString(TAG_TITLE_MESSAGE, str3);
- bundle.putString(TAG_POSITIVE_MESSAGE, str4);
- bundle.putString(TAG_NEUTRAL_MESSAGE, str5);
- bundle.putString(TAG_NEGATIVE_MESSAGE, str6);
- dialogProgress.setArguments(bundle);
- return dialogProgress;
- }
- private void deleteFragment(FragmentManager fragmentManager, String str) {
- Dialog dialog;
- DialogProgress dialogProgress = (DialogProgress) fragmentManager.findFragmentByTag(str);
- if (dialogProgress != null && (dialog = dialogProgress.getDialog()) != null && dialog.isShowing()) {
- dialogProgress.dismiss();
- }
- }
- @NonNull
- public Dialog onCreateDialog(@Nullable Bundle bundle) {
- this.mTag = getArguments().getString(TAG_DIALOG);
- int i = getArguments().getInt("position");
- String string = getArguments().getString("message");
- String string2 = getArguments().getString(TAG_TITLE_MESSAGE);
- String string3 = getArguments().getString(TAG_POSITIVE_MESSAGE);
- String string4 = getArguments().getString(TAG_NEUTRAL_MESSAGE);
- String string5 = getArguments().getString(TAG_NEGATIVE_MESSAGE);
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- View inflate = getActivity().getLayoutInflater().inflate(R.layout.dialog_progress, (ViewGroup) null);
- try {
- this.mActivity = (DialogButtonClick) getActivity();
- } catch (ClassCastException unused) {
- this.mActivity = null;
- }
- if (string2 != null) {
- builder.setTitle((CharSequence) string2);
- }
- if (string3 != null) {
- builder.setPositiveButton((CharSequence) string3, (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
- public final void onClick(DialogInterface dialogInterface, int i) {
- DialogProgress.lambda$onCreateDialog$0(DialogProgress.this, dialogInterface, i);
- }
- });
- }
- if (string4 != null) {
- builder.setNeutralButton((CharSequence) string4, (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
- public final void onClick(DialogInterface dialogInterface, int i) {
- DialogProgress.lambda$onCreateDialog$1(DialogProgress.this, dialogInterface, i);
- }
- });
- }
- if (string5 != null) {
- builder.setNegativeButton((CharSequence) string5, (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
- public final void onClick(DialogInterface dialogInterface, int i) {
- DialogProgress.lambda$onCreateDialog$2(DialogProgress.this, dialogInterface, i);
- }
- });
- }
- ProgressBar progressBar = (ProgressBar) inflate.findViewById(R.C2137id.dialog_progress_id);
- if (i == 1) {
- RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) progressBar.getLayoutParams();
- layoutParams.addRule(14);
- progressBar.setLayoutParams(layoutParams);
- TextView textView = (TextView) inflate.findViewById(R.C2137id.dialog_progress_text_bottom);
- textView.setText(string);
- progressBar.setVisibility(0);
- textView.setVisibility(0);
- } else if (i == 0) {
- TextView textView2 = (TextView) inflate.findViewById(R.C2137id.dialog_progress_text_right);
- textView2.setText(string);
- progressBar.setVisibility(0);
- textView2.setVisibility(0);
- } else {
- TextView textView3 = (TextView) inflate.findViewById(R.C2137id.dialog_progress_text_right);
- textView3.setText(string);
- textView3.setVisibility(0);
- }
- builder.setView(inflate);
- return builder.create();
- }
- public static /* synthetic */ void lambda$onCreateDialog$0(DialogProgress dialogProgress, DialogInterface dialogInterface, int i) {
- dialogProgress.dismiss();
- DialogButtonClick dialogButtonClick = dialogProgress.mActivity;
- if (dialogButtonClick != null) {
- dialogButtonClick.onPositiveClick(dialogProgress.mTag);
- }
- }
- public static /* synthetic */ void lambda$onCreateDialog$1(DialogProgress dialogProgress, DialogInterface dialogInterface, int i) {
- dialogProgress.dismiss();
- DialogButtonClick dialogButtonClick = dialogProgress.mActivity;
- if (dialogButtonClick != null) {
- dialogButtonClick.onNeutralClick(dialogProgress.mTag);
- }
- }
- public static /* synthetic */ void lambda$onCreateDialog$2(DialogProgress dialogProgress, DialogInterface dialogInterface, int i) {
- dialogProgress.dismiss();
- DialogButtonClick dialogButtonClick = dialogProgress.mActivity;
- if (dialogButtonClick != null) {
- dialogButtonClick.onNegativeClick(dialogProgress.mTag);
- }
- }
- public void onCancel(DialogInterface dialogInterface) {
- DialogButtonClick dialogButtonClick = this.mActivity;
- if (dialogButtonClick != null) {
- dialogButtonClick.onCancelDialog(this.mTag);
- }
- super.onCancel(dialogInterface);
- }
- public void show(FragmentManager fragmentManager, String str) {
- deleteFragment(fragmentManager, str);
- super.showNow(fragmentManager, str);
- }
- }
|