109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly/* 209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * Copyright (c) 2008-2009, Motorola, Inc. 309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * 409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * All rights reserved. 509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * 609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * Redistribution and use in source and binary forms, with or without 709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * modification, are permitted provided that the following conditions are met: 809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * 909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * - Redistributions of source code must retain the above copyright notice, 1009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * this list of conditions and the following disclaimer. 1109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * 1209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * - Redistributions in binary form must reproduce the above copyright notice, 1309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * this list of conditions and the following disclaimer in the documentation 1409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * and/or other materials provided with the distribution. 1509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * 1609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * - Neither the name of the Motorola, Inc. nor the names of its contributors 1709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * may be used to endorse or promote products derived from this software 1809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * without specific prior written permission. 1909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * 2009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * POSSIBILITY OF SUCH DAMAGE. 3109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly */ 3209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 3309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellypackage com.android.bluetooth.opp; 3409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 356769b59d715ea98bd72eafcfea9acd2714a887daTao Liejunimport com.android.bluetooth.R; 366769b59d715ea98bd72eafcfea9acd2714a887daTao Liejun 3709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.content.DialogInterface; 3809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.content.Intent; 3909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.os.Bundle; 4009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.view.View; 4109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.widget.TextView; 4209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.widget.Toast; 4309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 4409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport com.android.internal.app.AlertActivity; 4509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport com.android.internal.app.AlertController; 4609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 4709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly/** 4809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * This class is designed to show BT enable confirmation dialog; 4909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly */ 5009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellypublic class BluetoothOppBtEnableActivity extends AlertActivity implements 5109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly DialogInterface.OnClickListener { 5209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 5309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly @Override 5409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly protected void onCreate(Bundle savedInstanceState) { 5509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly super.onCreate(savedInstanceState); 5609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 5709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly // Set up the "dialog" 5809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly final AlertController.AlertParams p = mAlertParams; 5909f5dca9925c75166688e1ab7aa5ce377277e395Björn Lundén p.mIconAttrId = android.R.attr.alertDialogIcon; 6009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly p.mTitle = getString(R.string.bt_enable_title); 6109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly p.mView = createView(); 6209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly p.mPositiveButtonText = getString(R.string.bt_enable_ok); 6309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly p.mPositiveButtonListener = this; 6409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly p.mNegativeButtonText = getString(R.string.bt_enable_cancel); 6509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly p.mNegativeButtonListener = this; 6609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly setupAlert(); 6709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly } 6809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 6909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly private View createView() { 7009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly View view = getLayoutInflater().inflate(R.layout.confirm_dialog, null); 7109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly TextView contentView = (TextView)view.findViewById(R.id.content); 7209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly contentView.setText(getString(R.string.bt_enable_line1) + "\n\n" 73dc3bacd6eb626a93f2c3c4c62b3ef6aa9e575d92Lixin Yue + getString(R.string.bt_enable_line2) + "\n"); 7409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 7509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly return view; 7609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly } 7709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 7809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly public void onClick(DialogInterface dialog, int which) { 7909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly switch (which) { 8009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly case DialogInterface.BUTTON_POSITIVE: 8109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(this); 8209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly mOppManager.enableBluetooth(); // this is an asyn call 8309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly mOppManager.mSendingFlag = true; 8409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 8509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly Toast.makeText(this, getString(R.string.enabling_progress_content), 8609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly Toast.LENGTH_SHORT).show(); 8709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 8809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly Intent in = new Intent(this, BluetoothOppBtEnablingActivity.class); 8909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 9009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly this.startActivity(in); 9109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 9209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly finish(); 9309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly break; 9409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly 9509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly case DialogInterface.BUTTON_NEGATIVE: 9609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly finish(); 9709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly break; 9809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly } 9909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly } 10009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly} 101