Android Open Source - nxt-remote-controller Ripple View






From Project

Back to project page nxt-remote-controller.

License

The source code is released under:

MIT License

If you think the Android project nxt-remote-controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gc.materialdesign.views;
/*from  w ww  . j a v a2s.  c  om*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;

public abstract class RippleView extends CustomView{
  
  protected boolean settedRippleColor = false;
  
  protected int rippleSize = 3;//???????????????????
  protected Integer rippleColor = null;//the color of ripple
  protected float rippleSpeed;//the speed of ripple translate
  
  protected OnClickListener onClickListener;
  protected boolean clickAfterRipple = true;//view is click until the ripple is end
  
  public RippleView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setAttributes(attrs);
  }
  
  // Set atributtes of XML to View
  @Override
  protected void setAttributes(AttributeSet attrs) {
    super.setAttributes(attrs);
    setRippleAttributes(attrs);
  }
  
  protected void setRippleAttributes(AttributeSet attrs) {
    /**
     * ????????????
     * Set Ripple Color
     * Color by resource
     */
    int color = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"rippleColor",-1);
    if(color != -1){
      rippleColor = getResources().getColor(color);
      settedRippleColor = true;
    }else{
      // Color by hexadecimal
      int rColor = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);// 16?????
      if(rColor != -1 && !isInEditMode()) {
        rippleColor = rColor;
        settedRippleColor = true;
      }
    }
    
    /**
     * ??????????? 
     * init Ripple speed
     */
    rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed);
    
    /**
     * ?????????
     */
    clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple);
  }
  
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    // super.onInterceptTouchEvent(ev);
    return true;
  }
  
  // ripple position
  protected float x = -1;
  protected float y = -1;
  protected float radius = -1;
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (isEnabled()) {
      isLastTouch = true;
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        radius = getHeight() / rippleSize;
        x = event.getX();
        y = event.getY();
      } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        radius = getHeight() / rippleSize;
        x = event.getX();
        y = event.getY();
        if (!((event.getX() <= getWidth() && event.getX() >= 0) && 
            (event.getY() <= getHeight() && event.getY() >= 0))) {
          isLastTouch = false;
          x = -1;
          y = -1;
        }
      } else if (event.getAction() == MotionEvent.ACTION_UP) {
        if ((event.getX() <= getWidth() && event.getX() >= 0)
            && (event.getY() <= getHeight() && event.getY() >= 0)) {
          radius++;
        } else {
          isLastTouch = false;
          x = -1;
          y = -1;
        }
        if (clickAfterRipple == false && onClickListener != null) {
          onClickListener.onClick(this);
        }
      }
    }
    return true;
  }
  
  public Bitmap makeCircleFromBitmap(Bitmap output) {
    Canvas canvas = new Canvas(output);
    canvas.drawARGB(0, 0, 0, 0);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    if (rippleColor == null) {
      paint.setColor(makePressColor(255));
    }else {
      paint.setColor(rippleColor);
    }
    canvas.drawCircle(x, y, radius, paint);
    if (radius > getHeight() / rippleSize)
      radius += rippleSpeed;
    if (radius >= getWidth()) {
      x = -1;
      y = -1;
      radius = getHeight() / rippleSize;
      if(clickAfterRipple == true && onClickListener != null)
        onClickListener.onClick(this);
    }
    return output;
  }
  
  @Override
  protected void onFocusChanged(boolean gainFocus, int direction,
      Rect previouslyFocusedRect) {
    if (!gainFocus) {
      x = -1;
      y = -1;
    }
  }
  
  
  @Override
  public void setOnClickListener(OnClickListener l) {
    onClickListener = l;
  }
  
  /**
   * set and get ripple color
   * @param color
   */
  public void setRippleColor(int color) {
    rippleColor = color;
    settedRippleColor = true;
  }
  
  public int getRippleColor() {
    if (rippleColor != null) {
      return rippleColor;
    }else {
      return makePressColor(255);
    }
  }
  
  /**
   * set and get ripple speed
   * @param speed
   */
  public void setRippleSpeed(float speed) {
    rippleSpeed = speed;
  }
  
  public float getRippleSpeed() {
    return rippleSpeed;
  }
  
  /**
   * ?????????????????????????????????????
   * @param clickAfterRipple
   */
  public void setClickAfterRipple(boolean clickAfterRipple) {
    this.clickAfterRipple = clickAfterRipple;
  }
  
  public boolean getClickAfterRipple() {
    return clickAfterRipple;
  }

}




Java Source Code List

.OldPadControllerFragment.java
com.andexert.library.ApplicationTest.java
com.andexert.library.RippleView.java
com.andexert.rippleeffect.ApplicationTest.java
com.andexert.rippleeffect.CustomAdapter.java
com.andexert.rippleeffect.MainActivity.java
com.andexert.rippleeffect.OnTapListener.java
com.gc.materialdesign.utils.Utils.java
com.gc.materialdesign.views.ButtonFlat.java
com.gc.materialdesign.views.ButtonFloatSmall.java
com.gc.materialdesign.views.ButtonFloat.java
com.gc.materialdesign.views.ButtonIcon.java
com.gc.materialdesign.views.ButtonRectangle.java
com.gc.materialdesign.views.Button.java
com.gc.materialdesign.views.Card.java
com.gc.materialdesign.views.CheckBox.java
com.gc.materialdesign.views.CustomView.java
com.gc.materialdesign.views.LayoutRipple.java
com.gc.materialdesign.views.ProgressBarCircularIndeterminate.java
com.gc.materialdesign.views.ProgressBarDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminate.java
com.gc.materialdesign.views.RippleView.java
com.gc.materialdesign.views.ScrollView.java
com.gc.materialdesign.views.Slider.java
com.gc.materialdesign.views.Switch.java
com.gc.materialdesign.widgets.ColorSelector.java
com.gc.materialdesign.widgets.Dialog.java
com.gc.materialdesign.widgets.SnackBar.java
git.egatuts.nxtremotecontroller.ApplicationTest.java
git.egatuts.nxtremotecontroller.GlobalUtils.java
git.egatuts.nxtremotecontroller.activity.ActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.BaseActivity.java
git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
git.egatuts.nxtremotecontroller.activity.DefaultActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.MainActivity.java
git.egatuts.nxtremotecontroller.activity.SettingsActivity.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothConstants.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils.java
git.egatuts.nxtremotecontroller.bluetooth.NXTConnector.java
git.egatuts.nxtremotecontroller.device.PairedDeviceAdapter.java
git.egatuts.nxtremotecontroller.device.PairedDeviceItemClickListener.java
git.egatuts.nxtremotecontroller.device.PairedDeviceViewHolder.java
git.egatuts.nxtremotecontroller.device.PairedDevice.java
git.egatuts.nxtremotecontroller.exception.SocketCreationException.java
git.egatuts.nxtremotecontroller.fragment.ActivityBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BluetoothFragment.java
git.egatuts.nxtremotecontroller.fragment.ControllerBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.DefaultFragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.FragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.HomeFragment.java
git.egatuts.nxtremotecontroller.fragment.LocalControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.ScanFragment.java
git.egatuts.nxtremotecontroller.fragment.SettingsFragment.java
git.egatuts.nxtremotecontroller.listener.AnimationEndListener.java
git.egatuts.nxtremotecontroller.listener.AppKillerListener.java
git.egatuts.nxtremotecontroller.listener.BaseListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothDiscoveryListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothEnableListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothPairingListener.java
git.egatuts.nxtremotecontroller.navigation.DrawerItemViewHolder.java
git.egatuts.nxtremotecontroller.navigation.DrawerItem.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerAdapter.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerCallback.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerFragment.java
git.egatuts.nxtremotecontroller.preference.PreferencesUtils.java
git.egatuts.nxtremotecontroller.receiver.AppKillerReceiver.java
git.egatuts.nxtremotecontroller.receiver.BaseReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothDiscoveryReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothEnableReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothPairingReceiver.java
git.egatuts.nxtremotecontroller.thread.BaseThread.java
git.egatuts.nxtremotecontroller.thread.ConnectThread.java
git.egatuts.nxtremotecontroller.thread.ConnectedThread.java
git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.BaseProgressDialog.java
git.egatuts.nxtremotecontroller.views.JoystickView.java
git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog.java