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.abcvoipsip.ui.SipHome.java

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

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && !Compatibility.isCompatible(5)) {
        onBackPressed();//  w w w  . j  av a  2 s .com

    }
    return super.onKeyDown(keyCode, event);
}

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

public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override/*from  ww w.j  av  a2 s  .c o m*/
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0
                        && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.primary_text));
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null,
                    null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon),
                    null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}

From source file:website.openeng.anki.Statistics.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Timber.i("Statistics:: Statistics - onBackPressed()");
        Intent data = new Intent();
        if (getIntent().hasExtra("selectedDeck")) {
            data.putExtra("originalDeck", getIntent().getLongExtra("selectedDeck", 0L));
        }//from   w ww .  j  a  v a2s.c  o m
        setResult(RESULT_CANCELED, data);
        finishWithAnimation(ActivityTransitionAnimation.RIGHT);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Timber.i("Preferences:: onBackPressed()");
        closePreferences();/*from ww w. ja  v  a  2 s .c  o  m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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

/**
 * KeyDown/KeyUp code derived from/* w  w  w  .  j  a va  2  s.  c  o m*/
 * http://developer.android.com/sdk/android-2.0.html (read very bottom of
 * page)
 * <p>
 * The user may tap the back button, but then drag off of the button to
 * avoid a button press
 * 
 * @see android.support.v4.app.FragmentActivity#onKeyDown(int,
 *      android.view.KeyEvent)
 * 
 * 
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        event.startTracking();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
    if (isMenuOpen() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
            && event.getRepeatCount() == 0) {
        closeMenu();/*from w  w  w.j av a  2 s .  c o  m*/
        return true;
    }

    return super.dispatchKeyEventPreIme(event);
}

From source file:com.example.android.mediarouter.player.MainActivity.java

public boolean handleMediaKey(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: {
            Log.d(TAG, "Received Play/Pause event from RemoteControlClient");
            mPaused = !mPaused;/*  w w  w. ja  va  2s.c  om*/
            if (mPaused) {
                mSessionManager.pause();
            } else {
                mSessionManager.resume();
            }
            return true;
        }
        case KeyEvent.KEYCODE_MEDIA_PLAY: {
            Log.d(TAG, "Received Play event from RemoteControlClient");
            if (mPaused) {
                mPaused = false;
                mSessionManager.resume();
            }
            return true;
        }
        case KeyEvent.KEYCODE_MEDIA_PAUSE: {
            Log.d(TAG, "Received Pause event from RemoteControlClient");
            if (!mPaused) {
                mPaused = true;
                mSessionManager.pause();
            }
            return true;
        }
        case KeyEvent.KEYCODE_MEDIA_STOP: {
            Log.d(TAG, "Received Stop event from RemoteControlClient");
            mPaused = false;
            mSessionManager.stop();
            return true;
        }
        default:
            break;
        }
    }
    return false;
}

From source file:com.lt.adamlee.aagame.GameActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == 4 && event.getRepeatCount() == 0) {
        if (GameView.mainpage == 1 && !GameView.bak4) {
            GameView.mainpage = -1;//w ww.  jav a2s .  c om
            //                vimapad.isBottomAdVisible(true);
            //                vimapad.isTopAdVisible(false);
        }
        if (GameView.mainpage == DEFAULT_MAX_SIGN_IN_ATTEMPTS) {
            GameView.mainpage = 1;
            //                vimapad.isBottomAdVisible(true);
            //                vimapad.isTopAdVisible(false);
            //                beginUserInitiatedSignIn();
            //                if (isSignedIn()) {
            //                    submitScoreAndShowLeaderBoard();
            //                }
            saveState();
            GameView.reset();
        }
        if (GameView.mainpage == 4) {
            GameView.mainpage = 1;
            GameView.reset();
        }
        if (GameView.mainpage == 5) {
            GameView.mainpage = 1;
            GameView.reset();
        }
        if (GameView.mainpage == 6) {
            int j;
            GameView.mainpage = DEFAULT_MAX_SIGN_IN_ATTEMPTS;
            //                vimapad.isBottomAdVisible(true);
            //                vimapad.isTopAdVisible(false);
            GameView.circleblink = false;
            GameView.reset();
            GameView.errorcircle = false;
            GameView.linecounter = GameView.NoOfInitialLines - 1;
            for (j = 0; j < GameView.NoOfInitialLines; j++) {
                GameView.blinedraw[j] = true;
            }
            for (j = 0; j < GameView.rotation.length; j++) {
                GameView.rotation[j] = 0.0f;
            }
            for (j = 0; j < GameView.NoOfInitialLines; j++) {
                GameView.rotation[j] = (float) ((j + 1) * (360 / GameView.NoOfInitialLines));
                if (GameView.rotation[j] > 360.0f) {
                    GameView.rotation[j] = GameView.rotation[j] - 360.0f;
                }
            }
        }
        if (GameView.mainpage == 7) {
            GameView.mainpage = 1;
            GameView.reset();
        }
    }
    return true;
}

From source file:com.freecast.LudoCast.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

        Log.d(TAG, "Run in Back Key ");
        onDestroy();//w  w w.j a  va  2s. c  om

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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

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