Example usage for android.view KeyEvent getRepeatCount

List of usage examples for android.view KeyEvent getRepeatCount

Introduction

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

Prototype

public final int getRepeatCount() 

Source Link

Document

Retrieve the repeat count of the event.

Usage

From source file:Main.java

public static boolean onKeyBackGoHome(Activity activity, int i, KeyEvent keyEvent) {
    if (i != 4 || keyEvent.getRepeatCount() != 0) {
        return false;
    }//from   ww w .j  a  v a 2  s . c o m
    activity.startActivity(
            new Intent().setAction("android.intent.action.MAIN").addCategory("android.intent.category.HOME"));
    return true;
}

From source file:Main.java

public static boolean onKeyBackGoHome(Activity activity, int keyCode, KeyEvent event) {
    if (!(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)) {
        return false; // continue
    }// ww  w  . j  a  va  2 s .c  o m

    activity.startActivity(new Intent().setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
    return true;
}

From source file:Main.java

public static ProgressDialog showProgressDialog(Context context) {
    ProgressDialog myProgressDialog = new ProgressDialog(context);
    myProgressDialog.setMessage("Please wait...");
    myProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    myProgressDialog.show();/*from   w w  w. ja v  a  2 s .co m*/
    myProgressDialog.setCancelable(false);
    myProgressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
                return true;
            }
            return false;
        }

    });
    return myProgressDialog;
}

From source file:Main.java

public static void createNonCancellableAcceptOrCancelDialog(Context context, String title, String message,
        String acceptButtonText, String cancelButtonText, final Runnable onAccept, final Runnable onCancel) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);/*from   w  w  w  .  ja  va  2  s  .  c o m*/
    builder.setTitle(title);
    builder.setMessage(message);
    builder.setInverseBackgroundForced(true);
    builder.setPositiveButton(acceptButtonText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (onAccept != null)
                onAccept.run();
        }
    });

    builder.setNegativeButton(cancelButtonText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (onCancel != null)
                onCancel.run();
        }
    });
    AlertDialog alert = builder.create();
    alert.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
                return true; // Pretend we processed it
            }
            return false; // Any other keys are still processed as normal
        }
    });
    alert.show();
}

From source file:de.androvdr.activities.RecordingsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        getController().action(RecordingController.RECORDING_ACTION_KEY_BACK);
        return true;
    } else/*  w  w  w .  ja  v a  2s .c om*/
        return super.onKeyDown(keyCode, event);
}

From source file:com.ichi2.anki.CramDeckActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Log.i(AnkiDroidApp.TAG, "StudyOptions - onBackPressed()");
        //         if (mCurrentContentView == CONTENT_CONGRATS) {
        //            finishCongrats();
        //         } else {
        //            closeStudyOptions();
        //         }
        closeCramDeckAdder();/*from  w w w.j  av a  2  s.  c  o  m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.seuf.arseuf.arseuf.java

public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (event.getRepeatCount() == 0) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            startActivity(new Intent(this, Preferences.class));
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
            sendRequestToArduino("fwd");
            break; // Cross = FORWARD
        case KeyEvent.KEYCODE_BUTTON_X:
            sendRequestToArduino("back");
            break; // square = BACKWARD
        case KeyEvent.KEYCODE_DPAD_LEFT:
            sendRequestToArduino("tl");
            break; // Left Dpad = turn left
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            sendRequestToArduino("tr");
            break; // Right Dpad = turn right
        case KeyEvent.KEYCODE_BUTTON_Y:
            sendRequestToArduino("play");
            break; // triangle = klaxon
        }/*from  w  w  w  .ja v  a 2s.c o m*/
    }
    return true;
}

From source file:com.mercandalli.android.apps.files.file.text.FileTextActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        this.finish();
        this.overridePendingTransition(R.anim.right_in, R.anim.right_out);
    }//  www.ja  va 2  s.com
    return super.onKeyDown(keyCode, event);
}

From source file:org.mariotaku.twidere.activity.support.ThemedFragmentActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (handleKeyboardShortcutRepeat(mKeyboardShortcutsHandler, keyCode, event.getRepeatCount(), event))
        return true;
    return super.onKeyDown(keyCode, event);
}

From source file:com.mercandalli.android.apps.files.file.image.FileImageActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        supportFinishAfterTransition();//from w  w w .  ja va2s .c o  m
    }
    return super.onKeyDown(keyCode, event);
}