List of usage examples for android.view KeyEvent KEYCODE_DPAD_CENTER
int KEYCODE_DPAD_CENTER
To view the source code for android.view KeyEvent KEYCODE_DPAD_CENTER.
Click Source Link
From source file:org.musicmod.android.app.MusicPlaybackActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { int repcnt = event.getRepeatCount(); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: if (!useDpadMusicControl()) { break; }// ww w . j a v a 2s. c o m if (!mPrevButton.hasFocus()) { mPrevButton.requestFocus(); } scanBackward(repcnt, event.getEventTime() - event.getDownTime()); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!useDpadMusicControl()) { break; } if (!mNextButton.hasFocus()) { mNextButton.requestFocus(); } scanForward(repcnt, event.getEventTime() - event.getDownTime()); return true; // case KeyEvent.KEYCODE_R: // toggleRepeat(); // return true; // // case KeyEvent.KEYCODE_S: // toggleShuffle(); // return true; case KeyEvent.KEYCODE_N: if (mService != null) { try { mService.next(); return true; } catch (RemoteException e) { e.printStackTrace(); } } else { return false; } case KeyEvent.KEYCODE_P: if (mService != null) { try { mService.prev(); return true; } catch (RemoteException e) { e.printStackTrace(); } } else { return false; } case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_SPACE: doPauseResume(); return true; } return super.onKeyDown(keyCode, event); }
From source file:info.guardianproject.otr.app.im.app.ChatView.java
@Override protected void onFinishInflate() { // mStatusIcon = (ImageView) findViewById(R.id.statusIcon); // mDeliveryIcon = (ImageView) findViewById(R.id.deliveryIcon); // mTitle = (TextView) findViewById(R.id.title); mHistory = (ListView) findViewById(R.id.history); mComposeMessage = (EditText) findViewById(R.id.composeMessage); mSendButton = (ImageButton) findViewById(R.id.btnSend); mHistory.setOnItemClickListener(mOnItemClickListener); mButtonAttach = (ImageButton) findViewById(R.id.btnAttach); mViewAttach = findViewById(R.id.attachPanel); mStatusWarningView = findViewById(R.id.warning); mWarningText = (TextView) findViewById(R.id.warningText); mProgressTransfer = (ProgressBar) findViewById(R.id.progressTransfer); // mOtrSwitch = (CompoundButton)findViewById(R.id.otrSwitch); mProgressBarOtr = (ProgressBar) findViewById(R.id.progressBarOtr); mButtonAttach.setOnClickListener(new OnClickListener() { @Override/*from w w w . jav a 2s .co m*/ public void onClick(View v) { if (mViewAttach.getVisibility() == View.GONE) mViewAttach.setVisibility(View.VISIBLE); else mViewAttach.setVisibility(View.GONE); } }); ((ImageButton) findViewById(R.id.btnAttachAudio)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startAudioPicker(); } }); ((ImageButton) findViewById(R.id.btnAttachPicture)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startImagePicker(); } }); ((ImageButton) findViewById(R.id.btnTakePicture)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startPhotoTaker(); } }); ((ImageButton) findViewById(R.id.btnAttachFile)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startFilePicker(); } }); 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) mNewChatActivity .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(textToCopy); // } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mNewChatActivity .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("chat", textToCopy); clipboard.setPrimaryClip(clip); // } Toast.makeText(mNewChatActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard), Toast.LENGTH_SHORT).show(); return true; } return false; } }); mWarningText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showVerifyDialog(); } }); //mOtrSwitch.setOnCheckedChangeListener(mOtrListener); mComposeMessage.setOnKeyListener(new 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(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) { //log("TextWatcher: " + s); userActionDetected(); } public void afterTextChanged(Editable s) { } }); mSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { sendMessage(); } }); Button btnApproveSubscription = (Button) findViewById(R.id.btnApproveSubscription); btnApproveSubscription.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.approveSubscription(mProviderId, mRemoteAddress); mHandler.postDelayed(new Runnable() { public void run() { bindChat(mLastChatId); } }, 2000); } }); Button btnDeclineSubscription = (Button) findViewById(R.id.btnDeclineSubscription); btnDeclineSubscription.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mHandler.postDelayed(new Runnable() { public void run() { mNewChatActivity.declineSubscription(mProviderId, mRemoteAddress); } }, 500); } }); /* mActionBox = (View)findViewById(R.id.actionBox); ImageButton btnActionBox = (ImageButton)findViewById(R.id.btnActionBox); btnActionBox.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { mEmojiPager.setVisibility(View.GONE); if (mActionBox.getVisibility() == View.GONE) mActionBox.setVisibility(View.VISIBLE); else mActionBox.setVisibility(View.GONE); } }); View btnEndChat = findViewById(R.id.btnEndChat); btnEndChat.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { ChatView.this.closeChatSession(); } }); View btnProfile = findViewById(R.id.btnProfile); btnProfile.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { viewProfile(); } }); View btnSharePicture = findViewById(R.id.btnSendPicture); btnSharePicture.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED) { mNewChatActivity.startImagePicker(); } else { mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files)); } } }); View btnShareFile = findViewById(R.id.btnSendFile); btnShareFile.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED) { mNewChatActivity.startFilePicker(); } else { mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files)); } } }); */ initEmoji(); mMessageAdapter = new MessageAdapter(mNewChatActivity, null); mHistory.setAdapter(mMessageAdapter); }
From source file:info.bartowski.easteregg.MLand.java
@Override public boolean onKeyDown(int keyCode, KeyEvent ev) { L("keyDown: %d", keyCode); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_BUTTON_A: int player = getControllerPlayer(ev.getDeviceId()); poke(player);//from www .j a v a2 s . c o m return true; } return false; }
From source file:info.bartowski.easteregg.MLand.java
@Override public boolean onKeyUp(int keyCode, KeyEvent ev) { L("keyDown: %d", keyCode); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_BUTTON_A: int player = getControllerPlayer(ev.getDeviceId()); unpoke(player);/*from ww w . j a v a 2 s . c o m*/ return true; } return false; }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: //fall through case KeyEvent.KEYCODE_BUTTON_A: if (mIsPlaying) { mElfAccelY = mThrustAccelY;// ww w. j a v a 2 s .c o m if (!mElfIsHit) { updateElfThrust(1); } mJetThrustStream = mSoundPool.play(mJetThrustSound, 1.0f, 1.0f, 1, -1, 1.0f); } else if (!mCountdownStarted && !mMoviePlaying) { //game is paused. resume it. mBigPlayButton.setPressed(true); } return true; } return super.onKeyDown(keyCode, event); }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: //fall through case KeyEvent.KEYCODE_BUTTON_A: if (mIsPlaying) { mElfAccelY = 0.0f;//from www .ja v a2s . c om if (!mElfIsHit) { updateElfThrust(0); } if (mJetThrustStream > 0) { mSoundPool.stop(mJetThrustStream); mJetThrustStream = 0; } } else if (mMoviePlaying) { endIntro(); } else if (mBigPlayButton.isPressed()) { mBigPlayButton.setPressed(false); mBigPlayButton.performClick(); } return true; case KeyEvent.KEYCODE_BUTTON_B: onBackPressed(); return true; } return super.onKeyUp(keyCode, event); }
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 av a 2 s. 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) 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.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)/*from w w w . ja va2s .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);/* w ww. ja v a 2 s . c o m*/ 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); }