package epson.common; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.p000v4.app.DialogFragment; import android.support.p000v4.app.FragmentManager; import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; 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) { 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 { mActivity = (DialogButtonClick) getActivity(); } catch (ClassCastException unused) { 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.id.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.id.dialog_progress_text_bottom); textView.setText(string); progressBar.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE); } else if (i == 0) { TextView textView2 = (TextView) inflate.findViewById(R.id.dialog_progress_text_right); textView2.setText(string); progressBar.setVisibility(View.VISIBLE); textView2.setVisibility(View.VISIBLE); } else { TextView textView3 = (TextView) inflate.findViewById(R.id.dialog_progress_text_right); textView3.setText(string); textView3.setVisibility(View.VISIBLE); } 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 = mActivity; if (dialogButtonClick != null) { dialogButtonClick.onCancelDialog(mTag); } super.onCancel(dialogInterface); } public void show(FragmentManager fragmentManager, String str) { deleteFragment(fragmentManager, str); super.showNow(fragmentManager, str); } }