Example usage for android.view KeyEvent getKeyCode

List of usage examples for android.view KeyEvent getKeyCode

Introduction

In this page you can find the example usage for android.view KeyEvent getKeyCode.

Prototype

public final int getKeyCode() 

Source Link

Document

Retrieve the key code of the key event.

Usage

From source file:com.syncedsynapse.kore2.ui.RemoteActivity.java

/**
 * Override hardware volume keys and send to Kodi
 *//*from w  ww.  j  a v a2s . co  m*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Check whether we should intercept this
    boolean useVolumeKeys = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
            Settings.KEY_PREF_USE_HARDWARE_VOLUME_KEYS, Settings.DEFAULT_PREF_USE_HARDWARE_VOLUME_KEYS);
    if (useVolumeKeys) {
        int action = event.getAction();
        int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                new Application.SetVolume(GlobalType.IncrementDecrement.INCREMENT)
                        .execute(hostManager.getConnection(), null, null);
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                new Application.SetVolume(GlobalType.IncrementDecrement.DECREMENT)
                        .execute(hostManager.getConnection(), null, null);
            }
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LogUtils.v(LOGTAG, "dispatchKeyEvent: %s", keyEvent);

    switch (keyEvent.getKeyCode()) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_POWER:
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) {
            switch (mVolumeBehavior) {
            case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE:
                snooze();//from  w  ww.  j a v  a  2 s . c o m
                break;
            case SettingsActivity.VOLUME_BEHAVIOR_DISMISS:
                dismiss();
                break;
            default:
                break;
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(keyEvent);
    }
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java

/**
 * Trigger the autocomplete on enter on the erkennings- en sollicitatenummer search textviews
 * @param view the autocomplete textview
 * @param actionId the type of action//  w ww .  j  a va 2s .  co  m
 * @param event the type of keyevent
 */
@OnEditorAction({ R.id.search_erkenningsnummer, R.id.search_sollicitatienummer })
public boolean onAutoCompleteEnter(AutoCompleteTextView view, int actionId, KeyEvent event) {
    if (((event != null) && (event.getAction() == KeyEvent.ACTION_DOWN)
            && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
        showDropdown(view);
    }
    return true;
}

From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java

@Override
public final boolean dispatchKeyEvent(final KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            //true????
            return true;
        }//from   w w  w . j a va2  s .  c o m
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.stasbar.knowyourself.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LOGGER.v("dispatchKeyEvent: %s", keyEvent);

    switch (keyEvent.getKeyCode()) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_POWER:
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_HEADSETHOOK:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) {
            switch (mVolumeBehavior) {
            case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE:
                snooze();/*  www.  j av a2 s.  co  m*/
                break;
            case SettingsActivity.VOLUME_BEHAVIOR_DISMISS:
                dismiss();
                break;
            default:
                break;
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(keyEvent);
    }
}

From source file:com.entertailion.android.dial.ServerFinder.java

private ProgressDialog buildProgressDialog(String message, DialogInterface.OnClickListener cancelListener) {
    ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(message);/*from w w w .jav a  2 s  . c  o  m*/
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface dialogInterface, int which, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                finish();
                return true;
            }
            return false;
        }
    });
    dialog.setButton(getString(R.string.finder_cancel), cancelListener);
    return dialog;
}

From source file:com.androidinspain.deskclock.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LOGGER.v("dispatchKeyEvent: %s", keyEvent);

    final int keyCode = keyEvent.getKeyCode();
    switch (keyCode) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_HEADSETHOOK:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled) {
            switch (mVolumeBehavior) {
            case SNOOZE:
                if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                    snooze();//from  w ww  .java  2s .  co m
                }
                return true;
            case DISMISS:
                if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                    dismiss();
                }
                return true;
            }
        }
    }
    return super.dispatchKeyEvent(keyEvent);
}

From source file:net.olejon.mdapp.MedicationActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Intent//from  w w w. j a va  2 s .  c o m
    final Intent intent = getIntent();

    medicationId = intent.getLongExtra("id", 0);

    if (medicationId == 0) {
        mTools.showToast(getString(R.string.medication_could_not_find_medication), 1);

        finish();

        return;
    }

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout
    setContentView(R.layout.activity_medication);

    // View
    mRelativeLayout = (RelativeLayout) findViewById(R.id.medication_inner_layout);

    // Toolbar
    mToolbar = (Toolbar) findViewById(R.id.medication_toolbar);
    mToolbar.setTitle("");

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.medication_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.medication_toolbar_search);

    // View pager
    mViewPager = (ViewPager) findViewById(R.id.medication_pager);

    // Find in text
    mToolbarSearchEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            String find = mToolbarSearchEditText.getText().toString().trim();

            if (find.equals("")) {
                if (mWebView != null)
                    mWebView.clearMatches();
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    if (mWebView != null)
                        mWebView.findAllAsync(find);
                } else {
                    if (mWebView != null) {
                        //noinspection deprecation
                        mWebView.findAll(find);
                    }
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                return true;
            }

            return false;
        }
    });
}

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;// ww w.jav  a 2  s.  com
            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.waz.zclient.ui.cursor.CursorLayout.java

/**
 * EditText callback when user sent text.
 *///from   w w  w  . j  a va2s .com
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEND || (actionId != EditorInfo.IME_ACTION_UNSPECIFIED
            && event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
            && event.getAction() == KeyEvent.ACTION_DOWN)) {

        if (isEditingMessage()) {
            onApproveEditMessage();
            return true;
        }

        String sendText = textView.getText().toString();
        if (TextUtils.isEmpty(sendText)) {
            return false;
        }
        if (cursorCallback != null) {
            cursorCallback.onMessageSubmitted(sendText);
        }
        return true;
    }
    return false;
}