1 /* 2 * Copyright (C) 2015 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 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and limitations under the 13 * License. 14 * 15 */ 16 17 package com.android.benchmark.app; 18 19 import android.content.Intent; 20 import android.os.AsyncTask; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.Menu; 24 import android.view.MenuItem; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.Button; 28 import android.widget.ExpandableListView; 29 import android.widget.Toast; 30 31 import androidx.appcompat.app.AppCompatActivity; 32 import androidx.appcompat.widget.Toolbar; 33 34 import com.android.benchmark.R; 35 import com.android.benchmark.registry.BenchmarkRegistry; 36 import com.android.benchmark.results.GlobalResultsStore; 37 38 import com.google.android.material.floatingactionbutton.FloatingActionButton; 39 40 import java.io.IOException; 41 import java.util.LinkedList; 42 import java.util.Queue; 43 44 public class HomeActivity extends AppCompatActivity implements Button.OnClickListener { 45 46 private FloatingActionButton mStartButton; 47 private BenchmarkRegistry mRegistry; 48 private Queue<Intent> mRunnableBenchmarks; 49 50 @Override onCreate(Bundle savedInstanceState)51 protected void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 setContentView(R.layout.activity_home); 54 55 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 56 setSupportActionBar(toolbar); 57 58 mStartButton = (FloatingActionButton) findViewById(R.id.start_button); 59 mStartButton.setActivated(true); 60 mStartButton.setOnClickListener(this); 61 62 mRegistry = new BenchmarkRegistry(this); 63 64 mRunnableBenchmarks = new LinkedList<>(); 65 66 ExpandableListView listView = (ExpandableListView) findViewById(R.id.test_list); 67 BenchmarkListAdapter adapter = 68 new BenchmarkListAdapter(LayoutInflater.from(this), mRegistry); 69 listView.setAdapter(adapter); 70 71 adapter.notifyDataSetChanged(); 72 ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); 73 layoutParams.height = 2048; 74 listView.setLayoutParams(layoutParams); 75 listView.requestLayout(); 76 System.out.println(System.getProperties().stringPropertyNames()); 77 } 78 79 @Override onCreateOptionsMenu(Menu menu)80 public boolean onCreateOptionsMenu(Menu menu) { 81 // Inflate the menu; this adds items to the action bar if it is present. 82 getMenuInflater().inflate(R.menu.menu_main, menu); 83 return true; 84 } 85 86 @Override onOptionsItemSelected(MenuItem item)87 public boolean onOptionsItemSelected(MenuItem item) { 88 // Handle action bar item clicks here. The action bar will 89 // automatically handle clicks on the Home/Up button, so long 90 // as you specify a parent activity in AndroidManifest.xml. 91 int id = item.getItemId(); 92 93 //noinspection SimplifiableIfStatement 94 if (id == R.id.action_settings) { 95 new AsyncTask<Void, Void, Void>() { 96 @Override 97 protected Void doInBackground(Void... voids) { 98 try { 99 HomeActivity.this.runOnUiThread(new Runnable() { 100 @Override 101 public void run() { 102 Toast.makeText(HomeActivity.this, "Exporting...", Toast.LENGTH_LONG).show(); 103 } 104 }); 105 GlobalResultsStore.getInstance(HomeActivity.this).exportToCsv(); 106 } catch (IOException e) { 107 e.printStackTrace(); 108 } 109 return null; 110 } 111 112 @Override 113 protected void onPostExecute(Void aVoid) { 114 HomeActivity.this.runOnUiThread(new Runnable() { 115 @Override 116 public void run() { 117 Toast.makeText(HomeActivity.this, "Done", Toast.LENGTH_LONG).show(); 118 } 119 }); 120 } 121 }.execute(); 122 123 return true; 124 } 125 126 return super.onOptionsItemSelected(item); 127 } 128 129 @Override onClick(View v)130 public void onClick(View v) { 131 final int groupCount = mRegistry.getGroupCount(); 132 for (int i = 0; i < groupCount; i++) { 133 134 Intent intent = mRegistry.getBenchmarkGroup(i).getIntent(); 135 if (intent != null) { 136 mRunnableBenchmarks.add(intent); 137 } 138 } 139 140 handleNextBenchmark(); 141 } 142 143 @Override onActivityResult(int requestCode, int resultCode, Intent data)144 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 145 146 } 147 handleNextBenchmark()148 private void handleNextBenchmark() { 149 Intent nextIntent = mRunnableBenchmarks.peek(); 150 startActivityForResult(nextIntent, 0); 151 } 152 } 153