Java Code Examples for android.view.KeyEvent#isCanceled()

The following examples show how to use android.view.KeyEvent#isCanceled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            // Tell the framework to start tracking this event.
            getKeyDispatcherState().startTracking(event, this);
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            getKeyDispatcherState().handleUpEvent(event);
            if (event.isTracking() && !event.isCanceled()) {
                mFindToolbar.deactivate();
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: BottomSheetLayout.java    From bottomsheet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && isSheetShowing()) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            KeyEvent.DispatcherState state = getKeyDispatcherState();
            if (state != null) {
                state.startTracking(event, this);
            }
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            KeyEvent.DispatcherState dispatcherState = getKeyDispatcherState();
            if (dispatcherState != null) {
                dispatcherState.handleUpEvent(event);
            }
            if (isSheetShowing() && event.isTracking() && !event.isCanceled()) {
                if (state == State.EXPANDED && peekOnDismiss) {
                    peekSheet();
                } else {
                    dismissSheet();
                }
                return true;
            }
        }
    }
    return super.onKeyPreIme(keyCode, event);
}
 
Example 3
Source File: UrlBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            // Tell the framework to start tracking this event.
            getKeyDispatcherState().startTracking(event, this);
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            getKeyDispatcherState().handleUpEvent(event);
            if (event.isTracking() && !event.isCanceled()) {
                mUrlBarDelegate.backKeyPressed();
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: AppMenu.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (mPopup == null || mPopup.getListView() == null) return false;

    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            event.startTracking();
            v.getKeyDispatcherState().startTracking(event, this);
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            v.getKeyDispatcherState().handleUpEvent(event);
            if (event.isTracking() && !event.isCanceled()) {
                dismiss();
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: ImageViewTouchBase.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        if (getScale() > 1.0f) {
            // If we're zoomed in, pressing Back jumps out to show the
            // entire image, otherwise Back returns the user to the gallery
            zoomTo(1.0f);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 6
Source File: ImageViewTouchBase.java    From droidddle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        if (getScale() > 1.0f) {
            // If we're zoomed in, pressing Back jumps out to show the
            // entire image, otherwise Back returns the user to the gallery.
            zoomTo(1.0f);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 7
Source File: OPDSActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see android.app.Activity#onKeyUp(int, android.view.KeyEvent)
 */
@Override
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && !event.isCanceled()) {
        final Feed current = getController().adapter.getCurrentFeed();
        if (current == null) {
            finish();
        } else {
            getController().setCurrentFeed(current.parent);
        }
        return true;
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 8
Source File: EmojiAltPhysicalKeyDetector.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public void onKeyUp(@Nonnull final KeyEvent keyEvent) {
    if (DEBUG) {
        Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - considering " + keyEvent);
    }

    final int keyCode = keyEvent.getKeyCode();
    int metaState = keyEvent.getMetaState();
    if (KeyEvent.isModifierKey(keyCode)) {
         // Try restoring meta stat in case the released key was a modifier.
         // I am sure one can come up with scenarios to break this, but it
         // seems to work well in practice.
         metaState |= mMetaState;
    }

    final Pair<Integer, Integer> key = Pair.create(keyCode, metaState);
    if (mKeySet.contains(key)) {
        if (mCanFire) {
            if (!keyEvent.isCanceled()) {
                if (DEBUG) {
                    Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - firing action");
                }
                action();
            } else {
                // This key up event was a part of key combinations and
                // should be ignored.
                if (DEBUG) {
                    Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - canceled, ignoring action");
                }
            }
            mCanFire = false;
        }
    }

    if (mCanFire) {
        if (DEBUG) {
            Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - disabling action");
        }
        mCanFire = false;
    }
}
 
Example 9
Source File: XanderPanel.java    From XanderPanel with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
            && !event.isCanceled() && mCancelable && !mDismissing) {
        dismiss();
        return true;
    }
    return false;
}
 
Example 10
Source File: ImageViewTouchBase.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        if (getScale() > 1.0f) {
            // If we're zoomed in, pressing Back jumps out to show the
            // entire image, otherwise Back returns the user to the gallery
            zoomTo(1.0f);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 11
Source File: ImageViewer.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
/**
 * Resets image on {@literal KeyEvent.KEYCODE_BACK} to normal scale if needed, otherwise - hide the viewer.
 */
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK &&
            event.getAction() == KeyEvent.ACTION_UP &&
            !event.isCanceled()) {
        if (viewer.isScaled()) {
            viewer.resetScale();
        } else {
            dialog.cancel();
        }
    }
    return true;
}
 
Example 12
Source File: ImageViewTouchBase.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        if (getScale() > 1.0f) {
            // If we're zoomed in, pressing Back jumps out to show the
            // entire image, otherwise Back returns the user to the gallery
            zoomTo(1.0f);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 13
Source File: PopupWindow.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
	if (BuildConfig.DEBUG) {
		Log.v("PopupWindow", "--onKey(" + String.valueOf(keyCode) + ')');
	}
	
	switch (keyCode) {
		case KeyEvent.KEYCODE_BACK: {
			switch (event.getAction()) {
				case KeyEvent.ACTION_UP: {
					if (!event.isCanceled()) {
						onBackPressed();
					}
					break;
				}
			}
			return true;
		}
	}
	
	// Delay auto-hiding if set to do so (and we didn't already handle this event).
	if (event.getAction() == KeyEvent.ACTION_DOWN) {
		onUserInteraction();
	}
	
	return false;
}
 
Example 14
Source File: ImageViewTouchBase.java    From styT with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        if (getScale() > 1.0f) {
            // If we're zoomed in, pressing Back jumps out to show the
            // entire image, otherwise Back returns the user to the gallery
            zoomTo(1.0f);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 15
Source File: EmojiAltPhysicalKeyDetector.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public void onKeyUp(@Nonnull final KeyEvent keyEvent) {
    if (DEBUG) {
        Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - considering " + keyEvent);
    }

    final int keyCode = keyEvent.getKeyCode();
    int metaState = keyEvent.getMetaState();
    if (KeyEvent.isModifierKey(keyCode)) {
         // Try restoring meta stat in case the released key was a modifier.
         // I am sure one can come up with scenarios to break this, but it
         // seems to work well in practice.
         metaState |= mMetaState;
    }

    final Pair<Integer, Integer> key = Pair.create(keyCode, metaState);
    if (mKeySet.contains(key)) {
        if (mCanFire) {
            if (!keyEvent.isCanceled()) {
                if (DEBUG) {
                    Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - firing action");
                }
                action();
            } else {
                // This key up event was a part of key combinations and
                // should be ignored.
                if (DEBUG) {
                    Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - canceled, ignoring action");
                }
            }
            mCanFire = false;
        }
    }

    if (mCanFire) {
        if (DEBUG) {
            Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - disabling action");
        }
        mCanFire = false;
    }
}
 
Example 16
Source File: ZoomButtonsController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean onContainerKey(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if (isInterestingKey(keyCode)) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (event.getAction() == KeyEvent.ACTION_DOWN
                    && event.getRepeatCount() == 0) {
                if (mOwnerView != null) {
                    KeyEvent.DispatcherState ds = mOwnerView.getKeyDispatcherState();
                    if (ds != null) {
                        ds.startTracking(event, this);
                    }
                }
                return true;
            } else if (event.getAction() == KeyEvent.ACTION_UP
                    && event.isTracking() && !event.isCanceled()) {
                setVisible(false);
                return true;
            }

        } else {
            dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT);
        }

        // Let the container handle the key
        return false;

    } else {

        ViewRootImpl viewRoot = mOwnerView.getViewRootImpl();
        if (viewRoot != null) {
            viewRoot.dispatchInputEvent(event);
        }

        // We gave the key to the owner, don't let the container handle this key
        return true;
    }
}
 
Example 17
Source File: Dialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * A key was released.
 * <p>
 * Default implementation consumes {@link KeyEvent#KEYCODE_BACK KEYCODE_BACK}
 * and, as of {@link android.os.Build.VERSION_CODES#P P}, {@link KeyEvent#KEYCODE_ESCAPE
 * KEYCODE_ESCAPE} to close the dialog.
 *
 * @see #onKeyDown
 * @see android.view.KeyEvent
 */
@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
            && event.isTracking()
            && !event.isCanceled()) {
        onBackPressed();
        return true;
    }
    return false;
}
 
Example 18
Source File: QImageView.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
		if (getScale() > 1.0f) {
			zoomTo(1.0f);
			return true;
		}
	}
	return super.onKeyUp(keyCode, event);
}
 
Example 19
Source File: ImageViewTouchBase.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        if (getScale() > 1.0f) {
            // If we're zoomed in, pressing Back jumps out to show the
            // entire image, otherwise Back returns the user to the gallery
            zoomTo(1.0f);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 20
Source File: AbstractViewController.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
/**
    * {@inheritDoc}
    *
    * @see org.ebookdroid.ui.viewer.IViewController#dispatchKeyEvent(android.view.KeyEvent)
    */
   @Override
   public final boolean dispatchKeyEvent(final KeyEvent event) {
if (event.isCanceled()) {
    return false;
}

       // Special case to ignore KeyEvent.KEYCODE_VOLUME_UP and KeyEvent.KEYCODE_VOLUME_DOWN
       // if the app setting is disabled
       final int eventKeyCode = event.getKeyCode();
       if (!AppSettings.current().volumeKeyScrolling
           && (eventKeyCode == KeyEvent.KEYCODE_VOLUME_UP
               || eventKeyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
           return false;
       }

       // By default, this is only used to handle actions_verticalConfigScrollUp and
       // actions_verticalConfigScrollDown.
       // The best UX for these actions is to deliver them on key down events only.
       if (event.getAction() == KeyEvent.ACTION_DOWN) {
           final Integer actionId = KeyBindingsManager.getAction(event);
           final ActionEx action = actionId != null ? getOrCreateAction(actionId) : null;
           if (action != null) {
               if (LCTX.isDebugEnabled()) {
                   LCTX.d("Key action: " + action.name + ", " + action.getMethod().toString());
               }
               action.run();
               return true;
           } else {
               if (LCTX.isDebugEnabled()) {
                   LCTX.d("Key action not found: " + event);
               }
           }
       } else if (event.getAction() == KeyEvent.ACTION_UP) {
           final Integer id = KeyBindingsManager.getAction(event);
           if (id != null) {
               // We handled the KeyEvent.ACTION_DOWN, so return true to indicate we are handling
               // the KeyEvent.ACTION_UP as well.
               // Returning false here causes the volume keys to beep when scrolling.
               return true;
           }
       }

       return false;
   }