Example usage for android.view KeyEvent isCanceled

List of usage examples for android.view KeyEvent isCanceled

Introduction

In this page you can find the example usage for android.view KeyEvent isCanceled.

Prototype

public final boolean isCanceled() 

Source Link

Document

For #ACTION_UP events, indicates that the event has been canceled as per #FLAG_CANCELED .

Usage

From source file:it.mb.whatshare.PatchedDialogFragment.java

/**
 * Returns a builder that will create a dialog that can only be canceled by
 * clicking OK or by pressing back.//from  w  w w. j av a2s .c o  m
 * 
 * <p>
 * Whenever the dialog is dismissed, {@link Activity#finish()} is called on
 * the argument <tt>activity</tt>.
 * 
 * <p>
 * The builder has already the correct theme set (for making it look ok even
 * on wonderful Android pre-v11), so {@link Builder#getContext()} can be
 * used to inflate layouts with.
 * 
 * @param activity
 *            the caller activity
 * @return a builder to be used to create a dialog with
 */
protected Builder getNoUiBuilder(final FragmentActivity activity) {
    context = new ContextThemeWrapper(activity, R.style.DialogTheme);
    // @formatter:off
    return new AlertDialog.Builder(context).setCancelable(false)
            .setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                            && !event.isCanceled()) {
                        dialog.cancel();
                        activity.finish();
                        return true;
                    }
                    return false;
                }
            }).setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.finish();
                }
            });
    // @formatter:on
}

From source file:com.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java

@Override
public boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
    boolean result = true;

    if (event.isTracking() && !event.isCanceled() && !mApp.isLocalAudible()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            MPDControl.run(MPDControl.ACTION_VOLUME_STEP_UP);
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            MPDControl.run(MPDControl.ACTION_VOLUME_STEP_DOWN);
            break;
        default://from   w  w w.  j a  v  a  2  s  . c  om
            result = super.onKeyUp(keyCode, event);
            break;
        }
    } else {
        result = super.onKeyUp(keyCode, event);
    }

    return result;
}

From source file:com.launcher.silverfish.launcher.LauncherActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // Override the functionality of back and home key
    if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) && event.isTracking()
            && !event.isCanceled()) {
        mViewPager.setCurrentItem(1);//from  w  ww.  j a v a 2 s.  c  o m
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.stfalcon.frescoimageviewer.ImageViewer.java

/**
 * Resets image on {@literal KeyEvent.KEYCODE_BACK} to normal scale if needed, otherwise - hide the viewer.
 *///from   ww  w.ja va2s .  c  o m
@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;
}

From source file:com.gigaset.home.Home.java

/**
 * Catch keys to avoid back through HOME in Back Stack
 *///  ww w .  ja  v  a  2s  . c  om
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            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()) {
                // Do BACK behavior.
            }
            return true;
        case KeyEvent.KEYCODE_HOME:
            if (!event.isCanceled()) {
                // Do HOME behavior.
                myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER);
            }
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.holo.fileexplorer.MainActivity.java

/**
 * /*ww w. ja  v a  2  s  .  c o m*/
 */
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
        // *** DO ACTION HERE ***
        if (mViewPager.getFragment(mPager, mPager.getCurrentItem()).backOneLevel()) {
            return true;
        } else {
            new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage("Quit the application?")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // android.os.Debug.stopMethodTracing();
                            finish();
                        }

                    }).setNegativeButton("No", null).show();
        }
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.android.kalite27.ScriptActivity.java

/**
 * Check if the path contains a data and a content folder
 * @param path//from  w w  w . j  a v a  2  s  . c o m
 * @return
 */
private boolean check_directory(String path) {
    File content_file = new File(path + "/content");
    // if the directory doesn't contain data or content folder, alert
    if (!content_file.exists()) {
        new AlertDialog.Builder(this).setTitle("Invalid Directory")
                .setMessage("The selected directory doesn't contain the content folder")
                .setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        isFileBrowserClosed = true;
                        openWebViewIfAllConditionsMeet();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        isFileBrowserClosed = true;
                        openWebViewIfAllConditionsMeet();
                    }
                }).setOnKeyListener(new DialogInterface.OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                                && !event.isCanceled()) {
                            dialog.cancel();
                            isFileBrowserClosed = true;
                            openWebViewIfAllConditionsMeet();
                            return true;
                        }
                        return false;
                    }
                }).show();
        return false;
    } else {
        return true;
    }
}

From source file:su.comp.bk.ui.BkEmuActivity.java

@Override
public void onBackPressed() {
    KeyboardController keyboardController = this.computer.getKeyboardController();
    if (keyboardController.isOnScreenKeyboardVisible()) {
        keyboardController.setOnScreenKeyboardVisibility(false);
    } else {/*from  w w  w .  ja  v  a2s  . c  o m*/
        this.computer.pause();
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.exit_confirm_title).setMessage(R.string.exit_confirm_message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        BkEmuActivity.this.computer.resume();
                    }
                }).setOnKeyListener(new OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                                && !event.isCanceled()) {
                            BkEmuActivity.this.computer.resume();
                        }
                        return false;
                    }
                }).show();
    }
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

@Override
public final boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
    boolean result = true;

    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (event.isTracking() && !event.isCanceled() && !mApp.isLocalAudible()) {
            if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                MPDControl.run(MPDControl.ACTION_VOLUME_STEP_UP);
            } else {
                MPDControl.run(MPDControl.ACTION_VOLUME_STEP_DOWN);
            }/*  w w  w  . ja  v a2  s. c om*/
        }
        break;
    default:
        result = super.onKeyUp(keyCode, event);
        break;
    }

    return result;
}

From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java

/**
 * Get image from photo library.//ww w .j av a2  s  . c om
 * 
 * @param quality
 *            Compression quality hint (0-100: 0=low quality & high
 *            compression, 100=compress of max quality)
 * @param srcType
 *            The album to get image from.
 * @param returnType
 *            Set the type of image to return.
 */
// TODO: Images selected from SDCARD don't display correctly, but from
// CAMERA ALBUM do!
public void getImage(int srcType, int returnType) {

    final int srcTypeFinal = srcType;
    final int returnTypeFinal = returnType;

    String[] choices = { "Upload a Photo", "Upload a Video" };

    AlertDialog.Builder builder = new AlertDialog.Builder(this.cordova.getActivity());
    builder.setItems(choices, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Log.d(LOG_TAG, "Index #" + which + " chosen.");
            Intent intent = new Intent();
            if (which == 0) {
                // set up photo intent
                WsiCameraLauncher.this.mediaType = PICTURE;
                intent.setType("image/*");
            } else if (which == 1) {
                // set up video intent
                WsiCameraLauncher.this.mediaType = VIDEO;
                intent.setType("video/*");
            } else {
                WsiCameraLauncher.this.failPicture("Selection cancelled.");
                return;
            }
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            if (WsiCameraLauncher.this.cordova != null) {
                WsiCameraLauncher.this.cordova.startActivityForResult((CordovaPlugin) WsiCameraLauncher.this,
                        Intent.createChooser(intent, new String("Pick")),
                        (srcTypeFinal + 1) * 16 + returnTypeFinal + 1);
            }
        }
    });
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                    && !event.isCanceled()) {
                dialog.cancel();
                WsiCameraLauncher.this.failPicture("Selection cancelled.");
                return true;
            }
            return false;
        }
    });
    builder.show();
}