package epson.print.storage;

import android.app.Dialog;
import android.os.Bundle;


import android.support.p000v4.app.DialogFragment;
import android.support.p000v4.app.FragmentManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;



public class LocalProgressDialog extends DialogFragment {
    private static final String LOG_TAG = "MyProgress";
    private static final String PARAM_CANCELABLE = "cancelable";
    private static final String PARAM_CANCEL_CONFIRM_DIALOG_TAG = "tag_confirm-cancel";
    private static final String PARAM_MESSAGE_ID = "message-id";
    private String mCancelConfirmDialogTag;

    public static LocalProgressDialog newInstance(boolean z, int i, @NonNull String str) {
        if (!z || str != null) {
            LocalProgressDialog localProgressDialog = new LocalProgressDialog();
            Bundle bundle = new Bundle();
            bundle.putBoolean(PARAM_CANCELABLE, z);
            bundle.putInt(PARAM_MESSAGE_ID, i);
            bundle.putString(PARAM_CANCEL_CONFIRM_DIALOG_TAG, str);
            localProgressDialog.setArguments(bundle);
            return localProgressDialog;
        }
        throw new IllegalArgumentException();
    }

    @Nullable
    public View onCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        Bundle arguments = getArguments();
        boolean z = arguments.getBoolean(PARAM_CANCELABLE, false);
        int i = arguments.getInt(PARAM_MESSAGE_ID, 0);
        mCancelConfirmDialogTag = arguments.getString(PARAM_CANCEL_CONFIRM_DIALOG_TAG);
        View inflate = layoutInflater.inflate(R.layout.my_progress, viewGroup, false);
        Button button = (Button) inflate.findViewById(R.id.cancelButton);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                LocalProgressDialog.this.showCancelConfirmDialog();
            }
        });
        button.setText(R.string.str_cancel);
        int i2 = 8;
        button.setVisibility(z ? 0 : 8);
        TextView textView = (TextView) inflate.findViewById(R.id.messageText);
        if (i != 0) {
            textView.setText(i);
        }
        if (i != 0) {
            i2 = 0;
        }
        textView.setVisibility(i2);
        ((LinearLayout) inflate.findViewById(R.id.dialog_back)).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            }
        });
        inflate.setFocusableInTouchMode(true);
        inflate.requestFocus();
        inflate.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                return i == 4;
            }
        });
        setCancelable(false);
        return inflate;
    }

    @NonNull
    public Dialog onCreateDialog(Bundle bundle) {
        Dialog onCreateDialog = super.onCreateDialog(bundle);
        onCreateDialog.requestWindowFeature(1);
        return onCreateDialog;
    }

    private void showCancelConfirmDialog() {
        if (mCancelConfirmDialogTag != null) {
            FragmentManager fragmentManager = getFragmentManager();
            if (fragmentManager != null) {
                ConfirmCancelDialog.newInstance(R.string.str_msg_scan_cancel).show(fragmentManager, mCancelConfirmDialogTag);
                return;
            }
            return;
        }
        throw new IllegalStateException();
    }
}
