From f5b5e4d6c87a247aff5b477cea13859338f813fa Mon Sep 17 00:00:00 2001 From: gabrielemariotti Date: Wed, 12 Nov 2014 08:34:15 +0100 Subject: [PATCH] Fixed the NPE on ForegroundLinearLayout and improved the hotspot on foreground. Check also: 61ffadb07ab184a655d62e714851c45892c25cf0 --- .../it/gmariotti/cardslib/library/view/CardView.java | 11 +++++++++++ .../cardslib/library/view/CardViewNative.java | 10 ++++++++++ .../cardslib/library/view/ForegroundLinearLayout.java | 11 +++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardView.java b/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardView.java index eb4e803c..69ee2f37 100644 --- a/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardView.java +++ b/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardView.java @@ -22,11 +22,13 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.AttributeSet; import android.util.Log; import android.view.View; @@ -202,6 +204,15 @@ protected void initAttrs(AttributeSet attrs, int defStyle) { } } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Override + public void drawableHotspotChanged(float x, float y) { + super.drawableHotspotChanged(x, y); + if (mInternalMainCardLayout != null && mInternalMainCardLayout instanceof ForegroundLinearLayout) { + mInternalMainCardLayout.drawableHotspotChanged(x,y); + } + } + //-------------------------------------------------------------------------- // Card //-------------------------------------------------------------------------- diff --git a/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardViewNative.java b/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardViewNative.java index afdd46b9..5c43360d 100644 --- a/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardViewNative.java +++ b/library-core/src/main/java/it/gmariotti/cardslib/library/view/CardViewNative.java @@ -22,6 +22,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -290,6 +291,15 @@ protected void initView() { } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Override + public void drawableHotspotChanged(float x, float y) { + super.drawableHotspotChanged(x, y); + if (mInternalMainCardLayout != null && mInternalMainCardLayout instanceof ForegroundLinearLayout) { + mInternalMainCardLayout.drawableHotspotChanged(x,y); + } + } + //-------------------------------------------------------------------------- // Card //-------------------------------------------------------------------------- diff --git a/library-core/src/main/java/it/gmariotti/cardslib/library/view/ForegroundLinearLayout.java b/library-core/src/main/java/it/gmariotti/cardslib/library/view/ForegroundLinearLayout.java index 4c2d978c..19eb2ace 100644 --- a/library-core/src/main/java/it/gmariotti/cardslib/library/view/ForegroundLinearLayout.java +++ b/library-core/src/main/java/it/gmariotti/cardslib/library/view/ForegroundLinearLayout.java @@ -28,7 +28,6 @@ import android.os.Build; import android.util.AttributeSet; import android.view.Gravity; -import android.view.MotionEvent; import android.widget.LinearLayout; import it.gmariotti.cardslib.library.R; @@ -224,15 +223,15 @@ public void draw(Canvas canvas) { } } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override - public boolean onTouchEvent(MotionEvent e) { + public void drawableHotspotChanged(float x, float y) { + super.drawableHotspotChanged(x, y); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (e.getActionMasked() == MotionEvent.ACTION_DOWN) { - if (mForeground != null) - mForeground.setHotspot(e.getX(), e.getY()); + if (mForeground != null) { + mForeground.setHotspot(x, y); } } - return super.onTouchEvent(e); } } \ No newline at end of file