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