| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 39 |
public IsAcceleratedView(Context context) { |
| 40 |
super(context); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 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 |
|
| 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 |
| 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 |
} |