IPControlsJB.java revision bde1a28e6652f25e4f74f018cb7d1dcba65a51e4
1/* 2 * Copyright (C) 2013 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.rs.imagejb; 18 19import android.app.Activity; 20import android.os.Bundle; 21import android.os.Handler; 22import android.os.Message; 23import android.graphics.Canvas; 24import android.view.SurfaceView; 25import android.widget.AdapterView; 26import android.widget.ArrayAdapter; 27import android.widget.ImageView; 28import android.widget.SeekBar; 29import android.widget.Spinner; 30import android.widget.ToggleButton; 31import android.widget.TextView; 32import android.widget.CompoundButton; 33import android.widget.ListView; 34import android.view.View; 35import java.util.ArrayList; 36import java.util.ListIterator; 37import android.util.Log; 38import android.content.Intent; 39 40import android.os.Environment; 41import java.io.BufferedWriter; 42import java.io.File; 43import java.io.FileWriter; 44import java.io.IOException; 45 46public class IPControlsJB extends Activity { 47 private final String TAG = "Img"; 48 public final String RESULT_FILE = "image_processing_result.csv"; 49 50 private ToggleButton mIOButton; 51 private Spinner mResSpinner; 52 private ListView mTestListView; 53 54 private ArrayAdapter<String> mTestListAdapter; 55 private ArrayList<String> mTestList = new ArrayList<String>(); 56 57 private boolean mToggleIO = true; 58 private boolean mToggleDVFS = true; 59 private boolean mToggleLong = false; 60 private boolean mTogglePause = false; 61 62 63 public enum Resolutions { 64 RES_4K(3840, 2160, "4k (3840x2160)"), 65 RES_1080P(1920, 1080, "1080p (1920x1080)"), 66 RES_720P(1280, 720, "720p (1280x720)"), 67 RES_WVGA(800, 480, "WVGA (800x480)"); 68 69 private final String name; 70 public final int width; 71 public final int height; 72 73 private Resolutions(int w, int h, String s) { 74 width = w; 75 height = h; 76 name = s; 77 } 78 79 // return quoted string as displayed test name 80 public String toString() { 81 return name; 82 } 83 } 84 85 86 private AdapterView.OnItemSelectedListener mResSpinnerListener = 87 new AdapterView.OnItemSelectedListener() { 88 public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { 89 //changeTest(IPTestListJB.TestName.values()[pos]); 90 } 91 92 public void onNothingSelected(AdapterView parent) { 93 } 94 }; 95 96 void init() { 97 mIOButton = (ToggleButton) findViewById(R.id.io_control); 98 99 mResSpinner = (Spinner) findViewById(R.id.image_size); 100 mResSpinner.setOnItemSelectedListener(mResSpinnerListener); 101 mResSpinner.setAdapter(new ArrayAdapter<Resolutions>( 102 this, R.layout.spinner_layout, Resolutions.values())); 103 104 for (int i=0; i < IPTestListJB.TestName.values().length; i++) { 105 mTestList.add(IPTestListJB.TestName.values()[i].toString()); 106 } 107 108 mTestListView = (ListView) findViewById(R.id.test_list); 109 mTestListAdapter = new ArrayAdapter(this, 110 android.R.layout.simple_list_item_activated_1, 111 mTestList); 112 113 mTestListView.setAdapter(mTestListAdapter); 114 mTestListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 115 mTestListAdapter.notifyDataSetChanged(); 116 117 ToggleButton toggle; 118 toggle = (ToggleButton) findViewById(R.id.io_control); 119 toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 120 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 121 mToggleIO = isChecked; 122 } 123 }); 124 toggle.setChecked(mToggleIO); 125 126 toggle = (ToggleButton) findViewById(R.id.length_control); 127 toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 128 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 129 mToggleLong = isChecked; 130 } 131 }); 132 toggle.setChecked(mToggleLong); 133 134 toggle = (ToggleButton) findViewById(R.id.background_work); 135 toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 136 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 137 mToggleDVFS = isChecked; 138 } 139 }); 140 toggle.setChecked(mToggleDVFS); 141 142 toggle = (ToggleButton) findViewById(R.id.pause); 143 toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 144 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 145 mTogglePause = isChecked; 146 } 147 }); 148 toggle.setChecked(mTogglePause); 149 150 151 } 152 153 @Override 154 protected void onCreate(Bundle savedInstanceState) { 155 super.onCreate(savedInstanceState); 156 setContentView(R.layout.controls); 157 init(); 158 } 159 160 @Override 161 protected void onPause() { 162 super.onPause(); 163 164 //cleanup(); 165 } 166 167 168 @Override 169 protected void onResume() { 170 super.onResume(); 171 172 // init(); 173 } 174 175 private void checkGroup(int group) { 176 IPTestListJB.TestName t[] = IPTestListJB.TestName.values(); 177 for (int i=0; i < t.length; i++) { 178 mTestListView.setItemChecked(i, group == t[i].group); 179 } 180 } 181 182 public void btnRun(View v) { 183 IPTestListJB.TestName t[] = IPTestListJB.TestName.values(); 184 185 int count = 0; 186 for (int i = 0; i < t.length; i++) { 187 if (mTestListView.isItemChecked(i)) { 188 count++; 189 } 190 } 191 if (count == 0) { 192 return; 193 } 194 195 int testList[] = new int[count]; 196 count = 0; 197 for (int i = 0; i < t.length; i++) { 198 if (mTestListView.isItemChecked(i)) { 199 testList[count++] = i; 200 } 201 } 202 203 Intent intent = new Intent(this, ImageProcessingActivityJB.class); 204 intent.putExtra("tests", testList); 205 intent.putExtra("enable io", mToggleIO); 206 intent.putExtra("enable dvfs", mToggleDVFS); 207 intent.putExtra("enable long", mToggleLong); 208 intent.putExtra("enable pause", mTogglePause); 209 startActivityForResult(intent, 0); 210 } 211 212 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 213 if (requestCode == 0) { 214 if (resultCode == RESULT_OK) { 215 float r[] = data.getFloatArrayExtra("results"); 216 int id[] = data.getIntArrayExtra("tests"); 217 218 for (int ct=0; ct < id.length; ct++) { 219 IPTestListJB.TestName t = IPTestListJB.TestName.values()[id[ct]]; 220 221 String s = IPTestListJB.TestName.values()[id[ct]].toString(); 222 s += " " + r[ct] + "ms"; 223 mTestList.set(id[ct], s); 224 mTestListAdapter.notifyDataSetChanged(); 225 } 226 227 android.util.Log.v("rs", "result " + r); 228 } 229 } 230 } 231 232 public void btnSelAll(View v) { 233 IPTestListJB.TestName t[] = IPTestListJB.TestName.values(); 234 for (int i=0; i < t.length; i++) { 235 mTestListView.setItemChecked(i, true); 236 } 237 } 238 239 public void btnSelNone(View v) { 240 checkGroup(-1); 241 } 242 243 public void btnSelHp(View v) { 244 checkGroup(0); 245 } 246 247 public void btnSelLp(View v) { 248 checkGroup(1); 249 } 250 251 public void btnSelIntrinsic(View v) { 252 checkGroup(2); 253 } 254 255 256 257} 258