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:research.sg.edu.edapp.kb.KbSoftKeyboard.java

/**
 * Helper to send a character to the editor as raw key events.
 *///from   w w w.  j  a v  a  2s  .co m
private void sendKey(int keyCode) {
    switch (keyCode) {
    case '\n':
        keyDownUp(KeyEvent.KEYCODE_ENTER);
        break;
    default:
        if (keyCode >= '0' && keyCode <= '9') {
            keyDownUp(keyCode - '0' + KeyEvent.KEYCODE_0);
        } else {
            getCurrentInputConnection().commitText(String.valueOf((char) keyCode), 1);
        }
        break;
    }
}

From source file:com.dish.browser.activity.BrowserActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mSearch.hasFocus()) {
            searchTheWeb(mSearch.getText().toString());
        }/*ww  w .  ja  va2  s.co m*/
    } else if ((keyCode == KeyEvent.KEYCODE_MENU) && (Build.VERSION.SDK_INT <= 16)
            && (Build.MANUFACTURER.compareTo("LGE") == 0)) {
        // Workaround for stupid LG devices that crash
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.borax12.materialdaterangepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.//from  ww w.ja v a 2s.c o  m
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if (isCancelable())
            dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes(),
                    mTimePickerEnd.getHours(), mTimePickerEnd.getMinutes());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                if (tabHost.getCurrentTab() == 0) {
                    Utils.tryAccessibilityAnnounce(mTimePicker,
                            String.format(mDeletedKeyFormat, deletedKeyStr));
                } else {
                    Utils.tryAccessibilityAnnounce(mTimePickerEnd,
                            String.format(mDeletedKeyFormat, deletedKeyStr));
                }

                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}

From source file:android.support.v7.widget.ListPopupWindow.java

/**
 * Filter key down events. By forwarding key down events to this function,
 * views using non-modal ListPopupWindow can have it handle key selection of items.
 *
 * @param keyCode keyCode param passed to the host view's onKeyDown
 * @param event event param passed to the host view's onKeyDown
 * @return true if the event was handled, false if it was ignored.
 *
 * @see #setModal(boolean)/*from  w w w  .  j  a  v  a 2s  .com*/
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // when the drop down is shown, we drive it directly
    if (isShowing()) {
        // the key events are forwarded to the list in the drop down view
        // note that ListView handles space but we don't want that to happen
        // also if selection is not currently in the drop down, then don't
        // let center or enter presses go there since that would cause it
        // to select one of its items
        if (keyCode != KeyEvent.KEYCODE_SPACE
                && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) {
            int curIndex = mDropDownList.getSelectedItemPosition();
            boolean consumed;

            final boolean below = !mPopup.isAboveAnchor();

            final ListAdapter adapter = mAdapter;

            boolean allEnabled;
            int firstItem = Integer.MAX_VALUE;
            int lastItem = Integer.MIN_VALUE;

            if (adapter != null) {
                allEnabled = adapter.areAllItemsEnabled();
                firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true);
                lastItem = allEnabled ? adapter.getCount() - 1
                        : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
            }

            if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem)
                    || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
                // When the selection is at the top, we block the key
                // event to prevent focus from moving.
                clearListSelection();
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
                show();
                return true;
            } else {
                // WARNING: Please read the comment where mListSelectionHidden
                //          is declared
                mDropDownList.mListSelectionHidden = false;
            }

            consumed = mDropDownList.onKeyDown(keyCode, event);
            if (DEBUG)
                Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed);

            if (consumed) {
                // If it handled the key event, then the user is
                // navigating in the list, so we should put it in front.
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
                // Here's a little trick we need to do to make sure that
                // the list view is actually showing its focus indicator,
                // by ensuring it has focus and getting its window out
                // of touch mode.
                mDropDownList.requestFocusFromTouch();
                show();

                switch (keyCode) {
                // avoid passing the focus from the text view to the
                // next component
                case KeyEvent.KEYCODE_ENTER:
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_DPAD_DOWN:
                case KeyEvent.KEYCODE_DPAD_UP:
                    return true;
                }
            } else {
                if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    // when the selection is at the bottom, we block the
                    // event to avoid going to the next focusable widget
                    if (curIndex == lastItem) {
                        return true;
                    }
                } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private boolean configureEmailAutoComplete(boolean autoShowSuggestions) {
    T.UI();//from  w w  w.  ja v a  2s .  c  om
    final boolean getAccountsPermissionWasGranted = mService.isPermitted(Manifest.permission.GET_ACCOUNTS);
    if (getAccountsPermissionWasGranted) {
        mAccountManager = new AccountManager(this);
        mAccounts = mAccountManager.getAccounts();
        List<String> emails = new ArrayList<String>();
        for (Account account : mAccounts) {
            if (RegexPatterns.EMAIL.matcher(account.name).matches() && !emails.contains(account.name))
                emails.add(account.name);
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, emails);
        mEnterEmailAutoCompleteTextView.setAdapter(adapter);
        mEnterEmailAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                requestPin();
            }
        });
        mEnterEmailAutoCompleteTextView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                mEnterEmailAutoCompleteTextView.setThreshold(1);
                return false;
            }
        });
        if (autoShowSuggestions)
            mEnterEmailAutoCompleteTextView.showDropDown();
    }
    mEnterEmailAutoCompleteTextView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                requestPin();
                return true;
            }
            return false;
        }
    });
    return getAccountsPermissionWasGranted;
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.ListPopupWindow.java

/**
 * Filter key down events. By forwarding key down events to this function,
 * views using non-modal ListPopupWindow can have it handle key selection of items.
 *
 * @param keyCode keyCode param passed to the host view's onKeyDown
 * @param event event param passed to the host view's onKeyDown
 * @return true if the event was handled, false if it was ignored.
 *
 * @see #setModal(boolean)// w ww .j  av a 2s . c om
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // when the drop down is shown, we drive it directly
    if (isShowing()) {
        // the key events are forwarded to the list in the drop down view
        // note that ListView handles space but we don't want that to happen
        // also if selection is not currently in the drop down, then don't
        // let center or enter presses go there since that would cause it
        // to select one of its items
        if (keyCode != KeyEvent.KEYCODE_SPACE
                && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) {
            int curIndex = mDropDownList.getSelectedItemPosition();
            boolean consumed;

            final boolean below = !mPopup.isAboveAnchor();

            final ListAdapter adapter = mAdapter;

            boolean allEnabled;
            int firstItem = Integer.MAX_VALUE;
            int lastItem = Integer.MIN_VALUE;

            if (adapter != null) {
                allEnabled = adapter.areAllItemsEnabled();
                firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true);
                lastItem = allEnabled ? adapter.getCount() - 1
                        : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
            }

            if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem)
                    || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
                // When the selection is at the top, we block the key
                // event to prevent focus from moving.
                clearListSelection();
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
                show();
                return true;
            } else {
                // WARNING: Please read the comment where mListSelectionHidden
                //          is declared
                mDropDownList.mListSelectionHidden = false;
            }

            consumed = mDropDownList.onKeyDown(keyCode, event);
            if (DEBUG)
                Timber.v("Key down: code=" + keyCode + " list consumed=" + consumed);

            if (consumed) {
                // If it handled the key event, then the user is
                // navigating in the list, so we should put it in front.
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
                // Here's a little trick we need to do to make sure that
                // the list view is actually showing its focus indicator,
                // by ensuring it has focus and getting its window out
                // of touch mode.
                mDropDownList.requestFocusFromTouch();
                show();

                switch (keyCode) {
                // avoid passing the focus from the text view to the
                // next component
                case KeyEvent.KEYCODE_ENTER:
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_DPAD_DOWN:
                case KeyEvent.KEYCODE_DPAD_UP:
                    return true;
                }
            } else {
                if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    // when the selection is at the bottom, we block the
                    // event to avoid going to the next focusable widget
                    if (curIndex == lastItem) {
                        return true;
                    }
                } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:org.awesomeapp.messenger.ui.ConversationView.java

protected void initViews() {
    //  mStatusIcon = (ImageView) mActivity.findViewById(R.id.statusIcon);
    //   mDeliveryIcon = (ImageView) mActivity.findViewById(R.id.deliveryIcon);
    // mTitle = (TextView) mActivity.findViewById(R.id.title);
    mHistory = (RecyclerView) mActivity.findViewById(R.id.history);
    LinearLayoutManager llm = new LinearLayoutManager(mHistory.getContext());
    llm.setStackFromEnd(true);/*from   www . j  ava2s  .com*/
    mHistory.setLayoutManager(llm);

    mComposeMessage = (EditText) mActivity.findViewById(R.id.composeMessage);
    mSendButton = (ImageButton) mActivity.findViewById(R.id.btnSend);
    mMicButton = (ImageButton) mActivity.findViewById(R.id.btnMic);
    mButtonTalk = (TextView) mActivity.findViewById(R.id.buttonHoldToTalk);

    mButtonDeleteVoice = (ImageView) mActivity.findViewById(R.id.btnDeleteVoice);
    mViewDeleteVoice = mActivity.findViewById(R.id.viewDeleteVoice);

    mButtonDeleteVoice.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                int resolvedColor = mHistory.getResources().getColor(android.R.color.holo_red_light);
                mButtonDeleteVoice.setBackgroundColor(resolvedColor);
            }

            return false;
        }
    });

    mButtonAttach = (ImageButton) mActivity.findViewById(R.id.btnAttach);
    mViewAttach = mActivity.findViewById(R.id.attachPanel);

    mStatusWarningView = mActivity.findViewById(R.id.warning);
    mWarningText = (TextView) mActivity.findViewById(R.id.warningText);

    mButtonAttach.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            toggleAttachMenu();
        }

    });

    mActivity.findViewById(R.id.btnAttachPicture).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.startImagePicker();
        }

    });

    mActivity.findViewById(R.id.btnTakePicture).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.startPhotoTaker();
        }

    });

    /**
    mActivity.findViewById(R.id.btnAttachFile).setOnClickListener(new View.OnClickListener() {
            
    @Override
    public void onClick(View v) {
        mActivity.startFilePicker();
    }
            
    });*/

    mActivity.findViewById(R.id.btnAttachSticker).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleAttachMenu();
            showStickers();
        }

    });

    mMicButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //this is the tap to change to hold to talk mode
            if (mMicButton.getVisibility() == View.VISIBLE) {
                mComposeMessage.setVisibility(View.GONE);
                mMicButton.setVisibility(View.GONE);

                // Check if no view has focus:
                View view = mActivity.getCurrentFocus();
                if (view != null) {
                    InputMethodManager imm = (InputMethodManager) mActivity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }

                mSendButton.setImageResource(R.drawable.ic_keyboard_black_36dp);
                mSendButton.setVisibility(View.VISIBLE);
                mButtonTalk.setVisibility(View.VISIBLE);

            }
        }

    });

    final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {

            //this is for recording audio directly from one press
            mActivity.startAudioRecording();

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {

            if (mActivity.isAudioRecording()) {
                boolean send = true;//inViewInBounds(mMicButton, (int) motionEvent.getX(), (int) motionEvent.getY());
                mActivity.stopAudioRecording(send);
            }

            return super.onSingleTapUp(e);
        }
    });

    mMicButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return gestureDetector.onTouchEvent(motionEvent);

        }
    });

    mButtonTalk.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View btnTalk, MotionEvent theMotion) {
            switch (theMotion.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mActivity.startAudioRecording();
                mButtonTalk.setText(mActivity.getString(R.string.recording_release));
                mViewDeleteVoice.setVisibility(View.VISIBLE);

                break;
            case MotionEvent.ACTION_MOVE:
                boolean inBounds = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
                if (!inBounds)
                    mButtonTalk.setText(mActivity.getString(R.string.recording_delete));
                else {
                    mButtonTalk.setText(mActivity.getString(R.string.recording_release));
                    mViewDeleteVoice.setVisibility(View.VISIBLE);
                }
                break;
            case MotionEvent.ACTION_UP:
                mButtonTalk.setText(mActivity.getString(R.string.push_to_talk));
                boolean send = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
                mActivity.stopAudioRecording(send);
                mViewDeleteVoice.setVisibility(View.GONE);

                break;
            }
            return true;
        }
    });
    /**
    mHistory.setOnItemLongClickListener(new OnItemLongClickListener ()
    {
            
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            
            
     if (arg1 instanceof MessageView)
     {
            
         String textToCopy = ((MessageView)arg1).getLastMessage();
            
         int sdk = android.os.Build.VERSION.SDK_INT;
         if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
             android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
             clipboard.setText(textToCopy); //
         } else {
             android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
             android.content.ClipData clip = android.content.ClipData.newPlainText("chat",textToCopy);
             clipboard.setPrimaryClip(clip); //
         }
            
         Toast.makeText(mActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard), Toast.LENGTH_SHORT).show();
            
         return true;
            
     }
            
        return false;
    }
            
    });**/

    mWarningText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showVerifyDialog();
        }
    });

    mComposeMessage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            sendTypingStatus(true);

            return false;
        }
    });

    mComposeMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            sendTypingStatus(hasFocus);

        }
    });

    mComposeMessage.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                    sendMessage();
                    return true;

                case KeyEvent.KEYCODE_ENTER:
                    if (event.isAltPressed()) {
                        mComposeMessage.append("\n");
                        return true;
                    }
                }

            }

            return false;
        }
    });

    mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                if (event.isAltPressed()) {
                    return false;
                }
            }

            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null && imm.isActive(v)) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
            sendMessage();
            return true;
        }
    });

    // TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with
    // the soft keyboard, we should remove this hack.
    mComposeMessage.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int before, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int after) {

        }

        public void afterTextChanged(Editable s) {
            doWordSearch();
            userActionDetected();
        }
    });

    mSendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (mComposeMessage.getVisibility() == View.VISIBLE)
                sendMessage();
            else {
                mSendButton.setImageResource(R.drawable.ic_send_holo_light);

                if (mLastSessionStatus == SessionStatus.ENCRYPTED)
                    mSendButton.setImageResource(R.drawable.ic_send_secure);

                mSendButton.setVisibility(View.GONE);
                mButtonTalk.setVisibility(View.GONE);
                mComposeMessage.setVisibility(View.VISIBLE);
                mMicButton.setVisibility(View.VISIBLE);

            }
        }
    });

    mMessageAdapter = new ConversationRecyclerViewAdapter(mActivity, null);
    mHistory.setAdapter(mMessageAdapter);

}

From source file:com.mobicage.rogerthat.AddFriendsActivity.java

private void configureMailView() {
    T.UI();// w  w  w .j  a  va  2s . c  o  m
    final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_email_text_field);
    emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>()));
    emailText.setThreshold(1);

    if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) {
        mService.postAtFrontOfBIZZHandler(new SafeRunnable() {

            @SuppressWarnings("unchecked")
            @Override
            protected void safeRun() throws Exception {
                L.d("AddFriendsActivity getEmailAddresses");
                List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.this);
                ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter();
                for (int i = 0; i < emailList.size(); i++) {
                    a.add(emailList.get(i));
                }
                a.notifyDataSetChanged();
                L.d("AddFriendsActivity gotEmailAddresses");
            }
        });
    }

    final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            String email = emailText.getText().toString().trim();
            if (RegexPatterns.EMAIL.matcher(email).matches()) {
                if (mFriendsPlugin.inviteFriend(email, null, null, true)) {
                    emailText.setText(null);
                    UIUtils.hideKeyboard(AddFriendsActivity.this, emailText);
                } else {
                    UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed));
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this);
                builder.setMessage(R.string.registration_email_not_valid);
                builder.setPositiveButton(R.string.rogerthat, null);
                builder.create().show();
            }
        }
    };
    ((Button) findViewById(R.id.add_via_email_button)).setOnClickListener(onClickListener);

    emailText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                onClickListener.onClick(view);
                return true;
            }
            return false;
        }
    });
}

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

@Override
public void onResponseReceived(BroadcastDataSet bcast) {

    /* unset loading progress */
    setProgressBarIndeterminateVisibility(Boolean.FALSE);

    if (bcast != null) {
        debug.logV(TAG, "onResponseReceived called with bcast " + bcast.getId());
    } else {//from w w  w.  j  a  v  a 2s . co m
        debug.logV(TAG, "onResponseReceived called with bcast NULL");
    }

    boolean newBcast = false;
    if (bcast != null) {
        /* start async call to fetch user data */
        AsyncFlipInterface.getUser(bcast.getUsername(), user.getToken(), this);

        if (isNewBcast(bcast)) {
            debug.logV(TAG, "onResponseReceived, is a new broadcast");
            saveBcast(bcast);
            newBcast = true;
        } else {
            debug.logV(TAG, "onResponseReceived, is not a new broadcast");
        }
    } else {
        // try again with bcast from settings...
        if (!mSavedBcast) {
            mSavedBcast = true;
            AsyncFlipInterface.getBroadcast(getBcastFromSettings(), this);
        }
        return;
    }

    this.bcast = bcast;

    mUrl = getCurrentUrl(bcast);
    if (bcast != null) {
        mTitle = bcast.getUsername();
        if (bcast.getText() != null)
            mTitle += " - " + bcast.getText();
    }

    debug.logV(TAG, "onResponseReceived, got URL " + mUrl);

    /* layout */
    ImageView bg = (ImageView) findViewById(R.id.user_avatar);

    final TextView title_tv = (TextView) findViewById(R.id.title);
    final TextView time_tv = (TextView) findViewById(R.id.time_str);
    final TextView listeners_tv = (TextView) findViewById(R.id.listeners);
    final TextView username_tv = (TextView) findViewById(R.id.username);
    username_tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Player.this, Profile.class);
            i.putExtra("user", ((TextView) findViewById(R.id.username)).getText());
            startActivity(i);
        }
    });

    bg.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Player.this, Profile.class);
            i.putExtra("user", ((TextView) findViewById(R.id.username)).getText());
            startActivity(i);
        }
    });

    final TextView bottom_title_tv = (TextView) findViewById(R.id.player_title_bottom);

    // fix padding for player
    //      ScrollingTextView sc_tv = (ScrollingTextView) findViewById(R.id.actionbar_title);
    //      sc_tv.setPadding(35, 0, 0, 0);

    /* action bar */
    //      ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    //      actionBar.setHomeLogo(R.drawable.logo2);

    if (bcast != null) {
        UrlImageViewHelper.setUrlDrawable(bg, bcast.getImgUrl(), R.drawable.icon_sq);
        getSupportActionBar().setTitle(bcast.getUsername());
        username_tv.setText(bcast.getUsername());
        CharSequence title = bcast.getText();
        if (title == null)
            title = getText(R.string.empty_title);
        title_tv.setText(title);
        bottom_title_tv.setText(mTitle);
        bottom_title_tv.setSelected(true); // hack to make text scroll
        if (bcast.getTimeStr() != null) {
            time_tv.setText(bcast.getTimeStr());
        }
        if (bcast.getListens() == null) {
            // maybe erased? Go back...
            Player.this.finish();
        }
        try {
            Integer listens = Integer.parseInt(bcast.getListens()) + 1;
            listeners_tv.setText(listens.toString());
        } catch (NumberFormatException e) {
            Player.this.finish();
        }
    }

    // EditText comment listener
    final EditText comment_et = (EditText) findViewById(R.id.post_comment_et);
    comment_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
                postComment();
                return true;
            }
            return false;
        }
    });

    /* start bcast if it's a new one */
    if (newBcast) {
        debug.logV(TAG, "onResponseReceived, newBcast, sending PLAY");
        sendPlay();
    } else {
        if (mState == playerState.STOPPED)
            sendPlay();
    }

    /* stats thread */
    if (bcast != null) {
        if (bcast.getId() != null) {
            AsyncFlipInterface.getComments(Integer.parseInt(bcast.getId()), Player.this);
        }
        if (bcast.isLive()) {
            if (mState == playerState.PLAYING)
                setLiveVisible(true);
            liveHandler.removeCallbacks(mCheckLiveTask);
            liveHandler.postDelayed(mCheckLiveTask, 5000);
        } else {
            timerHandler.removeCallbacks(mTimerTask);
            timerHandler.postDelayed(mTimerTask, 1000);
        }
    }
}

From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.//from   www .  ja va 2s . c om
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if (isCancelable())
            dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes(),
                    mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}