package epson.maintain.activity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import epson.print.R;

public class NozzleGuidanceDialog extends DialogFragment {
    public Dialog onCreateDialog(Bundle bundle) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View inflate = getActivity().getLayoutInflater().inflate(R.layout.dialog_nozzle_check_guidance, (ViewGroup) null);
        ((Button) inflate.findViewById(R.id.close_button)).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                NozzleGuidanceDialog.this.dismiss();
            }
        });
        ((Button) inflate.findViewById(R.id.browse_button)).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                NozzleGuidanceDialog.this.startBrowser();
                NozzleGuidanceDialog.this.dismiss();
            }
        });
        builder.setView(inflate);
        AlertDialog create = builder.create();
        create.setCanceledOnTouchOutside(false);
        create.setOnKeyListener(new DialogInterface.OnKeyListener() {
            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                return keyEvent.getKeyCode() == 84;
            }
        });
        return create;
    }

    private void startBrowser() {
        MaintainActivity maintainActivity = (MaintainActivity) getActivity();
        if (maintainActivity != null) {
            maintainActivity.startBrowseNozzleCheckGuidance();
        }
    }
}
