Example usage for android.view KeyEvent KEYCODE_ENTER

List of usage examples for android.view KeyEvent KEYCODE_ENTER

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_ENTER.

Prototype

int KEYCODE_ENTER

To view the source code for android.view KeyEvent KEYCODE_ENTER.

Click Source Link

Document

Key code constant: Enter key.

Usage

From source file:Main.java

/**
 * Checks whether the given event is any of ENTER or NUMPAD ENTER.
 * @param event Event to be checked.//from   ww  w . j  a v a  2 s .  c  o m
 * @return Whether the event should be processed as ENTER.
 */
public static boolean isEnter(KeyEvent event) {
    return isActionUp(event) && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
            || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_ENTER);
}

From source file:Main.java

/**
 * Used to alter the edit text so that when they click the bottom right button on their,
 * keyboard, it will simulate an enter press
 * @param et Edit text being altered//from  w  w w.  ja va 2s.  c o  m
 * @param listener Listener to decide the reaction to said click
 * @param <T> T extends Edit Text
 */
private static <T extends EditText> void addIMEFunctionality(T et, TextView.OnEditorActionListener listener) {
    et.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    et.setImeActionLabel("Enter", KeyEvent.KEYCODE_ENTER);
    et.setOnEditorActionListener(listener);
    /*
    et.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    et.setImeActionLabel("Enter", KeyEvent.KEYCODE_ENTER);
    et.setOnEditorActionListener(listener);
            
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if(actionId == KeyEvent.KEYCODE_ENTER){
            doStuff();
        }
        if(actionId == EditorInfo.IME_ACTION_SEARCH){
            doStuff();
        }
        return false;
    }
            
            
            
    //Make sure to include this code below in class calling this method/ function
            
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if(actionId == KeyEvent.KEYCODE_ENTER){
        //Action happens here, IE Submit or enter
    }
    if(actionId == EditorInfo.IME_ACTION_SEARCH){
        //Action happens here, IE Submit or enter
    }
    return false;
    }
     */
}

From source file:Main.java

public static int lookupKeycode(boolean shiftDown, int keycode) {
    switch (keycode) {
    // case KeyEvent.KEYCODE_SHIFT_LEFT: return 0x00;
    // case KeyEvent.KEYCODE_SHIFT_RIGHT: return 0x00;
    case KeyEvent.KEYCODE_0:
        return shiftDown ? 0x126 : 0x27;
    case KeyEvent.KEYCODE_1:
        return 0x30;
    case KeyEvent.KEYCODE_2:
        return 0x31;
    case KeyEvent.KEYCODE_3:
        return 0x11;
    case KeyEvent.KEYCODE_4:
        return 0x12;
    case KeyEvent.KEYCODE_5:
        return 0x13;
    case KeyEvent.KEYCODE_6:
        return 0x34;
    case KeyEvent.KEYCODE_7:
        return shiftDown ? 0x134 : 0x24;
    case KeyEvent.KEYCODE_8:
        return 0x15;
    case KeyEvent.KEYCODE_9:
        return shiftDown ? 0x115 : 0x26;
    case KeyEvent.KEYCODE_A:
        return 0x41;
    case KeyEvent.KEYCODE_B:
        return 0x64;
    case KeyEvent.KEYCODE_C:
        return 0x52;
    case KeyEvent.KEYCODE_D:
        return 0x32;
    case KeyEvent.KEYCODE_E:
        return 0x22;
    case KeyEvent.KEYCODE_F:
        return 0x43;
    case KeyEvent.KEYCODE_G:
        return 0x53;
    case KeyEvent.KEYCODE_H:
        return 0x54;
    case KeyEvent.KEYCODE_I:
        return 0x25;
    case KeyEvent.KEYCODE_J:
        return 0x45;
    case KeyEvent.KEYCODE_K:
        return 0x46;
    case KeyEvent.KEYCODE_L:
        return 0x56;
    case KeyEvent.KEYCODE_M:
        return 0x65;
    case KeyEvent.KEYCODE_N:
        return 0x55;
    case KeyEvent.KEYCODE_O:
        return 0x36;
    case KeyEvent.KEYCODE_P:
        return 0x37;
    case KeyEvent.KEYCODE_Q:
        return 0x10;
    case KeyEvent.KEYCODE_R:
        return 0x33;
    case KeyEvent.KEYCODE_S:
        return 0x51;
    case KeyEvent.KEYCODE_T:
        return 0x23;
    case KeyEvent.KEYCODE_U:
        return 0x35;
    case KeyEvent.KEYCODE_V:
        return 0x63;
    case KeyEvent.KEYCODE_W:
        return 0x21;
    case KeyEvent.KEYCODE_X:
        return 0x42;
    case KeyEvent.KEYCODE_Y:
        return 0x44;
    case KeyEvent.KEYCODE_Z:
        return 0x61;
    case KeyEvent.KEYCODE_SPACE:
        return 0x62;
    case KeyEvent.KEYCODE_ENTER:
        return 0x49;
    case KeyEvent.KEYCODE_DEL:
        return 0x59;
    case KeyEvent.KEYCODE_APOSTROPHE:
        return shiftDown ? 0x31 : 0x124;
    case KeyEvent.KEYCODE_POUND:
        return 0x111; // '#' is Shift+3
    case KeyEvent.KEYCODE_MINUS:
        return shiftDown ? 0x238 : 0x17;
    case KeyEvent.KEYCODE_EQUALS:
        return 0x117;
    case KeyEvent.KEYCODE_AT:
        return 0x47;
    case KeyEvent.KEYCODE_STAR:
        return 0x148;
    case KeyEvent.KEYCODE_PERIOD:
        return shiftDown ? 0x248 : 0x67;
    case KeyEvent.KEYCODE_SEMICOLON:
        return 0x57;
    case KeyEvent.KEYCODE_SLASH:
        return 0x68;
    case KeyEvent.KEYCODE_PLUS:
        return 0x157;
    case KeyEvent.KEYCODE_COMMA:
        return 0x66;
    // case KeyEvent.KEYCODE_GRAVE: return 0x??;
    // case KeyEvent.KEYCODE_LEFT_BRACKET: return 0x??;
    // case KeyEvent.KEYCODE_RIGHT_BRACKET: return 0x??;
    }//from w w  w.  j av a  2  s .co m
    return 0xaa;
}

From source file:Main.java

public static String getChar(int keyCode) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_0:
        return "0";
    case KeyEvent.KEYCODE_1:
        return "1";
    case KeyEvent.KEYCODE_2:
        return "2";
    case KeyEvent.KEYCODE_3:
        return "3";
    case KeyEvent.KEYCODE_4:
        return "4";
    case KeyEvent.KEYCODE_5:
        return "5";
    case KeyEvent.KEYCODE_6:
        return "6";
    case KeyEvent.KEYCODE_7:
        return "7";
    case KeyEvent.KEYCODE_8:
        return "8";
    case KeyEvent.KEYCODE_9:
        return "9";
    case KeyEvent.KEYCODE_A:
        return "a";
    case KeyEvent.KEYCODE_B:
        return "b";
    case KeyEvent.KEYCODE_C:
        return "c";
    case KeyEvent.KEYCODE_D:
        return "d";
    case KeyEvent.KEYCODE_E:
        return "e";
    case KeyEvent.KEYCODE_F:
        return "f";
    case KeyEvent.KEYCODE_G:
        return "g";
    case KeyEvent.KEYCODE_H:
        return "h";
    case KeyEvent.KEYCODE_I:
        return "i";
    case KeyEvent.KEYCODE_J:
        return "j";
    case KeyEvent.KEYCODE_K:
        return "k";
    case KeyEvent.KEYCODE_L:
        return "l";
    case KeyEvent.KEYCODE_M:
        return "m";
    case KeyEvent.KEYCODE_N:
        return "n";
    case KeyEvent.KEYCODE_O:
        return "o";
    case KeyEvent.KEYCODE_P:
        return "p";
    case KeyEvent.KEYCODE_Q:
        return "q";
    case KeyEvent.KEYCODE_R:
        return "r";
    case KeyEvent.KEYCODE_S:
        return "s";
    case KeyEvent.KEYCODE_T:
        return "t";
    case KeyEvent.KEYCODE_U:
        return "u";
    case KeyEvent.KEYCODE_V:
        return "v";
    case KeyEvent.KEYCODE_W:
        return "w";
    case KeyEvent.KEYCODE_X:
        return "x";
    case KeyEvent.KEYCODE_Y:
        return "y";
    case KeyEvent.KEYCODE_Z:
        return "z";
    case KeyEvent.KEYCODE_DEL:
        return "{BKSP}";
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "{ENTER}";
    case KeyEvent.KEYCODE_SPACE:
        return " ";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "{DOWN}";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "{UP}";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "{LEFT}";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "{RIGHT}";
    }/*from w ww .j a va2 s .  co m*/
    return null;
}

From source file:com.digium.respoke.GroupChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group_chat);

    Button buttonSend = (Button) findViewById(R.id.buttonSend);

    EditText chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                sendChatMessage();//from w  w  w.java2 s.c  o  m
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String groupID = null;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        groupID = savedInstanceState.getString(GROUP_ID_KEY);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            groupID = extras.getString(GROUP_ID_KEY);
        } else {
            // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data.
            SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0);
            groupID = prefs.getString(GROUP_ID_KEY, "");
        }
    }

    this.setTitle(groupID);

    for (RespokeGroup eachGroup : ContactManager.sharedInstance().groups) {
        if (eachGroup.getGroupID().equals(groupID)) {
            group = eachGroup;
            break;
        }
    }

    conversation = ContactManager.sharedInstance().groupConversations.get(groupID);

    listAdapter = new ListDataAdapter();

    ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout
    lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView
}

From source file:com.munger.passwordkeeper.alert.InputFragment.java

/**
 * grab references to all the alert components and setup event handlers.
 *//*from   ww  w . j ava2 s.  c o  m*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    inputView = new EditText(getActivity());
    inputView.setHint(prompt);
    inputView.setSingleLine();

    //submit on keyboard enter
    inputView.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                okay();
                return true;
            } else
                return false;
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(inputView);
    builder.setMessage(message);

    //this is a blank handler, the real one is in the onStart method
    builder.setPositiveButton("Okay", null);

    builder.setNegativeButton("Cacnel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            listener.cancel();
        }
    });

    return builder.create();
}

From source file:com.flipzu.flipzu.SearchFragment.java

@Override
public void onResume() {
    super.onResume();

    debug.logV(TAG, "onResume()");

    final EditText search_et = (EditText) getActivity().findViewById(R.id.search);
    search_et.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                mSearch = search_et.getText().toString().trim();
                debug.logV(TAG, "onKey, got " + mSearch);
                EventNotifier.getInstance().signalNewSearch(mSearch);
                return true;
            }/* w  w w  .  j  a va2  s.  com*/
            return false;
        }
    });

    search_et.setText("");
    //      mSearch = search_et.getText().toString();
    //      
    //      if ( mSearch != null ) {
    //         debug.logV(TAG, "searching for " + mSearch);
    //         EventNotifier.getInstance().signalNewSearch(mSearch);         
    //      }
}

From source file:net.thetabx.gcd.activity.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    header = (TextView) findViewById(R.id.txt_chat_header);
    listView = (ListView) findViewById(R.id.lview_chat);
    swipe = (SwipeRefreshLayout) findViewById(R.id.swipe_chat);
    swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override/*from w  w  w. j av a  2  s .  co m*/
        public void onRefresh() {
            fetchFreshData();
        }
    });
    edit = (EditText) findViewById(R.id.etxt_chat_send);
    edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE
                    || event.getAction() == KeyEvent.ACTION_DOWN
                            && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                header.setText(String.format("Sent %s", v.getText()));
                sendChatMessage(v);
                //v.setText("");
                fetchFreshData();
            }
            return false;
        }
    });

    header.setText("Start");
    if (messages == null) {
        fetchFreshData();
    } else
        fillActivity();
}

From source file:org.linesofcode.alltrack.graph.CreateGraphActivity.java

private void initializeContent() {
    Button okButton = (Button) findViewById(R.id.graph_detail_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   ww  w. j ava 2  s .c o  m
        public void onClick(View v) {
            createGraph();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.graph_detail_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(CREATE_GRAPH_ACTION_CODE));
            finish();
        }
    });

    EditText graphName = (EditText) findViewById(R.id.edit_graph_name);
    graphName.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    createGraph();
                    return true;
                }
            }
            return false;
        }
    });
}