Home | History | Annotate | Download | only in handover
      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 
     17 package com.android.nfc.handover;
     18 
     19 import android.app.Activity;
     20 import android.app.AlertDialog;
     21 import android.bluetooth.BluetoothDevice;
     22 import android.content.DialogInterface;
     23 import android.content.Intent;
     24 import android.content.res.Resources;
     25 import android.os.Bundle;
     26 
     27 import com.android.nfc.R;
     28 
     29 public 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,
     35                 AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
     36         Intent launchIntent = getIntent();
     37         mDevice = launchIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     38         if (mDevice == null) finish();
     39         Resources res = getResources();
     40         String deviceName = mDevice.getName() != null ? mDevice.getName() : "";
     41         String confirmString = String.format(res.getString(R.string.confirm_pairing), deviceName);
     42         builder.setMessage(confirmString)
     43                .setCancelable(false)
     44                .setPositiveButton(res.getString(R.string.pair_yes),
     45                        new DialogInterface.OnClickListener() {
     46                    public void onClick(DialogInterface dialog, int id) {
     47                         Intent allowIntent = new Intent(BluetoothPeripheralHandover.ACTION_ALLOW_CONNECT);
     48                         allowIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
     49                         sendBroadcast(allowIntent);
     50                         ConfirmConnectActivity.this.finish();
     51                    }
     52                })
     53                .setNegativeButton(res.getString(R.string.pair_no),
     54                        new DialogInterface.OnClickListener() {
     55                    public void onClick(DialogInterface dialog, int id) {
     56                        Intent denyIntent = new Intent(BluetoothPeripheralHandover.ACTION_DENY_CONNECT);
     57                        denyIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
     58                        sendBroadcast(denyIntent);
     59                        ConfirmConnectActivity.this.finish();
     60                    }
     61                });
     62         AlertDialog alert = builder.create();
     63         alert.show();
     64     }
     65 }
     66