1/*
2 * Copyright (C) 2012 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.nfc.handover;
18
19import android.app.Activity;
20import android.app.AlertDialog;
21import android.bluetooth.BluetoothDevice;
22import android.content.DialogInterface;
23import android.content.Intent;
24import android.content.res.Resources;
25import android.os.Bundle;
26
27import com.android.nfc.R;
28
29public class ConfirmConnectActivity extends Activity {
30    BluetoothDevice mDevice;
31    @Override
32    protected void onCreate(Bundle savedInstanceState) {
33        super.onCreate(savedInstanceState);
34        AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_DARK);
35        Intent launchIntent = getIntent();
36        mDevice = launchIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
37        if (mDevice == null) finish();
38        Resources res = getResources();
39        String deviceName = mDevice.getName() != null ? mDevice.getName() : "";
40        String confirmString = String.format(res.getString(R.string.confirm_pairing), deviceName);
41        builder.setMessage(confirmString)
42               .setCancelable(false)
43               .setPositiveButton(res.getString(R.string.pair_yes),
44                       new DialogInterface.OnClickListener() {
45                   public void onClick(DialogInterface dialog, int id) {
46                        Intent allowIntent = new Intent(BluetoothHeadsetHandover.ACTION_ALLOW_CONNECT);
47                        allowIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
48                        sendBroadcast(allowIntent);
49                        ConfirmConnectActivity.this.finish();
50                   }
51               })
52               .setNegativeButton(res.getString(R.string.pair_no),
53                       new DialogInterface.OnClickListener() {
54                   public void onClick(DialogInterface dialog, int id) {
55                       Intent denyIntent = new Intent(BluetoothHeadsetHandover.ACTION_DENY_CONNECT);
56                       denyIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
57                       sendBroadcast(denyIntent);
58                       ConfirmConnectActivity.this.finish();
59                   }
60               });
61        AlertDialog alert = builder.create();
62        alert.show();
63    }
64}
65