Created
January 20, 2016 10:53
-
-
Save ZieIony/8480b2d335c1aeb51167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.marcin.splitlayout; | |
import android.annotation.TargetApi; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.Path; | |
import android.graphics.PorterDuff; | |
import android.graphics.PorterDuffXfermode; | |
import android.graphics.Region; | |
import android.graphics.Xfermode; | |
import android.os.Build; | |
import android.util.AttributeSet; | |
import android.util.DisplayMetrics; | |
import android.util.TypedValue; | |
import android.widget.FrameLayout; | |
import android.widget.LinearLayout; | |
/** | |
* Created by Marcin on 20.01.2016. | |
*/ | |
public class CutLayout extends FrameLayout { | |
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
private Xfermode pdMode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); | |
private Path path = new Path(); | |
public CutLayout(Context context) { | |
super(context); | |
} | |
public CutLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public CutLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
public CutLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |
super(context, attrs, defStyleAttr, defStyleRes); | |
} | |
@Override | |
protected void dispatchDraw(Canvas canvas) { | |
int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG); | |
super.dispatchDraw(canvas); | |
paint.setXfermode(pdMode); | |
path.reset(); | |
path.moveTo(0, getHeight()); | |
path.lineTo(getWidth(), getHeight()); | |
path.lineTo(getWidth(), getHeight() - TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics())); | |
path.close(); | |
canvas.drawPath(path, paint); | |
canvas.restoreToCount(saveCount); | |
paint.setXfermode(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment