blob: 1c7e0b6bd4cfddd0b076baaa8b53582f857d345b [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
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
17package com.android.settings;
18
19import android.app.Activity;
20import android.content.Intent;
21import android.os.Bundle;
22import android.view.KeyEvent;
23import android.view.View;
24import android.view.View.OnClickListener;
25import android.view.View.OnKeyListener;
26import android.widget.Button;
27import android.widget.EditText;
28import android.widget.TextView;
29
30public 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}