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  *
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.mtp;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.util.Log;
24 import android.view.ViewGroup.LayoutParams;
25 import android.widget.LinearLayout;
26 import android.widget.TextView;
27 
28 
29 /**
30  * Activity that shows the test results instead of adb while using USB port to connect MTP device.
31  */
32 public class TestResultActivity extends Activity {
33     private final static String TAG = "MtpDocumentsProviderTest";
34     private TextView mTextView;
35 
show(Context context, String message)36     static void show(Context context, String message) {
37         Log.d(TAG, message);
38         final Intent intent = new Intent(context, TestResultActivity.class);
39         intent.putExtra("message", message);
40         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
41         context.startActivity(intent);
42     }
43 
44     @Override
onCreate(Bundle savedInstanceState)45     public void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47 
48         final LinearLayout linearLayout = new LinearLayout(this);
49         linearLayout.setOrientation(LinearLayout.VERTICAL);
50         setContentView(linearLayout);
51 
52         mTextView = new TextView(this);
53         mTextView.setText(getIntent().getStringExtra("message") + "\n");
54         linearLayout.addView(
55                 mTextView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
56     }
57 
58     @Override
onNewIntent(Intent intent)59     protected void onNewIntent(Intent intent) {
60         super.onNewIntent(intent);
61         mTextView.setText(mTextView.getText() + intent.getStringExtra("message") + "\n");
62     }
63 }
64