@Override
 public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && isSheetShowing()) {
     if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
       KeyEvent.DispatcherState state = getKeyDispatcherState();
       if (state != null) {
         state.startTracking(event, this);
       }
       return true;
     } else if (event.getAction() == KeyEvent.ACTION_UP) {
       KeyEvent.DispatcherState dispatcherState = getKeyDispatcherState();
       if (dispatcherState != null) {
         dispatcherState.handleUpEvent(event);
       }
       if (isSheetShowing() && event.isTracking() && !event.isCanceled()) {
         if (state == State.EXPANDED && peekOnDismiss) {
           peekSheet();
         } else {
           dismissSheet();
         }
         return true;
       }
     }
   }
   return super.onKeyPreIme(keyCode, event);
 }
Пример #2
0
 @Override
 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
     // special case for the back key, we do not even try to send it
     // to the drop down list but instead, consume it immediately
     if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
       KeyEvent.DispatcherState state = getKeyDispatcherState();
       if (state != null) {
         state.startTracking(event, this);
       }
       return true;
     } else if (event.getAction() == KeyEvent.ACTION_UP) {
       KeyEvent.DispatcherState state = getKeyDispatcherState();
       if (state != null) {
         state.handleUpEvent(event);
       }
       if (event.isTracking() && !event.isCanceled()) {
         mSearchView.clearFocus();
         mSearchView.setImeVisibility(false);
         return true;
       }
     }
   }
   return super.onKeyPreIme(keyCode, event);
 }
Пример #3
0
 public boolean onKeyPreIme(int i1, KeyEvent keyevent)
 {
     if (i1 == 4)
     {
         if (keyevent.getAction() == 0 && keyevent.getRepeatCount() == 0)
         {
             android.view.KeyEvent.DispatcherState dispatcherstate = getKeyDispatcherState();
             if (dispatcherstate != null)
             {
                 dispatcherstate.startTracking(keyevent, this);
             }
             return true;
         }
         if (keyevent.getAction() == 1)
         {
             android.view.KeyEvent.DispatcherState dispatcherstate1 = getKeyDispatcherState();
             if (dispatcherstate1 != null)
             {
                 dispatcherstate1.handleUpEvent(keyevent);
             }
             if (keyevent.isTracking() && !keyevent.isCanceled())
             {
                 b.clearFocus();
                 android.support.v7.widget.SearchView.a(b, false);
                 return true;
             }
         }
     }
     return super.onKeyPreIme(i1, keyevent);
 }
Пример #4
0
  @Override
  public boolean dispatchKeyEventPreIme(KeyEvent event) {
    Log.d(TAG, "dispatchKeyEventPreIme(" + event + ")");
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
      KeyEvent.DispatcherState state = getKeyDispatcherState();
      if (state != null) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
          state.startTracking(event, this);
          return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP
            && !event.isCanceled()
            && state.isTracking(event)) {
          //                    mSearchActivity.onBackPressed();
          return true;
        }
      }
    }

    return super.dispatchKeyEventPreIme(event);
  }
Пример #5
0
  /**
   * Overrides the handling of the back key to move back to the previous sources or dismiss the
   * search dialog, instead of dismissing the input method.
   */
  @Override
  public boolean dispatchKeyEventPreIme(KeyEvent event) {

    Log4Util.d(CCPHelper.DEMO_TAG, "dispatchKeyEventPreIme(" + event + ")");
    if (mGroupActivity != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
      KeyEvent.DispatcherState state = getKeyDispatcherState();
      if (state != null) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
          state.startTracking(event, this);
          return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP
            && !event.isCanceled()
            && state.isTracking(event)) {
          mGroupActivity.onKeyDown(event.getKeyCode(), event);
          return true;
        }
      }
    }

    return super.dispatchKeyEventPreIme(event);
  }
  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:
        {
          MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false);
          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) {
          return true; // suppress key event
        }
      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:
      case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
        {
          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);
            if (isUserSetupComplete()) {
              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();
              }
            } else {
              Log.i(TAG, "Not starting call activity because user " + "setup is in progress.");
            }
          }
          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);
            if (isUserSetupComplete()) {
              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);
            } else {
              Log.i(
                  TAG, "Not dispatching CAMERA long press because user " + "setup is in progress.");
            }
          }
          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) {
              if (isUserSetupComplete()) {
                // 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
                }
              } else {
                Log.i(
                    TAG,
                    "Not dispatching SEARCH long press because user " + "setup is in progress.");
              }
            }
          }
          break;
        }
    }
    return false;
  }
  boolean onKeyUp(int keyCode, KeyEvent event) {
    if (DEBUG) {
      Log.d(TAG, "up " + keyCode);
    }
    final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();
    if (dispatcher != null) {
      dispatcher.handleUpEvent(event);
    }

    switch (keyCode) {
      case KeyEvent.KEYCODE_VOLUME_UP:
      case KeyEvent.KEYCODE_VOLUME_DOWN:
      case KeyEvent.KEYCODE_VOLUME_MUTE:
        {
          if (!event.isCanceled()) {
            MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false);
          }
          return true;
        }

      case KeyEvent.KEYCODE_HEADSETHOOK:
      case KeyEvent.KEYCODE_MUTE:
      case KeyEvent.KEYCODE_MEDIA_PLAY:
      case KeyEvent.KEYCODE_MEDIA_PAUSE:
      case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
      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:
      case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
        {
          handleMediaKeyEvent(event);
          return true;
        }

      case KeyEvent.KEYCODE_CAMERA:
        {
          if (getKeyguardManager().inKeyguardRestrictedInputMode()) {
            break;
          }
          if (event.isTracking() && !event.isCanceled()) {
            // Add short press behavior here if desired
          }
          return true;
        }

      case KeyEvent.KEYCODE_CALL:
        {
          if (getKeyguardManager().inKeyguardRestrictedInputMode()) {
            break;
          }
          if (event.isTracking() && !event.isCanceled()) {
            if (isUserSetupComplete()) {
              startCallActivity();
            } else {
              Log.i(TAG, "Not starting call activity because user " + "setup is in progress.");
            }
          }
          return true;
        }
    }
    return false;
  }