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.app.Activity; 20import android.content.Context; 21import android.graphics.Canvas; 22import android.graphics.Paint; 23import android.graphics.PaintFlagsDrawFilter; 24import android.os.Bundle; 25import android.view.View; 26 27@SuppressWarnings({"UnusedDeclaration"}) 28public class PaintDrawFilterActivity extends Activity { 29 @Override 30 protected void onCreate(Bundle savedInstanceState) { 31 super.onCreate(savedInstanceState); 32 33 setContentView(new CustomTextView(this)); 34 } 35 36 static class CustomTextView extends View { 37 private final Paint mMediumPaint; 38 private final PaintFlagsDrawFilter mDrawFilter; 39 40 CustomTextView(Context c) { 41 super(c); 42 43 mMediumPaint = new Paint(); 44 mMediumPaint.setAntiAlias(true); 45 mMediumPaint.setColor(0xff000000); 46 mMediumPaint.setFakeBoldText(true); 47 mMediumPaint.setTextSize(24.0f); 48 49 mDrawFilter = new PaintFlagsDrawFilter( 50 Paint.FAKE_BOLD_TEXT_FLAG, Paint.UNDERLINE_TEXT_FLAG); 51 } 52 53 @Override 54 protected void onDraw(Canvas canvas) { 55 super.onDraw(canvas); 56 canvas.drawRGB(255, 255, 255); 57 58 canvas.setDrawFilter(null); 59 canvas.drawText("Hello OpenGL renderer!", 100, 120, mMediumPaint); 60 canvas.setDrawFilter(mDrawFilter); 61 canvas.drawText("Hello OpenGL renderer!", 100, 220, mMediumPaint); 62 } 63 } 64} 65