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:tinkercoder.stockcalculator.calculator.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }//  w  w w.  j a  v a2 s .c  o m

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:Main.java

public static String getKeyNameByCode(int code) {
    switch (code) {
    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_APOSTROPHE:
        return "<'>";
    case KeyEvent.KEYCODE_AT:
        return "<@>";
    case KeyEvent.KEYCODE_BACK:
        return "<Back>";
    case KeyEvent.KEYCODE_BACKSLASH:
        return "<\\>";
    case KeyEvent.KEYCODE_CALL:
        return "<Call>";
    case KeyEvent.KEYCODE_CAMERA:
        return "<Camera>";
    case KeyEvent.KEYCODE_CLEAR:
        return "<Clear>";
    case KeyEvent.KEYCODE_COMMA:
        return "<,>";
    case KeyEvent.KEYCODE_DEL:
        return "<Del>";
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "<PadCenter>";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "<PadDown>";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "<PadLeft>";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "<PadRight>";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "<PadUp>";
    case KeyEvent.KEYCODE_ENDCALL:
        return "<EndCall>";
    case KeyEvent.KEYCODE_ENTER:
        return "<Enter>";
    case KeyEvent.KEYCODE_ENVELOPE:
        return "<Envelope>";
    case KeyEvent.KEYCODE_EQUALS:
        return "<=>";
    case KeyEvent.KEYCODE_EXPLORER:
        return "<Explorer>";
    case KeyEvent.KEYCODE_FOCUS:
        return "<??? 0>";
    case KeyEvent.KEYCODE_GRAVE:
        return "<??? 1>";
    case KeyEvent.KEYCODE_HEADSETHOOK:
        return "<??? 2>";
    case KeyEvent.KEYCODE_HOME:
        return "<Home>";
    case KeyEvent.KEYCODE_LEFT_BRACKET:
        return "<(>";
    case KeyEvent.KEYCODE_MENU:
        return "<Menu>";
    case KeyEvent.KEYCODE_MINUS:
        return "<->";
    case KeyEvent.KEYCODE_NOTIFICATION:
        return "<??? 3>";
    case KeyEvent.KEYCODE_NUM:
        return "<Num>";
    case KeyEvent.KEYCODE_PERIOD:
        return "<??? 4>";
    case KeyEvent.KEYCODE_PLUS:
        return "<+>";
    case KeyEvent.KEYCODE_POUND:
        return "<??? 5>";
    case KeyEvent.KEYCODE_POWER:
        return "<Power>";
    case KeyEvent.KEYCODE_RIGHT_BRACKET:
        return "<)>";
    case KeyEvent.KEYCODE_SEMICOLON:
        return "<;>";
    case KeyEvent.KEYCODE_SLASH:
        return "</>";
    case KeyEvent.KEYCODE_SOFT_LEFT:
        return "<??? 6>";
    case KeyEvent.KEYCODE_SOFT_RIGHT:
        return "<??? 7>";
    case KeyEvent.KEYCODE_SPACE:
        return "<Space>";
    case KeyEvent.KEYCODE_STAR:
        return "<*>";
    case KeyEvent.KEYCODE_SYM:
        return "<Sym>";
    case KeyEvent.KEYCODE_TAB:
        return "<Tab>";
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        return "<VolumeDown>";
    case KeyEvent.KEYCODE_VOLUME_UP:
        return "<VolumeUp>";
    case KeyEvent.KEYCODE_UNKNOWN:
    default://  w  w  w .  j av a2  s .  com
        return "<Unknown>";
    }
}

From source file:andlabs.lounge.lobby.ui.ChatFragment.java

@Override
public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) {
    final View chat = infl.inflate(R.layout.fragment_chat, p, false);
    mChatEditText = ((EditText) chat.findViewById(R.id.msg_field));
    ((ImageButton) chat.findViewById(R.id.btn_send)).setOnClickListener(this);
    ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() {

        @Override//  ww  w  .  j  av  a2s .c o  m
        public int getCount() {
            return mConversation.size();
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if (view == null)
                view = infl.inflate(R.layout.chat_list_entry, null);
            final ChatMessage msg = mConversation.get(position);
            ((TextView) view.findViewById(R.id.sender)).setText(msg.getPlayerName());
            ((TextView) view.findViewById(R.id.msg_text)).setText(msg.getMessage());
            return view;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }
    });
    // http://code.google.com/p/android/issues/detail?id=2516
    mChatEditText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                onClick(null);
                return true;
            }
            return false;
        }
    });
    return chat;
}

From source file:com.fusionx.lightirc.ui.IRCFragment.java

@Override
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
    final CharSequence text = mMessageBox.getText();
    if ((event == null || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE
            || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
            && StringUtils.isNotEmpty(text)) {
        final String message = text.toString();
        mMessageBox.setText("");
        onSendMessage(message);//from   w  ww .j ava 2  s .  c  o m
        return true;
    }
    return false;
}

From source file:com.aevi.simpleexample.SecureCommunicationsActivity.java

private void setupSearchTextEnterListener() {
    EditText searchText = (EditText) findViewById(R.id.searchText);
    searchText.setImeActionLabel("Search", KeyEvent.KEYCODE_ENTER);

    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override/*from  w  ww .  j  a v a  2 s .c o m*/
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && keyEvent.getAction() == keyEvent.ACTION_DOWN) {
                searchProjectsClick(textView);
                return true;
            }
            return false;
        }
    });
}

From source file:net.olejon.mdapp.Icd10Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout//  w  w  w .ja  va 2s .co  m
    setContentView(R.layout.activity_icd10);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.icd10_toolbar);
    toolbar.setTitle(getString(R.string.icd10_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.icd10_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.icd10_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());

                return true;
            }

            return false;
        }
    });

    ImageButton imageButton = (ImageButton) findViewById(R.id.icd10_toolbar_clear_search);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.icd10_list);

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.icd10_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());
            } else {
                mToolbarSearchLayout.setVisibility(View.VISIBLE);
                mToolbarSearchEditText.requestFocus();

                mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
            }
        }
    });

    // Get chapters
    GetChaptersTask getChaptersTask = new GetChaptersTask();
    getChaptersTask.execute();
}

From source file:com.simadanesh.isatis.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); //To change body of generated methods, choose Tools | Templates.
    try {//from www  .jav a 2 s .co  m
        CommonPlace.loginActivity = this;
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
                Log.e("Alert", "Lets See if it Works !!!" + paramThrowable.toString());
            }
        });

        setContentView(R.layout.activity_login);
        Utility.InitializeDefatultSettings(this);

        edUserName = (EditText) findViewById(R.id.edUserName);
        edPassword = (EditText) findViewById(R.id.edPassword);
        btnLogin = (Button) findViewById(R.id.btnLogin);
        btnCancel = (Button) findViewById(R.id.btnCancel);

        btnLogin.setOnClickListener(this);
        btnCancel.setOnClickListener(this);

        edUserName.setTypeface(Utility.getDefaultFont());
        edPassword.setTypeface(Utility.getDefaultFont());
        btnLogin.setTypeface(Utility.getDefaultFont());
        btnCancel.setTypeface(Utility.getDefaultFont());
        edPassword.setImeActionLabel("Login", KeyEvent.KEYCODE_ENTER);
        // edPassword.setImeActionLabel("Login", KeyEvent.IME_ACTION_DONE);
        edPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == KeyEvent.KEYCODE_ENTER) {
                    Login();
                }
                return true;
            }
        });

    } catch (Exception ex) {
        Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
    }

}

From source file:org.videolan.vlc.gui.MRLPanelFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == EditorInfo.IME_ACTION_DONE || keyCode == EditorInfo.IME_ACTION_GO
            || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        return processUri();
    }// w ww.  j  a v a2  s.c om
    return false;
}

From source file:eu.andlabs.studiolounge.chat.ChatFragment.java

@Override
public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) {
    final View chat = infl.inflate(R.layout.chat, p, false);
    mChatEditText = ((EditText) chat.findViewById(R.id.msg_field));
    ((ImageButton) chat.findViewById(R.id.btn_msgSend)).setOnClickListener(this);
    ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() {
        @Override/*  www  .j  av  a  2  s  . c  o  m*/
        public int getCount() {
            return mConversation.size();
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if (view == null)
                view = infl.inflate(R.layout.chat_list_entry, null);
            final ChatMessage msg = mConversation.get(position);
            final Player player = new Player(msg.player);
            ((TextView) view.findViewById(R.id.sender)).setText(player.getShortPlayername());
            ((TextView) view.findViewById(R.id.msg_text)).setText(msg.text);
            return view;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }
    });
    // http://code.google.com/p/android/issues/detail?id=2516
    mChatEditText.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                onClick(null);
                return true;
            }
            return false;
        }
    });
    return chat;
}

From source file:au.com.wallaceit.reddinator.ViewAllSubredditsActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    global = ((GlobalObjects) getApplicationContext());
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }/*  w  ww .  jav  a2s .  c om*/
    setContentView(R.layout.viewallsubreddit);
    // setup list view
    listview = getListView();
    listview.setTextFilterEnabled(true);
    listview.setEmptyView(findViewById(R.id.subredditload));
    listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(); // update subreddit without adding to list
            intent.putExtra("subreddit", sreddits.get(position));
            setResult(RESULT_SET_SUBREDDIT, intent);
            finish();
        }
    });
    // get empty view text for easy access later
    emptyview = (TextView) findViewById(R.id.poploadtxt);
    // setup search buttons
    searchbox = (EditText) this.findViewById(R.id.searchbox);
    searchbox.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
                search(v.getText().toString());
            }
            return true;
        }

    });
    ImageView searchbtn = (ImageView) this.findViewById(R.id.searchbutton);
    searchbtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String query = searchbox.getText().toString();
            if (!query.equals("")) {
                search(query);
            } else {
                new AlertDialog.Builder(ViewAllSubredditsActivity.this).setTitle("No Query")
                        .setMessage("Please enter something to search for").show();
            }
        }
    });
}