1 /* 2 * Copyright (C) 2014 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.app.Activity; 20 import android.app.Dialog; 21 import android.content.Context; 22 import android.content.DialogInterface; 23 import android.graphics.Canvas; 24 import android.os.Bundle; 25 import android.os.Looper; 26 import android.view.View; 27 import android.view.ViewGroup.LayoutParams; 28 import android.webkit.WebChromeClient; 29 import android.webkit.WebView; 30 import android.webkit.WebViewClient; 31 import android.widget.LinearLayout; 32 33 public class LooperAcceleration extends Activity { 34 35 static final boolean INCLUDE_WEBVIEW = false; 36 37 static class IsAcceleratedView extends View { 38 IsAcceleratedView(Context context)39 public IsAcceleratedView(Context context) { 40 super(context); 41 } 42 43 @Override onDraw(Canvas canvas)44 protected void onDraw(Canvas canvas) { 45 super.onDraw(canvas); 46 if (canvas.isHardwareAccelerated()) { 47 canvas.drawARGB(0xFF, 0x00, 0xFF, 0x00); 48 } else { 49 canvas.drawARGB(0xFF, 0xFF, 0x00, 0x00); 50 } 51 } 52 53 } 54 makeView()55 private View makeView() { 56 LinearLayout layout = new LinearLayout(this); 57 layout.addView(new IsAcceleratedView(this), LayoutParams.MATCH_PARENT, 60); 58 59 if (INCLUDE_WEBVIEW) { 60 WebView wv = new WebView(this); 61 wv.setWebViewClient(new WebViewClient()); 62 wv.setWebChromeClient(new WebChromeClient()); 63 wv.loadUrl("http://www.webkit.org/blog-files/3d-transforms/poster-circle.html"); 64 layout.addView(wv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 65 } 66 return layout; 67 } 68 69 @Override onCreate(Bundle savedInstanceState)70 protected void onCreate(Bundle savedInstanceState) { 71 super.onCreate(savedInstanceState); 72 73 setContentView(makeView()); 74 75 new Thread() { 76 @Override 77 public void run() { 78 Looper.prepare(); 79 final Context context = LooperAcceleration.this; 80 Dialog dlg = new Dialog(context); 81 dlg.addContentView(makeView(), new LayoutParams(300, 400)); 82 dlg.setCancelable(true); 83 dlg.setCanceledOnTouchOutside(true); 84 dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { 85 @Override 86 public void onDismiss(DialogInterface dialog) { 87 Looper.myLooper().quit(); 88 } 89 }); 90 dlg.setTitle("Not Looper.getMainLooper() check"); 91 dlg.show(); 92 Looper.loop(); 93 } 94 }.start(); 95 } 96 } 97