Search in sources :

Example 26 with KeyEvent

use of android.view.KeyEvent in project platform_frameworks_base by android.

the class ForwardDeleteTest method forwardDelete.

// Sync the state to the TextView and call onKeyDown with KEYCODE_FORWARD_DEL key event.
// Then update the state to the result of TextView.
private void forwardDelete(final EditorState state, int modifiers) {
    mActivity.runOnUiThread(new Runnable() {

        public void run() {
            mTextView.setText(state.mText, BufferType.EDITABLE);
            mTextView.setKeyListener(mKeyListener);
            mTextView.setSelection(state.mSelectionStart, state.mSelectionEnd);
        }
    });
    mInstrumentation.waitForIdleSync();
    assertTrue(mTextView.hasWindowFocus());
    final KeyEvent keyEvent = getKey(KeyEvent.KEYCODE_FORWARD_DEL, modifiers);
    mActivity.runOnUiThread(new Runnable() {

        public void run() {
            mTextView.onKeyDown(keyEvent.getKeyCode(), keyEvent);
        }
    });
    mInstrumentation.waitForIdleSync();
    state.mText = mTextView.getText();
    state.mSelectionStart = mTextView.getSelectionStart();
    state.mSelectionEnd = mTextView.getSelectionEnd();
}
Also used : KeyEvent(android.view.KeyEvent)

Example 27 with KeyEvent

use of android.view.KeyEvent in project httpclient by pixmob.

the class AstroboyMasterConsole method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    // @Inject, @InjectResource, and @InjectExtra injection happens during super.onCreate()
    super.onCreate(savedInstanceState);
    sayText.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            // Have the remoteControl tell Astroboy to say something
            remoteControl.say(textView.getText().toString());
            textView.setText(null);
            return true;
        }
    });
    brushTeethButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            remoteControl.brushTeeth();
        }
    });
    selfDestructButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            // Self destruct the remoteControl
            vibrator.vibrate(2000);
            remoteControl.selfDestruct();
        }
    });
    // Fighting the forces of evil deserves its own activity
    fightEvilButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            startActivity(new Intent(AstroboyMasterConsole.this, FightForcesOfEvilActivity.class));
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) Intent(android.content.Intent) ContentView(roboguice.inject.ContentView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) View(android.view.View)

Example 28 with KeyEvent

use of android.view.KeyEvent in project platform_frameworks_base by android.

the class PhoneWindowManager method dispatchUnhandledKey.

/** {@inheritDoc} */
@Override
public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
    // Note: This method is only called if the initial down was unhandled.
    if (DEBUG_INPUT) {
        Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() + ", flags=" + event.getFlags() + ", keyCode=" + event.getKeyCode() + ", scanCode=" + event.getScanCode() + ", metaState=" + event.getMetaState() + ", repeatCount=" + event.getRepeatCount() + ", policyFlags=" + policyFlags);
    }
    KeyEvent fallbackEvent = null;
    if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        final int keyCode = event.getKeyCode();
        final int metaState = event.getMetaState();
        final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0;
        // Check for fallback actions specified by the key character map.
        final FallbackAction fallbackAction;
        if (initialDown) {
            fallbackAction = kcm.getFallbackAction(keyCode, metaState);
        } else {
            fallbackAction = mFallbackActions.get(keyCode);
        }
        if (fallbackAction != null) {
            if (DEBUG_INPUT) {
                Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode + " metaState=" + Integer.toHexString(fallbackAction.metaState));
            }
            final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
            fallbackEvent = KeyEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), fallbackAction.keyCode, event.getRepeatCount(), fallbackAction.metaState, event.getDeviceId(), event.getScanCode(), flags, event.getSource(), null);
            if (!interceptFallback(win, fallbackEvent, policyFlags)) {
                fallbackEvent.recycle();
                fallbackEvent = null;
            }
            if (initialDown) {
                mFallbackActions.put(keyCode, fallbackAction);
            } else if (event.getAction() == KeyEvent.ACTION_UP) {
                mFallbackActions.remove(keyCode);
                fallbackAction.recycle();
            }
        }
    }
    if (DEBUG_INPUT) {
        if (fallbackEvent == null) {
            Slog.d(TAG, "No fallback.");
        } else {
            Slog.d(TAG, "Performing fallback: " + fallbackEvent);
        }
    }
    return fallbackEvent;
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap) FallbackAction(android.view.KeyCharacterMap.FallbackAction)

Example 29 with KeyEvent

use of android.view.KeyEvent in project androidannotations by androidannotations.

the class KeyEventsActivityTest method keyUpKeyCodeNameFromMethod.

@Test
public void keyUpKeyCodeNameFromMethod() {
    KeyEvent keyEvent = mock(KeyEvent.class);
    int keyCode = KeyEvent.KEYCODE_U;
    activity.onKeyUp(keyCode, keyEvent);
    assertThat(activity.isUKeyUp).isTrue();
}
Also used : KeyEvent(android.view.KeyEvent) Test(org.junit.Test)

Example 30 with KeyEvent

use of android.view.KeyEvent in project androidannotations by androidannotations.

the class KeyEventsActivityTest method multipleArguments.

@Test
public void multipleArguments() {
    KeyEvent keyEvent = mock(KeyEvent.class);
    int keyCode = KeyEvent.KEYCODE_W;
    int count = 1;
    when(keyEvent.getKeyCode()).thenReturn(keyCode);
    activity.onKeyMultiple(keyCode, count, keyEvent);
    assertThat(activity.isWMultiple).isTrue();
    assertThat(activity.isNineMultiple).isFalse();
}
Also used : KeyEvent(android.view.KeyEvent) Test(org.junit.Test)

Aggregations

KeyEvent (android.view.KeyEvent)513 View (android.view.View)145 TextView (android.widget.TextView)109 Intent (android.content.Intent)53 ImageView (android.widget.ImageView)38 DialogInterface (android.content.DialogInterface)36 EditText (android.widget.EditText)36 KeyCharacterMap (android.view.KeyCharacterMap)35 Editable (android.text.Editable)34 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Instrumentation (android.app.Instrumentation)30 OnClickListener (android.view.View.OnClickListener)30 Paint (android.graphics.Paint)27 Button (android.widget.Button)27 TextWatcher (android.text.TextWatcher)24 InputMethodManager (android.view.inputmethod.InputMethodManager)22 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 LayoutInflater (android.view.LayoutInflater)21 Test (org.junit.Test)20