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:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON);
    }//w  w w. j  av  a  2  s .  c  o m

    // Retrieve session object
    checkSession();

    if (getArguments() != null && getArguments().containsKey(ARGUMENT_MODE)) {
        fieldId = getArguments().getString(ARGUMENT_FIELD_ID);
        keywords = getArguments().getString(ARGUMENT_KEYWORD);
        title = getArguments().getString(ARGUMENT_TITLE);
        mode = getArguments().getInt(ARGUMENT_MODE);
        singleChoice = getArguments().getBoolean(ARGUMENT_SINGLE_CHOICE);
        String pickFragmentTag = getArguments().getString(ARGUMENT_FRAGMENT_TAG);
        fragmentPick = getFragmentManager().findFragmentByTag(pickFragmentTag);
        if (fragmentPick != null && fragmentPick instanceof UserPickerCallback) {
            selectedItems = ((UserPickerCallback) fragmentPick).retrieveSelection();
        } else if (fragmentPick instanceof onPickAuthorityFragment && fieldId != null) {
            selectedItems = ((onPickAuthorityFragment) fragmentPick).getPersonSelected(fieldId);
        }
    }

    // Create View
    setRootView(inflater.inflate(R.layout.app_pick_person, container, false));
    if (getSession() == null) {
        return getRootView();
    }

    // Init list
    init(getRootView(), R.string.person_not_found);
    gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
    setListShown(true);

    if (keywords != null && !keywords.isEmpty()) {
        search(keywords);
        hide(R.id.search_form_group);
    } else {
        // Init form search
        searchForm = (EditText) viewById(R.id.search_query);
        searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

        searchForm.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                        && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                                || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                    if (searchForm.getText().length() > 0) {
                        keywords = searchForm.getText().toString();
                        search(keywords);
                    } else {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showLongToast(getString(R.string.search_form_hint));
                    }
                    return true;
                }
                return false;
            }
        });

        // Speech to Text
        Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity());
        ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone);
        if (hasTextToSpeech) {
            speechToText.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    speechToText();
                }
            });
        } else {
            hide(R.id.search_microphone);
        }
    }

    if (getMode() == MODE_PICK) {
        show(R.id.validation_panel);
        validation = UIUtils.initValidation(getRootView(), R.string.done);
        updatePickButton();
        validation.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onSelect(selectedItems);
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });

        Button cancel = UIUtils.initCancel(getRootView(), R.string.cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });
    } else {
        hide(R.id.validation_panel);
    }

    return getRootView();
}

From source file:com.kinvey.sample.kitchensink.account.LoginFragment.java

protected void addEditListeners() {
    login.setEnabled(validateInput());//from ww w. ja va 2s.c om

    username.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            login.setEnabled(validateInput());
        }
    });

    username.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE
                    || (event.getAction() == KeyEvent.ACTION_DOWN
                            && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                    && username.getText().length() < MIN_USERNAME_LENGTH) {

                CharSequence text = "User name must contain at least " + MIN_USERNAME_LENGTH + " characters";
                Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });

    password.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            login.setEnabled(validateInput());
        }
    });

    password.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE
                    || (event.getAction() == KeyEvent.ACTION_DOWN
                            && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                    && password.getText().length() < MIN_USERNAME_LENGTH) {
                CharSequence text = "Password must contain at least " + MIN_PASSWORD_LENGTH + " characters";
                Toast.makeText(getSherlockActivity(), text, Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });

}

From source file:com.waz.zclient.pages.main.popup.QuickReplyFragment.java

@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
            && event.getAction() == KeyEvent.ACTION_DOWN)) {
        final String sendText = textView.getText().toString();
        if (TextUtils.isEmpty(sendText)) {
            return false;
        }/*  w w w .j a  va 2s  . co  m*/
        conversation.sendMessage(new MessageContent.Text(sendText));

        TrackingUtils.onSentTextMessage(getControllerFactory().getTrackingController(),
                getStoreFactory().getConversationStore().getCurrentConversation());
        getActivity().finish();
        return true;
    }
    return false;
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_ENTER:
        findViewById(R.id.id_btn_get_pnr_sts).performClick();
        return true;
    default://from  w  ww . ja v  a 2 s.c om
        return super.onKeyUp(keyCode, event);
    }
}

From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java

void resetUI(PickSubredditAdapter adapter) {
    findViewById(R.id.loading_light).setVisibility(View.GONE);
    findViewById(R.id.loading_dark).setVisibility(View.GONE);

    synchronized (ADAPTER_LOCK) {
        if (adapter == null) {
            // Reset the list to be empty.
            mSubredditsList = new ArrayList<String>();
            mSubredditsAdapter = new PickSubredditAdapter(this, mSubredditsList);
        } else {//from  w  w  w .  j a  v  a 2  s  . com
            mSubredditsAdapter = adapter;
        }
        setListAdapter(mSubredditsAdapter);
        mSubredditsAdapter.mLoading = false;
        mSubredditsAdapter.notifyDataSetChanged(); // Just in case
    }
    Common.updateListDrawables(this, mSettings.getTheme());

    // Set the EditText to do same thing as onListItemClick
    mEt = (EditText) findViewById(R.id.pick_subreddit_input);
    if (mEt != null) {
        mEt.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    returnSubreddit(mEt.getText().toString().trim());
                    return true;
                }
                return false;
            }
        });
        mEt.setFocusableInTouchMode(true);
    }
    Button goButton = (Button) findViewById(R.id.pick_subreddit_button);
    if (goButton != null) {
        goButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                returnSubreddit(mEt.getText().toString().trim());
            }
        });
    }

    getListView().requestFocus();
}

From source file:de.vanita5.twittnuker.activity.support.QuickSearchBarActivity.java

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (event == null)
        return false;
    switch (event.getKeyCode()) {
    case KeyEvent.KEYCODE_ENTER: {
        doSearch();//from  www  .  j  a  va 2  s . co m
        return true;
    }
    }
    return false;
}

From source file:in.shick.diode.reddits.PickSubredditActivity.java

void resetUI(PickSubredditAdapter adapter) {
    findViewById(R.id.loading_light).setVisibility(View.GONE);
    findViewById(R.id.loading_dark).setVisibility(View.GONE);

    synchronized (ADAPTER_LOCK) {
        if (adapter == null) {
            // Reset the list to be empty.
            mSubredditsList = new ArrayList<SubredditInfo>();
            mSubredditsAdapter = new PickSubredditAdapter(this, mSubredditsList);
        } else {/*from  w  ww .ja v  a 2s .c  om*/
            mSubredditsAdapter = adapter;
        }
        setListAdapter(mSubredditsAdapter);
        mSubredditsAdapter.mLoading = false;
        mSubredditsAdapter.notifyDataSetChanged(); // Just in case
    }
    Common.updateListDrawables(this, mSettings.getTheme());

    // Set the EditText to do same thing as onListItemClick
    mEt = (EditText) findViewById(R.id.pick_subreddit_input);
    if (mEt != null) {
        mEt.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    returnSubreddit(mEt.getText().toString().trim());
                    return true;
                }
                return false;
            }
        });
        mEt.setFocusableInTouchMode(true);
    }
    Button goButton = (Button) findViewById(R.id.pick_subreddit_button);
    if (goButton != null) {
        goButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                returnSubreddit(mEt.getText().toString().trim());
            }
        });
    }

    getListView().requestFocus();
}

From source file:org.alfresco.mobile.android.application.fragments.search.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(true);//w w w  .j  a  v  a  2 s  . c o m

    setRootView(inflater.inflate(R.layout.app_search_history, container, false));
    init(getRootView(), emptyListMessageId);

    // Folder path
    if (getArguments() != null && getArguments().containsKey(ARGUMENT_FOLDER)) {
        pathView = (TextView) viewById(R.id.search_path);
        show(R.id.search_path_panel);
        displayPathOption();
    } else {
        hide(R.id.search_path_panel);
    }

    // Search Icon
    searchIcon = (ImageView) viewById(R.id.search_icon);

    // Search Input
    searchForm = (EditText) viewById(R.id.search_query);
    searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchForm.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                    && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                            || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                if (searchForm.getText().length() > 0) {
                    search(searchForm.getText().toString());
                    UIUtils.hideKeyboard(getActivity());
                } else {
                    AlfrescoNotificationManager.getInstance(getActivity())
                            .showLongToast(getString(R.string.search_form_hint));
                }
                return true;
            }
            return false;
        }
    });

    // Speech to Text
    Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity());
    ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone);
    if (hasTextToSpeech) {
        speechToText.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                speechToText();
            }
        });
    } else {
        hide(R.id.search_microphone);
    }

    return getRootView();
}

From source file:org.mozilla.gecko.AwesomeBar.java

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

    Log.d(LOGTAG, "creating awesomebar");

    mResolver = Tabs.getInstance().getContentResolver();

    setContentView(R.layout.awesomebar);

    if (Build.VERSION.SDK_INT >= 11) {
        RelativeLayout actionBarLayout = (RelativeLayout) GeckoActionBar.getCustomView(this);
        mGoButton = (ImageButton) actionBarLayout.findViewById(R.id.awesomebar_button);
        mText = (AwesomeBarEditText) actionBarLayout.findViewById(R.id.awesomebar_text);
    } else {//from   w ww  . ja  v a2s  .  c  o  m
        mGoButton = (ImageButton) findViewById(R.id.awesomebar_button);
        mText = (AwesomeBarEditText) findViewById(R.id.awesomebar_text);
    }

    TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
    tabWidget.setDividerDrawable(null);

    mAwesomeTabs = (AwesomeBarTabs) findViewById(R.id.awesomebar_tabs);
    mAwesomeTabs.setOnUrlOpenListener(new AwesomeBarTabs.OnUrlOpenListener() {
        public void onUrlOpen(String url) {
            openUrlAndFinish(url);
        }

        public void onSearch(String engine) {
            openSearchAndFinish(mText.getText().toString(), engine);
        }
    });

    mGoButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            openUserEnteredAndFinish(mText.getText().toString());
        }
    });

    Resources resources = getResources();

    int padding[] = { mText.getPaddingLeft(), mText.getPaddingTop(), mText.getPaddingRight(),
            mText.getPaddingBottom() };

    GeckoStateListDrawable states = new GeckoStateListDrawable();
    states.initializeFilter(GeckoApp.mBrowserToolbar.getHighlightColor());
    states.addState(new int[] { android.R.attr.state_focused },
            resources.getDrawable(R.drawable.address_bar_url_pressed));
    states.addState(new int[] { android.R.attr.state_pressed },
            resources.getDrawable(R.drawable.address_bar_url_pressed));
    states.addState(new int[] {}, resources.getDrawable(R.drawable.address_bar_url_default));
    mText.setBackgroundDrawable(states);

    mText.setPadding(padding[0], padding[1], padding[2], padding[3]);

    Intent intent = getIntent();
    String currentUrl = intent.getStringExtra(CURRENT_URL_KEY);
    mType = intent.getStringExtra(TYPE_KEY);
    if (currentUrl != null) {
        mText.setText(currentUrl);
        mText.selectAll();
    }

    mText.setOnKeyPreImeListener(new AwesomeBarEditText.OnKeyPreImeListener() {
        public boolean onKeyPreIme(View v, int keyCode, KeyEvent event) {
            // We only want to process one event per tap
            if (event.getAction() != KeyEvent.ACTION_DOWN)
                return false;

            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                openUserEnteredAndFinish(mText.getText().toString());
                return true;
            }

            // If input method is in fullscreen mode, we want to dismiss
            // it instead of closing awesomebar straight away.
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (keyCode == KeyEvent.KEYCODE_BACK && !imm.isFullscreenMode()) {
                // Let mAwesomeTabs try to handle the back press, since we may be in a
                // bookmarks sub-folder.
                if (mAwesomeTabs.onBackPressed())
                    return true;

                // If mAwesomeTabs.onBackPressed() returned false, we didn't move up
                // a folder level, so just exit the activity.
                cancelAndFinish();
                return true;
            }

            return false;
        }
    });

    mText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            // do nothing
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // do nothing
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String text = s.toString();

            mAwesomeTabs.filter(text);
            updateGoButton(text);
        }
    });

    mText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (event.getAction() != KeyEvent.ACTION_DOWN)
                    return true;

                openUserEnteredAndFinish(mText.getText().toString());
                return true;
            } else {
                return false;
            }
        }
    });

    mText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    });

    registerForContextMenu(mAwesomeTabs.findViewById(R.id.all_pages_list));
    registerForContextMenu(mAwesomeTabs.findViewById(R.id.bookmarks_list));
    registerForContextMenu(mAwesomeTabs.findViewById(R.id.history_list));

    GeckoAppShell.registerGeckoEventListener("SearchEngines:Data", this);
    GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null));
}

From source file:org.bombusim.lime.fragments.ChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.chat, container, false);

    contactBar = (ContactBar) v.findViewById(R.id.contact_head);
    mMessageBox = (ChatEditText) v.findViewById(R.id.messageBox);
    mSendButton = (ImageButton) v.findViewById(R.id.sendButton);
    mSmileButton = (ImageButton) v.findViewById(R.id.smileButton);
    chatListView = (ListView) v.findViewById(R.id.chatListView);

    mChatActive = v.findViewById(R.id.chatActive);
    mChatInactive = v.findViewById(R.id.chatInactive);

    if (!getChatFragmentListener().isTabMode()) {
        contactBar.setVisibility(View.GONE);

        View abCustomView = getSherlockActivity().getSupportActionBar().getCustomView();

        contactBar = (ContactBar) abCustomView.findViewById(R.id.contactHeadActionbar);
        contactBar.removeBackground();/*from  w w w . ja va  2s. c  o  m*/
    }

    registerForContextMenu(chatListView);
    enableTrackballTraversing();

    mSendButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sendMessage();
        }
    });

    mSmileButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mMessageBox.showAddSmileDialog();
        }
    });

    //TODO: optional
    mMessageBox.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() != KeyEvent.ACTION_DOWN)
                return false; //filtering only KEY_DOWN

            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;
            //if (event.isShiftPressed()) return false; //typing multiline messages with SHIFT+ENTER
            sendMessage();
            return true; //Key was processed
        }
    });

    mMessageBox.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() > 0)
                sendChatState(ChatStates.COMPOSING);
        }
    });

    //TODO: optional behavior
    //messageBox.setImeActionLabel("Send", EditorInfo.IME_ACTION_SEND); //Keeps IME opened
    mMessageBox.setImeActionLabel(getString(R.string.sendMessage), EditorInfo.IME_ACTION_DONE); //Closes IME

    mMessageBox.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_SEND:
                sendMessage();
                return true;
            case EditorInfo.IME_ACTION_DONE:
                sendMessage();
                return false; //let IME to be closed
            }
            return false;
        }
    });

    contactBar.getContactIconView().setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new ContactResourceSwitcher().showResources(getActivity(), visavis);
        }
    });

    return v;
}