diff options
22 files changed, 276 insertions, 280 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AirplaneButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AirplaneButton.java index 7e2f20c..e1820ef 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AirplaneButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AirplaneButton.java @@ -21,8 +21,8 @@ public class AirplaneButton extends PowerButton { public AirplaneButton() { mType = BUTTON_AIRPLANE; } @Override - protected void updateState() { - if (getState(mView.getContext())) { + protected void updateState(Context context) { + if (getState(context)) { mIcon = R.drawable.stat_airplane_on; mState = STATE_ENABLED; } else { @@ -32,8 +32,7 @@ public class AirplaneButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); + protected void toggleState(Context context) { boolean state = getState(context); Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, state ? 0 : 1); @@ -45,11 +44,11 @@ public class AirplaneButton extends PowerButton { } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.AIRPLANE_MODE_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } @@ -58,7 +57,7 @@ public class AirplaneButton extends PowerButton { return OBSERVED_URIS; } - private static boolean getState(Context context) { + private boolean getState(Context context) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,0) == 1; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AutoRotateButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AutoRotateButton.java index 81262c5..b06c83b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AutoRotateButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/AutoRotateButton.java @@ -20,8 +20,8 @@ public class AutoRotateButton extends PowerButton { public AutoRotateButton() { mType = BUTTON_AUTOROTATE; } @Override - protected void updateState() { - if (getOrientationState(mView.getContext()) == 1) { + protected void updateState(Context context) { + if (getOrientationState(context) == 1) { mIcon = R.drawable.stat_orientation_on; mState = STATE_ENABLED; } else { @@ -31,9 +31,8 @@ public class AutoRotateButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); - if(getOrientationState(context) == 0) { + protected void toggleState(Context context) { + if (getOrientationState(context) == 0) { Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1); @@ -46,11 +45,11 @@ public class AutoRotateButton extends PowerButton { @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.DISPLAY_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } @@ -59,7 +58,7 @@ public class AutoRotateButton extends PowerButton { return OBSERVED_URIS; } - private static int getOrientationState(Context context) { + private int getOrientationState(Context context) { return Settings.System.getInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BluetoothButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BluetoothButton.java index fad57d3..6b1a2a2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BluetoothButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BluetoothButton.java @@ -80,8 +80,8 @@ public class BluetoothButton extends PowerButton { public BluetoothButton() { mType = BUTTON_BLUETOOTH; } @Override - protected void updateState() { - mState = sBluetoothState.getTriState(mView.getContext()); + protected void updateState(Context context) { + mState = sBluetoothState.getTriState(context); switch (mState) { case STATE_DISABLED: mIcon = R.drawable.stat_bluetooth_off; @@ -105,16 +105,16 @@ public class BluetoothButton extends PowerButton { } @Override - protected void toggleState() { - sBluetoothState.toggleState(mView.getContext()); + protected void toggleState(Context context) { + sBluetoothState.toggleState(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.BLUETOOTH_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BrightnessButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BrightnessButton.java index 4968d6d..c4f5cdc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BrightnessButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/BrightnessButton.java @@ -7,8 +7,8 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.os.IPowerManager; import android.os.Power; +import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; import android.preference.MultiSelectListPreference; @@ -79,12 +79,12 @@ public class BrightnessButton extends PowerButton { Context context = mView.getContext(); mAutoBrightnessSupported = context.getResources().getBoolean( com.android.internal.R.bool.config_automatic_brightness_available); - updateSettings(); + updateSettings(context.getContentResolver()); } } @Override - protected void updateState() { + protected void updateState(Context context) { if (mAutoBrightness) { mIcon = R.drawable.stat_brightness_auto; mState = STATE_ENABLED; @@ -101,42 +101,37 @@ public class BrightnessButton extends PowerButton { } @Override - protected void toggleState() { - try { - IPowerManager power = IPowerManager.Stub - .asInterface(ServiceManager.getService("power")); - if (power != null) { - ContentResolver resolver = mView.getContext().getContentResolver(); - mCurrentBacklightIndex++; - if (mCurrentBacklightIndex > mBacklightValues.length - 1) { - mCurrentBacklightIndex = 0; - } - int backlightIndex = mBacklightValues[mCurrentBacklightIndex]; - int brightness = BACKLIGHTS[backlightIndex]; - if (brightness == AUTO_BACKLIGHT) { - Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, - Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); - } else { - if (mAutoBrightnessSupported) { - Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, - Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); - } - power.setBacklightBrightness(brightness); - Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness); - } - } - } catch (RemoteException e) { - Log.e(TAG, "toggleState()", e); + protected void toggleState(Context context) { + PowerManager power = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + ContentResolver resolver = context.getContentResolver(); + + mCurrentBacklightIndex++; + if (mCurrentBacklightIndex > mBacklightValues.length - 1) { + mCurrentBacklightIndex = 0; } + int backlightIndex = mBacklightValues[mCurrentBacklightIndex]; + int brightness = BACKLIGHTS[backlightIndex]; + + if (brightness == AUTO_BACKLIGHT) { + Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, + Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); + } else { + if (mAutoBrightnessSupported) { + Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, + Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); + } + power.setBacklightBrightness(brightness); + Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness); + } } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.DISPLAY_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } @@ -146,8 +141,7 @@ public class BrightnessButton extends PowerButton { } @Override - protected void onChangeUri(Uri uri) { - ContentResolver resolver = mView.getContext().getContentResolver(); + protected void onChangeUri(ContentResolver resolver, Uri uri) { if (BRIGHTNESS_URI.equals(uri)) { mCurrentBrightness = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS, 0); @@ -155,13 +149,11 @@ public class BrightnessButton extends PowerButton { mAutoBrightness = (Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, 0) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); } else { - updateSettings(); + updateSettings(resolver); } } - private void updateSettings() { - ContentResolver resolver = mView.getContext().getContentResolver(); - + private void updateSettings(ContentResolver resolver) { boolean lightSensorCustom = (Settings.System.getInt(resolver, Settings.System.LIGHT_SENSOR_CUSTOM, 0) != 0); if (lightSensorCustom) { @@ -198,7 +190,5 @@ public class BrightnessButton extends PowerButton { } } } - updateState(); } - } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/FlashlightButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/FlashlightButton.java index a9f17bc..cf8ed2d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/FlashlightButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/FlashlightButton.java @@ -20,8 +20,8 @@ public class FlashlightButton extends PowerButton { public FlashlightButton() { mType = BUTTON_FLASHLIGHT; } @Override - protected void updateState() { - boolean enabled = Settings.System.getInt(mView.getContext().getContentResolver(), Settings.System.TORCH_STATE, 0) == 1; + protected void updateState(Context context) { + boolean enabled = Settings.System.getInt(context.getContentResolver(), Settings.System.TORCH_STATE, 0) == 1; if(enabled) { mIcon = R.drawable.stat_flashlight_on; mState = STATE_ENABLED; @@ -32,8 +32,7 @@ public class FlashlightButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); + protected void toggleState(Context context) { boolean bright = Settings.System.getInt(context.getContentResolver(), Settings.System.EXPANDED_FLASH_MODE, 0) == 1; Intent i = new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"); @@ -42,13 +41,13 @@ public class FlashlightButton extends PowerButton { } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { // it may be better to make an Intent action for the Torch // we may want to look at that option later Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName("net.cactii.flash2", "net.cactii.flash2.MainActivity"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/GPSButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/GPSButton.java index 32a1ea3..579d1d9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/GPSButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/GPSButton.java @@ -22,8 +22,8 @@ public class GPSButton extends PowerButton { public GPSButton() { mType = BUTTON_GPS; } @Override - protected void updateState() { - if(getGpsState(mView.getContext())) { + protected void updateState(Context context) { + if (getGpsState(context)) { mIcon = R.drawable.stat_gps_on; mState = STATE_ENABLED; } else { @@ -33,8 +33,7 @@ public class GPSButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); + protected void toggleState(Context context) { ContentResolver resolver = context.getContentResolver(); boolean enabled = getGpsState(context); Settings.Secure.setLocationProviderEnabled(resolver, @@ -42,11 +41,11 @@ public class GPSButton extends PowerButton { } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.LOCATION_SOURCE_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } @@ -55,7 +54,7 @@ public class GPSButton extends PowerButton { return OBSERVED_URIS; } - private static boolean getGpsState(Context context) { + private boolean getGpsState(Context context) { ContentResolver resolver = context.getContentResolver(); return Settings.Secure.isLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/LockScreenButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/LockScreenButton.java index a36c495..0a1959f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/LockScreenButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/LockScreenButton.java @@ -2,30 +2,24 @@ package com.android.systemui.statusbar.powerwidget; import com.android.systemui.R; -import android.app.Activity; import android.app.KeyguardManager; import android.app.KeyguardManager.KeyguardLock; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.view.Gravity; -import android.widget.Toast; +import android.view.View; public class LockScreenButton extends PowerButton { - - private static Boolean LOCK_SCREEN_STATE = null; + private static final String KEY_DISABLED = "lockscreen_disabled"; private KeyguardLock mLock = null; + private boolean mDisabledLockscreen = false; public LockScreenButton() { mType = BUTTON_LOCKSCREEN; } @Override - protected void updateState() { - getState(); - if (LOCK_SCREEN_STATE == null) { - mIcon = R.drawable.stat_lock_screen_off; - mState = STATE_INTERMEDIATE; - } else if (LOCK_SCREEN_STATE) { + protected void updateState(Context context) { + if (!mDisabledLockscreen) { mIcon = R.drawable.stat_lock_screen_on; mState = STATE_ENABLED; } else { @@ -35,54 +29,50 @@ public class LockScreenButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); - getState(); - if(LOCK_SCREEN_STATE == null) { - Toast msg = Toast.makeText(context, "Not yet initialized", Toast.LENGTH_LONG); - msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2, msg.getYOffset() / 2); - msg.show(); - } else { - getLock(context); - if (mLock != null) { - if (LOCK_SCREEN_STATE) { - mLock.disableKeyguard(); - LOCK_SCREEN_STATE = false; - } else { - mLock.reenableKeyguard(); - LOCK_SCREEN_STATE = true; - } - } + protected void setupButton(View view) { + super.setupButton(view); + + if (view == null && mDisabledLockscreen) { + mLock.reenableKeyguard(); + mLock = null; + } else if (view != null) { + Context context = view.getContext(); + mDisabledLockscreen = getPreferences(context).getBoolean(KEY_DISABLED, false); + applyState(context); } + } - // we're handling this, so just update our buttons now - // this is UGLY, do it better later >.> - update(); + @Override + protected void toggleState(Context context) { + mDisabledLockscreen = !mDisabledLockscreen; + + SharedPreferences.Editor editor = getPreferences(context).edit(); + editor.putBoolean(KEY_DISABLED, mDisabledLockscreen); + editor.apply(); + + applyState(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.SECURITY_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } - private KeyguardLock getLock(Context context) { + private void applyState(Context context) { if (mLock == null) { - KeyguardManager keyguardManager = (KeyguardManager)context. - getSystemService(Activity.KEYGUARD_SERVICE); - mLock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE); + KeyguardManager keyguardManager = (KeyguardManager) + context.getSystemService(Context.KEYGUARD_SERVICE); + mLock = keyguardManager.newKeyguardLock("PowerWidget"); } - return mLock; - } - - private static boolean getState() { - if (LOCK_SCREEN_STATE == null) { - LOCK_SCREEN_STATE = true; + if (mDisabledLockscreen) { + mLock.disableKeyguard(); + } else { + mLock.reenableKeyguard(); } - return LOCK_SCREEN_STATE; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaKeyEventButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaKeyEventButton.java index f722036..62ddbbd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaKeyEventButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaKeyEventButton.java @@ -14,10 +14,9 @@ import android.view.View; public abstract class MediaKeyEventButton extends PowerButton { private static final String TAG = "MediaKeyEventButton"; - private static AudioManager AUDIO_MANAGER = null; + private AudioManager mAM = null; - protected void sendMediaKeyEvent(int code) { - Context context = mView.getContext(); + protected void sendMediaKeyEvent(Context context, int code) { long eventtime = SystemClock.uptimeMillis(); Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); @@ -31,11 +30,11 @@ public abstract class MediaKeyEventButton extends PowerButton { context.sendOrderedBroadcast(upIntent, null); } - protected static AudioManager getAudioManager(Context context) { - if(AUDIO_MANAGER == null) { - AUDIO_MANAGER = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + protected AudioManager getAudioManager(Context context) { + if (mAM == null) { + mAM = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } - return AUDIO_MANAGER; + return mAM; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaNextButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaNextButton.java index d416c9a..c5c0791 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaNextButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaNextButton.java @@ -9,18 +9,18 @@ public class MediaNextButton extends MediaKeyEventButton { public MediaNextButton() { mType = BUTTON_MEDIA_NEXT; } @Override - protected void updateState() { + protected void updateState(Context context) { mIcon = R.drawable.stat_media_next; mState = STATE_DISABLED; } @Override - protected void toggleState() { - sendMediaKeyEvent(KeyEvent.KEYCODE_MEDIA_NEXT); + protected void toggleState(Context context) { + sendMediaKeyEvent(context, KeyEvent.KEYCODE_MEDIA_NEXT); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { return false; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPlayPauseButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPlayPauseButton.java index ea814e3..9a6ec71 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPlayPauseButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPlayPauseButton.java @@ -16,9 +16,9 @@ public class MediaPlayPauseButton extends MediaKeyEventButton { private int mCurrentState = MEDIA_STATE_UNKNOWN; @Override - protected void updateState() { + protected void updateState(Context context) { mState = STATE_DISABLED; - if(isMusicActive()) { + if (isMusicActive(context)) { mIcon = R.drawable.stat_media_pause; } else { mIcon = R.drawable.stat_media_play; @@ -26,24 +26,24 @@ public class MediaPlayPauseButton extends MediaKeyEventButton { } @Override - protected void toggleState() { - sendMediaKeyEvent(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); + protected void toggleState(Context context) { + sendMediaKeyEvent(context, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); - mCurrentState = (isMusicActive() ? MEDIA_STATE_INACTIVE : MEDIA_STATE_ACTIVE); + mCurrentState = (isMusicActive(context) ? MEDIA_STATE_INACTIVE : MEDIA_STATE_ACTIVE); - update(); + update(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { return false; } - private boolean isMusicActive() { - if(mCurrentState == MEDIA_STATE_UNKNOWN) { + private boolean isMusicActive(Context context) { + if (mCurrentState == MEDIA_STATE_UNKNOWN) { mCurrentState = MEDIA_STATE_INACTIVE; - AudioManager am = getAudioManager(mView.getContext()); - if(am != null) { + AudioManager am = getAudioManager(context); + if (am != null) { mCurrentState = (am.isMusicActive() ? MEDIA_STATE_ACTIVE : MEDIA_STATE_INACTIVE); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPreviousButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPreviousButton.java index b7657f6..362b1f7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPreviousButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MediaPreviousButton.java @@ -9,18 +9,18 @@ public class MediaPreviousButton extends MediaKeyEventButton { public MediaPreviousButton() { mType = BUTTON_MEDIA_PREVIOUS; } @Override - protected void updateState() { + protected void updateState(Context context) { mIcon = R.drawable.stat_media_previous; mState = STATE_DISABLED; } @Override - protected void toggleState() { - sendMediaKeyEvent(KeyEvent.KEYCODE_MEDIA_PREVIOUS); + protected void toggleState(Context context) { + sendMediaKeyEvent(context, KeyEvent.KEYCODE_MEDIA_PREVIOUS); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { return false; } } 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 cb0666c..41495ad 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/MobileDataButton.java @@ -21,8 +21,8 @@ public class MobileDataButton extends PowerButton { public MobileDataButton() { mType = BUTTON_MOBILEDATA; } @Override - protected void updateState() { - if (getDataState(mView.getContext())) { + protected void updateState(Context context) { + if (getDataState(context)) { mIcon = R.drawable.stat_data_on; mState = STATE_ENABLED; } else { @@ -32,8 +32,7 @@ public class MobileDataButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); + protected void toggleState(Context context) { boolean mobiledataEnabled = getDataState(context); boolean toggleNetworkMode = Settings.System.getInt(context.getContentResolver(), @@ -63,13 +62,13 @@ public class MobileDataButton extends PowerButton { } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { // it may be better to make an Intent action for this or find the appropriate one // we may want to look at that option later Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName("com.android.phone", "com.android.phone.Settings"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } @@ -80,12 +79,7 @@ public class MobileDataButton extends PowerButton { return filter; } - private static boolean getDataRomingEnabled(Context context) { - return Settings.Secure.getInt(context.getContentResolver(), - Settings.Secure.DATA_ROAMING,0) > 0; - } - - private static boolean getDataState(Context context) { + private boolean getDataState(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getMobileDataEnabled(); 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 53a4e79..028d49c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/NetworkModeButton.java @@ -43,8 +43,7 @@ public class NetworkModeButton extends PowerButton{ public NetworkModeButton() { mType = BUTTON_NETWORKMODE; } @Override - protected void updateState() { - Context context = mView.getContext(); + protected void updateState(Context context) { mMode = get2G3G(context); mState = networkModeToState(context); @@ -79,8 +78,7 @@ public class NetworkModeButton extends PowerButton{ } @Override - protected void toggleState() { - Context context = mView.getContext(); + protected void toggleState(Context context) { int currentMode = getCurrentCMMode(context); Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE); @@ -120,13 +118,13 @@ public class NetworkModeButton extends PowerButton{ } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { // it may be better to make an Intent action for this or find the appropriate one // we may want to look at that option later Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName("com.android.phone", "com.android.phone.Settings"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } 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 fe96309..e1bd565 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java @@ -6,6 +6,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.graphics.PorterDuff.Mode; @@ -102,12 +103,12 @@ public abstract class PowerButton { } }; - protected abstract void updateState(); - protected abstract void toggleState(); - protected abstract boolean handleLongClick(); + protected abstract void updateState(Context context); + protected abstract void toggleState(Context context); + protected abstract boolean handleLongClick(Context context); - protected void update() { - updateState(); + protected void update(Context context) { + updateState(context); updateView(); } @@ -116,7 +117,7 @@ public abstract class PowerButton { // to broadcast events from the StatusBarService broadcast receiver } - protected void onChangeUri(Uri uri) { + protected void onChangeUri(ContentResolver resolver, Uri uri) { // do nothing as a standard, override this if the button needs to respond // to a changed setting } @@ -150,7 +151,8 @@ public abstract class PowerButton { private View.OnClickListener mClickListener = new View.OnClickListener() { public void onClick(View v) { - toggleState(); + toggleState(v.getContext()); + update(v.getContext()); if (mExternalClickListener != null) { mExternalClickListener.onClick(v); @@ -160,7 +162,7 @@ public abstract class PowerButton { private View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() { public boolean onLongClick(View v) { - boolean result = handleLongClick(); + boolean result = handleLongClick(v.getContext()); if (result && mExternalLongClickListener != null) { mExternalLongClickListener.onLongClick(v); @@ -176,4 +178,8 @@ public abstract class PowerButton { void setExternalLongClickListener(View.OnLongClickListener listener) { mExternalLongClickListener = listener; } + + protected SharedPreferences getPreferences(Context context) { + return context.getSharedPreferences("PowerButton-" + mType, Context.MODE_PRIVATE); + } } 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 c82fc86..ebfed9b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java @@ -95,6 +95,7 @@ public class PowerWidget extends FrameLayout { // this is a list of our currently loaded buttons private final HashMap<String, PowerButton> mButtons = new HashMap<String, PowerButton>(); + private final ArrayList<String> mButtonNames = new ArrayList<String>(); private View.OnClickListener mAllButtonClickListener; private View.OnLongClickListener mAllButtonLongClickListener; @@ -105,6 +106,7 @@ public class PowerWidget extends FrameLayout { private WidgetBroadcastReceiver mBroadcastReceiver = null; private WidgetSettingsObserver mObserver = null; + private LinearLayout mButtonLayout; private HorizontalScrollView mScrollView; public PowerWidget(Context context, AttributeSet attrs) { @@ -126,12 +128,12 @@ public class PowerWidget extends FrameLayout { removeAllViews(); // unregister our content receiver - if(mBroadcastReceiver != null) { + if (mBroadcastReceiver != null) { mContext.unregisterReceiver(mBroadcastReceiver); mBroadcastReceiver = null; } // unobserve our content - if(mObserver != null) { + if (mObserver != null) { mObserver.unobserve(); mObserver = null; } @@ -147,7 +149,7 @@ public class PowerWidget extends FrameLayout { Log.i(TAG, "Setting up widget"); String buttons = Settings.System.getString(mContext.getContentResolver(), Settings.System.WIDGET_BUTTONS); - if(buttons == null) { + if (buttons == null) { Log.i(TAG, "Default buttons being loaded"); buttons = BUTTONS_DEFAULT; // Add the WiMAX button if it's supported @@ -157,43 +159,14 @@ public class PowerWidget extends FrameLayout { } Log.i(TAG, "Button list: " + buttons); - // create a linearlayout to hold our buttons - LinearLayout ll = new LinearLayout(mContext); - ll.setOrientation(LinearLayout.HORIZONTAL); - ll.setGravity(Gravity.CENTER_HORIZONTAL); - - int buttonCount = 0; - for(String button : buttons.split("\\|")) { - Log.i(TAG, "Setting up button: " + button); - // 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 (loadButton(button, buttonView)) { - // add the button here - ll.addView(buttonView, BUTTON_LAYOUT_PARAMS); - buttonCount++; + for (String button : buttons.split("\\|")) { + if (loadButton(button)) { + mButtonNames.add(button); } else { Log.e(TAG, "Error setting up button: " + button); } } - - // we determine if we're using a horizontal scroll view based on a threshold of button counts - if(buttonCount > LAYOUT_SCROLL_BUTTON_THRESHOLD) { - // we need our horizontal scroll view to wrap the linear layout - mScrollView = new HorizontalScrollView(mContext); - // make the fading edge the size of a button (makes it more noticible that we can scroll - mScrollView.setFadingEdgeLength(mContext.getResources().getDisplayMetrics().widthPixels / LAYOUT_SCROLL_BUTTON_THRESHOLD); - mScrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); - mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER); - // set the padding on the linear layout to the size of our scrollbar, so we don't have them overlap - ll.setPadding(ll.getPaddingLeft(), ll.getPaddingTop(), ll.getPaddingRight(), mScrollView.getVerticalScrollbarWidth()); - mScrollView.addView(ll, WIDGET_LAYOUT_PARAMS); - updateScrollbar(); - addView(mScrollView, WIDGET_LAYOUT_PARAMS); - } else { - // not needed, just add the linear layout - addView(ll, WIDGET_LAYOUT_PARAMS); - } + recreateButtonLayout(); // set up a broadcast receiver for our intents, based off of what our power buttons have been loaded setupBroadcastReceiver(); @@ -209,28 +182,24 @@ public class PowerWidget extends FrameLayout { mObserver.observe(); } - private boolean loadButton(String key, View view) { + private boolean loadButton(String key) { // first make sure we have a valid button - if (!sPossibleButtons.containsKey(key) || view == null) { + if (!sPossibleButtons.containsKey(key)) { 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) { + } catch (Exception e) { Log.e(TAG, "Error loading button: " + key, e); return false; } @@ -256,12 +225,52 @@ public class PowerWidget extends FrameLayout { // clear our list mButtons.clear(); + mButtonNames.clear(); + } + + private void recreateButtonLayout() { + removeAllViews(); + + // create a linearlayout to hold our buttons + mButtonLayout = new LinearLayout(mContext); + mButtonLayout.setOrientation(LinearLayout.HORIZONTAL); + mButtonLayout.setGravity(Gravity.CENTER_HORIZONTAL); + + for (String button : mButtonNames) { + PowerButton pb = mButtons.get(button); + if (pb != null) { + View buttonView = mInflater.inflate(R.layout.power_widget_button, null, false); + pb.setupButton(buttonView); + mButtonLayout.addView(buttonView, BUTTON_LAYOUT_PARAMS); + } + } + + // we determine if we're using a horizontal scroll view based on a threshold of button counts + if (mButtonLayout.getChildCount() > LAYOUT_SCROLL_BUTTON_THRESHOLD) { + // we need our horizontal scroll view to wrap the linear layout + mScrollView = new HorizontalScrollView(mContext); + // make the fading edge the size of a button (makes it more noticible that we can scroll + mScrollView.setFadingEdgeLength(mContext.getResources().getDisplayMetrics().widthPixels / LAYOUT_SCROLL_BUTTON_THRESHOLD); + mScrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); + mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER); + // set the padding on the linear layout to the size of our scrollbar, so we don't have them overlap + mButtonLayout.setPadding(mButtonLayout.getPaddingLeft(), + mButtonLayout.getPaddingTop(), + mButtonLayout.getPaddingRight(), + mScrollView.getVerticalScrollbarWidth()); + mScrollView.addView(mButtonLayout, WIDGET_LAYOUT_PARAMS); + updateScrollbar(); + addView(mScrollView, WIDGET_LAYOUT_PARAMS); + } else { + // not needed, just add the linear layout + addView(mButtonLayout, WIDGET_LAYOUT_PARAMS); + } } public void updateAllButtons() { // cycle through our buttons and update them for (PowerButton pb : mButtons.values()) { - pb.update(); + pb.update(mContext); } } @@ -316,7 +325,7 @@ public class PowerWidget extends FrameLayout { } private void setupBroadcastReceiver() { - if(mBroadcastReceiver == null) { + if (mBroadcastReceiver == null) { mBroadcastReceiver = new WidgetBroadcastReceiver(); } } @@ -351,7 +360,7 @@ public class PowerWidget extends FrameLayout { if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { updateButtonLayoutWidth(); - setupWidget(); + recreateButtonLayout(); } else { // handle the intent through our power buttons for (PowerButton button : mButtons.values()) { @@ -432,7 +441,7 @@ public class PowerWidget extends FrameLayout { // do whatever the individual buttons must for (PowerButton button : mButtons.values()) { if (button.getObservedUris().contains(uri)) { - button.onChangeUri(uri); + button.onChangeUri(resolver, uri); } } 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 632e16a..f5810ae 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/ScreenTimeoutButton.java @@ -8,6 +8,7 @@ import android.content.SharedPreferences; import android.net.Uri; import android.provider.Settings; import android.view.Gravity; +import android.view.View; import android.widget.Toast; import java.util.ArrayList; @@ -36,8 +37,17 @@ public class ScreenTimeoutButton extends PowerButton { public ScreenTimeoutButton() { mType = BUTTON_SCREENTIMEOUT; } @Override - protected void updateState() { - int timeout = getScreenTimeout(mView.getContext()); + protected void setupButton(View view) { + super.setupButton(view); + if (view == null && mToast != null) { + mToast.cancel(); + mToast = null; + } + } + + @Override + protected void updateState(Context context) { + int timeout = getScreenTimeout(context); if (timeout <= SCREEN_TIMEOUT_LOW) { mIcon = R.drawable.stat_screen_timeout_off; @@ -52,8 +62,7 @@ public class ScreenTimeoutButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); + protected void toggleState(Context context) { int screenTimeout = getScreenTimeout(context); int currentMode = getCurrentCMMode(context); @@ -111,11 +120,11 @@ public class ScreenTimeoutButton extends PowerButton { } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.DISPLAY_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SleepButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SleepButton.java index 61fecc9..65f3963 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SleepButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SleepButton.java @@ -13,24 +13,24 @@ public class SleepButton extends PowerButton { public SleepButton() { mType = BUTTON_SLEEP; } @Override - protected void updateState() { + protected void updateState(Context context) { mIcon = R.drawable.stat_sleep; mState = STATE_DISABLED; } @Override - protected void toggleState() { - PowerManager pm = (PowerManager)mView.getContext() - .getSystemService(Context.POWER_SERVICE); + protected void toggleState(Context context) { + PowerManager pm = (PowerManager) + context.getSystemService(Context.POWER_SERVICE); pm.goToSleep(SystemClock.uptimeMillis() + 1); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.DISPLAY_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SoundButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SoundButton.java index ec69d4d..95a2521 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SoundButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SoundButton.java @@ -70,13 +70,13 @@ public class SoundButton extends PowerButton { Context context = mView.getContext(); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - updateSettings(); + updateSettings(context.getContentResolver()); } } @Override - protected void updateState() { - findCurrentState(); + protected void updateState(Context context) { + findCurrentState(context); switch (mRingersIndex) { case 0: mIcon = R.drawable.stat_silent; @@ -104,7 +104,7 @@ public class SoundButton extends PowerButton { } @Override - protected void toggleState() { + protected void toggleState(Context context) { mRingerValuesIndex++; if (mRingerValuesIndex > mRingerValues.length - 1) { mRingerValuesIndex = 0; @@ -114,21 +114,21 @@ public class SoundButton extends PowerButton { mRingersIndex = 0; } Ringer ringer = mRingers[mRingersIndex]; - ringer.execute(); + ringer.execute(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.SOUND_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } @Override - protected void onChangeUri(Uri uri) { - updateSettings(); + protected void onChangeUri(ContentResolver cr, Uri uri) { + updateSettings(cr); } @Override @@ -141,9 +141,7 @@ public class SoundButton extends PowerButton { return INTENT_FILTER; } - private void updateSettings() { - ContentResolver resolver = mView.getContext().getContentResolver(); - + private void updateSettings(ContentResolver resolver) { int expandedHapticFeedback = Settings.System.getInt(resolver, Settings.System.EXPANDED_HAPTIC_FEEDBACK, 2); if (expandedHapticFeedback == 2) { @@ -165,13 +163,12 @@ public class SoundButton extends PowerButton { mRingerValues[i] = Integer.valueOf(modes[i]); } } - - updateState(); } - private void findCurrentState() { - ContentResolver resolver = mView.getContext().getContentResolver(); - boolean vibrateInSilent = Settings.System.getInt(resolver, + private void findCurrentState(Context context) { + ensureAudioManager(context); + + boolean vibrateInSilent = Settings.System.getInt(context.getContentResolver(), Settings.System.VIBRATE_IN_SILENT, 0) == 1; int vibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); int ringerMode = mAudioManager.getRingerMode(); @@ -198,8 +195,13 @@ public class SoundButton extends PowerButton { } } - private class Ringer { + private void ensureAudioManager(Context context) { + if (mAudioManager == null) { + mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + } + } + private class Ringer { final boolean mVibrateInSilent; final int mVibrateSetting; final int mRingerMode; @@ -212,10 +214,12 @@ public class SoundButton extends PowerButton { mDoHapticFeedback = doHapticFeedback; } - void execute() { - ContentResolver resolver = mView.getContext().getContentResolver(); + void execute(Context context) { + ContentResolver resolver = context.getContentResolver(); Settings.System.putInt(resolver, Settings.System.VIBRATE_IN_SILENT, (mVibrateInSilent ? 1 : 0)); + + ensureAudioManager(context); mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, mVibrateSetting); mAudioManager.setRingerMode(mRingerMode); if (mDoHapticFeedback && mHapticFeedbackEnabled) { 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 ffb5877..3c5f547 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/SyncButton.java @@ -18,7 +18,9 @@ public class SyncButton extends PowerButton { private SyncStatusObserver mSyncObserver = new SyncStatusObserver() { public void onStatusChanged(int which) { // update state/view if something happened - update(); + if (mView != null) { + update(mView.getContext()); + } } }; private Object mSyncObserverHandle = null; @@ -38,8 +40,8 @@ public class SyncButton extends PowerButton { } @Override - protected void updateState() { - if (getSyncState(mView.getContext())) { + protected void updateState(Context context) { + if (getSyncState(context)) { mIcon = R.drawable.stat_sync_on; mState = STATE_ENABLED; } else { @@ -49,10 +51,9 @@ public class SyncButton extends PowerButton { } @Override - protected void toggleState() { - Context context = mView.getContext(); - ConnectivityManager connManager = (ConnectivityManager)context - .getSystemService(Context.CONNECTIVITY_SERVICE); + protected void toggleState(Context context) { + ConnectivityManager connManager = (ConnectivityManager) + context.getSystemService(Context.CONNECTIVITY_SERVICE); boolean backgroundData = getBackgroundDataState(context); boolean sync = ContentResolver.getMasterSyncAutomatically(); @@ -82,21 +83,21 @@ public class SyncButton extends PowerButton { } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.SYNC_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } - private static boolean getBackgroundDataState(Context context) { - ConnectivityManager connManager = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); + private boolean getBackgroundDataState(Context context) { + ConnectivityManager connManager = (ConnectivityManager) + context.getSystemService(Context.CONNECTIVITY_SERVICE); return connManager.getBackgroundDataSetting(); } - private static boolean getSyncState(Context context) { + private boolean getSyncState(Context context) { boolean backgroundData = getBackgroundDataState(context); boolean sync = ContentResolver.getMasterSyncAutomatically(); return backgroundData && sync; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiApButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiApButton.java index 3df4578..f90fb87 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiApButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiApButton.java @@ -99,8 +99,8 @@ public class WifiApButton extends PowerButton { public WifiApButton() { mType = BUTTON_WIFIAP; } @Override - protected void updateState() { - mState = sWifiApState.getTriState(mView.getContext()); + protected void updateState(Context context) { + mState = sWifiApState.getTriState(context); switch (mState) { case STATE_DISABLED: mIcon = R.drawable.stat_wifi_ap_off; @@ -124,18 +124,18 @@ public class WifiApButton extends PowerButton { } @Override - protected void toggleState() { - sWifiApState.toggleState(mView.getContext()); + protected void toggleState(Context context) { + sWifiApState.toggleState(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { // it may be better to make an Intent action for the WifiAp settings // we may want to look at that option later Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName("com.android.settings", "com.android.settings.TetherSettings"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiButton.java index bc0aca9..b55ba36 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WifiButton.java @@ -95,8 +95,8 @@ public class WifiButton extends PowerButton{ public WifiButton() { mType = BUTTON_WIFI; } @Override - protected void updateState() { - mState = sWifiState.getTriState(mView.getContext()); + protected void updateState(Context context) { + mState = sWifiState.getTriState(context); switch (mState) { case STATE_DISABLED: mIcon = R.drawable.stat_wifi_off; @@ -120,16 +120,16 @@ public class WifiButton extends PowerButton{ } @Override - protected void toggleState() { - sWifiState.toggleState(mView.getContext()); + protected void toggleState(Context context) { + sWifiState.toggleState(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.WIFI_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WimaxButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WimaxButton.java index 43e6a5b..a68f7a3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WimaxButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/WimaxButton.java @@ -105,8 +105,8 @@ public class WimaxButton extends PowerButton { public WimaxButton() { mType = BUTTON_WIMAX; } @Override - protected void updateState() { - mState = sWimaxState.getTriState(mView.getContext()); + protected void updateState(Context context) { + mState = sWimaxState.getTriState(context); switch (mState) { case STATE_DISABLED: mIcon = R.drawable.stat_wimax_off; @@ -130,16 +130,16 @@ public class WimaxButton extends PowerButton { } @Override - protected void toggleState() { - sWimaxState.toggleState(mView.getContext()); + protected void toggleState(Context context) { + sWimaxState.toggleState(context); } @Override - protected boolean handleLongClick() { + protected boolean handleLongClick(Context context) { Intent intent = new Intent("android.settings.WIMAX_SETTINGS"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mView.getContext().startActivity(intent); + context.startActivity(intent); return true; } |