ScaledTextActivity.java revision 5b4628aeeaa0462cd99256d28b636c06b1845930
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 17package com.android.test.hwui; 18 19import android.animation.ObjectAnimator; 20import android.app.Activity; 21import android.content.Context; 22import android.graphics.Canvas; 23import android.graphics.Paint; 24import android.os.Bundle; 25import android.view.View; 26 27@SuppressWarnings({"UnusedDeclaration"}) 28public class ScaledTextActivity extends Activity { 29 30 @Override 31 protected void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 34 final ScaledTextView view = new ScaledTextView(this); 35 setContentView(view); 36 37 ObjectAnimator animation = ObjectAnimator.ofFloat(view, "textScale", 1.0f, 10.0f); 38 animation.setDuration(3000); 39 animation.setRepeatCount(ObjectAnimator.INFINITE); 40 animation.setRepeatMode(ObjectAnimator.REVERSE); 41 animation.start(); 42 43 } 44 45 public static class ScaledTextView extends View { 46 private final Paint mPaint; 47 private float mScale = 1.0f; 48 49 public ScaledTextView(Context c) { 50 super(c); 51 52 mPaint = new Paint(); 53 mPaint.setAntiAlias(true); 54 mPaint.setTextSize(20.0f); 55 } 56 57 public float getTextScale() { 58 return mScale; 59 } 60 61 public void setTextScale(float scale) { 62 mScale = scale; 63 invalidate(); 64 } 65 66 @Override 67 protected void onDraw(Canvas canvas) { 68 super.onDraw(canvas); 69 canvas.drawARGB(255, 255, 255, 255); 70 71 canvas.drawText("Hello libhwui!", 30.0f, 30.0f, mPaint); 72 canvas.translate(0.0f, 50.0f); 73 canvas.save(); 74 canvas.scale(mScale, mScale); 75 canvas.drawText("Hello libhwui!", 30.0f, 30.0f, mPaint); 76 canvas.restore(); 77 } 78 } 79} 80