Debian Codegraph @

tests/HwAccelerationTest/src/com/android/test/hwui/GlyphCacheActivity.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2012 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
20 import android.app.Activity;
21 import android.os.Bundle;
22 import android.view.ViewGroup;
23 import android.widget.LinearLayout;
24 import android.widget.ScrollView;
25 import android.widget.TextView;
26
27 import static android.widget.LinearLayout.LayoutParams;
28
29 public class GlyphCacheActivity extends Activity {
30
31 private static final String mCharacterSet = "abcdefghijklmnopqrstuvwxyz" +
32 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "~!@#$%^&*()_+-={}[]:\";'<>?,./";
33 private int mTotalChars = 0;
34
35 @Override
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38
39 ScrollView scrollView = new ScrollView(this);
40 scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
41 ViewGroup.LayoutParams.MATCH_PARENT));
42 LinearLayout layout = new LinearLayout(this);
43 layout.setOrientation(LinearLayout.VERTICAL);
44 layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
45 ViewGroup.LayoutParams.WRAP_CONTENT));
46 scrollView.addView(layout);
47
48 while (mTotalChars < 10000) {
49 layout.addView(createTextView());
50 }
51 setContentView(scrollView);
52 }
53
54 private TextView createTextView() {
55 TextView textview = new TextView(this);
56 textview.setTextSize(6 + (int) (Math.random() * 5) * 10);
57 textview.setTextColor(0xff << 24 | (int) (Math.random() * 255) << 16 |
58 (int) (Math.random() * 255) << 8 | (int) (Math.random() * 255) << 16);
59 textview.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
60 ViewGroup.LayoutParams.WRAP_CONTENT));
61 int numChars = 5 + (int) (Math.random() * 10);
62 mTotalChars += numChars;
63 textview.setText(createString(numChars));
64
65 return textview;
66 }
67
68 private String createString(int length) {
69 StringBuilder sb = new StringBuilder();
70 for (int i = 0; i < length; i++) {
71 sb.append(mCharacterSet.charAt((int)(Math.random() * mCharacterSet.length())));
72 }
73 return sb.toString();
74 }
75 }