Home | History | Annotate | Download | only in verifier
      1 /*
      2  * Copyright (C) 2010 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.cts.verifier;
     18 
     19 import android.app.ListActivity;
     20 import android.content.Intent;
     21 import android.os.Bundle;
     22 import android.util.Log;
     23 import android.view.Menu;
     24 import android.view.MenuInflater;
     25 import android.view.MenuItem;
     26 import android.widget.Toast;
     27 
     28 import java.io.IOException;
     29 
     30 /** Top-level {@link ListActivity} for launching tests and managing results. */
     31 public class TestListActivity extends AbstractTestListActivity {
     32 
     33     private static final String TAG = TestListActivity.class.getSimpleName();
     34 
     35     @Override
     36     protected void onCreate(Bundle savedInstanceState) {
     37         super.onCreate(savedInstanceState);
     38         setTitle(getString(R.string.title_version, Version.getVersionName(this)));
     39         setTestListAdapter(new ManifestTestListAdapter(this, null));
     40     }
     41 
     42     @Override
     43     public boolean onCreateOptionsMenu(Menu menu) {
     44         MenuInflater inflater = getMenuInflater();
     45         inflater.inflate(R.menu.test_list_menu, menu);
     46         return true;
     47     }
     48 
     49     @Override
     50     public boolean onOptionsItemSelected(MenuItem item) {
     51         switch (item.getItemId()) {
     52             case R.id.clear:
     53                 handleClearItemSelected();
     54                 return true;
     55 
     56             case R.id.view:
     57                 handleViewItemSelected();
     58                 return true;
     59 
     60             case R.id.export:
     61                 handleExportItemSelected();
     62                 return true;
     63 
     64             default:
     65                 return super.onOptionsItemSelected(item);
     66         }
     67     }
     68 
     69     private void handleClearItemSelected() {
     70         mAdapter.clearTestResults();
     71         Toast.makeText(this, R.string.test_results_cleared, Toast.LENGTH_SHORT).show();
     72     }
     73 
     74     private void handleViewItemSelected() {
     75         try {
     76             TestResultsReport report = new TestResultsReport(this, mAdapter);
     77             Intent intent = new Intent(this, ReportViewerActivity.class);
     78             intent.putExtra(ReportViewerActivity.EXTRA_REPORT_CONTENTS, report.getContents());
     79             startActivity(intent);
     80         } catch (IOException e) {
     81             Toast.makeText(this, R.string.test_results_error, Toast.LENGTH_SHORT).show();
     82             Log.e(TAG, "Couldn't copy test results report", e);
     83         }
     84     }
     85 
     86     private void handleExportItemSelected() {
     87         new ReportExporter(this, mAdapter).execute();
     88     }
     89 }
     90