119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes/* 219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * Copyright (C) 2014 The Android Open Source Project 319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * 419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * Licensed under the Apache License, Version 2.0 (the "License"); 519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * you may not use this file except in compliance with the License. 619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * You may obtain a copy of the License at 719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * 819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * http://www.apache.org/licenses/LICENSE-2.0 919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * 1019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * Unless required by applicable law or agreed to in writing, software 1119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * distributed under the License is distributed on an "AS IS" BASIS, 1219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * See the License for the specific language governing permissions and 1419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes * limitations under the License. 1519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes */ 1619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 1719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banespackage com.android.test.hwui; 1819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 1919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.animation.ObjectAnimator; 2019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.animation.ValueAnimator; 2119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.app.Activity; 2219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.content.Context; 2319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.graphics.Canvas; 2419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.graphics.Outline; 2519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banesimport android.graphics.Path; 26d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banesimport android.graphics.Rect; 27d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banesimport android.os.Bundle; 28d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banesimport android.view.View; 29512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banesimport android.view.ViewOutlineProvider; 30512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banesimport android.widget.FrameLayout; 31d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banesimport android.widget.TextView; 32512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes 3319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banespublic class ClipOutlineActivity extends Activity { 3419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes @Override 3519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes protected void onCreate(Bundle savedInstanceState) { 3619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes super.onCreate(savedInstanceState); 3719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 3819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes final RegionView group = new RegionView(this); 3919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 4019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes final TextView text = new TextView(this); 4119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes text.setText(buildText()); 4219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes group.addView(text); 4319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 4419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes setContentView(group); 4519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 4619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes ObjectAnimator animator = ObjectAnimator.ofFloat(group, "clipPosition", 0.0f, 1.0f); 4719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes animator.setDuration(3000); 4819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes animator.setRepeatCount(ValueAnimator.INFINITE); 4919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes animator.setRepeatMode(ValueAnimator.REVERSE); 5019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes animator.start(); 5119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 5219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 5319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes private static CharSequence buildText() { 5419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes StringBuffer buffer = new StringBuffer(); 5519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes for (int i = 0; i < 10; i++) { 5619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes buffer.append(LOREM_IPSUM); 5719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 5819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes return buffer; 5919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 6019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 6119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes public static class RegionView extends FrameLayout { 6219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes private float mClipPosition = 0.0f; 6319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes private Rect mRect = new Rect(); 6419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 6519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes public RegionView(Context c) { 6619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes super(c); 6719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes setOutlineProvider(new ViewOutlineProvider() { 6819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 6919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes @Override 7019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes public void getOutline(View view, Outline outline) { 7119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes int w = getWidth() / 2; 72512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes int h = getHeight() / 2; 7319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 7419eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes mRect.set(0, 0, w, h); 7519eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes mRect.offset((int) (mClipPosition * w), getHeight() / 4); 7619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 7719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes outline.setRoundRect(mRect, w / 2); 7819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 7919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes }); 8019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes setClipToOutline(true); 8119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 8219eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 8319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes public float getClipPosition() { 84512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes return mClipPosition; 85512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes } 8619eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 8719eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes public void setClipPosition(float clipPosition) { 8819eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes mClipPosition = clipPosition; 8919eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes invalidateOutline(); 9019eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 9119eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes } 92512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes 9319eaf14cb3cca613f984a32be2fab2534427fb29Chris Banes 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."; 94512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes} 95512bb28a39aed8b154b60f3fc1752aa96f7f1125Chris Banes