Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2008 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.settings.bluetooth;
     18 
     19 import android.bluetooth.BluetoothDevice;
     20 
     21 import com.android.settings.R;
     22 
     23 /**
     24  * SettingsBtStatus is a helper class that contains constants for various status
     25  * codes.
     26  */
     27 public class SettingsBtStatus {
     28     private static final String TAG = "SettingsBtStatus";
     29 
     30     // Connection status
     31 
     32     public static final int CONNECTION_STATUS_UNKNOWN = 0;
     33     public static final int CONNECTION_STATUS_ACTIVE = 1;
     34     /** Use {@link #isConnectionStatusConnected} to check for the connected state */
     35     public static final int CONNECTION_STATUS_CONNECTED = 2;
     36     public static final int CONNECTION_STATUS_CONNECTING = 3;
     37     public static final int CONNECTION_STATUS_DISCONNECTED = 4;
     38     public static final int CONNECTION_STATUS_DISCONNECTING = 5;
     39 
     40     public static final int getConnectionStatusSummary(int connectionStatus) {
     41         switch (connectionStatus) {
     42         case CONNECTION_STATUS_ACTIVE:
     43             return R.string.bluetooth_connected;
     44         case CONNECTION_STATUS_CONNECTED:
     45             return R.string.bluetooth_connected;
     46         case CONNECTION_STATUS_CONNECTING:
     47             return R.string.bluetooth_connecting;
     48         case CONNECTION_STATUS_DISCONNECTED:
     49             return R.string.bluetooth_disconnected;
     50         case CONNECTION_STATUS_DISCONNECTING:
     51             return R.string.bluetooth_disconnecting;
     52         case CONNECTION_STATUS_UNKNOWN:
     53             return R.string.bluetooth_unknown;
     54         default:
     55             return 0;
     56         }
     57     }
     58 
     59     public static final boolean isConnectionStatusConnected(int connectionStatus) {
     60         return connectionStatus == CONNECTION_STATUS_ACTIVE
     61                 || connectionStatus == CONNECTION_STATUS_CONNECTED;
     62     }
     63 
     64     public static final boolean isConnectionStatusBusy(int connectionStatus) {
     65         return connectionStatus == CONNECTION_STATUS_CONNECTING
     66                 || connectionStatus == CONNECTION_STATUS_DISCONNECTING;
     67     }
     68 
     69     public static final int getPairingStatusSummary(int bondState) {
     70         switch (bondState) {
     71         case BluetoothDevice.BOND_BONDED:
     72             return R.string.bluetooth_paired;
     73         case BluetoothDevice.BOND_BONDING:
     74             return R.string.bluetooth_pairing;
     75         case BluetoothDevice.BOND_NONE:
     76             return R.string.bluetooth_not_connected;
     77         default:
     78             return 0;
     79         }
     80     }
     81 }
     82