13c099c42fd7ead1429076055990ae39b72c904f4Romain Guy/* 23c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * Copyright (C) 2010 The Android Open Source Project 33c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * 43c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 53c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * you may not use this file except in compliance with the License. 63c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * You may obtain a copy of the License at 73c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * 83c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * http://www.apache.org/licenses/LICENSE-2.0 93c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * 103c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * Unless required by applicable law or agreed to in writing, software 113c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * distributed under the License is distributed on an "AS IS" BASIS, 123c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * See the License for the specific language governing permissions and 143c099c42fd7ead1429076055990ae39b72c904f4Romain Guy * limitations under the License. 153c099c42fd7ead1429076055990ae39b72c904f4Romain Guy */ 163c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 173c099c42fd7ead1429076055990ae39b72c904f4Romain Guypackage com.android.test.hwui; 183c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 193c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.app.Activity; 203c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.content.Context; 213c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.graphics.Canvas; 223c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.graphics.Path; 233c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.os.Bundle; 243c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.widget.FrameLayout; 253c099c42fd7ead1429076055990ae39b72c904f4Romain Guyimport android.widget.TextView; 263c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 273c099c42fd7ead1429076055990ae39b72c904f4Romain Guy@SuppressWarnings({"UnusedDeclaration"}) 283c099c42fd7ead1429076055990ae39b72c904f4Romain Guypublic class ClipRegion3Activity extends Activity { 293c099c42fd7ead1429076055990ae39b72c904f4Romain Guy @Override 303c099c42fd7ead1429076055990ae39b72c904f4Romain Guy protected void onCreate(Bundle savedInstanceState) { 313c099c42fd7ead1429076055990ae39b72c904f4Romain Guy super.onCreate(savedInstanceState); 323c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 333c099c42fd7ead1429076055990ae39b72c904f4Romain Guy final RegionView group = new RegionView(this); 343c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 353c099c42fd7ead1429076055990ae39b72c904f4Romain Guy final TextView text = new TextView(this); 363c099c42fd7ead1429076055990ae39b72c904f4Romain Guy text.setText(buildText()); 373c099c42fd7ead1429076055990ae39b72c904f4Romain Guy group.addView(text); 383c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 393c099c42fd7ead1429076055990ae39b72c904f4Romain Guy setContentView(group); 403c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 413c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 423c099c42fd7ead1429076055990ae39b72c904f4Romain Guy private static CharSequence buildText() { 433c099c42fd7ead1429076055990ae39b72c904f4Romain Guy StringBuffer buffer = new StringBuffer(); 443c099c42fd7ead1429076055990ae39b72c904f4Romain Guy for (int i = 0; i < 10; i++) { 453c099c42fd7ead1429076055990ae39b72c904f4Romain Guy buffer.append(LOREM_IPSUM); 463c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 473c099c42fd7ead1429076055990ae39b72c904f4Romain Guy return buffer; 483c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 493c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 503c099c42fd7ead1429076055990ae39b72c904f4Romain Guy public static class RegionView extends FrameLayout { 513c099c42fd7ead1429076055990ae39b72c904f4Romain Guy private final Path mClipPath = new Path(); 523c099c42fd7ead1429076055990ae39b72c904f4Romain Guy private float mClipPosition = 0.5f; 533c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 543c099c42fd7ead1429076055990ae39b72c904f4Romain Guy public RegionView(Context c) { 553c099c42fd7ead1429076055990ae39b72c904f4Romain Guy super(c); 563c099c42fd7ead1429076055990ae39b72c904f4Romain Guy setAlpha(0.5f); 573c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 583c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 593c099c42fd7ead1429076055990ae39b72c904f4Romain Guy @Override 603c099c42fd7ead1429076055990ae39b72c904f4Romain Guy protected void onSizeChanged(int w, int h, int oldw, int oldh) { 613c099c42fd7ead1429076055990ae39b72c904f4Romain Guy super.onSizeChanged(w, h, oldw, oldh); 623c099c42fd7ead1429076055990ae39b72c904f4Romain Guy mClipPath.reset(); 633c099c42fd7ead1429076055990ae39b72c904f4Romain Guy mClipPath.addCircle(0.0f, 0.0f, getWidth() / 4.0f, Path.Direction.CW); 643c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 653c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 663c099c42fd7ead1429076055990ae39b72c904f4Romain Guy @Override 673c099c42fd7ead1429076055990ae39b72c904f4Romain Guy protected void dispatchDraw(Canvas canvas) { 683c099c42fd7ead1429076055990ae39b72c904f4Romain Guy canvas.drawARGB(255, 255, 255, 255); 693c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 703c099c42fd7ead1429076055990ae39b72c904f4Romain Guy canvas.save(Canvas.MATRIX_SAVE_FLAG); 713c099c42fd7ead1429076055990ae39b72c904f4Romain Guy canvas.translate(mClipPosition * getWidth(), getHeight() / 2.0f); 723c099c42fd7ead1429076055990ae39b72c904f4Romain Guy canvas.clipPath(mClipPath); 733c099c42fd7ead1429076055990ae39b72c904f4Romain Guy canvas.restore(); 743c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 753c099c42fd7ead1429076055990ae39b72c904f4Romain Guy super.dispatchDraw(canvas); 763c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 773c099c42fd7ead1429076055990ae39b72c904f4Romain Guy invalidate(); 783c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 793c099c42fd7ead1429076055990ae39b72c904f4Romain Guy } 803c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 813c099c42fd7ead1429076055990ae39b72c904f4Romain Guy 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."; 823c099c42fd7ead1429076055990ae39b72c904f4Romain Guy} 83