Exemplo n.º 1
0
 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
     if (!event.isTracking()) {
       return true;
     }
     if (!event.isLongPress()) {
       AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
       audio.adjustVolume(
           AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
       return true;
     }
   }
   if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
     if (!event.isTracking()) {
       return true;
     }
     if (!event.isLongPress()) {
       AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
       audio.adjustVolume(
           AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
       return true;
     }
   }
   return false;
 }
Exemplo n.º 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);
 }
 @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);
 }
Exemplo n.º 4
0
 /**
  * A key was released.
  *
  * <p>The default implementation handles KEYCODE_BACK to close the dialog.
  *
  * @see #onKeyDown
  * @see KeyEvent
  */
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
     onBackPressed();
     return true;
   }
   return false;
 }
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
     if (getScale() > 1.0f) {
       zoomTo(1.0f);
       return true;
     }
   }
   return super.onKeyUp(keyCode, event);
 }
 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
     if (getScale() > 1.0f) {
       // If we're zoomed in, pressing Back jumps out to show the
       // entire image, otherwise Back returns the user to the gallery.
       zoomTo(1.0f);
       return true;
     }
   }
   return super.onKeyUp(keyCode, event);
 }
Exemplo n.º 7
0
  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (mPopup == null || mPopup.getListView() == null) return false;

    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
      if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
        event.startTracking();
        v.getKeyDispatcherState().startTracking(event, this);
        return true;
      } else if (event.getAction() == KeyEvent.ACTION_UP) {
        v.getKeyDispatcherState().handleUpEvent(event);
        if (event.isTracking() && !event.isCanceled()) {
          dismiss();
          return true;
        }
      }
    }
    return false;
  }
 public static boolean b(KeyEvent paramKeyEvent) {
   if ((paramKeyEvent.isTracking()) && (!paramKeyEvent.isCanceled())) ;
   for (int i = 1; ; i = 0) return i;
 }
  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;
  }