1 /* 2 * Copyright (C) 2008 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.statusbartest; 18 19 import android.app.ListActivity; 20 import android.app.PendingIntent; 21 import android.widget.ArrayAdapter; 22 import android.view.View; 23 import android.widget.ListView; 24 import android.content.Intent; 25 import android.os.Bundle; 26 import android.os.Handler; 27 import android.util.Log; 28 import android.net.Uri; 29 import android.os.SystemClock; 30 import android.view.Gravity; 31 import android.widget.RemoteViews; 32 import android.widget.Toast; 33 import android.widget.TextView; 34 import android.os.PowerManager; 35 36 import java.io.FileReader; 37 import java.io.IOException; 38 39 public class ToastTest extends TestActivity 40 { 41 private final static String TAG = "ToastTest"; 42 43 Handler mHandler = new Handler(); 44 Toast mToast1; 45 Toast mToast2; 46 47 @Override 48 protected String tag() { 49 return TAG; 50 } 51 52 @Override 53 protected Test[] tests() { 54 return mTests; 55 } 56 57 private static String readFile(String fn) { 58 FileReader f; 59 int len; 60 61 f = null; 62 try { 63 f = new FileReader(fn); 64 String s = ""; 65 char[] cbuf = new char[200]; 66 while ((len = f.read(cbuf, 0, cbuf.length)) >= 0) { 67 s += String.valueOf(cbuf, 0, len); 68 } 69 return s; 70 } catch (IOException ex) { 71 return "ERROR"; 72 } finally { 73 if (f != null) { 74 try { 75 f.close(); 76 } catch (IOException ex) { 77 return "ERROR!"; 78 } 79 } 80 } 81 } 82 83 private Test[] mTests = new Test[] { 84 new Test("Read lights") { 85 public void run() 86 { 87 String text = "freq=" + readFile("/sys/class/leds/red/device/grpfreq") 88 + "\npwm=" + readFile("/sys/class/leds/red/device/grppwm"); 89 mToast1 = Toast.makeText(ToastTest.this, text, Toast.LENGTH_SHORT); 90 mToast1.show(); 91 } 92 }, 93 94 new Test("Make Toast #1") { 95 public void run() 96 { 97 mToast1 = Toast.makeText(ToastTest.this, "hi 1", Toast.LENGTH_SHORT); 98 } 99 }, 100 101 new Test("Show Toast #1") { 102 public void run() 103 { 104 mToast1.show(); 105 } 106 }, 107 108 new Test("Update Toast #1") { 109 public void run() 110 { 111 TextView view = new TextView(ToastTest.this); 112 view.setText("replaced!"); 113 mToast1.setView(view); 114 mToast1.show(); 115 } 116 }, 117 118 new Test("Make Toast #2") { 119 public void run() 120 { 121 mToast2 = Toast.makeText(ToastTest.this, "hi 2", Toast.LENGTH_SHORT); 122 } 123 }, 124 125 new Test("Show Toast #2") { 126 public void run() 127 { 128 mToast2.show(); 129 } 130 }, 131 132 new Test("Gravity Toast LEFT") { 133 public void run() 134 { 135 Toast toast = Toast.makeText(ToastTest.this, "LEFT", Toast.LENGTH_SHORT); 136 toast.setGravity(Gravity.LEFT, 0, 0); 137 toast.show(); 138 } 139 }, 140 141 new Test("Gravity Toast FILL_HORIZONTAL") { 142 public void run() 143 { 144 Toast toast = Toast.makeText(ToastTest.this, "FILL_HORIZONTAL", 145 Toast.LENGTH_SHORT); 146 toast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0); 147 toast.show(); 148 } 149 }, 150 151 }; 152 } 153 154