diff --git a/README.md b/README.md index c16e716..97def52 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ You can change several attributes in the XML file, you have to remove "rv_" if y * app:rv_framerate [integer def:10] --> Frame rate of the ripple animation * app:rv_rippleDuration [integer def:400] --> Duration of the ripple animation * app:rv_ripplePadding [dimension def:0] --> Add a padding to the ripple +* app:rv_rippleDelayClick [boolean def:false] --> "true" means onLick event will be invoked after animation. * app:rv_color [color def:@android:color/white] --> Color of the ripple * app:rv_centered [boolean def:false] --> Center ripple in the child view * app:rv_type [enum (simpleRipple, doubleRipple) def:simpleRipple] --> Simple or double ripple diff --git a/build.gradle b/build.gradle index 6e050ab..805db68 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:2.0.+' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -22,3 +22,8 @@ allprojects { jcenter() } } + +task clean(type: Delete) { + delete rootProject.buildDir +} + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7ab78aa..c6f72ed 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/library/build.gradle b/library/build.gradle index cf42a06..d1384ff 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 22 - buildToolsVersion "22.0.1" + compileSdkVersion 23 + buildToolsVersion "23.0.2" defaultConfig { minSdkVersion 9 - targetSdkVersion 22 + targetSdkVersion 23 versionCode 9 versionName "1.3" } @@ -23,7 +23,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-annotations:22.0.0' + compile 'com.android.support:support-annotations:23.1.1' } if (hasProperty("VERSION_NAME")) diff --git a/library/src/main/java/com/andexert/library/RippleView.java b/library/src/main/java/com/andexert/library/RippleView.java index dc18d44..befb656 100644 --- a/library/src/main/java/com/andexert/library/RippleView.java +++ b/library/src/main/java/com/andexert/library/RippleView.java @@ -77,6 +77,7 @@ public class RippleView extends RelativeLayout { private Bitmap originBitmap; private int rippleColor; private int ripplePadding; + private boolean rippleDelayClick; private GestureDetector gestureDetector; private final Runnable runnable = new Runnable() { @Override @@ -105,7 +106,7 @@ public RippleView(Context context, AttributeSet attrs, int defStyle) { * Method that initializes all fields and sets listeners * * @param context Context used to create this view - * @param attrs Attribute used to initialize fields + * @param attrs Attribute used to initialize fields */ private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) @@ -123,6 +124,7 @@ private void init(final Context context, final AttributeSet attrs) { canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); + rippleDelayClick = typedArray.getBoolean(R.styleable.RippleView_rv_rippleDelayClick, true); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); @@ -136,7 +138,9 @@ private void init(final Context context, final AttributeSet attrs) { public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); - sendClickEvent(true); + if (!rippleDelayClick) { + sendClickEvent(true); + } } @Override @@ -163,9 +167,18 @@ public void draw(Canvas canvas) { timer = 0; durationEmpty = -1; timerEmpty = 0; - canvas.restore(); + try { + canvas.restore(); + }catch(Exception e){ + e.printStackTrace(); + } invalidate(); - if (onCompletionListener != null) onCompletionListener.onComplete(this); + if (rippleDelayClick) { + sendClickEvent(false); + } + if (onCompletionListener != null) { + onCompletionListener.onComplete(this); + } return; } else canvasHandler.postDelayed(runnable, frameRate); @@ -195,8 +208,7 @@ public void draw(Canvas canvas) { paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timerEmpty * frameRate) / (durationEmpty))))); else paint.setAlpha(rippleAlpha); - } - else + } else paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timer * frameRate) / rippleDuration)))); timer++; @@ -273,9 +285,11 @@ private void createAnimation(final float x, final float y) { public boolean onTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { animateRipple(event); - sendClickEvent(false); + if (!rippleDelayClick) { + sendClickEvent(false); + } } - return super.onTouchEvent(event); + return rippleDelayClick ? true : super.onTouchEvent(event); } @Override @@ -301,6 +315,8 @@ private void sendClickEvent(final Boolean isLongClick) { if (adapterView.getOnItemClickListener() != null) adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id); } + } else { + performClick(); } } @@ -308,7 +324,7 @@ private Bitmap getCircleBitmap(final int radius) { final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); - final Rect rect = new Rect((int)(x - radius), (int)(y - radius), (int)(x + radius), (int)(y + radius)); + final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius)); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); @@ -326,16 +342,23 @@ private Bitmap getCircleBitmap(final int radius) { * @param rippleColor New color resource */ @ColorRes - public void setRippleColor(int rippleColor) { - this.rippleColor = getResources().getColor(rippleColor); - } + public void setRippleColor(int rippleColor) { + this.rippleColor = getResources().getColor(rippleColor); + } - public int getRippleColor() { - return rippleColor; - } + public int getRippleColor() { + return rippleColor; + } + + public boolean isRippleDelayClick() { + return rippleDelayClick; + } + + public void setRippleDelayClick(boolean rippleDelayClick) { + this.rippleDelayClick = rippleDelayClick; + } - public RippleType getRippleType() - { + public RippleType getRippleType() { return RippleType.values()[rippleType]; } @@ -344,13 +367,11 @@ public RippleType getRippleType() * * @param rippleType New Ripple type for next animation */ - public void setRippleType(final RippleType rippleType) - { + public void setRippleType(final RippleType rippleType) { this.rippleType = rippleType.ordinal(); } - public Boolean isCentered() - { + public Boolean isCentered() { return isCentered; } @@ -359,13 +380,11 @@ public Boolean isCentered() * * @param isCentered */ - public void setCentered(final Boolean isCentered) - { + public void setCentered(final Boolean isCentered) { this.isCentered = isCentered; } - public int getRipplePadding() - { + public int getRipplePadding() { return ripplePadding; } @@ -374,13 +393,11 @@ public int getRipplePadding() * * @param ripplePadding New Ripple padding in pixel, default is 0px */ - public void setRipplePadding(int ripplePadding) - { + public void setRipplePadding(int ripplePadding) { this.ripplePadding = ripplePadding; } - public Boolean isZooming() - { + public Boolean isZooming() { return hasToZoom; } @@ -389,13 +406,11 @@ public Boolean isZooming() * * @param hasToZoom Do the child views have to zoom ? default is False */ - public void setZooming(Boolean hasToZoom) - { + public void setZooming(Boolean hasToZoom) { this.hasToZoom = hasToZoom; } - public float getZoomScale() - { + public float getZoomScale() { return zoomScale; } @@ -404,13 +419,11 @@ public float getZoomScale() * * @param zoomScale Value of scale animation, default is 1.03f */ - public void setZoomScale(float zoomScale) - { + public void setZoomScale(float zoomScale) { this.zoomScale = zoomScale; } - public int getZoomDuration() - { + public int getZoomDuration() { return zoomDuration; } @@ -419,13 +432,11 @@ public int getZoomDuration() * * @param zoomDuration Duration, default is 200ms */ - public void setZoomDuration(int zoomDuration) - { + public void setZoomDuration(int zoomDuration) { this.zoomDuration = zoomDuration; } - public int getRippleDuration() - { + public int getRippleDuration() { return rippleDuration; } @@ -434,13 +445,11 @@ public int getRippleDuration() * * @param rippleDuration Duration, default is 400ms */ - public void setRippleDuration(int rippleDuration) - { + public void setRippleDuration(int rippleDuration) { this.rippleDuration = rippleDuration; } - public int getFrameRate() - { + public int getFrameRate() { return frameRate; } @@ -449,13 +458,11 @@ public int getFrameRate() * * @param frameRate New framerate value, default is 10 */ - public void setFrameRate(int frameRate) - { + public void setFrameRate(int frameRate) { this.frameRate = frameRate; } - public int getRippleAlpha() - { + public int getRippleAlpha() { return rippleAlpha; } @@ -464,8 +471,7 @@ public int getRippleAlpha() * * @param rippleAlpha Alpha value between 0 and 255, default is 90 */ - public void setRippleAlpha(int rippleAlpha) - { + public void setRippleAlpha(int rippleAlpha) { this.rippleAlpha = rippleAlpha; } @@ -487,8 +493,7 @@ public enum RippleType { int type; - RippleType(int type) - { + RippleType(int type) { this.type = type; } } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 34028d8..bf825b4 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -39,6 +39,7 @@ + \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index a488ccf..6b2f973 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' + compileSdkVersion 23 + buildToolsVersion '23.0.2' defaultConfig { minSdkVersion 14 - targetSdkVersion 22 + targetSdkVersion 23 versionCode 1 versionName '1.0' } @@ -23,10 +23,10 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.github.traex.rippleeffect:library:1.3' - compile 'com.android.support:appcompat-v7:22.0.0' - compile 'com.android.support:palette-v7:22.0.0' - compile 'com.android.support:recyclerview-v7:22.0.0' - compile 'com.android.support:support-v4:22.0.0' + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:palette-v7:23.1.1' + compile 'com.android.support:recyclerview-v7:23.1.1' + compile 'com.android.support:support-v4:23.1.1' compile 'com.squareup.picasso:picasso:2.5.1' + compile project (":library") } diff --git a/sample/src/main/java/com/andexert/rippleeffect/MainActivity.java b/sample/src/main/java/com/andexert/rippleeffect/MainActivity.java index d0df20d..80b7f17 100644 --- a/sample/src/main/java/com/andexert/rippleeffect/MainActivity.java +++ b/sample/src/main/java/com/andexert/rippleeffect/MainActivity.java @@ -12,6 +12,7 @@ import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.andexert.library.RippleView; @@ -87,15 +88,19 @@ public void onClick(View v) CustomAdapter customAdapter = new CustomAdapter(); customAdapter.updateList(sourcesArrayList); - customAdapter.setOnTapListener(new OnTapListener() - { + customAdapter.setOnTapListener(new OnTapListener() { @Override - public void onTapView(int position) - { + public void onTapView(int position) { Log.e("MainActivity", "Tap item : " + position); } }); recyclerView.setAdapter(customAdapter); + customAdapter.setOnTapListener(new OnTapListener() { + @Override + public void onTapView(int position) { + Toast.makeText(getApplicationContext(), "performClick", Toast.LENGTH_SHORT).show(); + } + }); } else { @@ -103,14 +108,18 @@ public void onTapView(int position) CustomListViewAdapter customListViewAdapter = new CustomListViewAdapter(this); customListViewAdapter.updateList(sourcesArrayList); listView.setAdapter(customListViewAdapter); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() - { + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override - public void onItemClick(AdapterView parent, View view, int position, long id) - { + public void onItemClick(AdapterView parent, View view, int position, long id) { Log.e("MainActivity", "ListView tap item : " + position); } }); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Toast.makeText(getApplicationContext(), "performClick", Toast.LENGTH_SHORT).show(); + } + }); } } diff --git a/sample/src/main/res/layout/row_view.xml b/sample/src/main/res/layout/row_view.xml index 601e6c3..fb07fa6 100644 --- a/sample/src/main/res/layout/row_view.xml +++ b/sample/src/main/res/layout/row_view.xml @@ -4,7 +4,8 @@ xmlns:ripple="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - ripple:rv_type="rectangle"> + ripple:rv_type="rectangle" + ripple:rv_rippleDelayClick="true">