1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.android_webview.test; |
6 | |
7 | import android.app.Activity; |
8 | import android.os.Bundle; |
9 | import android.util.Log; |
10 | import android.view.View; |
11 | import android.view.ViewGroup.LayoutParams; |
12 | import android.view.WindowManager; |
13 | import android.widget.LinearLayout; |
14 | |
15 | /* |
16 | * This is a lightweight activity for tests that only require WebView functionality. |
17 | */ |
18 | public class AwTestRunnerActivity extends Activity { |
19 | |
20 | private LinearLayout mLinearLayout; |
21 | |
22 | @Override |
23 | public void onCreate(Bundle savedInstanceState) { |
24 | super.onCreate(savedInstanceState); |
25 | |
26 | // TODO(joth): When SW-renderer is available, we'll want to enable this on a per-test |
27 | // basis. |
28 | boolean hardwareAccelerated = true; |
29 | Log.i("AwTestRunnerActivity", "Is " + (hardwareAccelerated ? "" : "NOT ") |
30 | + "hardware accelerated"); |
31 | |
32 | if (hardwareAccelerated) { |
33 | getWindow().setFlags( |
34 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, |
35 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
36 | } |
37 | |
38 | mLinearLayout = new LinearLayout(this); |
39 | mLinearLayout.setOrientation(LinearLayout.VERTICAL); |
40 | mLinearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); |
41 | mLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, |
42 | LayoutParams.WRAP_CONTENT)); |
43 | |
44 | setContentView(mLinearLayout); |
45 | } |
46 | |
47 | public int getRootLayoutWidth() { |
48 | return mLinearLayout.getWidth(); |
49 | } |
50 | |
51 | /** |
52 | * Adds a view to the main linear layout. |
53 | */ |
54 | public void addView(View view) { |
55 | view.setLayoutParams(new LinearLayout.LayoutParams( |
56 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f)); |
57 | mLinearLayout.addView(view); |
58 | } |
59 | |
60 | /** |
61 | * Clears the main linear layout. |
62 | */ |
63 | public void removeAllViews() { |
64 | mLinearLayout.removeAllViews(); |
65 | } |
66 | } |