Jeff Sharkey | 1482789 | 2013-07-01 17:22:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.documentsui; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.os.Bundle; |
| 23 | import android.view.View; |
| 24 | import android.view.View.OnClickListener; |
| 25 | import android.widget.Button; |
| 26 | import android.widget.CheckBox; |
| 27 | import android.widget.LinearLayout; |
| 28 | import android.widget.TextView; |
| 29 | |
| 30 | public class TestActivity extends Activity { |
| 31 | private TextView mResult; |
| 32 | |
| 33 | @Override |
| 34 | public void onCreate(Bundle icicle) { |
| 35 | super.onCreate(icicle); |
| 36 | |
| 37 | final Context context = this; |
| 38 | |
| 39 | final LinearLayout view = new LinearLayout(context); |
| 40 | view.setOrientation(LinearLayout.VERTICAL); |
| 41 | |
| 42 | final CheckBox multiple = new CheckBox(context); |
| 43 | multiple.setText("ALLOW_MULTIPLE"); |
| 44 | view.addView(multiple); |
| 45 | |
| 46 | Button button; |
| 47 | button = new Button(context); |
| 48 | button.setText("OPEN_DOC */*"); |
| 49 | button.setOnClickListener(new OnClickListener() { |
| 50 | @Override |
| 51 | public void onClick(View v) { |
| 52 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); |
| 53 | intent.setType("*/*"); |
| 54 | if (multiple.isChecked()) { |
| 55 | intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); |
| 56 | } |
| 57 | startActivityForResult(intent, 42); |
| 58 | } |
| 59 | }); |
| 60 | view.addView(button); |
| 61 | |
| 62 | button = new Button(context); |
| 63 | button.setText("OPEN_DOC image/*"); |
| 64 | button.setOnClickListener(new OnClickListener() { |
| 65 | @Override |
| 66 | public void onClick(View v) { |
| 67 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); |
| 68 | intent.setType("image/*"); |
| 69 | if (multiple.isChecked()) { |
| 70 | intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); |
| 71 | } |
| 72 | startActivityForResult(intent, 42); |
| 73 | } |
| 74 | }); |
| 75 | view.addView(button); |
| 76 | |
| 77 | button = new Button(context); |
| 78 | button.setText("OPEN_DOC text/plain, application/msword"); |
| 79 | button.setOnClickListener(new OnClickListener() { |
| 80 | @Override |
| 81 | public void onClick(View v) { |
| 82 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); |
| 83 | intent.setType("*/*"); |
| 84 | intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { |
| 85 | "text/plain", "application/msword" }); |
| 86 | if (multiple.isChecked()) { |
| 87 | intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); |
| 88 | } |
| 89 | startActivityForResult(intent, 42); |
| 90 | } |
| 91 | }); |
| 92 | view.addView(button); |
| 93 | |
| 94 | button = new Button(context); |
| 95 | button.setText("CREATE_DOC text/plain"); |
| 96 | button.setOnClickListener(new OnClickListener() { |
| 97 | @Override |
| 98 | public void onClick(View v) { |
| 99 | Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); |
| 100 | intent.setType("text/plain"); |
| 101 | intent.putExtra(Intent.EXTRA_TITLE, "foobar.txt"); |
| 102 | startActivityForResult(intent, 42); |
| 103 | } |
| 104 | }); |
| 105 | view.addView(button); |
| 106 | |
| 107 | mResult = new TextView(context); |
| 108 | view.addView(mResult); |
| 109 | |
| 110 | setContentView(view); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 115 | mResult.setText("resultCode=" + resultCode + ", data=" + String.valueOf(data)); |
| 116 | } |
| 117 | } |