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:com.quickcar.thuexe.UI.ListPassengerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        if (doubleBackToExitPressedOnce) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);//www.j  a v  a2  s  . co m
        } else {
            Toast.makeText(mContext, getResources().getString(R.string.notice_close_app), Toast.LENGTH_SHORT)
                    .show();
            this.doubleBackToExitPressedOnce = true;
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    doubleBackToExitPressedOnce = false;
                }
            }, 2000);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 1) {
        finish();
    }

    return super.onKeyDown(keyCode, event);
}

From source file:moose.com.ac.ArticleViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        doExitActivity();//from ww  w .ja va  2  s  . c  o m
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.ushahidi.android.app.activities.BaseActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        log("onKeyDown KEYCODE_BACK");
    }/*from  w w  w.  j  av  a2  s .c om*/
    return super.onKeyDown(keyCode, event);
}

From source file:com.hichinaschool.flashcards.anki.Preferences.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()");
        closePreferences();/*from w w  w  . j ava  2  s.c  o  m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:own.projects.lemiroapp.GameModeActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        new AlertDialog.Builder(THIS).setIcon(android.R.drawable.ic_dialog_info).setTitle("Options")
                .setMessage("What do you want to do?")
                .setPositiveButton("Quit", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        new AlertDialog.Builder(THIS).setCancelable(false).setTitle("Quit?")
                                .setMessage("Do you really want to Quit?")
                                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        setResult(RESULT_CANCELED);
                                        gameThread.interrupt();
                                        finish();
                                    }/*ww  w  . j a va2 s .  c o m*/
                                }).setNegativeButton("No", null).show();
                    }
                }).setNegativeButton("Cancel", null)
                .setNeutralButton("New Game", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        new AlertDialog.Builder(THIS).setTitle("New Game?")
                                .setMessage("Do you want to start a new Game?")
                                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        setResult(RESULT_RESTART);
                                        gameThread.interrupt();
                                        finish();
                                    }
                                }).setNegativeButton("No", null).show();
                    }
                }).show();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.hichinaschool.flashcards.anki.Feedback.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        deleteFiles(true, false);/*from   w  ww  . j a  v  a  2 s . c  o m*/
        closeFeedback();
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.CrestronXPanelApp.CrestronXPanelApp.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (event.getRepeatCount() == 0 && specialList.containsKey("sideup")) {
            sendDigitalListMessage(specialList.get("sideup"), 1);
        }/*from   w  w  w .  j a  v a 2s  . c om*/
        return true;
    }
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (event.getRepeatCount() == 0 && specialList.containsKey("sidedown")) {
            sendDigitalListMessage(specialList.get("sidedown"), 1);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.CrestronXPanelApp.CrestronXPanelApp.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (event.getRepeatCount() == 0 && specialList.containsKey("sideup")) {
            sendDigitalListMessage(specialList.get("sideup"), 0);
        }//from ww w.j  a  v  a2  s.  c  om
        return true;
    }
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (event.getRepeatCount() == 0 && specialList.containsKey("sidedown")) {
            sendDigitalListMessage(specialList.get("sidedown"), 0);
        }
        return true;
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        this.finish();
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public void toggleSubMenu() {
    if (popupLayout == null) {
        return;/*from  w  w  w.  ja  v  a  2 s  .c om*/
    }
    if (showMenuRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(showMenuRunnable);
        showMenuRunnable = null;
    }
    if (popupWindow != null && popupWindow.isShowing()) {
        popupWindow.dismiss();
        return;
    }
    if (popupWindow == null) {
        popupWindow = new ActionBarPopupWindow(popupLayout, LayoutHelper.WRAP_CONTENT,
                LayoutHelper.WRAP_CONTENT);
        if (Build.VERSION.SDK_INT >= 19) {
            popupWindow.setAnimationStyle(0);
        } else {
            popupWindow.setAnimationStyle(R.style.PopupAnimation);
        }
        popupWindow.setOutsideTouchable(true);
        popupWindow.setClippingEnabled(true);
        popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
        popupLayout.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST),
                MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST));
        popupWindow.getContentView().setFocusableInTouchMode(true);
        popupWindow.getContentView().setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0
                        && event.getAction() == KeyEvent.ACTION_UP && popupWindow != null
                        && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                    return true;
                }
                return false;
            }
        });
    }
    processedPopupClick = false;
    popupWindow.setFocusable(true);
    if (popupLayout.getMeasuredWidth() == 0) {
        updateOrShowPopup(true, true);
    } else {
        updateOrShowPopup(true, false);
    }
    popupWindow.startAnimation();
}

From source file:com.jecelyin.editor.v2.ui.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        if (mDrawerLayout != null) {
            if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
                mDrawerLayout.closeDrawer(Gravity.LEFT);
                return true;
            }/*from  w  ww  . j  a  va  2 s  .  c  om*/
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
                return true;
            }
        }
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            UIUtils.toast(getContext(), R.string.press_again_will_exit);
            mExitTime = System.currentTimeMillis();
            return true;
        } else {
            return tabManager == null || tabManager.closeAllTabAndExitApp();
        }
    }
    return super.onKeyDown(keyCode, event);
}