| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
} |