summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java20
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java68
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java296
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java170
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java58
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java2
7 files changed, 267 insertions, 350 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java
index 8783a85..69fac7b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java
@@ -429,7 +429,6 @@ public class StatusBarService extends Service implements CommandQueue.Callbacks
mLatestTitle.setVisibility(View.GONE);
mPowerWidget = (PowerWidget)expanded.findViewById(R.id.exp_power_stat);
- mPowerWidget.setupSettingsObserver(mHandler);
mPowerWidget.setGlobalButtonOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(Settings.System.getInt(getContentResolver(),
@@ -917,7 +916,7 @@ public class StatusBarService extends Service implements CommandQueue.Callbacks
mExpandedVisible = true;
visibilityChanged(true);
- mPowerWidget.updateWidget();
+ mPowerWidget.updateAllButtons();
updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java
index 562ac2d..7dd1c7b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java
@@ -14,22 +14,14 @@ import com.android.internal.telephony.Phone;
public class MobileDataButton extends PowerButton {
- public static final String MOBILE_DATA_CHANGED = "com.android.internal.telephony.MOBILE_DATA_CHANGED";
-
public static final String ACTION_MODIFY_NETWORK_MODE = "com.android.internal.telephony.MODIFY_NETWORK_MODE";
-
public static final String EXTRA_NETWORK_MODE = "networkMode";
- public static boolean STATE_CHANGE_REQUEST = false;
-
public MobileDataButton() { mType = BUTTON_MOBILEDATA; }
@Override
protected void updateState() {
- if (STATE_CHANGE_REQUEST) {
- mIcon = R.drawable.stat_data_on;
- mState = STATE_INTERMEDIATE;
- } else if (getDataState(mView.getContext())) {
+ if (getDataState(mView.getContext())) {
mIcon = R.drawable.stat_data_on;
mState = STATE_ENABLED;
} else {
@@ -97,14 +89,4 @@ public class MobileDataButton extends PowerButton {
.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getMobileDataEnabled();
}
-
- public void networkModeChanged(Context context, int networkMode) {
- if (STATE_CHANGE_REQUEST) {
- ConnectivityManager cm = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- cm.setMobileDataEnabled(true);
- STATE_CHANGE_REQUEST=false;
- }
- }
-
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java
index 8aa5e5c..53a4e79 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java
@@ -36,16 +36,16 @@ public class NetworkModeButton extends PowerButton{
private static final int CM_MODE_3GONLY = 1;
private static final int CM_MODE_BOTH = 2;
- private static int NETWORK_MODE = NO_NETWORK_MODE_YET;
- private static int INTENDED_NETWORK_MODE = NO_NETWORK_MODE_YET;
- private static int CURRENT_INTERNAL_STATE = STATE_INTERMEDIATE;
+ private int mMode = NO_NETWORK_MODE_YET;
+ private int mIntendedMode = NO_NETWORK_MODE_YET;
+ private int mInternalState = STATE_INTERMEDIATE;
public NetworkModeButton() { mType = BUTTON_NETWORKMODE; }
@Override
protected void updateState() {
Context context = mView.getContext();
- NETWORK_MODE = get2G3G(context);
+ mMode = get2G3G(context);
mState = networkModeToState(context);
switch (mState) {
@@ -53,7 +53,7 @@ public class NetworkModeButton extends PowerButton{
mIcon = R.drawable.stat_2g3g_off;
break;
case STATE_ENABLED:
- if (NETWORK_MODE == Phone.NT_MODE_WCDMA_ONLY) {
+ if (mMode == Phone.NT_MODE_WCDMA_ONLY) {
mIcon = R.drawable.stat_3g_on;
} else {
mIcon = R.drawable.stat_2g3g_on;
@@ -65,8 +65,8 @@ public class NetworkModeButton extends PowerButton{
// the top dark-gray-or-bright-white logo shows the
// user's intent. This is much easier to see in
// sunlight.
- if (CURRENT_INTERNAL_STATE == STATE_TURNING_ON) {
- if (INTENDED_NETWORK_MODE == Phone.NT_MODE_WCDMA_ONLY) {
+ if (mInternalState == STATE_TURNING_ON) {
+ if (mIntendedMode == Phone.NT_MODE_WCDMA_ONLY) {
mIcon = R.drawable.stat_3g_on;
} else {
mIcon = R.drawable.stat_2g3g_on;
@@ -84,38 +84,38 @@ public class NetworkModeButton extends PowerButton{
int currentMode = getCurrentCMMode(context);
Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE);
- switch (NETWORK_MODE) {
+ switch (mMode) {
case Phone.NT_MODE_WCDMA_PREF:
case Phone.NT_MODE_GSM_UMTS:
intent.putExtra(EXTRA_NETWORK_MODE, Phone.NT_MODE_GSM_ONLY);
- CURRENT_INTERNAL_STATE = STATE_TURNING_OFF;
- INTENDED_NETWORK_MODE=Phone.NT_MODE_GSM_ONLY;
+ mInternalState = STATE_TURNING_OFF;
+ mIntendedMode = Phone.NT_MODE_GSM_ONLY;
break;
case Phone.NT_MODE_WCDMA_ONLY:
- if(currentMode == CM_MODE_3GONLY) {
+ if (currentMode == CM_MODE_3GONLY) {
intent.putExtra(EXTRA_NETWORK_MODE, Phone.NT_MODE_GSM_ONLY);
- CURRENT_INTERNAL_STATE = STATE_TURNING_OFF;
- INTENDED_NETWORK_MODE = Phone.NT_MODE_GSM_ONLY;
+ mInternalState = STATE_TURNING_OFF;
+ mIntendedMode = Phone.NT_MODE_GSM_ONLY;
} else {
intent.putExtra(EXTRA_NETWORK_MODE, Phone.NT_MODE_WCDMA_PREF);
- CURRENT_INTERNAL_STATE = STATE_TURNING_ON;
- INTENDED_NETWORK_MODE = Phone.NT_MODE_WCDMA_PREF;
+ mInternalState = STATE_TURNING_ON;
+ mIntendedMode = Phone.NT_MODE_WCDMA_PREF;
}
break;
case Phone.NT_MODE_GSM_ONLY:
- if(currentMode == CM_MODE_3GONLY || currentMode == CM_MODE_BOTH) {
+ if (currentMode == CM_MODE_3GONLY || currentMode == CM_MODE_BOTH) {
intent.putExtra(EXTRA_NETWORK_MODE, Phone.NT_MODE_WCDMA_ONLY);
- CURRENT_INTERNAL_STATE = STATE_TURNING_ON;
- INTENDED_NETWORK_MODE = Phone.NT_MODE_WCDMA_ONLY;
+ mInternalState = STATE_TURNING_ON;
+ mIntendedMode = Phone.NT_MODE_WCDMA_ONLY;
} else {
intent.putExtra(EXTRA_NETWORK_MODE, Phone.NT_MODE_WCDMA_PREF);
- CURRENT_INTERNAL_STATE = STATE_TURNING_ON;
- INTENDED_NETWORK_MODE = Phone.NT_MODE_WCDMA_PREF;
+ mInternalState = STATE_TURNING_ON;
+ mIntendedMode = Phone.NT_MODE_WCDMA_PREF;
}
break;
}
- NETWORK_MODE = NETWORK_MODE_UNKNOWN;
+ mMode = NETWORK_MODE_UNKNOWN;
context.sendBroadcast(intent);
}
@@ -133,22 +133,14 @@ public class NetworkModeButton extends PowerButton{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getExtras() != null) {
- NETWORK_MODE = intent.getExtras().getInt(EXTRA_NETWORK_MODE);
+ mMode = intent.getExtras().getInt(EXTRA_NETWORK_MODE);
//Update to actual state
- INTENDED_NETWORK_MODE = NETWORK_MODE;
+ mIntendedMode = mMode;
}
//need to clear intermediate states
- CURRENT_INTERNAL_STATE = STATE_ENABLED;
-
- int widgetState = networkModeToState(context);
- CURRENT_INTERNAL_STATE = widgetState;
- if (widgetState == STATE_ENABLED) {
- MobileDataButton mdb = (MobileDataButton)getLoadedButton(BUTTON_MOBILEDATA);
- if(mdb != null) {
- mdb.networkModeChanged(context, NETWORK_MODE);
- }
- }
+ mInternalState = STATE_ENABLED;
+ mInternalState = networkModeToState(context);
}
@Override
@@ -173,12 +165,12 @@ public class NetworkModeButton extends PowerButton{
return state;
}
- private static int networkModeToState(Context context) {
- if (CURRENT_INTERNAL_STATE == STATE_TURNING_ON ||
- CURRENT_INTERNAL_STATE == STATE_TURNING_OFF)
+ private int networkModeToState(Context context) {
+ if (mInternalState == STATE_TURNING_ON || mInternalState == STATE_TURNING_OFF) {
return STATE_INTERMEDIATE;
+ }
- switch(NETWORK_MODE) {
+ switch (mMode) {
case Phone.NT_MODE_WCDMA_PREF:
case Phone.NT_MODE_WCDMA_ONLY:
case Phone.NT_MODE_GSM_UMTS:
@@ -190,7 +182,7 @@ public class NetworkModeButton extends PowerButton{
case Phone.NT_MODE_EVDO_NO_CDMA:
case Phone.NT_MODE_GLOBAL:
// need to check wtf is going on
- Log.d(TAG, "Unexpected network mode (" + NETWORK_MODE + ")");
+ Log.d(TAG, "Unexpected network mode (" + mMode + ")");
return STATE_DISABLED;
}
return STATE_INTERMEDIATE;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java
index dd1eb19..fe96309 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java
@@ -2,6 +2,7 @@ package com.android.systemui.statusbar.powerwidget;
import com.android.systemui.R;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -18,9 +19,7 @@ import android.provider.Settings;
import android.view.View;
import android.provider.Settings;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
public abstract class PowerButton {
public static final String TAG = "PowerButton";
@@ -55,85 +54,53 @@ public abstract class PowerButton {
private static final Mode MASK_MODE = Mode.SCREEN;
- // this is a list of all of our buttons and their corresponding classes
- private static final HashMap<String, Class<? extends PowerButton>> BUTTONS = new HashMap<String, Class<? extends PowerButton>>();
- static {
- BUTTONS.put(BUTTON_WIFI, WifiButton.class);
- BUTTONS.put(BUTTON_GPS, GPSButton.class);
- BUTTONS.put(BUTTON_BLUETOOTH, BluetoothButton.class);
- BUTTONS.put(BUTTON_BRIGHTNESS, BrightnessButton.class);
- BUTTONS.put(BUTTON_SOUND, SoundButton.class);
- BUTTONS.put(BUTTON_SYNC, SyncButton.class);
- BUTTONS.put(BUTTON_WIFIAP, WifiApButton.class);
- BUTTONS.put(BUTTON_SCREENTIMEOUT, ScreenTimeoutButton.class);
- BUTTONS.put(BUTTON_MOBILEDATA, MobileDataButton.class);
- BUTTONS.put(BUTTON_LOCKSCREEN, LockScreenButton.class);
- BUTTONS.put(BUTTON_NETWORKMODE, NetworkModeButton.class);
- BUTTONS.put(BUTTON_AUTOROTATE, AutoRotateButton.class);
- BUTTONS.put(BUTTON_AIRPLANE, AirplaneButton.class);
- BUTTONS.put(BUTTON_FLASHLIGHT, FlashlightButton.class);
- BUTTONS.put(BUTTON_SLEEP, SleepButton.class);
- BUTTONS.put(BUTTON_MEDIA_PLAY_PAUSE, MediaPlayPauseButton.class);
- BUTTONS.put(BUTTON_MEDIA_PREVIOUS, MediaPreviousButton.class);
- BUTTONS.put(BUTTON_MEDIA_NEXT, MediaNextButton.class);
- BUTTONS.put(BUTTON_WIMAX, WimaxButton.class);
- }
- // this is a list of our currently loaded buttons
- private static final HashMap<String, PowerButton> BUTTONS_LOADED = new HashMap<String, PowerButton>();
-
protected int mIcon;
protected int mState;
protected View mView;
protected String mType = BUTTON_UNKNOWN;
- // a static onclicklistener that can be set to register a callback when ANY button is clicked
- private static View.OnClickListener GLOBAL_ON_CLICK_LISTENER = null;
+ private ImageView mIconView;
+ private ImageView mIndicatorView;
- // a static onlongclicklistener that can be set to register a callback when ANY button is long clicked
- private static View.OnLongClickListener GLOBAL_ON_LONG_CLICK_LISTENER = null;
+ private View.OnClickListener mExternalClickListener;
+ private View.OnLongClickListener mExternalLongClickListener;
// we use this to ensure we update our views on the UI thread
private Handler mViewUpdateHandler = new Handler() {
- public void handleMessage(Message msg) {
- // this is only used to update the view, so do it
- if(mView != null) {
- Context context = mView.getContext();
- Resources res = context.getResources();
- int buttonLayer = R.id.power_widget_button;
- int buttonIcon = R.id.power_widget_button_image;
- int buttonState = R.id.power_widget_button_indic;
- ImageView indic = (ImageView)mView.findViewById(R.id.power_widget_button_indic);
- if ((Settings.System.getInt(context.getContentResolver(),Settings.System.EXPANDED_HIDE_INDICATOR, 0)) == 1){
- indic.setVisibility(8);
- }else{
- indic.setVisibility(0);
- }
- updateImageView(buttonIcon, mIcon);
-
- int sColorMaskBase = Settings.System.getInt(context.getContentResolver(),
- Settings.System.EXPANDED_VIEW_WIDGET_COLOR, 0xFF8DE20D);
- int sColorMaskOn = (sColorMaskBase & 0x00FFFFFF) | 0xA0000000;
- int sColorMaskOff = (sColorMaskBase & 0x00FFFFFF) | 0x33000000;
- int sColorMaskInter = (sColorMaskBase & 0x00FFFFFF) | 0x60000000;
-
- /* Button State */
- switch(mState) {
- case STATE_ENABLED:
- updateImageView(buttonState,
- res.getDrawable(R.drawable.stat_bgon_custom, sColorMaskOn, MASK_MODE));
- break;
- case STATE_DISABLED:
- updateImageView(buttonState,
- res.getDrawable(R.drawable.stat_bgon_custom, sColorMaskOff, MASK_MODE));
- break;
- default:
- updateImageView(buttonState,
- res.getDrawable(R.drawable.stat_bgon_custom, sColorMaskInter, MASK_MODE));
- break;
- }
+ @Override
+ public void handleMessage(Message msg) {
+ if (mIconView != null) {
+ mIconView.setImageResource(mIcon);
+ }
+ if (mIndicatorView != null) {
+ Context context = mIndicatorView.getContext();
+ ContentResolver cr = context.getContentResolver();
+
+ boolean visible = Settings.System.getInt(cr,
+ Settings.System.EXPANDED_HIDE_INDICATOR, 0) != 1;
+ int colorMaskBase = Settings.System.getInt(cr,
+ Settings.System.EXPANDED_VIEW_WIDGET_COLOR, 0xFF8DE20D);
+ int colorMask;
+
+ mIndicatorView.setVisibility(visible ? View.VISIBLE : View.GONE);
+
+ switch (mState) {
+ case STATE_ENABLED:
+ colorMask = (colorMaskBase & 0x00FFFFFF) | 0xA0000000;
+ break;
+ case STATE_DISABLED:
+ colorMask = (colorMaskBase & 0x00FFFFFF) | 0x33000000;
+ break;
+ default:
+ colorMask = (colorMaskBase & 0x00FFFFFF) | 0x60000000;
+ break;
}
+
+ mIndicatorView.setImageDrawable(context.getResources().getDrawable(
+ R.drawable.stat_bgon_custom, colorMask, MASK_MODE));
}
- };
+ }
+ };
protected abstract void updateState();
protected abstract void toggleState();
@@ -164,10 +131,16 @@ public abstract class PowerButton {
protected void setupButton(View view) {
mView = view;
- if(mView != null) {
+ if (mView != null) {
mView.setTag(mType);
mView.setOnClickListener(mClickListener);
mView.setOnLongClickListener(mLongClickListener);
+
+ mIconView = (ImageView) mView.findViewById(R.id.power_widget_button_image);
+ mIndicatorView = (ImageView) mView.findViewById(R.id.power_widget_button_indic);
+ } else {
+ mIconView = null;
+ mIndicatorView = null;
}
}
@@ -175,193 +148,32 @@ public abstract class PowerButton {
mViewUpdateHandler.sendEmptyMessage(0);
}
- private void updateImageView(int id, int resId) {
- ImageView imageIcon = (ImageView)mView.findViewById(id);
- imageIcon.setImageResource(resId);
- }
-
- private void updateImageView(int id, Drawable resDraw) {
- ImageView imageIcon = (ImageView)mView.findViewById(id);
- imageIcon.setImageResource(R.drawable.stat_bgon_custom);
- imageIcon.setImageDrawable(resDraw);
- }
-
private View.OnClickListener mClickListener = new View.OnClickListener() {
public void onClick(View v) {
- String type = (String)v.getTag();
+ toggleState();
- for(Map.Entry<String, PowerButton> entry : BUTTONS_LOADED.entrySet()) {
- if(entry.getKey().equals(type)) {
- entry.getValue().toggleState();
- break;
- }
- }
-
- // call our static listener if it's set
- if(GLOBAL_ON_CLICK_LISTENER != null) {
- GLOBAL_ON_CLICK_LISTENER.onClick(v);
+ if (mExternalClickListener != null) {
+ mExternalClickListener.onClick(v);
}
}
};
private View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() {
public boolean onLongClick(View v) {
- boolean result = false;
- String type = (String)v.getTag();
- for (Map.Entry<String, PowerButton> entry : BUTTONS_LOADED.entrySet()) {
- if(entry.getKey().endsWith(type)) {
- result = entry.getValue().handleLongClick();
- break;
- }
- }
+ boolean result = handleLongClick();
- if(result && GLOBAL_ON_LONG_CLICK_LISTENER != null) {
- GLOBAL_ON_LONG_CLICK_LISTENER.onLongClick(v);
+ if (result && mExternalLongClickListener != null) {
+ mExternalLongClickListener.onLongClick(v);
}
return result;
}
};
- public static boolean loadButton(String key, View view) {
- // first make sure we have a valid button
- if(BUTTONS.containsKey(key) && view != null) {
- synchronized (BUTTONS_LOADED) {
- if(BUTTONS_LOADED.containsKey(key)) {
- // setup the button again
- BUTTONS_LOADED.get(key).setupButton(view);
- } else {
- try {
- // we need to instantiate a new button and add it
- PowerButton pb = BUTTONS.get(key).newInstance();
- // set it up
- pb.setupButton(view);
- // save it
- BUTTONS_LOADED.put(key, pb);
- } catch(Exception e) {
- Log.e(TAG, "Error loading button: " + key, e);
- }
- }
- }
- return true;
- } else {
- return false;
- }
- }
-
- public static void unloadButton(String key) {
- synchronized (BUTTONS_LOADED) {
- // first make sure we have a valid button
- if(BUTTONS_LOADED.containsKey(key)) {
- // wipe out the button view
- BUTTONS_LOADED.get(key).setupButton(null);
- // remove the button from our list of loaded ones
- BUTTONS_LOADED.remove(key);
- }
- }
+ void setExternalClickListener(View.OnClickListener listener) {
+ mExternalClickListener = listener;
}
- public static void unloadAllButtons() {
- synchronized (BUTTONS_LOADED) {
- // cycle through setting the buttons to null
- for(PowerButton pb : BUTTONS_LOADED.values()) {
- pb.setupButton(null);
- }
-
- // clear our list
- BUTTONS_LOADED.clear();
- }
- }
-
- public static void updateAllButtons() {
- synchronized (BUTTONS_LOADED) {
- // cycle through our buttons and update them
- for(PowerButton pb : BUTTONS_LOADED.values()) {
- pb.update();
- }
- }
- }
-
- // glue for broadcast receivers
- public static IntentFilter getAllBroadcastIntentFilters() {
- IntentFilter filter = new IntentFilter();
-
- synchronized(BUTTONS_LOADED) {
- for(PowerButton button : BUTTONS_LOADED.values()) {
- IntentFilter tmp = button.getBroadcastIntentFilter();
-
- // cycle through these actions, and see if we need them
- int num = tmp.countActions();
- for(int i = 0; i < num; i++) {
- String action = tmp.getAction(i);
- if(!filter.hasAction(action)) {
- filter.addAction(action);
- }
- }
- }
- }
-
- // return our merged filter
- return filter;
- }
-
- // glue for content observation
- public static List<Uri> getAllObservedUris() {
- List<Uri> uris = new ArrayList<Uri>();
-
- synchronized(BUTTONS_LOADED) {
- for(PowerButton button : BUTTONS_LOADED.values()) {
- List<Uri> tmp = button.getObservedUris();
-
- for(Uri uri : tmp) {
- if(!uris.contains(uri)) {
- uris.add(uri);
- }
- }
- }
- }
-
- return uris;
- }
-
- public static void handleOnReceive(Context context, Intent intent) {
- String action = intent.getAction();
-
- // cycle through power buttons
- synchronized(BUTTONS_LOADED) {
- for(PowerButton button : BUTTONS_LOADED.values()) {
- // call "onReceive" on those that matter
- if(button.getBroadcastIntentFilter().hasAction(action)) {
- button.onReceive(context, intent);
- }
- }
- }
- }
-
- public static void handleOnChangeUri(Uri uri) {
- synchronized(BUTTONS_LOADED) {
- for(PowerButton button : BUTTONS_LOADED.values()) {
- if(button.getObservedUris().contains(uri)) {
- button.onChangeUri(uri);
- }
- }
- }
- }
-
- public static void setGlobalOnClickListener(View.OnClickListener listener) {
- GLOBAL_ON_CLICK_LISTENER = listener;
- }
-
- public static void setGlobalOnLongClickListener(View.OnLongClickListener listener) {
- GLOBAL_ON_LONG_CLICK_LISTENER = listener;
- }
-
- protected static PowerButton getLoadedButton(String key) {
- synchronized(BUTTONS_LOADED) {
- if(BUTTONS_LOADED.containsKey(key)) {
- return BUTTONS_LOADED.get(key);
- } else {
- return null;
- }
- }
+ void setExternalLongClickListener(View.OnLongClickListener listener) {
+ mExternalLongClickListener = listener;
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java
index b51ff3d..c82fc86 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java
@@ -41,6 +41,8 @@ import com.android.systemui.R;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class PowerWidget extends FrameLayout {
private static final String TAG = "PowerWidget";
@@ -65,7 +67,40 @@ public class PowerWidget extends FrameLayout {
private static final int LAYOUT_SCROLL_BUTTON_THRESHOLD = 6;
+ // this is a list of all possible buttons and their corresponding classes
+ private static final HashMap<String, Class<? extends PowerButton>> sPossibleButtons =
+ new HashMap<String, Class<? extends PowerButton>>();
+
+ static {
+ sPossibleButtons.put(PowerButton.BUTTON_WIFI, WifiButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_GPS, GPSButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_BLUETOOTH, BluetoothButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_BRIGHTNESS, BrightnessButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_SOUND, SoundButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_SYNC, SyncButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_WIFIAP, WifiApButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_SCREENTIMEOUT, ScreenTimeoutButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_MOBILEDATA, MobileDataButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_LOCKSCREEN, LockScreenButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_NETWORKMODE, NetworkModeButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_AUTOROTATE, AutoRotateButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_AIRPLANE, AirplaneButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_FLASHLIGHT, FlashlightButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_SLEEP, SleepButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_MEDIA_PLAY_PAUSE, MediaPlayPauseButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_MEDIA_PREVIOUS, MediaPreviousButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_MEDIA_NEXT, MediaNextButton.class);
+ sPossibleButtons.put(PowerButton.BUTTON_WIMAX, WimaxButton.class);
+ }
+
+ // this is a list of our currently loaded buttons
+ private final HashMap<String, PowerButton> mButtons = new HashMap<String, PowerButton>();
+
+ private View.OnClickListener mAllButtonClickListener;
+ private View.OnLongClickListener mAllButtonLongClickListener;
+
private Context mContext;
+ private Handler mHandler;
private LayoutInflater mInflater;
private WidgetBroadcastReceiver mBroadcastReceiver = null;
private WidgetSettingsObserver mObserver = null;
@@ -76,6 +111,7 @@ public class PowerWidget extends FrameLayout {
super(context, attrs);
mContext = context;
+ mHandler = new Handler();
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// get an initial width
@@ -101,7 +137,7 @@ public class PowerWidget extends FrameLayout {
}
// clear the button instances
- PowerButton.unloadAllButtons();
+ unloadAllButtons();
}
@@ -132,7 +168,7 @@ public class PowerWidget extends FrameLayout {
// inflate our button, we don't add it to a parent and don't do any layout shit yet
View buttonView = mInflater.inflate(R.layout.power_widget_button, null, false);
- if(PowerButton.loadButton(button, buttonView)) {
+ if (loadButton(button, buttonView)) {
// add the button here
ll.addView(buttonView, BUTTON_LAYOUT_PARAMS);
buttonCount++;
@@ -161,7 +197,7 @@ public class PowerWidget extends FrameLayout {
// set up a broadcast receiver for our intents, based off of what our power buttons have been loaded
setupBroadcastReceiver();
- IntentFilter filter = PowerButton.getAllBroadcastIntentFilters();
+ IntentFilter filter = getMergedBroadcastIntentFilter();
// we add this so we can update views and such if the settings for our widget change
filter.addAction(Settings.SETTINGS_CHANGED);
// we need to detect orientation changes and update the static button width value appropriately
@@ -169,27 +205,114 @@ public class PowerWidget extends FrameLayout {
// register the receiver
mContext.registerReceiver(mBroadcastReceiver, filter);
// register our observer
- if(mObserver != null) {
- mObserver.observe();
+ mObserver = new WidgetSettingsObserver(mHandler);
+ mObserver.observe();
+ }
+
+ private boolean loadButton(String key, View view) {
+ // first make sure we have a valid button
+ if (!sPossibleButtons.containsKey(key) || view == null) {
+ return false;
+ }
+
+ if (mButtons.containsKey(key)) {
+ // setup the button again
+ mButtons.get(key).setupButton(view);
+ return true;
}
+
+ try {
+ // we need to instantiate a new button and add it
+ PowerButton pb = sPossibleButtons.get(key).newInstance();
+ // set it up
+ pb.setupButton(view);
+ pb.setExternalClickListener(mAllButtonClickListener);
+ pb.setExternalLongClickListener(mAllButtonLongClickListener);
+ // save it
+ mButtons.put(key, pb);
+ } catch(Exception e) {
+ Log.e(TAG, "Error loading button: " + key, e);
+ return false;
+ }
+
+ return true;
}
- public void updateWidget() {
- PowerButton.updateAllButtons();
+ private void unloadButton(String key) {
+ // first make sure we have a valid button
+ if (mButtons.containsKey(key)) {
+ // wipe out the button view
+ mButtons.get(key).setupButton(null);
+ // remove the button from our list of loaded ones
+ mButtons.remove(key);
+ }
}
- public void setupSettingsObserver(Handler handler) {
- if(mObserver == null) {
- mObserver = new WidgetSettingsObserver(handler);
+ private void unloadAllButtons() {
+ // cycle through setting the buttons to null
+ for (PowerButton pb : mButtons.values()) {
+ pb.setupButton(null);
}
+
+ // clear our list
+ mButtons.clear();
+ }
+
+ public void updateAllButtons() {
+ // cycle through our buttons and update them
+ for (PowerButton pb : mButtons.values()) {
+ pb.update();
+ }
+ }
+
+ private IntentFilter getMergedBroadcastIntentFilter() {
+ IntentFilter filter = new IntentFilter();
+
+ for (PowerButton button : mButtons.values()) {
+ IntentFilter tmp = button.getBroadcastIntentFilter();
+
+ // cycle through these actions, and see if we need them
+ int num = tmp.countActions();
+ for (int i = 0; i < num; i++) {
+ String action = tmp.getAction(i);
+ if(!filter.hasAction(action)) {
+ filter.addAction(action);
+ }
+ }
+ }
+
+ // return our merged filter
+ return filter;
+ }
+
+ private List<Uri> getAllObservedUris() {
+ List<Uri> uris = new ArrayList<Uri>();
+
+ for (PowerButton button : mButtons.values()) {
+ List<Uri> tmp = button.getObservedUris();
+
+ for (Uri uri : tmp) {
+ if (!uris.contains(uri)) {
+ uris.add(uri);
+ }
+ }
+ }
+
+ return uris;
}
public void setGlobalButtonOnClickListener(View.OnClickListener listener) {
- PowerButton.setGlobalOnClickListener(listener);
+ mAllButtonClickListener = listener;
+ for (PowerButton pb : mButtons.values()) {
+ pb.setExternalClickListener(listener);
+ }
}
public void setGlobalButtonOnLongClickListener(View.OnLongClickListener listener) {
- PowerButton.setGlobalOnLongClickListener(listener);
+ mAllButtonLongClickListener = listener;
+ for (PowerButton pb : mButtons.values()) {
+ pb.setExternalLongClickListener(listener);
+ }
}
private void setupBroadcastReceiver() {
@@ -224,16 +347,23 @@ public class PowerWidget extends FrameLayout {
// our own broadcast receiver :D
private class WidgetBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
- if(intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
+ String action = intent.getAction();
+
+ if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
updateButtonLayoutWidth();
setupWidget();
} else {
// handle the intent through our power buttons
- PowerButton.handleOnReceive(context, intent);
+ for (PowerButton button : mButtons.values()) {
+ // call "onReceive" on those that matter
+ if (button.getBroadcastIntentFilter().hasAction(action)) {
+ button.onReceive(context, intent);
+ }
+ }
}
// update our widget
- updateWidget();
+ updateAllButtons();
}
};
@@ -272,7 +402,7 @@ public class PowerWidget extends FrameLayout {
false, this);
// watch for power-button specifc stuff that has been loaded
- for(Uri uri : PowerButton.getAllObservedUris()) {
+ for(Uri uri : getAllObservedUris()) {
resolver.registerContentObserver(uri, false, this);
}
}
@@ -300,10 +430,14 @@ public class PowerWidget extends FrameLayout {
}
// do whatever the individual buttons must
- PowerButton.handleOnChangeUri(uri);
+ for (PowerButton button : mButtons.values()) {
+ if (button.getObservedUris().contains(uri)) {
+ button.onChangeUri(uri);
+ }
+ }
// something happened so update the widget
- updateWidget();
+ updateAllButtons();
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java
index acac53e..632e16a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java
@@ -26,7 +26,7 @@ public class ScreenTimeoutButton extends PowerButton {
private static final int CM_MODE_15_60_300 = 0;
private static final int CM_MODE_30_120_300 = 1;
- private static Toast TOAST = null;
+ private Toast mToast = null;
private static final List<Uri> OBSERVED_URIS = new ArrayList<Uri>();
static {
@@ -37,7 +37,7 @@ public class ScreenTimeoutButton extends PowerButton {
@Override
protected void updateState() {
- int timeout=getScreenTtimeout(mView.getContext());
+ int timeout = getScreenTimeout(mView.getContext());
if (timeout <= SCREEN_TIMEOUT_LOW) {
mIcon = R.drawable.stat_screen_timeout_off;
@@ -54,57 +54,55 @@ public class ScreenTimeoutButton extends PowerButton {
@Override
protected void toggleState() {
Context context = mView.getContext();
- int screentimeout = getScreenTtimeout(context);
+ int screenTimeout = getScreenTimeout(context);
int currentMode = getCurrentCMMode(context);
- if (screentimeout < SCREEN_TIMEOUT_MIN) {
+ if (screenTimeout < SCREEN_TIMEOUT_MIN) {
if (currentMode == CM_MODE_15_60_300) {
- screentimeout = SCREEN_TIMEOUT_MIN;
+ screenTimeout = SCREEN_TIMEOUT_MIN;
} else {
- screentimeout = SCREEN_TIMEOUT_LOW;
+ screenTimeout = SCREEN_TIMEOUT_LOW;
}
- } else if (screentimeout < SCREEN_TIMEOUT_LOW) {
+ } else if (screenTimeout < SCREEN_TIMEOUT_LOW) {
if (currentMode == CM_MODE_15_60_300) {
- screentimeout = SCREEN_TIMEOUT_NORMAL;
+ screenTimeout = SCREEN_TIMEOUT_NORMAL;
} else {
- screentimeout = SCREEN_TIMEOUT_LOW;
+ screenTimeout = SCREEN_TIMEOUT_LOW;
}
- } else if (screentimeout < SCREEN_TIMEOUT_NORMAL) {
+ } else if (screenTimeout < SCREEN_TIMEOUT_NORMAL) {
if (currentMode == CM_MODE_15_60_300) {
- screentimeout = SCREEN_TIMEOUT_NORMAL;
+ screenTimeout = SCREEN_TIMEOUT_NORMAL;
} else {
- screentimeout = SCREEN_TIMEOUT_HIGH;
+ screenTimeout = SCREEN_TIMEOUT_HIGH;
}
- } else if (screentimeout < SCREEN_TIMEOUT_HIGH) {
+ } else if (screenTimeout < SCREEN_TIMEOUT_HIGH) {
if (currentMode == CM_MODE_15_60_300) {
- screentimeout = SCREEN_TIMEOUT_MAX;
+ screenTimeout = SCREEN_TIMEOUT_MAX;
} else {
- screentimeout = SCREEN_TIMEOUT_HIGH;
+ screenTimeout = SCREEN_TIMEOUT_HIGH;
}
- } else if (screentimeout < SCREEN_TIMEOUT_MAX) {
- screentimeout = SCREEN_TIMEOUT_MAX;
+ } else if (screenTimeout < SCREEN_TIMEOUT_MAX) {
+ screenTimeout = SCREEN_TIMEOUT_MAX;
} else if (currentMode == CM_MODE_30_120_300) {
- screentimeout = SCREEN_TIMEOUT_LOW;
+ screenTimeout = SCREEN_TIMEOUT_LOW;
} else {
- screentimeout = SCREEN_TIMEOUT_MIN;
+ screenTimeout = SCREEN_TIMEOUT_MIN;
}
Settings.System.putInt(
context.getContentResolver(),
- Settings.System.SCREEN_OFF_TIMEOUT, screentimeout);
-
- // create our toast
- if(TOAST == null) {
- TOAST = Toast.makeText(context, "", Toast.LENGTH_LONG);
- }
+ Settings.System.SCREEN_OFF_TIMEOUT, screenTimeout);
// cancel any previous toast
- TOAST.cancel();
+ if (mToast != null) {
+ mToast.cancel();
+ }
// inform users of how long the timeout is now
- TOAST.setText("Screen timeout set to: " + timeoutToString(screentimeout));
- TOAST.setGravity(Gravity.CENTER, TOAST.getXOffset() / 2, TOAST.getYOffset() / 2);
- TOAST.show();
+ mToast = Toast.makeText(context, "Screen timeout set to: " + timeoutToString(screenTimeout),
+ Toast.LENGTH_LONG);
+ mToast.setGravity(Gravity.CENTER, mToast.getXOffset() / 2, mToast.getYOffset() / 2);
+ mToast.show();
}
@Override
@@ -121,7 +119,7 @@ public class ScreenTimeoutButton extends PowerButton {
return true;
}
- private static int getScreenTtimeout(Context context) {
+ private static int getScreenTimeout(Context context) {
return Settings.System.getInt(
context.getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT, 0);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java
index 81167c2..ffb5877 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java
@@ -92,7 +92,7 @@ public class SyncButton extends PowerButton {
private static boolean getBackgroundDataState(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
return connManager.getBackgroundDataSetting();
}