The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 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.content.Intent; |
| 21 | import android.os.Bundle; |
| 22 | import android.view.KeyEvent; |
| 23 | import android.view.View; |
| 24 | import android.view.View.OnClickListener; |
| 25 | import android.view.View.OnKeyListener; |
| 26 | import android.widget.Button; |
| 27 | import android.widget.EditText; |
| 28 | import android.widget.TextView; |
| 29 | |
| 30 | public class BluetoothDataEntry extends Activity implements OnKeyListener { |
| 31 | |
| 32 | private Bundle extras; |
| 33 | |
| 34 | @Override |
| 35 | public void onCreate(Bundle icicle) { |
| 36 | super.onCreate(icicle); |
| 37 | |
| 38 | setContentView(R.layout.bluetooth_data_entry); |
| 39 | |
| 40 | mDataLabel = (TextView)findViewById(R.id.dataLabel); |
| 41 | mDataEntry = (EditText)findViewById(R.id.dataEntry); |
| 42 | mConfirmButton = (Button)findViewById(R.id.confirmButton); |
| 43 | mCancelButton = (Button)findViewById(R.id.cancelButton); |
| 44 | |
| 45 | mDataEntry.setOnKeyListener(this); |
| 46 | Intent intent = getIntent(); |
| 47 | String label = null; |
| 48 | { |
| 49 | String labelExtra = intent.getStringExtra("label"); |
| 50 | if (labelExtra != null) { |
| 51 | label = labelExtra; |
| 52 | } |
| 53 | } |
| 54 | extras = intent.getBundleExtra("extras"); |
| 55 | if (label != null && label.length() > 0) { |
| 56 | mDataLabel.setText(label); |
| 57 | } |
| 58 | |
| 59 | mConfirmButton.setOnClickListener(new ConfirmButtonListener()); |
| 60 | mCancelButton.setOnClickListener(new CancelButtonListener()); |
| 61 | } |
| 62 | |
| 63 | private class ConfirmButtonListener implements OnClickListener { |
| 64 | public void onClick(View v) { |
| 65 | activityResult(RESULT_OK, mDataEntry.getText().toString(), extras); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | private class CancelButtonListener implements OnClickListener { |
| 70 | public void onClick(View v) { |
| 71 | activityResult(RESULT_CANCELED, null, null); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | protected void activityResult(int result, String data, Bundle extras) { |
| 76 | setResult(result, (new Intent()).setAction(data).putExtras(extras)); |
| 77 | finish(); |
| 78 | } |
| 79 | |
| 80 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
| 81 | if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER |
| 82 | || keyCode == KeyEvent.KEYCODE_ENTER) { |
| 83 | activityResult(RESULT_OK, mDataEntry.getText().toString(), extras); |
| 84 | return true; |
| 85 | } |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | protected TextView mDataLabel; |
| 90 | protected EditText mDataEntry; |
| 91 | protected Button mConfirmButton; |
| 92 | protected Button mCancelButton; |
| 93 | } |