aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/CardView.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/view/CardView.java b/app/src/main/java/github/daneren2005/dsub/view/CardView.java
index 576aa52d..b9e0bcce 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/CardView.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/CardView.java
@@ -8,12 +8,15 @@ import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.View;
import android.widget.FrameLayout;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.util.DrawableTint;
public class CardView extends FrameLayout{
+ private static final String TAG = CardView.class.getSimpleName();
+
public CardView(Context context) {
super(context);
init(context);
@@ -37,11 +40,14 @@ public class CardView extends FrameLayout{
@Override
public void onDraw(Canvas canvas) {
- Path clipPath = new Path();
-
- float roundedDp = getResources().getDimension(R.dimen.Card_Radius);
- clipPath.addRoundRect(new RectF(canvas.getClipBounds()), roundedDp, roundedDp, Path.Direction.CW);
- canvas.clipPath(clipPath);
+ try {
+ Path clipPath = new Path();
+ float roundedDp = getResources().getDimension(R.dimen.Card_Radius);
+ clipPath.addRoundRect(new RectF(canvas.getClipBounds()), roundedDp, roundedDp, Path.Direction.CW);
+ canvas.clipPath(clipPath);
+ } catch(Exception e) {
+ Log.e(TAG, "Failed to clip path on canvas", e);
+ }
super.onDraw(canvas);
}
@@ -51,5 +57,12 @@ public class CardView extends FrameLayout{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setElevation(getResources().getInteger(R.integer.Card_Elevation));
}
+
+ // clipPath is not supported with Hardware Acceleration before API 18
+ // http://stackoverflow.com/questions/8895677/work-around-canvas-clippath-that-is-not-supported-in-android-any-more/8895894#8895894
+ if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && isHardwareAccelerated()) {
+ Log.d(TAG, "Change to software");
+ setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ }
}
}