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 17 package com.android.test.hwui; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.graphics.Canvas; 22 import android.graphics.Path; 23 import android.os.Bundle; 24 import android.widget.FrameLayout; 25 import android.widget.TextView; 26 27 @SuppressWarnings({"UnusedDeclaration"}) 28 public class ClipRegion3Activity extends Activity { 29 @Override 30 protected void onCreate(Bundle savedInstanceState) { 31 super.onCreate(savedInstanceState); 32 33 final RegionView group = new RegionView(this); 34 35 final TextView text = new TextView(this); 36 text.setText(buildText()); 37 group.addView(text); 38 39 setContentView(group); 40 } 41 42 private static CharSequence buildText() { 43 StringBuffer buffer = new StringBuffer(); 44 for (int i = 0; i < 10; i++) { 45 buffer.append(LOREM_IPSUM); 46 } 47 return buffer; 48 } 49 50 public static class RegionView extends FrameLayout { 51 private final Path mClipPath = new Path(); 52 private float mClipPosition = 0.5f; 53 54 public RegionView(Context c) { 55 super(c); 56 setAlpha(0.5f); 57 } 58 59 @Override 60 protected void onSizeChanged(int w, int h, int oldw, int oldh) { 61 super.onSizeChanged(w, h, oldw, oldh); 62 mClipPath.reset(); 63 mClipPath.addCircle(0.0f, 0.0f, getWidth() / 4.0f, Path.Direction.CW); 64 } 65 66 @Override 67 protected void dispatchDraw(Canvas canvas) { 68 canvas.drawARGB(255, 255, 255, 255); 69 70 canvas.save(Canvas.MATRIX_SAVE_FLAG); 71 canvas.translate(mClipPosition * getWidth(), getHeight() / 2.0f); 72 canvas.clipPath(mClipPath); 73 canvas.restore(); 74 75 super.dispatchDraw(canvas); 76 77 invalidate(); 78 } 79 } 80 81 private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sagittis molestie aliquam. Donec metus metus, laoreet nec sagittis vitae, ultricies sit amet eros. Suspendisse sed massa sit amet felis consectetur gravida. In vitae erat mi, in egestas nisl. Phasellus quis ipsum massa, at scelerisque arcu. Nam lectus est, pellentesque eget lacinia non, congue vitae augue. Aliquam erat volutpat. Pellentesque bibendum tincidunt viverra. Aliquam erat volutpat. Maecenas pretium vulputate placerat. Nulla varius elementum rutrum. Aenean mollis blandit imperdiet. Pellentesque interdum fringilla ligula."; 82 } 83