Merge "Trim unwanted whitespace from translations.  DO NOT MERGE" into gingerbread
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
index cc3db6e..4d124b3 100644
--- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
+++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
@@ -83,7 +83,7 @@
                 if (bondState == BluetoothDevice.BOND_NONE) {
                     if (device.isBluetoothDock()) {
                         // After a dock is unpaired, we will forget the
-                        // setttings
+                        // settings
                         mManager.removeDockAutoConnectSetting(device.getAddress());
 
                         // if the device is undocked, remove it from the list as
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 9b16005..32f7ff3 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -86,6 +86,8 @@
     // See mConnectAttempted
     private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
 
+    /** Auto-connect after pairing only if locally initiated. */
+    private boolean mConnectAfterPairing;
 
     /**
      * Describes the current device and profile for logging.
@@ -343,7 +345,10 @@
         if (!mDevice.createBond()) {
             mLocalManager.showError(mDevice, R.string.bluetooth_error_title,
                     R.string.bluetooth_pairing_error_message);
+            return;
         }
+
+        mConnectAfterPairing = true;  // auto-connect after pairing
     }
 
     public void unpair() {
@@ -589,9 +594,19 @@
     public void onBondingStateChanged(int bondState) {
         if (bondState == BluetoothDevice.BOND_NONE) {
             mProfiles.clear();
+            mConnectAfterPairing = false;  // cancel auto-connect
         }
 
         refresh();
+
+        if (bondState == BluetoothDevice.BOND_BONDED) {
+            if (mDevice.isBluetoothDock()) {
+                onBondingDockConnect();
+            } else if (mConnectAfterPairing) {
+                connect();
+            }
+            mConnectAfterPairing = false;
+        }
     }
 
     public void setBtClass(BluetoothClass btClass) {
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
index 4497480..b2b1326 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
@@ -182,15 +182,6 @@
         }
 
         cachedDevice.onBondingStateChanged(bondState);
-
-        if (bondState == BluetoothDevice.BOND_BONDED) {
-            // Auto-connect after pairing
-            if (!device.isBluetoothDock()) {
-                cachedDevice.connect();
-            } else {
-                cachedDevice.onBondingDockConnect();
-            }
-        }
     }
 
     /**
diff --git a/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java b/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java
index 2a8af5f..ed9a974 100644
--- a/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java
+++ b/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java
@@ -72,7 +72,7 @@
         }
 
         if (device == null) {
-            Log.w(TAG, "Activity started without a remote blueototh device");
+            Log.w(TAG, "Activity started without a remote Bluetooth device");
             finish();
         }
 
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index 97e823e..4ba06da 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -45,9 +45,8 @@
 
     private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
 
+    /** Singleton instance. */
     private static LocalBluetoothManager INSTANCE;
-    /** Used when obtaining a reference to the singleton instance. */
-    private static Object INSTANCE_LOCK = new Object();
     private boolean mInitialized;
 
     private Context mContext;
@@ -86,7 +85,7 @@
     private long mLastScan;
 
     public static LocalBluetoothManager getInstance(Context context) {
-        synchronized (INSTANCE_LOCK) {
+        synchronized (LocalBluetoothManager.class) {
             if (INSTANCE == null) {
                 INSTANCE = new LocalBluetoothManager();
             }
diff --git a/src/com/android/settings/bluetooth/SettingsBtStatus.java b/src/com/android/settings/bluetooth/SettingsBtStatus.java
index e2285e9..c6ec23b 100644
--- a/src/com/android/settings/bluetooth/SettingsBtStatus.java
+++ b/src/com/android/settings/bluetooth/SettingsBtStatus.java
@@ -31,7 +31,7 @@
 
     public static final int CONNECTION_STATUS_UNKNOWN = 0;
     public static final int CONNECTION_STATUS_ACTIVE = 1;
-    /** Use {@link #isConnected} to check for the connected state */
+    /** Use {@link #isConnectionStatusConnected} to check for the connected state */
     public static final int CONNECTION_STATUS_CONNECTED = 2;
     public static final int CONNECTION_STATUS_CONNECTING = 3;
     public static final int CONNECTION_STATUS_DISCONNECTED = 4;
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index 444b8d4..533b5e4 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -68,6 +68,28 @@
     private static final int STATE_UNKNOWN = 4;
     private static final int STATE_INTERMEDIATE = 5;
 
+    // Position in the widget bar, to enable different graphics for left, center and right buttons
+    private static final int POS_LEFT = 0;
+    private static final int POS_CENTER = 1;
+    private static final int POS_RIGHT = 2;
+
+    private static final int[] IND_DRAWABLE_OFF = {
+        R.drawable.appwidget_settings_ind_off_l,
+        R.drawable.appwidget_settings_ind_off_c,
+        R.drawable.appwidget_settings_ind_off_r
+    };
+
+    private static final int[] IND_DRAWABLE_MID = {
+        R.drawable.appwidget_settings_ind_mid_l,
+        R.drawable.appwidget_settings_ind_mid_c,
+        R.drawable.appwidget_settings_ind_mid_r
+    };
+
+    private static final int[] IND_DRAWABLE_ON = {
+        R.drawable.appwidget_settings_ind_on_l,
+        R.drawable.appwidget_settings_ind_on_c,
+        R.drawable.appwidget_settings_ind_on_r
+    };
 
     /**
      * Minimum and maximum brightnesses.  Don't go to 0 since that makes the display unusable
@@ -152,22 +174,28 @@
         public abstract int getButtonImageId(boolean on);
 
         /**
+         * Returns the position in the button bar - either POS_LEFT, POS_RIGHT or POS_CENTER.
+         */
+        public int getPosition() { return POS_CENTER; }
+
+        /**
          * Updates the remote views depending on the state (off, on,
          * turning off, turning on) of the setting.
          */
         public final void setImageViewResources(Context context, RemoteViews views) {
             int buttonId = getButtonId();
             int indicatorId = getIndicatorId();
+            int pos = getPosition();
             switch (getTriState(context)) {
                 case STATE_DISABLED:
                     views.setImageViewResource(buttonId, getButtonImageId(false));
                     views.setImageViewResource(
-                        indicatorId, R.drawable.appwidget_settings_ind_off_l);
+                        indicatorId, IND_DRAWABLE_OFF[pos]);
                     break;
                 case STATE_ENABLED:
                     views.setImageViewResource(buttonId, getButtonImageId(true));
                     views.setImageViewResource(
-                        indicatorId, R.drawable.appwidget_settings_ind_on_l);
+                        indicatorId, IND_DRAWABLE_ON[pos]);
                     break;
                 case STATE_INTERMEDIATE:
                     // In the transitional state, the bottom green bar
@@ -178,11 +206,11 @@
                     if (isTurningOn()) {
                         views.setImageViewResource(buttonId, getButtonImageId(true));
                         views.setImageViewResource(
-                            indicatorId, R.drawable.appwidget_settings_ind_mid_l);
+                            indicatorId, IND_DRAWABLE_MID[pos]);
                     } else {
                         views.setImageViewResource(buttonId, getButtonImageId(false));
                         views.setImageViewResource(
-                            indicatorId, R.drawable.appwidget_settings_ind_off_l);
+                            indicatorId, IND_DRAWABLE_OFF[pos]);
                     }
                     break;
             }
@@ -299,6 +327,9 @@
         }
 
         @Override
+        public int getPosition() { return POS_LEFT; }
+
+        @Override
         public int getActualState(Context context) {
             WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
             if (wifiManager != null) {