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.codeskraps.lolo.home.PrefsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onKeyDown");

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
            && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Take care of calling this method on earlier versions of
        // the platform where it doesn't exist.
        Log.d(TAG, "SDK < Eclair");
        onBackPressed();//from  w  w  w  . j a v a2  s  .com
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.skalski.websocketsclient.ActivityMain.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        onBackPressed();/*from  w w w . j ava2s .  c o  m*/
    }
    return true;
}

From source file:com.mobirix.battlefieldcommander.activity.BillingNativeActivity.java

public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
        return mUnityPlayer.onKeyMultiple(event.getKeyCode(), event.getRepeatCount(), event);
    return super.dispatchKeyEvent(event);
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Timber.i("DeckOptions - onBackPressed()");
        closeDeckOptions();/*from  w  ww.  j  a v  a2s. co m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()");
        finish();//from   w  w w  . j  av  a  2 s .c om
        if (AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.tweetlanes.android.core.view.TweetSpotlightActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Intent returnIntent = new Intent();
        if (mStatus != null) {
            returnIntent.putExtra("status", mStatus.toString());
        }//  w  ww. j a  v  a 2  s.c  om
        setResult(RESULT_OK, returnIntent);
        finish();
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:passenger.view.activity.LoginActivity.java

public void showLoadingDialog(String text) {
    myProgressDialog = new MyCarDialog(LoginActivity.this);
    myProgressDialog.show();//from  w  w w .jav  a  2s .  co m
    myProgressDialog.setCancelable(false);
    myProgressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                myProgressDialog.dismiss();
                finish();
            }
            return false;
        }
    });
}

From source file:com.dragedy.playermusic.service.MediaButtonIntentReceiver.java

public static boolean handleIntent(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return false;
        }/* w ww. j  av  a  2  s.c o m*/

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventTime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.ACTION_STOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.ACTION_TOGGLE_PAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.ACTION_SKIP;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.ACTION_REWIND;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.ACTION_PAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.ACTION_PLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventTime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        final NetworkItemsLoader loader = NetworkLibrary.Instance().getStoredLoader(getCurrentTree());
        if (loader != null) {
            loader.interrupt();/*from   w  w  w.  j  a v  a 2 s  .  co m*/
        }
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()");
        finish();/*from   w  w  w . j a v  a  2s .  c om*/
        if (AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}