1/* 2 * Copyright (C) 2007 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 17package com.android.dumprendertree; 18 19import android.content.Intent; 20import android.os.Bundle; 21import android.util.Log; 22 23import java.io.BufferedOutputStream; 24import java.io.File; 25import java.io.FileOutputStream; 26 27public class Menu extends FileList { 28 29 private static final int MENU_START = 0x01; 30 private static String LOGTAG = "MenuActivity"; 31 static final String LAYOUT_TESTS_LIST_FILE = "/sdcard/android/layout_tests_list.txt"; 32 33 public void onCreate(Bundle icicle) { 34 super.onCreate(icicle); 35 } 36 37 boolean fileFilter(File f) { 38 if (f.getName().startsWith(".")) 39 return false; 40 if (f.getName().equalsIgnoreCase("resources")) 41 return false; 42 if (f.isDirectory()) 43 return true; 44 if (f.getPath().toLowerCase().endsWith("ml")) 45 return true; 46 return false; 47 } 48 49 void processFile(String filename, boolean selection) { 50 Intent intent = new Intent(Intent.ACTION_VIEW); 51 intent.setClass(this, TestShellActivity.class); 52 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 53 intent.putExtra(TestShellActivity.TEST_URL, "file://" + filename); 54 startActivity(intent); 55 } 56 57 @Override 58 void processDirectory(String path, boolean selection) { 59 generateTestList(path); 60 Intent intent = new Intent(Intent.ACTION_VIEW); 61 intent.setClass(this, TestShellActivity.class); 62 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 63 intent.putExtra(TestShellActivity.UI_AUTO_TEST, LAYOUT_TESTS_LIST_FILE); 64 startActivity(intent); 65 } 66 67 private void generateTestList(String path) { 68 try { 69 File tests_list = new File(LAYOUT_TESTS_LIST_FILE); 70 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tests_list, false)); 71 FsUtils.findLayoutTestsRecursively(bos, path, false); // Don't ignore results 72 bos.flush(); 73 bos.close(); 74 } catch (Exception e) { 75 Log.e(LOGTAG, "Error when creating test list: " + e.getMessage()); 76 } 77 } 78 79} 80