1/* 2 * Copyright (C) 2010 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 17package com.android.test.hwui; 18 19import android.app.Activity; 20import android.content.Context; 21import android.graphics.Bitmap; 22import android.graphics.BitmapFactory; 23import android.graphics.Canvas; 24import android.graphics.Paint; 25import android.graphics.Path; 26import android.graphics.PorterDuff; 27import android.graphics.PorterDuffXfermode; 28import android.graphics.Region; 29import android.os.Bundle; 30import android.view.View; 31 32@SuppressWarnings({"UnusedDeclaration"}) 33public class ClipRegionActivity extends Activity { 34 @Override 35 protected void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 final RegionView view = new RegionView(this); 38 setContentView(view); 39 } 40 41 public static class RegionView extends View { 42 public RegionView(Context c) { 43 super(c); 44 } 45 46 @Override 47 protected void onDraw(Canvas canvas) { 48 super.onDraw(canvas); 49 50 canvas.save(); 51 canvas.clipRect(100.0f, 100.0f, getWidth() - 100.0f, getHeight() - 100.0f, 52 Region.Op.DIFFERENCE); 53 canvas.drawARGB(255, 255, 0, 0); 54 canvas.restore(); 55 } 56 } 57} 58