package tech.akpmakes.android.taskkeeper;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class AddItemDialog extends DialogFragment {
    /* The activity that creates an instance of this dialog fragment must
     * implement this interface in order to receive event callbacks.
     * Each method passes the DialogFragment in case the host needs to query it. */
    public interface AddItemDialogListener {
        public void onValue(String name);
    }

    // Use this instance of the interface to deliver action events
    AddItemDialogListener mListener;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        // Verify that the host activity implements the callback interface
        try {
            // Instantiate the AddItemDialogListener so we can send events to the host
            mListener = (AddItemDialogListener) activity;
        } catch (ClassCastException e) {
            // The activity doesn't implement the interface, throw exception
            throw new ClassCastException(activity.toString()
                    + " must implement NoticeDialogListener");
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        ((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                .toggleSoftInput(0, 0);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();
        final View view = inflater.inflate(R.layout.dialog_add_item, null);
        ((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(view)
                // Add action buttons
                .setPositiveButton(R.string.add_item, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        mListener.onValue(((EditText) view.findViewById(R.id.item_name)).getText().toString());
                    }
                })
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        AddItemDialog.this.getDialog().cancel();
                    }
                });
        return builder.create();
    }
}

@@ -428,16 +428,82 @@
 w.View;%0A
+import android.view.ViewGroup;%0Aimport android.view.WindowManager;%0A
 import a
@@ -538,32 +538,32 @@
 tMethodManager;%0A
-
 import android.w
@@ -1648,211 +1648,8 @@
  %7D%0A%0A
-    @Override%0A    public void onStop() %7B%0A        super.onStop();%0A        ((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))%0A                .toggleSoftInput(0, 0);%0A    %7D%0A%0A
     
@@ -1994,204 +1994,8 @@
 ll);
-%0A        ((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))%0A                .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
 %0A%0A  
@@ -2816,16 +2816,16 @@
     %7D);%0A
-
         
@@ -2854,11 +2854,375 @@
 );%0A    %7D
+%0A%0A    @Nullable%0A    @Override%0A    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) %7B%0A        View view = super.onCreateView(inflater, container, savedInstanceState);%0A        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);%0A        return view;%0A    %7D
 %0A%7D%0A

keyboard work