package com.stu.assistant.uitls;

import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

public class CodeConfig {
    private static CodeConfig newIns;
    private Context mContext;

    private CodeConfig(Context context) {
        mContext = context;
    }

    public static CodeConfig newInstance(Context context) {
        if (newIns == null) {
            synchronized (CodeConfig.class) {
                if (newIns == null) {
                    newIns = new CodeConfig(context);
                }
            }
        }
        return newIns;
    }

    public void setEcitTextviewClickListener(final EditText mEditText, final OnEcitTextviewClickListener listener) {

        mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEND
                        || actionId == EditorInfo.IME_ACTION_DONE
                        || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
                    listener.OnEcitTextviewClickListener(v);

                }
                return false;
            }
        });
    }

    public interface OnEcitTextviewClickListener {
        void OnEcitTextviewClickListener(View view);
    }
}
