blob: f0abb50559776d1e0d056e4acc6110cae94978a2 [file] [log] [blame]
Romain Guy529b60a2010-08-03 18:05:47 -07001/*
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
Romain Guyf607bdc2010-09-10 19:20:06 -070017package com.android.test.hwui;
Romain Guy529b60a2010-08-03 18:05:47 -070018
Romain Guyed6fcb02011-03-21 13:11:28 -070019import android.animation.ObjectAnimator;
Romain Guy529b60a2010-08-03 18:05:47 -070020import android.app.Activity;
21import android.content.Context;
22import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
24import android.graphics.BitmapShader;
25import android.graphics.Canvas;
26import android.graphics.Paint;
Romain Guy7230a742011-01-10 22:26:16 -080027import android.graphics.drawable.ColorDrawable;
Romain Guy529b60a2010-08-03 18:05:47 -070028import android.os.Bundle;
29import android.view.View;
30
31@SuppressWarnings({"UnusedDeclaration"})
32public class LinesActivity extends Activity {
Romain Guyed6fcb02011-03-21 13:11:28 -070033 private ObjectAnimator mAnimator;
34
Romain Guy529b60a2010-08-03 18:05:47 -070035 @Override
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
Romain Guy7230a742011-01-10 22:26:16 -080038 getWindow().setBackgroundDrawable(new ColorDrawable(0xffffffff));
Romain Guy529b60a2010-08-03 18:05:47 -070039 final LinesView view = new LinesView(this);
40 setContentView(view);
Romain Guyed6fcb02011-03-21 13:11:28 -070041
42 mAnimator = ObjectAnimator.ofFloat(view, "offset", 0.0f, 15.0f);
43 mAnimator.setDuration(1500);
44 mAnimator.setRepeatCount(ObjectAnimator.INFINITE);
45 mAnimator.setRepeatMode(ObjectAnimator.REVERSE);
46 mAnimator.start();
47 }
48
49 @Override
50 protected void onDestroy() {
51 super.onDestroy();
52 mAnimator.cancel();
Romain Guy529b60a2010-08-03 18:05:47 -070053 }
54
Xavier Ducrohet63fd8712010-12-21 01:33:04 -080055 public static class LinesView extends View {
Chet Haase5b0200b2011-04-13 17:58:08 -070056 private static final boolean LINE_AA = true;
Romain Guya957eea2010-12-08 18:34:42 -080057
Romain Guy529b60a2010-08-03 18:05:47 -070058 private final Bitmap mBitmap1;
59 private final Paint mSmallPaint;
60 private final Paint mMediumPaint;
61 private final Paint mLargePaint;
62 private final BitmapShader mShader;
63 private final float[] mPoints;
64 private final Paint mAlphaPaint;
Romain Guya957eea2010-12-08 18:34:42 -080065 private final Paint mHairLinePaint;
Romain Guy529b60a2010-08-03 18:05:47 -070066
Romain Guyed6fcb02011-03-21 13:11:28 -070067 private float mOffset;
68
Xavier Ducrohet63fd8712010-12-21 01:33:04 -080069 public LinesView(Context c) {
Romain Guy529b60a2010-08-03 18:05:47 -070070 super(c);
71
72 mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
73
74 mSmallPaint = new Paint();
Romain Guya957eea2010-12-08 18:34:42 -080075 mSmallPaint.setAntiAlias(LINE_AA);
Romain Guy529b60a2010-08-03 18:05:47 -070076 mSmallPaint.setColor(0xffff0000);
77 mSmallPaint.setStrokeWidth(1.0f);
78
79 mMediumPaint = new Paint();
Romain Guya957eea2010-12-08 18:34:42 -080080 mMediumPaint.setAntiAlias(LINE_AA);
Romain Guy529b60a2010-08-03 18:05:47 -070081 mMediumPaint.setColor(0xff0000ff);
82 mMediumPaint.setStrokeWidth(4.0f);
83
84 mLargePaint = new Paint();
Romain Guya957eea2010-12-08 18:34:42 -080085 mLargePaint.setAntiAlias(LINE_AA);
Romain Guy529b60a2010-08-03 18:05:47 -070086 mLargePaint.setColor(0xff00ff00);
87 mLargePaint.setStrokeWidth(15.0f);
88
89 mAlphaPaint = new Paint();
Romain Guya957eea2010-12-08 18:34:42 -080090 mAlphaPaint.setAntiAlias(LINE_AA);
Romain Guy529b60a2010-08-03 18:05:47 -070091 mAlphaPaint.setColor(0x7fff0050);
92 mAlphaPaint.setStrokeWidth(10.0f);
Xavier Ducrohet63fd8712010-12-21 01:33:04 -080093
Romain Guya957eea2010-12-08 18:34:42 -080094 mHairLinePaint = new Paint();
95 mHairLinePaint.setAntiAlias(LINE_AA);
96 mHairLinePaint.setColor(0xff0000ff);
97 mHairLinePaint.setStrokeWidth(0.0f);
98
Romain Guy529b60a2010-08-03 18:05:47 -070099 mShader = new BitmapShader(mBitmap1, BitmapShader.TileMode.MIRROR,
100 BitmapShader.TileMode.MIRROR);
101
102 mPoints = new float[] {
103 62.0f, 0.0f, 302.0f, 400.0f,
104 302.0f, 400.0f, 352.0f, 400.0f,
105 352.0f, 400.0f, 352.0f, 500.0f
106 };
107 }
Romain Guyed6fcb02011-03-21 13:11:28 -0700108
109 public void setOffset(float offset) {
110 mOffset = offset;
111 invalidate();
112 }
Romain Guy529b60a2010-08-03 18:05:47 -0700113
114 @Override
115 protected void onDraw(Canvas canvas) {
116 super.onDraw(canvas);
Romain Guyed6fcb02011-03-21 13:11:28 -0700117
Romain Guy529b60a2010-08-03 18:05:47 -0700118 canvas.save();
119 canvas.translate(100.0f, 20.0f);
120
121 canvas.drawLine(0.0f, 0.0f, 40.0f, 400.0f, mSmallPaint);
122 canvas.drawLine(5.0f, 0.0f, 95.0f, 400.0f, mMediumPaint);
123 canvas.drawLine(22.0f, 0.0f, 162.0f, 400.0f, mLargePaint);
Xavier Ducrohet63fd8712010-12-21 01:33:04 -0800124
Romain Guy529b60a2010-08-03 18:05:47 -0700125 mLargePaint.setShader(mShader);
126 canvas.drawLine(42.0f, 0.0f, 222.0f, 400.0f, mLargePaint);
Romain Guyed6fcb02011-03-21 13:11:28 -0700127 for (int x = 0; x < 20; x++) {
128 for (int y = 0; y < 20; y++) {
129 canvas.drawPoint(500.0f + x * (15.0f + mOffset),
130 y * (15.0f + mOffset), mLargePaint);
131 }
132 }
Romain Guy529b60a2010-08-03 18:05:47 -0700133 mLargePaint.setShader(null);
Xavier Ducrohet63fd8712010-12-21 01:33:04 -0800134
Romain Guy529b60a2010-08-03 18:05:47 -0700135 canvas.drawLines(mPoints, mAlphaPaint);
Romain Guy759ea802010-09-16 20:49:46 -0700136
137 mSmallPaint.setAntiAlias(false);
138 canvas.drawLine(0.0f, 0.0f, 400.0f, 0.0f, mSmallPaint);
Romain Guya957eea2010-12-08 18:34:42 -0800139 mSmallPaint.setAntiAlias(LINE_AA);
Romain Guy469b1db2010-10-05 11:49:57 -0700140 canvas.drawLine(0.0f, 0.0f, 0.0f, 400.0f, mSmallPaint);
141 canvas.drawLine(0.0f, 400.0f, 400.0f, 400.0f, mSmallPaint);
Xavier Ducrohet63fd8712010-12-21 01:33:04 -0800142
Romain Guy529b60a2010-08-03 18:05:47 -0700143 canvas.translate(120.0f, 0.0f);
Xavier Ducrohet63fd8712010-12-21 01:33:04 -0800144 mAlphaPaint.setShader(mShader);
Romain Guy529b60a2010-08-03 18:05:47 -0700145 canvas.drawLines(mPoints, mAlphaPaint);
146 mAlphaPaint.setShader(null);
147
148 canvas.restore();
Xavier Ducrohet63fd8712010-12-21 01:33:04 -0800149
Romain Guyed6fcb02011-03-21 13:11:28 -0700150 canvas.save();
Romain Guya957eea2010-12-08 18:34:42 -0800151 canvas.scale(10.0f, 10.0f);
152 canvas.drawLine(50.0f, 40.0f, 10.0f, 40.0f, mSmallPaint);
Chet Haase99ecdc42011-05-06 12:06:34 -0700153 canvas.drawLine(10.0f, 45.0f, 20.0f, 55.0f, mSmallPaint);
Romain Guya957eea2010-12-08 18:34:42 -0800154 canvas.drawLine(10.0f, 60.0f, 50.0f, 60.0f, mHairLinePaint);
155 canvas.restore();
Romain Guy529b60a2010-08-03 18:05:47 -0700156 }
157 }
158}