summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-11-08 13:28:47 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-11-08 13:28:47 -0800
commitf92562e9a223aabc70734faa736df19385e0da07 (patch)
tree24a2fc6a5d6db19b30d5cd15c8eec372a8198b05 /src/com
parent47a2d1f4454ada86637dadec01f732aaa2059f11 (diff)
parent66dc7065701d28d07f4a7dd49e95ed49aef64a8f (diff)
downloadpackages_apps_settings-f92562e9a223aabc70734faa736df19385e0da07.zip
packages_apps_settings-f92562e9a223aabc70734faa736df19385e0da07.tar.gz
packages_apps_settings-f92562e9a223aabc70734faa736df19385e0da07.tar.bz2
Merge "Don't stutter animations during Bluetooth broadcasts."
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/settings/bluetooth/BluetoothEventRedirector.java50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
index 947eaf6..c8787a2 100644
--- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
+++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
@@ -32,8 +32,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.os.Handler;
import android.util.Log;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
/**
* BluetoothEventRedirector receives broadcasts and callbacks from the Bluetooth
* API and dispatches the event on the UI thread to the right class in the
@@ -42,9 +47,14 @@ import android.util.Log;
public class BluetoothEventRedirector {
private static final String TAG = "BluetoothEventRedirector";
- private LocalBluetoothManager mManager;
+ private final LocalBluetoothManager mManager;
+
+ private final ThreadPoolExecutor mSerialExecutor = new ThreadPoolExecutor(
+ 0, 1, 1000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+
+ private final Handler mHandler = new Handler();
- private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Received " + intent.getAction());
@@ -57,13 +67,11 @@ public class BluetoothEventRedirector {
BluetoothAdapter.ERROR);
mManager.setBluetoothStateInt(state);
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) {
- persistDiscoveringTimestamp();
- mManager.onScanningStateChanged(true);
-
+ PendingResult pr = goAsync(); // so loading shared prefs doesn't kill animation
+ persistDiscoveringTimestamp(pr, true);
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
- persistDiscoveringTimestamp();
- mManager.onScanningStateChanged(false);
-
+ PendingResult pr = goAsync(); // so loading shared prefs doesn't kill animation
+ persistDiscoveringTimestamp(pr, false);
} else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
BluetoothClass btClass = intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS);
@@ -222,10 +230,26 @@ public class BluetoothEventRedirector {
return null;
}
- private void persistDiscoveringTimestamp() {
- SharedPreferences.Editor editor = mManager.getSharedPreferences().edit();
- editor.putLong(LocalBluetoothManager.SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP,
- System.currentTimeMillis());
- editor.apply();
+ private void persistDiscoveringTimestamp(
+ final BroadcastReceiver.PendingResult pr, final boolean newState) {
+ // Load the shared preferences and edit it on a background
+ // thread (but serialized!), but then post back to the main
+ // thread to run the onScanningStateChanged callbacks which
+ // update the UI...
+ mSerialExecutor.submit(new Runnable() {
+ public void run() {
+ SharedPreferences.Editor editor = mManager.getSharedPreferences().edit();
+ editor.putLong(
+ LocalBluetoothManager.SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP,
+ System.currentTimeMillis());
+ editor.apply();
+ mHandler.post(new Runnable() {
+ public void run() {
+ mManager.onScanningStateChanged(newState);
+ pr.finish();
+ }
+ });
+ }
+ });
}
}