Search in sources :

Example 16 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class KeyUtils method longClick.

/**
     * Simulates a long click via the keyboard.
     * 
     * @param test The test case that is being run. 
     */
public static void longClick(ActivityInstrumentationTestCase test) {
    final Instrumentation inst = test.getInstrumentation();
    inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
    try {
        Thread.sleep((long) (ViewConfiguration.getLongPressTimeout() * 1.5f));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
}
Also used : KeyEvent(android.view.KeyEvent) Instrumentation(android.app.Instrumentation)

Example 17 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class ListScrollListenerTest method testKeyScrolling.

@LargeTest
public void testKeyScrolling() {
    Instrumentation inst = getInstrumentation();
    int firstVisibleItem = mFirstVisibleItem;
    for (int i = 0; i < mVisibleItemCount * 2; i++) {
        inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
    }
    inst.waitForIdleSync();
    assertTrue("Arrow scroll did not happen", mFirstVisibleItem > firstVisibleItem);
    firstVisibleItem = mFirstVisibleItem;
    inst.sendCharacterSync(KeyEvent.KEYCODE_SPACE);
    inst.waitForIdleSync();
    assertTrue("Page scroll did not happen", mFirstVisibleItem > firstVisibleItem);
    firstVisibleItem = mFirstVisibleItem;
    KeyEvent down = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, 0, KeyEvent.META_ALT_ON);
    KeyEvent up = new KeyEvent(0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN, 0, KeyEvent.META_ALT_ON);
    inst.sendKeySync(down);
    inst.sendKeySync(up);
    inst.waitForIdleSync();
    assertTrue("Full scroll did not happen", mFirstVisibleItem > firstVisibleItem);
    assertEquals("Full scroll did not happen", mTotalItemCount, mFirstVisibleItem + mVisibleItemCount);
}
Also used : KeyEvent(android.view.KeyEvent) Instrumentation(android.app.Instrumentation) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 18 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class MediaKeyEventButton method sendMediaKeyEvent.

protected void sendMediaKeyEvent(Context context, int code) {
    long eventtime = SystemClock.uptimeMillis();
    KeyEvent key = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
    dispatchMediaKeyWithWakeLockToAudioService(key);
    dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction(key, KeyEvent.ACTION_UP));
}
Also used : KeyEvent(android.view.KeyEvent)

Example 19 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class PhoneFallbackEventHandler method onKeyDown.

boolean onKeyDown(int keyCode, KeyEvent event) {
    /* ****************************************************************************
         * HOW TO DECIDE WHERE YOUR KEY HANDLING GOES.
         * See the comment in PhoneWindow.onKeyDown
         * ****************************************************************************/
    final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();
    switch(keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_MUTE:
            {
                getAudioManager().handleKeyDown(event, AudioManager.USE_DEFAULT_STREAM_TYPE);
                return true;
            }
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            /* Suppress PLAY/PAUSE toggle when phone is ringing or in-call
                 * to avoid music playback */
            if (getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE) {
                // suppress key event
                return true;
            }
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            {
                handleMediaKeyEvent(event);
                return true;
            }
        case KeyEvent.KEYCODE_CALL:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    // launch the VoiceDialer
                    Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        sendCloseSystemWindows();
                        mContext.startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        startCallActivity();
                    }
                }
                return true;
            }
        case KeyEvent.KEYCODE_CAMERA:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    sendCloseSystemWindows();
                    // Broadcast an intent that the Camera button was longpressed
                    Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
                    intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
                    mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF, null, null, null, 0, null, null);
                }
                return true;
            }
        case KeyEvent.KEYCODE_SEARCH:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    Configuration config = mContext.getResources().getConfiguration();
                    if (config.keyboard == Configuration.KEYBOARD_NOKEYS || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
                        // launch the search activity
                        Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        try {
                            mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                            sendCloseSystemWindows();
                            getSearchManager().stopSearch();
                            mContext.startActivity(intent);
                            // Only clear this if we successfully start the
                            // activity; otherwise we will allow the normal short
                            // press action to be performed.
                            dispatcher.performedLongPress(event);
                            return true;
                        } catch (ActivityNotFoundException e) {
                        // Ignore
                        }
                    }
                }
                break;
            }
    }
    return false;
}
Also used : KeyEvent(android.view.KeyEvent) Configuration(android.content.res.Configuration) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Example 20 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class KeyguardTransportControlView method sendMediaButtonClick.

private void sendMediaButtonClick(int keyCode) {
    if (mClientIntent == null) {
        // Shouldn't be possible because this view should be hidden in this case.
        Log.e(TAG, "sendMediaButtonClick(): No client is currently registered");
        return;
    }
    // use the registered PendingIntent that will be processed by the registered
    //    media button event receiver, which is the component of mClientIntent
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button down: " + e);
        e.printStackTrace();
    }
    keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
    intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button up: " + e);
        e.printStackTrace();
    }
}
Also used : KeyEvent(android.view.KeyEvent) CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

KeyEvent (android.view.KeyEvent)499 View (android.view.View)135 TextView (android.widget.TextView)100 Intent (android.content.Intent)49 DialogInterface (android.content.DialogInterface)36 KeyCharacterMap (android.view.KeyCharacterMap)35 EditText (android.widget.EditText)35 ImageView (android.widget.ImageView)33 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Editable (android.text.Editable)31 Instrumentation (android.app.Instrumentation)30 Paint (android.graphics.Paint)27 OnClickListener (android.view.View.OnClickListener)27 Button (android.widget.Button)26 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 TextWatcher (android.text.TextWatcher)21 LayoutInflater (android.view.LayoutInflater)21 InputMethodManager (android.view.inputmethod.InputMethodManager)20 Test (org.junit.Test)20