• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.animation.ObjectAnimator;
20 import android.animation.ValueAnimator;
21 import android.app.Activity;
22 import android.content.Context;
23 import android.graphics.Canvas;
24 import android.graphics.Path;
25 import android.os.Bundle;
26 import android.widget.FrameLayout;
27 import android.widget.TextView;
28 
29 @SuppressWarnings({"UnusedDeclaration"})
30 public class ClipRegionActivity extends Activity {
31     @Override
onCreate(Bundle savedInstanceState)32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34 
35         final RegionView group = new RegionView(this);
36 
37         final TextView text = new TextView(this);
38         text.setText(buildText());
39         group.addView(text);
40 
41         setContentView(group);
42 
43         ObjectAnimator animator = ObjectAnimator.ofFloat(group, "clipPosition", 0.0f, 1.0f);
44         animator.setDuration(3000);
45         animator.setRepeatCount(ValueAnimator.INFINITE);
46         animator.setRepeatMode(ValueAnimator.REVERSE);
47         animator.start();
48     }
49 
buildText()50     private static CharSequence buildText() {
51         StringBuffer buffer = new StringBuffer();
52         for (int i = 0; i < 10; i++) {
53             buffer.append(LOREM_IPSUM);
54         }
55         return buffer;
56     }
57 
58     public static class RegionView extends FrameLayout {
59         private final Path mClipPath = new Path();
60         private float mClipPosition = 0.0f;
61 
RegionView(Context c)62         public RegionView(Context c) {
63             super(c);
64             setAlpha(0.5f);
65         }
66 
getClipPosition()67         public float getClipPosition() {
68             return mClipPosition;
69         }
70 
setClipPosition(float clipPosition)71         public void setClipPosition(float clipPosition) {
72             mClipPosition = clipPosition;
73             invalidate();
74         }
75 
76         @Override
dispatchDraw(Canvas canvas)77         protected void dispatchDraw(Canvas canvas) {
78 
79             canvas.save();
80 
81             mClipPath.reset();
82             mClipPath.addCircle(mClipPosition * getWidth(), getHeight() / 2.0f,
83                     getWidth() / 4.0f, Path.Direction.CW);
84 
85             canvas.clipPath(mClipPath);
86             super.dispatchDraw(canvas);
87 
88             canvas.restore();
89         }
90     }
91 
92     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.";
93 }
94