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:de.appetites.android.menuItemSearchAction.MenuItemSearchAction.java

/**
 * Listen for back button clicks, in order to close the keyboard and collapse the ActionView
 */// w  w  w.  jav  a2s  .c  o m
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        searchItem.collapseActionView();
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
        searchPerformListener.performSearch(MenuItemSearchAction.this.getText().toString());

        searchItem.collapseActionView();

    }
    return super.dispatchKeyEvent(event);
}

From source file:mobisocial.bento.todo.ui.TodoDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // extract UUID from intent
    mTodoUuid = getActivity().getIntent().getStringExtra(EXTRA_TODO_UUID);

    // View/*from   w ww  .  j a  v a  2  s  . c  o  m*/
    mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_todo_detail, container);

    mTitle = (EditText) mRootView.findViewById(R.id.todo_title);
    mDescription = (EditText) mRootView.findViewById(R.id.todo_description);
    mDescription.setOnEditorActionListener(new EditText.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) {
                Log.d(TAG, "onEditorAction");
                // clear focus
                v.clearFocus();

                // close keyboard
                InputMethodManager mgr = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.hideSoftInputFromWindow(mDescription.getWindowToken(), 0);

                return true;
            }
            return false;
        }
    });
    mImageView = (ImageView) mRootView.findViewById(R.id.todo_image);

    // retrieve Todo data
    if (mTodoUuid != null) {
        mTodoItem = mManager.getTodoListItem(mTodoUuid);
        if (mTodoItem != null) {
            mTitle.setText(mTodoItem.title);
            mDescription.setText(mTodoItem.description);
            if (mTodoItem.hasImage) {
                mImageView.setImageBitmap(mManager.getTodoBitmap(mTodoItem.uuid, IMG_WIDTH, IMG_HEIGHT, 0));
                mImageView.setVisibility(View.VISIBLE);
            } else {
                mImageView.setVisibility(View.GONE);
            }
        }
    }

    return mRootView;
}

From source file:com.bellman.bible.android.view.activity.search.Search.java

/**
 * Called when the activity is first created.
 *//*from w  w  w . ja  v a 2s  .com*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, true);
    Log.i(TAG, "Displaying Search view");
    setContentView(R.layout.search);

    if (!searchControl.validateIndex(getDocumentToSearch())) {
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred, new Callback() {
            @Override
            public void okay() {
                finish();
            }
        });
    }

    mSearchTextInput = (EditText) findViewById(R.id.searchText);
    mSearchTextInput.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
                onSearch(null);
                return true;
            }
            return false;
        }
    });

    // pre-load search string if passed in
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String searchText = extras.getString(SEARCH_TEXT_SAVE);
        if (StringUtils.isNotEmpty(searchText)) {
            mSearchTextInput.setText(searchText);
        }
    }

    RadioGroup wordsRadioGroup = (RadioGroup) findViewById(R.id.wordsGroup);
    wordsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            wordsRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int wordsSelection = extras.getInt(WORDS_SELECTION_SAVE, -1);
        if (wordsSelection != -1) {
            wordsRadioGroup.check(wordsSelection);
        }
    }

    RadioGroup sectionRadioGroup = (RadioGroup) findViewById(R.id.bibleSectionGroup);
    sectionRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            sectionRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int sectionSelection = extras.getInt(SECTION_SELECTION_SAVE, -1);
        if (sectionSelection != -1) {
            sectionRadioGroup.check(sectionSelection);
        }
    }

    // set text for current bible book on appropriate radio button
    RadioButton currentBookRadioButton = (RadioButton) findViewById(R.id.searchCurrentBook);

    // set current book to default and allow override if saved - implies returning via Back button
    currentBookName = searchControl.getCurrentBookName();
    if (extras != null) {
        String currentBibleBookSaved = extras.getString(CURRENT_BIBLE_BOOK_SAVE);
        if (currentBibleBookSaved != null) {
            currentBookName = currentBibleBookSaved;
        }
    }
    currentBookRadioButton.setText(currentBookName);

    Log.d(TAG, "Finished displaying Search view");
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    getActionBar().setDisplayHomeAsUpEnabled(true);

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

    EditText chatText = (EditText) findViewById(R.id.chatText);
    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();/* w w w . j  a  va2 s.co  m*/
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String remoteEndpointID = null;
    boolean shouldStartDirectConnection = false;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        remoteEndpointID = savedInstanceState.getString(ENDPOINT_ID_KEY);
        shouldStartDirectConnection = savedInstanceState.getBoolean(DIRECT_CONNECTION_KEY, false);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            remoteEndpointID = extras.getString(ENDPOINT_ID_KEY);
            shouldStartDirectConnection = extras.getBoolean(DIRECT_CONNECTION_KEY, false);
        } 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);
            remoteEndpointID = prefs.getString(ENDPOINT_ID_KEY, "");
            shouldStartDirectConnection = prefs.getBoolean(DIRECT_CONNECTION_KEY, false);
        }
    }

    conversation = ContactManager.sharedInstance().conversations.get(remoteEndpointID);
    remoteEndpoint = ContactManager.sharedInstance().sharedClient.getEndpoint(remoteEndpointID, true);
    setTitle(remoteEndpoint.getEndpointID());

    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

    if (shouldStartDirectConnection && (null == remoteEndpoint.directConnection())) {
        // If the direct connection has not been started yet, start it now
        remoteEndpoint.startDirectConnection();
    }

    directConnection = remoteEndpoint.directConnection();
    if (null != directConnection) {
        directConnection.setListener(this);
        RespokeCall call = directConnection.getCall();
        boolean caller = false;

        if (null != call) {
            call.setListener(this);
            caller = call.isCaller();
        }

        View answerView = findViewById(R.id.answer_view);
        View connectingView = findViewById(R.id.connecting_view);
        TextView callerNameView = (TextView) findViewById(R.id.caller_name_text);

        if (caller) {
            answerView.setVisibility(View.INVISIBLE);
            connectingView.setVisibility(View.VISIBLE);
        } else {
            answerView.setVisibility(View.VISIBLE);
            connectingView.setVisibility(View.INVISIBLE);
        }

        if (null != remoteEndpoint) {
            callerNameView.setText(remoteEndpoint.getEndpointID());
        } else {
            callerNameView.setText("Unknown Caller");
        }

        ActionBar actionBar = getActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(R.color.incoming_connection_bg));
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
    }
}

From source file:com.oda.calculator.EventListener.java

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  .ja va  2  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) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        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:com.aman.stockcalculator.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;
    }//from  ww w.j ava  2 s  .c  om

    //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) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        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:cl.ipp.katbag.fragment.Add.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_add, container, false);

    // rescues parameters
    Bundle bundle = getArguments();// w ww .  j  a  v a2  s  .  c o  m
    if (bundle != null) {
        type_app = bundle.getString("type_app");
    }

    progress = (ProgressBar) v.findViewById(R.id.progress);

    setTitleAndImageForTypeApp();

    name_app = (EditText) v.findViewById(R.id.name_app);
    name_app.setFilters(new InputFilter[] { KatbagUtilities.katbagAlphaNumericFilter,
            new InputFilter.LengthFilter(MAX_LENGTH) });
    name_app.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                validateName();
            }

            return false;
        }
    });

    config_app_worlds = (RelativeLayout) v.findViewById(R.id.config_app_worlds);
    config_app_drawings = (RelativeLayout) v.findViewById(R.id.config_app_drawings);
    config_app_developments = (RelativeLayout) v.findViewById(R.id.config_app_developments);
    config_app_pages = (RelativeLayout) v.findViewById(R.id.config_app_pages);

    config_app_worlds.setOnClickListener(this);
    config_app_drawings.setOnClickListener(this);
    config_app_developments.setOnClickListener(this);
    config_app_pages.setOnClickListener(this);

    if (type_app.contentEquals(MainActivity.TYPE_APP_GAME)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.VISIBLE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.GONE);

    } else if (type_app.contentEquals(MainActivity.TYPE_APP_BOOK)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.GONE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.VISIBLE);

    } else if (type_app.contentEquals(MainActivity.TYPE_APP_COMICS)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.GONE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.VISIBLE);
    }

    return v;
}

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

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

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

    // Layout//  w ww.  j  a va 2 s .  c  o m
    setContentView(R.layout.activity_calculators);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.calculators_toolbar);
    toolbar.setTitle(getString(R.string.calculators_title));

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

    // BMI
    final EditText bmiEditText = (EditText) findViewById(R.id.calculators_bmi_height);
    final TextView bmiButton = (TextView) findViewById(R.id.calculators_bmi_button);

    bmiButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            inputMethodManager.hideSoftInputFromWindow(bmiEditText.getWindowToken(), 0);

            calculateBmi();
        }
    });

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

                calculateBmi();

                return true;
            }

            return false;
        }
    });

    // Waist measurement
    final EditText waistMeasurementEditText = (EditText) findViewById(R.id.calculators_waist_measurement);
    final TextView waistMeasurementButton = (TextView) findViewById(R.id.calculators_waist_measurement_button);

    waistMeasurementButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            inputMethodManager.hideSoftInputFromWindow(waistMeasurementEditText.getWindowToken(), 0);

            calculateWaistMeasurement();
        }
    });

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

                calculateWaistMeasurement();

                return true;
            }

            return false;
        }
    });

    // Corrected QT time
    final EditText correctedQtTimeEditText = (EditText) findViewById(
            R.id.calculators_corrected_qt_time_rr_interval);
    final TextView correctedQtTimeButton = (TextView) findViewById(R.id.calculators_corrected_qt_time_button);

    correctedQtTimeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            inputMethodManager.hideSoftInputFromWindow(correctedQtTimeEditText.getWindowToken(), 0);

            calculateCorrectedQtTime();
        }
    });

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

                calculateCorrectedQtTime();

                return true;
            }

            return false;
        }
    });
}

From source file:com.redditandroiddevelopers.ircclient.ChannelFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View base = inflater.inflate(R.layout.chat_fragment, container, false);
    mChatContents = (TextView) base.findViewById(R.id.chat);
    mChatInput = (EditText) base.findViewById(R.id.edit);
    scroller = (ScrollView) base.findViewById(R.id.scroller);

    configureMessageHandler();/*  w  w  w  . j ava 2s.  co m*/

    if (ircClient == null) {
        ircClient = new IRCClient(nick, handler);
    }

    if (!ircClient.isConnected()) {
        ircClient.setLoginPublic(userName);
        connect();
        ircClient.identify(userPass);
    }

    mChatInput.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                String inputText = mChatInput.getText().toString();
                if (inputText.equals("/disconnect") || inputText == "/disconnect") {
                    ircClient.quitServer("I work when i want. You're not the boss of me.");
                } else if (inputText.matches("^/nick .*")) {
                    nick = ircClient.getNick();
                    String[] args = inputText.split(" ");
                    String newNick = args[1];
                    ircClient.changeNick(newNick);
                    boolean changeNickSuccessful = !(nick.equals(newNick)); // TODO: Not functioning properly
                    if (!changeNickSuccessful) {
                        showError(newNick + " already in use.");
                    }
                    nick = ircClient.getNick();
                } else if (inputText.matches("^/join .*")) {
                    String[] args = inputText.split(" ");
                    String newChannel = args[1];
                    ircClient.joinChannel(newChannel);
                    channel = newChannel;
                } else {
                    if (inputText == "" || (inputText.equals("")) || inputText == null) {
                        showError("Invalid input");
                    } else {
                        sendMessage(inputText);
                    }
                }

                mChatInput.setText("");
                return true;
            }
            return false;
        }
    });

    return base;
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    input = new EditText(getActivity());
    String message = getArguments().getString("title");
    CharSequence content;/*from  w w w  .j a va2 s  .  c  om*/
    if (savedInstanceState == null) {
        content = getArguments().getCharSequence("content");
    } else {
        content = savedInstanceState.getCharSequence("content");
    }
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    input.setText(content, TextView.BufferType.SPANNABLE);
    return new AlertDialog.Builder(getActivity()).setTitle(message).setView(input)
            .setPositiveButton(getResources().getText(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doPositiveClick();
                        }
                    })
            .setNegativeButton(getResources().getText(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doNegativeClick();
                        }
                    })
            .setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                    if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (i == KeyEvent.KEYCODE_ENTER)) {
                        dialogInterface.dismiss();
                        doPositiveClick();
                        return true;
                    }
                    return false;
                }
            }).create();
}