Introduce half-brightness icon in Power Control widget.

Bug: 5358696
Change-Id: Iae484e786f4dd7a5e88078b69053f01425b79aef
This commit is contained in:
Amith Yamasani
2011-10-03 11:54:16 -07:00
parent 326f96c5dc
commit a9125d4d59
5 changed files with 43 additions and 22 deletions

View File

@@ -1210,6 +1210,8 @@
android:enabled="@bool/has_powercontrol_widget"> android:enabled="@bool/has_powercontrol_widget">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
<action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" /> <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED" /> <action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED" />
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -100,6 +100,10 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10; private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON; private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON;
private static final int DEFAULT_BACKLIGHT = (int) (android.os.Power.BRIGHTNESS_ON * 0.4f); private static final int DEFAULT_BACKLIGHT = (int) (android.os.Power.BRIGHTNESS_ON * 0.4f);
/** Minimum brightness at which the indicator is shown at half-full and ON */
private static final int HALF_BRIGHTNESS_THRESHOLD = (int) (0.3 * MAXIMUM_BACKLIGHT);
/** Minimum brightness at which the indicator is shown at full */
private static final int FULL_BRIGHTNESS_THRESHOLD = (int) (0.8 * MAXIMUM_BACKLIGHT);
private static final StateTracker sWifiState = new WifiStateTracker(); private static final StateTracker sWifiState = new WifiStateTracker();
private static final StateTracker sBluetoothState = new BluetoothStateTracker(); private static final StateTracker sBluetoothState = new BluetoothStateTracker();
@@ -580,6 +584,14 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
} }
} }
private static void checkObserver(Context context) {
if (sSettingsObserver == null) {
sSettingsObserver = new SettingsObserver(new Handler(),
context.getApplicationContext());
sSettingsObserver.startObserving();
}
}
@Override @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) { int[] appWidgetIds) {
@@ -598,11 +610,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
new ComponentName("com.android.settings", ".widget.SettingsAppWidgetProvider"), new ComponentName("com.android.settings", ".widget.SettingsAppWidgetProvider"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP); PackageManager.DONT_KILL_APP);
if (sSettingsObserver == null) { checkObserver(context);
sSettingsObserver = new SettingsObserver(new Handler(),
context.getApplicationContext());
sSettingsObserver.startObserving();
}
} }
@Override @Override
@@ -653,6 +661,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
// Update specific list of appWidgetIds if given, otherwise default to all // Update specific list of appWidgetIds if given, otherwise default to all
final AppWidgetManager gm = AppWidgetManager.getInstance(context); final AppWidgetManager gm = AppWidgetManager.getInstance(context);
gm.updateAppWidget(THIS_APPWIDGET, views); gm.updateAppWidget(THIS_APPWIDGET, views);
checkObserver(context);
} }
/** /**
@@ -672,18 +681,29 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
R.drawable.ic_appwidget_settings_brightness_auto_holo); R.drawable.ic_appwidget_settings_brightness_auto_holo);
views.setImageViewResource(R.id.ind_brightness, views.setImageViewResource(R.id.ind_brightness,
R.drawable.appwidget_settings_ind_on_r_holo); R.drawable.appwidget_settings_ind_on_r_holo);
} else if (getBrightness(context)) { } else {
final int brightness = getBrightness(context);
// Set the icon
if (brightness > FULL_BRIGHTNESS_THRESHOLD) {
views.setImageViewResource(R.id.img_brightness, views.setImageViewResource(R.id.img_brightness,
R.drawable.ic_appwidget_settings_brightness_full_holo); R.drawable.ic_appwidget_settings_brightness_full_holo);
views.setImageViewResource(R.id.ind_brightness, } else if (brightness > HALF_BRIGHTNESS_THRESHOLD) {
R.drawable.appwidget_settings_ind_on_r_holo); views.setImageViewResource(R.id.img_brightness,
R.drawable.ic_appwidget_settings_brightness_half_holo);
} else { } else {
views.setImageViewResource(R.id.img_brightness, views.setImageViewResource(R.id.img_brightness,
R.drawable.ic_appwidget_settings_brightness_off_holo); R.drawable.ic_appwidget_settings_brightness_off_holo);
}
// Set the ON state
if (brightness > HALF_BRIGHTNESS_THRESHOLD) {
views.setImageViewResource(R.id.ind_brightness,
R.drawable.appwidget_settings_ind_on_r_holo);
} else {
views.setImageViewResource(R.id.ind_brightness, views.setImageViewResource(R.id.ind_brightness,
R.drawable.appwidget_settings_ind_off_r_holo); R.drawable.appwidget_settings_ind_off_r_holo);
} }
} }
}
/** /**
* Creates PendingIntent to notify the widget of a button click. * Creates PendingIntent to notify the widget of a button click.
@@ -747,24 +767,23 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
} }
/** /**
* Gets state of brightness. * Gets brightness level.
* *
* @param context * @param context
* @return true if more than moderately bright. * @return brightness level between 0 and 255.
*/ */
private static boolean getBrightness(Context context) { private static int getBrightness(Context context) {
try { try {
IPowerManager power = IPowerManager.Stub.asInterface( IPowerManager power = IPowerManager.Stub.asInterface(
ServiceManager.getService("power")); ServiceManager.getService("power"));
if (power != null) { if (power != null) {
int brightness = Settings.System.getInt(context.getContentResolver(), int brightness = Settings.System.getInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS); Settings.System.SCREEN_BRIGHTNESS);
return brightness > 100; return brightness;
} }
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, "getBrightness: " + e);
} }
return false; return 0;
} }
/** /**