BluetoothOppBtEnablingActivity.java revision ce4d93666275df294cb073fe41de5b85932570a8
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.os.Bundle;
3809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.util.Log;
3909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.view.View;
4009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.widget.TextView;
4109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport com.android.internal.app.AlertActivity;
4209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport com.android.internal.app.AlertController;
4309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
4409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly/**
4509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * This class is designed to show BT enabling progress; It will be killed when
4609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * received BT_ENABLED intent.
4709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly */
4809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellypublic class BluetoothOppBtEnablingActivity extends AlertActivity {
4909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    private static final String TAG = "BluetoothOppEnablingActivity";
50ce4d93666275df294cb073fe41de5b85932570a8Nick Pelly    private static final boolean D = Constants.DEBUG;
51ce4d93666275df294cb073fe41de5b85932570a8Nick Pelly    private static final boolean V = Constants.VERBOSE;
52ce4d93666275df294cb073fe41de5b85932570a8Nick Pelly
5309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
5409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    @Override
5509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    protected void onCreate(Bundle savedInstanceState) {
5609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        super.onCreate(savedInstanceState);
5709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
5809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        // Set up the "dialog"
5909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        final AlertController.AlertParams p = mAlertParams;
6009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        p.mIconId = android.R.drawable.ic_dialog_info;
6109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        p.mTitle = getString(R.string.enabling_progress_title);
6209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        p.mView = createView();
6309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        setupAlert();
6409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
6509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
6609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    private View createView() {
6709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        View view = getLayoutInflater().inflate(R.layout.bt_enabling_progress, null);
6809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        TextView contentView = (TextView)view.findViewById(R.id.progress_info);
6909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        contentView.setText(getString(R.string.enabling_progress_content));
7009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
7109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        return view;
7209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
7309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
7409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    // TODO(Moto): add timer mech to handle the case
7509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    // "can not enable BT and can not recv the bt enabled intent".
7609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
7709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    @Override
7809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    protected void onPause() {
7909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        super.onPause();
8009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
8109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(this);
8209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
8309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        // if user press "back" key during BT enabling, cancel the sending
8409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        // operation
8509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        if (mOppManager.mSendingFlag) {
8609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly            mOppManager.mSendingFlag = false;
8709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly            mOppManager.disableBluetooth(); // can work? May not!
88ce4d93666275df294cb073fe41de5b85932570a8Nick Pelly            if (V) Log.v(TAG, "Disabling Bluetooth:! ");
8909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        }
9009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
9109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        // In this dialog, when press "back" key, will call
9209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        // AlertActivity.cancel() function - finish()
9309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        finish();
94ce4d93666275df294cb073fe41de5b85932570a8Nick Pelly        if (V) Log.v(TAG, "onPause(): finish() called");
9509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
9609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly}
97