@TargetApi(Build.VERSION_CODES.LOLLIPOP)
 void onActionUp() {
   if (mBackgroundDrawable instanceof StateListDrawable) {
     StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
     drawable.setState(new int[] {android.R.attr.state_enabled});
   } else if (Util.hasLollipop()) {
     RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
     ripple.setState(new int[] {android.R.attr.state_enabled});
     ripple.setHotspot(calculateCenterX(), calculateCenterY());
     ripple.setVisible(true, true);
   }
 }
 private void updateRippleSize(int width, int height) {
   // center the touch feedback on the center of the icon, and dial it down a bit
   final int cx = width / 2;
   final int cy = height / 2;
   final int rad = (int) (mIcon.getHeight() * .85f);
   mRipple.setHotspotBounds(cx - rad, cy - rad, cx + rad, cy + rad);
 }
Пример #3
0
  private void startRipple() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      final CoordinatorLayout coordinatorLayout =
          (CoordinatorLayout) findViewById(R.id.coordinator_layout);
      Drawable d = coordinatorLayout.getBackground();
      final RippleDrawable rippleDrawable = (RippleDrawable) d;
      rippleDrawable.setHotspot(
          mReset.getX() + mReset.getWidth() / 2, mReset.getY() + mReset.getHeight() / 2);
      rippleDrawable.setState(
          new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled});
      coordinatorLayout.getBackground().setState(new int[] {});
    }

    mReset.hide();
    mElapsedTime = 0;
    setTime();
  }