1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.support.car.ui; 17 18 import android.content.Context; 19 import android.graphics.Canvas; 20 import android.graphics.Path; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.widget.FrameLayout; 24 25 /** 26 * FrameLayout that enables the user to set a Path that the view will be clipped to 27 * 28 * From GoogleSearch/com.google.android.shared.ui/CircularClipAnimation 29 * @hide 30 */ 31 public class ClippableFrameLayout extends FrameLayout implements PathClippingView { 32 private Path mClipPath; 33 34 public ClippableFrameLayout(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 } 37 38 @Override 39 public void setClipPath(Path clipPath) { 40 mClipPath = clipPath; 41 setClipToPadding(true); 42 setClipChildren(true); 43 setLayerType(View.LAYER_TYPE_SOFTWARE, null); 44 setWillNotDraw(false); 45 invalidate(); 46 } 47 48 @Override 49 protected void onDraw(Canvas canvas) { 50 if (mClipPath != null) { 51 canvas.clipPath(mClipPath); 52 } 53 super.onDraw(canvas); 54 } 55 } 56