Home | History | Annotate | Download | only in audioquality
      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.audioquality;
     18 
     19 import com.android.cts.verifier.R;
     20 
     21 import android.app.Activity;
     22 import android.content.ComponentName;
     23 import android.content.Intent;
     24 import android.net.Uri;
     25 import android.os.Bundle;
     26 import android.os.Parcelable;
     27 import android.view.View;
     28 import android.widget.Button;
     29 import android.widget.TextView;
     30 
     31 import java.io.File;
     32 import java.util.ArrayList;
     33 import java.util.List;
     34 
     35 /**
     36  * This Activity allows the user to examine the results of the
     37  * experiments which have been run so far.
     38  */
     39 public class ViewResultsActivity extends Activity implements View.OnClickListener {
     40     private TextView mTextView;
     41     private Button mDismissButton;
     42     private Button mSendResultsButton;
     43     private String mResults;
     44 
     45     private ArrayList<Experiment> mExperiments;
     46 
     47     // The package of the Gmail application
     48     private static final String GMAIL_PACKAGE = "com.google.android.gm";
     49 
     50     // The Gmail compose activity name
     51     private static final String GMAIL_ACTIVITY = GMAIL_PACKAGE
     52             + ".ComposeActivityGmail";
     53 
     54     @Override
     55     public void onCreate(Bundle savedInstanceState) {
     56         super.onCreate(savedInstanceState);
     57         setContentView(R.layout.aq_view_results);
     58 
     59         mDismissButton = (Button) findViewById(R.id.dismissButton);
     60         mDismissButton.setOnClickListener(this);
     61 
     62         mSendResultsButton = (Button) findViewById(R.id.sendResultsButton);
     63         mSendResultsButton.setOnClickListener(this);
     64 
     65         mTextView = (TextView) findViewById(R.id.textView);
     66 
     67         Intent intent = getIntent();
     68         mResults = intent.getStringExtra(AudioQualityVerifierActivity.EXTRA_RESULTS);
     69         mTextView.setText(mResults);
     70 
     71         mExperiments = VerifierExperiments.getExperiments(this);
     72     }
     73 
     74     private void sendResults() {
     75         Intent intent = new Intent();
     76         intent.setAction(Intent.ACTION_SEND_MULTIPLE);
     77         intent.setComponent(new ComponentName(GMAIL_PACKAGE, GMAIL_ACTIVITY));
     78         intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.aq_subject));
     79         intent.putExtra(Intent.EXTRA_TEXT, mResults);
     80 
     81         ArrayList<Parcelable> attachments = new ArrayList<Parcelable>();
     82         for (Experiment exp : mExperiments) {
     83             List<String> filenames = exp.getAudioFileNames();
     84             for (String filename : filenames) {
     85                 attachments.add(Uri.fromFile(new File(filename)));
     86             }
     87         }
     88         intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
     89 
     90         startActivity(intent);
     91     }
     92 
     93     // Implements View.OnClickListener
     94     public void onClick(View v) {
     95         if (v == mDismissButton) {
     96             finish();
     97         } else if (v == mSendResultsButton) {
     98             sendResults();
     99         }
    100     }
    101 }
    102