List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:org.telegram.ui.ChatActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (fragmentView == null) { fragmentView = inflater.inflate(R.layout.chat_layout, container, false); sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) fragmentView.findViewById(R.id.chat_layout); sizeNotifierRelativeLayout.delegate = this; contentView = sizeNotifierRelativeLayout; emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView); chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view); chatListView.setAdapter(chatAdapter = new ChatAdapter(parentActivity)); topPanel = fragmentView.findViewById(R.id.top_panel); topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close); topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text); bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay); bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text); View bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat); progressView = fragmentView.findViewById(R.id.progressLayout); pagedownButton = fragmentView.findViewById(R.id.pagedown_button); audioSendButton = (ImageButton) fragmentView.findViewById(R.id.chat_audio_send_button); View progressViewInner = progressView.findViewById(R.id.progressLayoutInner); updateContactStatus();//from ww w. j a va2 s.c o m ImageView backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); int selectedColor = preferences.getInt("selectedColor", 0); if (selectedColor != 0) { backgroundImage.setBackgroundColor(selectedColor); chatListView.setCacheColorHint(selectedColor); } else { chatListView.setCacheColorHint(0); if (selectedBackground == 1000001) { backgroundImage.setImageResource(R.drawable.background_hd); } else { File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); if (toFile.exists()) { if (ApplicationLoader.cachedWallpaper != null) { backgroundImage.setImageBitmap(ApplicationLoader.cachedWallpaper); } else { backgroundImage.setImageURI(Uri.fromFile(toFile)); if (backgroundImage.getDrawable() instanceof BitmapDrawable) { ApplicationLoader.cachedWallpaper = ((BitmapDrawable) backgroundImage.getDrawable()) .getBitmap(); } } isCustomTheme = true; } else { backgroundImage.setImageResource(R.drawable.background_hd); } } } if (currentEncryptedChat != null) { secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); if (isCustomTheme) { secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); } else { secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); } secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); secretChatPlaceholder.setPadding(Utilities.dp(16), Utilities.dp(12), Utilities.dp(16), Utilities.dp(12)); View v = contentView.findViewById(R.id.secret_placeholder); v.setVisibility(View.VISIBLE); if (currentEncryptedChat.admin_id == UserConfig.clientUserId) { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.first_name)); } else { secretViewStatusTextView.setText(String.format( getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.last_name)); } } else { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.first_name)); } else { secretViewStatusTextView.setText(String.format( getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.last_name)); } } updateSecretStatus(); } if (isCustomTheme) { progressViewInner.setBackgroundResource(R.drawable.system_loader2); emptyView.setBackgroundResource(R.drawable.system_black); } else { progressViewInner.setBackgroundResource(R.drawable.system_loader1); emptyView.setBackgroundResource(R.drawable.system_blue); } emptyView.setPadding(Utilities.dp(7), Utilities.dp(1), Utilities.dp(7), Utilities.dp(1)); if (currentUser != null && currentUser.id == 333000) { emptyView.setText(R.string.GotAQuestion); } chatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) { if (mActionMode == null) { createMenu(view, false); } return true; } }); chatListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (visibleItemCount > 0) { if (firstVisibleItem <= 4) { if (!endReached && !loading) { if (messagesByDays.size() != 0) { MessagesController.Instance.loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false); } else { MessagesController.Instance.loadMessages(dialog_id, 0, 20, 0, !cacheEndReaced, minDate, classGuid, false, false); } loading = true; } } if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) { if (!unread_end_reached && !loadingForward) { MessagesController.Instance.loadMessages(dialog_id, 0, 20, minMessageId, true, maxDate, classGuid, false, true); loadingForward = true; } } if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) { showPagedownButton(false, true); } } else { showPagedownButton(false, false); } } }); messsageEditText = (EditText) fragmentView.findViewById(R.id.chat_text_edit); sendButton = (ImageButton) fragmentView.findViewById(R.id.chat_send_button); sendButton.setEnabled(false); sendButton.setVisibility(View.INVISIBLE); emojiButton = (ImageView) fragmentView.findViewById(R.id.chat_smile_button); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.GONE); if (currentEncryptedChat == null) { chatListView.setEmptyView(emptyView); } else { chatListView.setEmptyView(secretChatPlaceholder); } } emojiButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (emojiPopup == null) { showEmojiPopup(true); } else { showEmojiPopup(!emojiPopup.isShowing()); } } }); messsageEditText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) { if (keyEvent.getAction() == 1) { showEmojiPopup(false); } return true; } else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { sendMessage(); return true; } return false; } }); messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEND) { sendMessage(); return true; } else if (sendByEnter) { if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { sendMessage(); return true; } } return false; } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { sendMessage(); } }); audioSendButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { startRecording(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { stopRecording(); } return false; } }); pagedownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (unread_end_reached || first_unread_id == 0) { chatListView.setSelectionFromTop(messages.size() - 1, -10000 - chatListView.getPaddingTop()); } else { messages.clear(); messagesByDays.clear(); messagesDict.clear(); progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); maxMessageId = Integer.MAX_VALUE; minMessageId = Integer.MIN_VALUE; maxDate = Integer.MIN_VALUE; minDate = 0; MessagesController.Instance.loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false); loading = true; chatAdapter.notifyDataSetChanged(); } } }); checkSendButton(); messsageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { String message = charSequence.toString().trim(); message = message.replaceAll("\n\n+", "\n\n"); message = message.replaceAll(" +", " "); sendButton.setEnabled(message.length() != 0); checkSendButton(); if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) { int currentTime = ConnectionsManager.Instance.getCurrentTime(); if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime && currentUser.status.was_online < currentTime) { return; } lastTypingTimeSend = System.currentTimeMillis(); MessagesController.Instance.sendTyping(dialog_id, classGuid); } } @Override public void afterTextChanged(Editable editable) { if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') { sendMessage(); } int i = 0; ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class); int j = arrayOfImageSpan.length; while (true) { if (i >= j) { Emoji.replaceEmoji(editable); return; } editable.removeSpan(arrayOfImageSpan[i]); i++; } } }); bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentChat != null) { MessagesController.Instance.deleteDialog(-currentChat.id, 0, false); finishFragment(); } } }); chatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mActionMode != null) { processRowSelect(view); return; } if (!spanClicked(chatListView, view, R.id.chat_message_text)) { createMenu(view, true); } } }); chatListView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e("tmessages", e); } finishFragment(true); } public void onSwipeLeft() { if (swipeOpening) { return; } try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e("tmessages", e); } if (avatarImageView != null) { swipeOpening = true; avatarImageView.performClick(); } } @Override public void onTouchUp(MotionEvent event) { mLastTouch.right = (int) event.getX(); mLastTouch.bottom = (int) event.getY(); } }); emptyView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { finishFragment(true); } public void onSwipeLeft() { if (swipeOpening) { return; } if (avatarImageView != null) { swipeOpening = true; avatarImageView.performClick(); } } }); if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left)) { bottomOverlayChat.setVisibility(View.VISIBLE); } else { bottomOverlayChat.setVisibility(View.GONE); } } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:com.android.launcher3.Launcher.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HOME: return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) { dumpState();/*w w w .j ava 2 s . c o m*/ return true; } break; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HOME: return true; } } return super.dispatchKeyEvent(event); }
From source file:com.android.mms.ui.ComposeMessageActivity.java
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null) { // if shift key is down, then we want to insert the '\n' char in the TextView; // otherwise, the default action is to send the message. if (!event.isShiftPressed() && event.getAction() == KeyEvent.ACTION_DOWN) { if (isPreparedForSending()) { confirmSendMessageIfNeeded(); }/* ww w . java 2 s .c o m*/ return true; } return false; } if (isPreparedForSending()) { confirmSendMessageIfNeeded(); } return true; }
From source file:com.irccloud.android.activity.MainActivity.java
@SuppressLint("NewApi") @SuppressWarnings({ "deprecation", "unchecked" }) @Override//from ww w. ja va 2 s. c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); suggestionsTimer = new Timer("suggestions-timer"); countdownTimer = new Timer("messsage-countdown-timer"); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(screenReceiver, filter); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); if (cloud != null) { setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC)); cloud.recycle(); } } setContentView(R.layout.activity_message); try { setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); } catch (Throwable t) { } suggestionsAdapter = new SuggestionsAdapter(); progressBar = (ProgressBar) findViewById(R.id.progress); errorMsg = (TextView) findViewById(R.id.errorMsg); buffersListView = findViewById(R.id.BuffersList); messageContainer = (LinearLayout) findViewById(R.id.messageContainer); drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); redColor = getResources().getColor(R.color.highlight_red); blueColor = getResources().getColor(R.color.dark_blue); messageTxt = (ActionEditText) findViewById(R.id.messageTxt); messageTxt.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (sendBtn.isEnabled() && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER && messageTxt.getText() != null && messageTxt.getText().length() > 0) { sendBtn.setEnabled(false); new SendTask().execute((Void) null); } else if (keyCode == KeyEvent.KEYCODE_TAB) { if (event.getAction() == KeyEvent.ACTION_DOWN) nextSuggestion(); return true; } return false; } }); messageTxt.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (drawerLayout != null && v == messageTxt && hasFocus) { drawerLayout.closeDrawers(); update_suggestions(false); } else if (!hasFocus) { runOnUiThread(new Runnable() { @Override public void run() { suggestionsContainer.setVisibility(View.INVISIBLE); } }); } } }); messageTxt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (drawerLayout != null) { drawerLayout.closeDrawers(); } } }); messageTxt.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (sendBtn.isEnabled() && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED && actionId == EditorInfo.IME_ACTION_SEND && messageTxt.getText() != null && messageTxt.getText().length() > 0) { sendBtn.setEnabled(false); new SendTask().execute((Void) null); } return true; } }); textWatcher = new TextWatcher() { public void afterTextChanged(Editable s) { Object[] spans = s.getSpans(0, s.length(), Object.class); for (Object o : spans) { if (((s.getSpanFlags(o) & Spanned.SPAN_COMPOSING) != Spanned.SPAN_COMPOSING) && (o.getClass() == StyleSpan.class || o.getClass() == ForegroundColorSpan.class || o.getClass() == BackgroundColorSpan.class || o.getClass() == UnderlineSpan.class || o.getClass() == URLSpan.class)) { s.removeSpan(o); } } if (s.length() > 0 && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED) { sendBtn.setEnabled(true); if (Build.VERSION.SDK_INT >= 11) sendBtn.setAlpha(1); } else { sendBtn.setEnabled(false); if (Build.VERSION.SDK_INT >= 11) sendBtn.setAlpha(0.5f); } String text = s.toString(); if (text.endsWith("\t")) { //Workaround for Swype text = text.substring(0, text.length() - 1); messageTxt.setText(text); nextSuggestion(); } else if (suggestionsContainer != null && suggestionsContainer.getVisibility() == View.VISIBLE) { runOnUiThread(new Runnable() { @Override public void run() { update_suggestions(false); } }); } else { if (suggestionsTimer != null) { if (suggestionsTimerTask != null) suggestionsTimerTask.cancel(); suggestionsTimerTask = new TimerTask() { @Override public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); update_suggestions(false); } }; suggestionsTimer.schedule(suggestionsTimerTask, 250); } } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }; messageTxt.addTextChangedListener(textWatcher); sendBtn = findViewById(R.id.sendBtn); sendBtn.setFocusable(false); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED) new SendTask().execute((Void) null); } }); photoBtn = findViewById(R.id.photoBtn); if (photoBtn != null) { photoBtn.setFocusable(false); photoBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { insertPhoto(); } }); } userListView = findViewById(R.id.usersListFragment); View v = getLayoutInflater().inflate(R.layout.actionbar_messageview, null); v.findViewById(R.id.actionTitleArea).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { show_topic_popup(); } }); if (drawerLayout != null) { if (findViewById(R.id.usersListFragment2) == null) { upDrawable = new DrawerArrowDrawable(this); greyColor = upDrawable.getColor(); ((Toolbar) findViewById(R.id.toolbar)).setNavigationIcon(upDrawable); ((Toolbar) findViewById(R.id.toolbar)).setNavigationContentDescription("Show navigation drawer"); drawerLayout.setDrawerListener(mDrawerListener); if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } } messageTxt.setDrawerLayout(drawerLayout); title = (TextView) v.findViewById(R.id.title); subtitle = (TextView) v.findViewById(R.id.subtitle); key = (ImageView) v.findViewById(R.id.key); getSupportActionBar().setCustomView(v); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); if (savedInstanceState != null && savedInstanceState.containsKey("cid")) { server = ServersDataSource.getInstance().getServer(savedInstanceState.getInt("cid")); buffer = BuffersDataSource.getInstance().getBuffer(savedInstanceState.getInt("bid")); backStack = (ArrayList<Integer>) savedInstanceState.getSerializable("backStack"); } if (savedInstanceState != null && savedInstanceState.containsKey("imagecaptureuri")) imageCaptureURI = Uri.parse(savedInstanceState.getString("imagecaptureuri")); else imageCaptureURI = null; ConfigInstance config = (ConfigInstance) getLastCustomNonConfigurationInstance(); if (config != null) { imgurTask = config.imgurUploadTask; fileUploadTask = config.fileUploadTask; } drawerLayout.setScrimColor(0); drawerLayout.closeDrawers(); getSupportActionBar().setElevation(0); }
From source file:com.cognizant.trumobi.PersonaLauncher.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: // 290661 commented this out to fix bug (Auto lock screen not popping up when back key is pressed from allapps screen) //TruMobiTimerClass.userInteractedStopTimer(); if (!allAppsOpen) { // android.os.Process.killProcess(android.os.Process.myPid()); mWorkspace.dispatchKeyEvent(event); finish();//from ww w . j a v a2 s . co m } mHandleView.updateIcon(); return true; case KeyEvent.KEYCODE_HOME: return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (!event.isCanceled()) { mWorkspace.dispatchKeyEvent(event); if (allAppsOpen) { closeDrawer(); } else { closeFolder(); } if (isPreviewing()) { dismissPreviews(); } if (mIsEditMode) { stopDesktopEdit(); } if (mIsWidgetEditMode) { stopWidgetEdit(); } } return true; case KeyEvent.KEYCODE_HOME: return true; } } return super.dispatchKeyEvent(event); }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { boolean ret = false; if (KeyEvent.ACTION_DOWN == event.getAction()) { ret = onCustomKeyDown(event.getKeyCode(), event); }/*from w w w . j a va 2 s. c o m*/ if (!ret) { ret = super.dispatchKeyEvent(event); } return ret; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Dispatch in the normal way boolean handled = super.dispatchKeyEvent(event); if (!handled) { // If we didn't handle it... final View focused = getFocusedChild(); if (focused != null && event.getAction() == KeyEvent.ACTION_DOWN) { // ... and our focused child didn't handle it // ... give it to ourselves so we can scroll if necessary handled = onKeyDown(event.getKeyCode(), event); }//from w w w .j a va 2 s . co m } return handled; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private boolean handleKeyEvent(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }/*from www . ja v a2 s . c om*/ if (mDataChanged) { layoutChildren(); } boolean handled = false; final int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_UP); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: { if (mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_DOWN); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_DOWN); } break; } case KeyEvent.KEYCODE_DPAD_LEFT: if (!mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_LEFT); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_RIGHT); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: if (!isEnabled()) { return true; } if (isClickable() && isPressed() && mSelectedPosition >= 0 && mAdapter != null && mSelectedPosition < mAdapter.getCount()) { final View child = getChildAt(mSelectedPosition - mFirstPosition); if (child != null) { performItemClick(child, mSelectedPosition, mSelectedRowId); child.setPressed(false); } setPressed(false); return true; } return false; case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: return false; } }
From source file:com.glview.widget.AbsListView.java
/** * Sends a key to the text filter window * * @param keyCode The keycode for the event * @param event The actual key event//ww w . j a v a 2s . c om * * @return True if the text filter handled the event, false otherwise. */ boolean sendToTextFilter(int keyCode, int count, KeyEvent event) { if (!acceptFilter()) { return false; } boolean handled = false; boolean okToSend = true; switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: okToSend = false; break; case KeyEvent.KEYCODE_BACK: okToSend = false; break; case KeyEvent.KEYCODE_SPACE: // Only send spaces once we are filtered okToSend = mFiltered; break; } if (okToSend) { KeyEvent forwardEvent = event; if (forwardEvent.getRepeatCount() > 0) { forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0); } int action = event.getAction(); switch (action) { case KeyEvent.ACTION_DOWN: break; case KeyEvent.ACTION_UP: break; case KeyEvent.ACTION_MULTIPLE: break; } } return handled; }
From source file:jmri.enginedriver.throttle.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { boolean isExternal = false; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { InputDevice idev = getDevice(event.getDeviceId()); if (idev != null && idev.toString() != null && idev.toString().contains("Location: external")) isExternal = true;/*from www .j a v a2 s . c om*/ } if (isExternal) { // if has come from the phone itself, don't try to process it here if (!whichGamePadMode.equals(WHICH_GAMEPAD_MODE_NONE)) { // respond to the gamepad and keyboard inputs only if the preference is set boolean acceptEvent = true; // default to assuming that we will respond to the event int action = event.getAction(); int keyCode = event.getKeyCode(); int repeatCnt = event.getRepeatCount(); int whichThrottle; int whichGamePadIsEventFrom = findWhichGamePadEventIsFrom(event.getDeviceId(), event.getKeyCode()); if ((whichGamePadIsEventFrom > -1) && (whichGamePadIsEventFrom < gamePadDeviceIdsTested.length)) { // the event came from a gamepad if (gamePadDeviceIdsTested[getGamePadIndexFromThrottleNo( whichGamePadIsEventFrom)] != GAMEPAD_GOOD) { //if not, testing for this gamepad is not complete or has failed acceptEvent = false; } } else { acceptEvent = false; } if (acceptEvent) { if ((usingMultiplePads) && (whichGamePadIsEventFrom >= -1)) { // we have multiple gamepads AND the preference is set to make use of them AND the event came for a gamepad if (whichGamePadIsEventFrom >= 0) { whichThrottle = whichGamePadIsEventFrom; } else { GamepadFeedbackSound(true); return (true); } } else { whichThrottle = whichVolume; // work out which throttle the volume keys are currently set to contol... and use that one } boolean isActive = getConsist(whichThrottle).isActive(); if (keyCode != 0) { Log.d("Engine_Driver", "keycode " + keyCode + " action " + action + " repeat " + repeatCnt); } if (action == ACTION_UP) { mGamepadAutoIncrement = false; mGamepadAutoDecrement = false; GamepadFeedbackSoundStop(); } if (keyCode == gamePadKeys[2]) { // DPAD Up Button performButtonAction(5, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[3]) { // DPAD Down Button performButtonAction(7, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[4]) { // DPAD Left Button performButtonAction(8, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[5]) { // DPAD Right Button performButtonAction(6, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[7]) { // ios button performButtonAction(1, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys_Up[8]) { // X button performButtonAction(3, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys_Up[9]) { // Triangle button performButtonAction(2, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys_Up[10]) { // @ button performButtonAction(4, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[6]) { // start button performButtonAction(0, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[11]) { // Left Shoulder button performButtonAction(10, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[12]) { // Left Shoulder button performButtonAction(11, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[13]) { // Left Shoulder button performButtonAction(12, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[14]) { // Left Shoulder button performButtonAction(13, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (keyCode == gamePadKeys[1]) { // Return button // NextThrottle /* if ((action == ACTION_DOWN) && (repeatCnt == 0)) { if (usingMultiplePads && whichGamePadIsEventFrom >= 0) { whichGamePadIsEventFrom = swapToNextAvilableThrottleForGamePad(whichGamePadIsEventFrom, false); } else { setNextActiveThrottle(true); } } */ performButtonAction(9, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } } else { // event is from a gamepad that has not finished testing. Ignore it return (true); // stop processing this key } // for now pass all keystrokes not in gamePadKeys[] to super // if problems occur, we can uncomment the next 2 lines // else if (!((keyCode == KEYCODE_BACK) || (keyCode == KEYCODE_VOLUME_DOWN) || (keyCode == KEYCODE_VOLUME_UP) || (keyCode == KEYCODE_MENU))) // return (true); // swallow all other keystrokes except back, menu and the volume keys } } else if (IS_ESU_MCII) { // Process ESU MCII keys int action = event.getAction(); int keyCode = event.getKeyCode(); int repeatCnt = event.getRepeatCount(); boolean isActive = getConsist(whichVolume).isActive(); if (keyCode != 0) { Log.d("Engine_Driver", "ESU_MCII: keycode " + keyCode + " action " + action + " repeat " + repeatCnt); if (action == ACTION_UP) { esuButtonAutoIncrement = false; esuButtonAutoDecrement = false; } switch (keyCode) { case MobileControl2.KEYCODE_TOP_LEFT: case MobileControl2.KEYCODE_BOTTOM_LEFT: case MobileControl2.KEYCODE_TOP_RIGHT: case MobileControl2.KEYCODE_BOTTOM_RIGHT: performEsuMc2ButtonAction(keyCode, action, isActive, whichVolume, repeatCnt); return true; // stop processing this key default: // Unrecognised key - do nothing Log.d("Engine_Driver", "ESU_MCII: Unrecognised keyCode: " + keyCode); } } } return super.dispatchKeyEvent(event); }