diff options
author | Jake Hamby <jhamby@google.com> | 2011-02-07 18:21:25 -0800 |
---|---|---|
committer | Jake Hamby <jhamby@google.com> | 2011-03-01 18:44:36 -0800 |
commit | 436b29e68e6608bed9e8e7d54385b8f62d89208e (patch) | |
tree | 60696619f093e2a9f8c9161804029b35d078a9bd /src/com/android/settings/widget | |
parent | 2adae4e274c00f0b05b405d60b8def23d9b28469 (diff) | |
download | packages_apps_settings-436b29e68e6608bed9e8e7d54385b8f62d89208e.zip packages_apps_settings-436b29e68e6608bed9e8e7d54385b8f62d89208e.tar.gz packages_apps_settings-436b29e68e6608bed9e8e7d54385b8f62d89208e.tar.bz2 |
Refactor Bluetooth settings for readability and performance.
Major refactoring of Bluetooth settings classes.
- Moved all functionality from LocalBluetoothManager into new
LocalBluetoothAdapter and LocalBluetoothPreferences, and into
existing classes.
- Refactored functionality from BluetoothEventRedirector into new
BluetoothEventManager class, deleting the original version. New
version uses a HashMap from action Strings to implementers of the
BluetoothEventManager.Handler interface.
- Created new BluetoothDiscoveryReceiver to update shared preferences
timestamp for Bluetooth discovery start/finish. This is the only event
handling we need to do when the settings app is not visible, so it has
its own receiver entry in AndroidManifest.xml. Edits are written using
QueuedWork.singleThreadExecutor(), which BroadcastReceiver knows about
and will wait for completion, eliminating the need for PendingResult.
- Miscellaneous cleanups to code style and logic for readability.
- Pulled some large switch statement code blocks into new methods.
- Changed all Bluetooth state references to the new BluetoothProfile
constants.
- Changed use of deprecated Notification constructor in
BluetoothPairingRequest to use Notification.Builder.
- Moved Utf8ByteLengthFilter helper function from BluetoothNamePreference
into its own class, and moved test cases into the same package.
- Moved all LocalBluetoothProfileManager functionality related to
specific profiles into new top-level classes (A2dpProfile, etc.), all
implementing the LocalBluetoothProfile interface.
- Moved all UI-related methods from CachedBluetoothDevice into the class
that uses the method, or into the static Utils class for shared methods.
Change-Id: I6d49b7f4ae0c7d7dcf62551ee40b51ecb5fe4f47
Diffstat (limited to 'src/com/android/settings/widget')
-rw-r--r-- | src/com/android/settings/widget/SettingsAppWidgetProvider.java | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java index 8f17e05..ba2b615 100644 --- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java +++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java @@ -38,6 +38,7 @@ import android.provider.Settings; import android.util.Log; import android.widget.RemoteViews; import com.android.settings.R; +import com.android.settings.bluetooth.LocalBluetoothAdapter; import com.android.settings.bluetooth.LocalBluetoothManager; /** @@ -50,7 +51,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { new ComponentName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); - private static LocalBluetoothManager sLocalBluetoothManager = null; + private static LocalBluetoothAdapter sLocalBluetoothAdapter = null; private static final int BUTTON_WIFI = 0; private static final int BUTTON_BRIGHTNESS = 1; @@ -411,18 +412,19 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { @Override public int getActualState(Context context) { - if (sLocalBluetoothManager == null) { - sLocalBluetoothManager = LocalBluetoothManager.getInstance(context); - if (sLocalBluetoothManager == null) { + if (sLocalBluetoothAdapter == null) { + LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context); + if (manager == null) { return STATE_UNKNOWN; // On emulator? } + sLocalBluetoothAdapter = manager.getBluetoothAdapter(); } - return bluetoothStateToFiveState(sLocalBluetoothManager.getBluetoothState()); + return bluetoothStateToFiveState(sLocalBluetoothAdapter.getBluetoothState()); } @Override protected void requestStateChange(Context context, final boolean desiredState) { - if (sLocalBluetoothManager == null) { + if (sLocalBluetoothAdapter == null) { Log.d(TAG, "No LocalBluetoothManager"); return; } @@ -433,7 +435,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... args) { - sLocalBluetoothManager.setBluetoothEnabled(desiredState); + sLocalBluetoothAdapter.setBluetoothEnabled(desiredState); return null; } }.execute(); @@ -584,7 +586,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Update each requested appWidgetId - RemoteViews view = buildUpdate(context, -1); + RemoteViews view = buildUpdate(context); for (int i = 0; i < appWidgetIds.length; i++) { appWidgetManager.updateAppWidget(appWidgetIds[i], view); @@ -613,22 +615,22 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { /** * Load image for given widget and build {@link RemoteViews} for it. */ - static RemoteViews buildUpdate(Context context, int appWidgetId) { + static RemoteViews buildUpdate(Context context) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); - views.setOnClickPendingIntent(R.id.btn_wifi, getLaunchPendingIntent(context, appWidgetId, + views.setOnClickPendingIntent(R.id.btn_wifi, getLaunchPendingIntent(context, BUTTON_WIFI)); views.setOnClickPendingIntent(R.id.btn_brightness, getLaunchPendingIntent(context, - appWidgetId, BUTTON_BRIGHTNESS)); + BUTTON_BRIGHTNESS)); views.setOnClickPendingIntent(R.id.btn_sync, getLaunchPendingIntent(context, - appWidgetId, BUTTON_SYNC)); + BUTTON_SYNC)); views.setOnClickPendingIntent(R.id.btn_gps, - getLaunchPendingIntent(context, appWidgetId, BUTTON_GPS)); + getLaunchPendingIntent(context, BUTTON_GPS)); views.setOnClickPendingIntent(R.id.btn_bluetooth, getLaunchPendingIntent(context, - appWidgetId, BUTTON_BLUETOOTH)); + BUTTON_BLUETOOTH)); updateButtons(views, context); return views; @@ -640,7 +642,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { * @param context */ public static void updateWidget(Context context) { - RemoteViews views = buildUpdate(context, -1); + RemoteViews views = buildUpdate(context); // Update specific list of appWidgetIds if given, otherwise default to all final AppWidgetManager gm = AppWidgetManager.getInstance(context); gm.updateAppWidget(THIS_APPWIDGET, views); @@ -680,10 +682,9 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { * Creates PendingIntent to notify the widget of a button click. * * @param context - * @param appWidgetId * @return */ - private static PendingIntent getLaunchPendingIntent(Context context, int appWidgetId, + private static PendingIntent getLaunchPendingIntent(Context context, int buttonId) { Intent launchIntent = new Intent(); launchIntent.setClass(context, SettingsAppWidgetProvider.class); |