Android Open Source - Material Ripple Manager






From Project

Back to project page Material.

License

The source code is released under:

Apache License

If you think the Android project Material 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.rey.material.view;
/*from   w  w w  . j  av  a 2 s.c o  m*/
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.rey.material.R;
import com.rey.material.drawable.RippleDrawable;
import com.rey.material.drawable.ToolbarRippleDrawable;

public final class RippleManager implements View.OnClickListener, Runnable{

  private View.OnClickListener mClickListener;
  private boolean mDelayClick = false;
  private View mView;  
    
  public RippleManager(){}
  
  @SuppressWarnings("deprecation")
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  public void onCreate(View v, Context context, AttributeSet attrs, int defStyle){
    mView = v;
    
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RippleView, 0, defStyle);
    int resId = a.getResourceId(R.styleable.RippleView_ripple, 0);    
    mDelayClick = a.getBoolean(R.styleable.RippleView_delayClick, mDelayClick);
    a.recycle();
    
    if(resId != 0){
      if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        mView.setBackground(new RippleDrawable.Builder(context, attrs, resId).build());
      else
        mView.setBackgroundDrawable(new RippleDrawable.Builder(context, attrs, resId).build());
    }    
  }
  
  public boolean isDelayClick(){
    return mDelayClick;
  }
  
  public void setDelayClick(boolean delay){
    mDelayClick = delay;
  }
  
  public void setOnClickListener(View.OnClickListener l) {
    mClickListener = l;
  }
    
  public boolean onTouchEvent(MotionEvent event){
    Drawable background = mView.getBackground();
        return background instanceof RippleDrawable && ((RippleDrawable) background).onTouch(mView, event);
    }
  
  @Override
  public void onClick(View v) {
    Drawable background = mView.getBackground();
    long delay = 0;
            
    if(background instanceof RippleDrawable)
      delay = ((RippleDrawable)background).getClickDelayTime(mDelayClick);
    else if(background instanceof ToolbarRippleDrawable)
      delay = ((ToolbarRippleDrawable)background).getClickDelayTime(mDelayClick);
      
    if(delay > 0)    
      mView.getHandler().postDelayed(this, delay);
    else
      run();
  }
    
  @Override
    public void run() {
      if(mClickListener != null)
        mClickListener.onClick(mView);
    }

  public static void cancelRipple(View v){
    Drawable background = v.getBackground();
    if(background instanceof RippleDrawable)
      ((RippleDrawable)background).cancel();
    else if(background instanceof ToolbarRippleDrawable)
      ((ToolbarRippleDrawable)background).cancel();
    
    if(v instanceof ViewGroup){
      ViewGroup vg = (ViewGroup)v;
      for(int i = 0, count = vg.getChildCount(); i < count; i++)
        RippleManager.cancelRipple(vg.getChildAt(i));
    }
  }
  
}




Java Source Code List

com.rey.material.ApplicationTest.java
com.rey.material.demo.ButtonFragment.java
com.rey.material.demo.MainActivity.java
com.rey.material.demo.ProgressFragment.java
com.rey.material.demo.SnackbarFragment.java
com.rey.material.demo.SwitchesFragment.java
com.rey.material.demo.TextfieldFragment.java
com.rey.material.drawable.ArrowDrawable.java
com.rey.material.drawable.BlankDrawable.java
com.rey.material.drawable.CheckBoxDrawable.java
com.rey.material.drawable.CircularProgressDrawable.java
com.rey.material.drawable.DividerDrawable.java
com.rey.material.drawable.LineMorphingDrawable.java
com.rey.material.drawable.LinearProgressDrawable.java
com.rey.material.drawable.NavigationDrawerDrawable.java
com.rey.material.drawable.RadioButtonDrawable.java
com.rey.material.drawable.RevealDrawable.java
com.rey.material.drawable.RippleDrawable.java
com.rey.material.drawable.ToolbarRippleDrawable.java
com.rey.material.util.ColorUtil.java
com.rey.material.util.ThemeUtil.java
com.rey.material.util.ViewUtil.java
com.rey.material.view.Button.java
com.rey.material.view.CheckBox.java
com.rey.material.view.CheckedTextView.java
com.rey.material.view.CompoundButton.java
com.rey.material.view.EditText.java
com.rey.material.view.FloatingActionButton.java
com.rey.material.view.ListPopupWindow.java
com.rey.material.view.ListView.java
com.rey.material.view.PopupWindow.java
com.rey.material.view.ProgressView.java
com.rey.material.view.RadioButton.java
com.rey.material.view.RippleManager.java
com.rey.material.view.SnackBar.java
com.rey.material.view.Spinner.java
com.rey.material.view.Switch.java
com.rey.material.view.TabPageIndicator.java
com.rey.material.view.TextView.java