The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.settings; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.widget.EditText; |
| 21 | import android.widget.Button; |
| 22 | import android.content.Intent; |
| 23 | import android.os.Bundle; |
| 24 | import android.view.View; |
| 25 | import android.text.TextUtils; |
| 26 | import android.text.Spannable; |
| 27 | import android.text.Selection; |
| 28 | import android.net.Uri; |
| 29 | |
| 30 | /** |
| 31 | * A simple activity that provides a UI for sending intents |
| 32 | */ |
| 33 | public class DebugIntentSender extends Activity { |
| 34 | private EditText mIntentField; |
| 35 | private EditText mDataField; |
| 36 | private EditText mAccountField; |
| 37 | private EditText mResourceField; |
| 38 | private Button mSendBroadcastButton; |
| 39 | private Button mStartActivityButton; |
| 40 | private View.OnClickListener mClicked = new View.OnClickListener() { |
| 41 | public void onClick(View v) { |
| 42 | if ((v == mSendBroadcastButton) || |
| 43 | (v == mStartActivityButton)) { |
| 44 | String intentAction = mIntentField.getText().toString(); |
| 45 | String intentData = mDataField.getText().toString(); |
| 46 | String account = mAccountField.getText().toString(); |
| 47 | String resource = mResourceField.getText().toString(); |
| 48 | |
| 49 | Intent intent = new Intent(intentAction); |
| 50 | if (!TextUtils.isEmpty(intentData)) { |
| 51 | intent.setData(Uri.parse(intentData)); |
| 52 | } |
| 53 | intent.putExtra("account", account); |
| 54 | intent.putExtra("resource", resource); |
| 55 | if (v == mSendBroadcastButton) { |
| 56 | sendBroadcast(intent); |
| 57 | } else { |
| 58 | startActivity(intent); |
| 59 | } |
| 60 | |
| 61 | setResult(RESULT_OK); |
| 62 | finish(); |
| 63 | } |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | @Override |
| 68 | public void onCreate(Bundle icicle) { |
| 69 | super.onCreate(icicle); |
| 70 | setContentView(R.layout.intent_sender); |
| 71 | |
| 72 | mIntentField = (EditText) findViewById(R.id.intent); |
| 73 | mIntentField.setText(Intent.ACTION_SYNC); |
| 74 | Selection.selectAll((Spannable) mIntentField.getText()); |
| 75 | |
| 76 | mDataField = (EditText) findViewById(R.id.data); |
| 77 | mDataField.setBackgroundResource(android.R.drawable.editbox_background); |
| 78 | |
| 79 | mAccountField = (EditText) findViewById(R.id.account); |
| 80 | mResourceField = (EditText) findViewById(R.id.resource); |
| 81 | |
| 82 | mSendBroadcastButton = (Button) findViewById(R.id.sendbroadcast); |
| 83 | mSendBroadcastButton.setOnClickListener(mClicked); |
| 84 | |
| 85 | mStartActivityButton = (Button) findViewById(R.id.startactivity); |
| 86 | mStartActivityButton.setOnClickListener(mClicked); |
| 87 | } |
| 88 | } |