diff options
Diffstat (limited to 'packages/SystemUI/src')
29 files changed, 545 insertions, 530 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/AirplaneModeTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/AirplaneModeTile.java index a4d64c0..c93385c 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/AirplaneModeTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/AirplaneModeTile.java @@ -9,7 +9,6 @@ import android.view.View.OnLongClickListener; import com.android.systemui.R; import com.android.systemui.statusbar.phone.QuickSettingsController; -import com.android.systemui.statusbar.phone.PhoneStatusBar; import com.android.systemui.statusbar.phone.QuickSettingsContainerView; import com.android.systemui.statusbar.policy.NetworkController; import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChangedCallback; @@ -22,13 +21,10 @@ public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignal QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - mLabel = mContext.getString(R.string.quick_settings_airplane_mode_label); - mOnClick = new View.OnClickListener() { - @Override public void onClick(View v) { - // Change the system setting + // Change the system setting Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, !enabled ? 1 : 0); @@ -52,10 +48,22 @@ public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignal void onPostCreate() { NetworkController controller = new NetworkController(mContext); controller.addNetworkSignalChangedCallback(this); + updateTile(); super.onPostCreate(); } @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mLabel = mContext.getString(R.string.quick_settings_airplane_mode_label); + mDrawable = (enabled) ? R.drawable.ic_qs_airplane_on : R.drawable.ic_qs_airplane_off; + } + + @Override public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId, String wifitSignalContentDescriptionId, String description) { } @@ -65,19 +73,12 @@ public class AirplaneModeTile extends QuickSettingsTile implements NetworkSignal int mobileSignalIconId, String mobileSignalContentDescriptionId, int dataTypeIconId, String dataTypeContentDescriptionId, String description) { - // TODO Auto-generated method stub - } @Override public void onAirplaneModeChanged(boolean enabled) { this.enabled = enabled; - if(enabled){ - mDrawable = R.drawable.ic_qs_airplane_on; - }else{ - mDrawable = R.drawable.ic_qs_airplane_off; - } - updateQuickSettings(); + updateResources(); } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/AlarmTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/AlarmTile.java index dd15e47..76867ce 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/AlarmTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/AlarmTile.java @@ -22,8 +22,6 @@ public class AlarmTile extends QuickSettingsTile { QuickSettingsController qsc, Handler handler) { super(context, inflater, container, qsc); - mDrawable = R.drawable.ic_qs_alarm_on; - mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { @@ -37,13 +35,34 @@ public class AlarmTile extends QuickSettingsTile { qsc.registerObservedContent(Settings.System.getUriFor( Settings.System.NEXT_ALARM_FORMATTED), this); - updateStatus(); + } + + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mDrawable = R.drawable.ic_qs_alarm_on; + mLabel = Settings.System.getString(mContext.getContentResolver(), + Settings.System.NEXT_ALARM_FORMATTED); + } + + @Override + public void onReceive(Context context, Intent intent) { + updateResources(); } @Override public void onChangeUri(ContentResolver resolver, Uri uri) { - updateStatus(); - updateQuickSettings(); + updateResources(); } @Override @@ -52,12 +71,4 @@ public class AlarmTile extends QuickSettingsTile { super.updateQuickSettings(); } - /** - * Updates the alarm status shown on the tile. - */ - private void updateStatus() { - mLabel = Settings.System.getString(mContext.getContentResolver(), - Settings.System.NEXT_ALARM_FORMATTED); - } - } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/AutoRotateTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/AutoRotateTile.java index c0fc428..1a91ea8 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/AutoRotateTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/AutoRotateTile.java @@ -17,8 +17,6 @@ import com.android.systemui.statusbar.phone.QuickSettingsContainerView; public class AutoRotateTile extends QuickSettingsTile { - private static final String TAG = "AutoRotateButton"; - public AutoRotateTile(Context context, LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc, Handler handler) { super(context, inflater, container, qsc); @@ -41,7 +39,13 @@ public class AutoRotateTile extends QuickSettingsTile { , this); } - void applyAutoRotationChanges() { + @Override + public void updateResources() { + updateTile(); + updateQuickSettings(); + } + + private synchronized void updateTile() { if(!getAutoRotation()){ mDrawable = R.drawable.ic_qs_rotation_locked; mLabel = mContext.getString(R.string.quick_settings_rotation_locked_label); @@ -49,12 +53,11 @@ public class AutoRotateTile extends QuickSettingsTile { mDrawable = R.drawable.ic_qs_auto_rotate; mLabel = mContext.getString(R.string.quick_settings_rotation_unlocked_label); } - updateQuickSettings(); } @Override void onPostCreate() { - applyAutoRotationChanges(); + updateTile(); super.onPostCreate(); } @@ -64,6 +67,6 @@ public class AutoRotateTile extends QuickSettingsTile { @Override public void onChangeUri(ContentResolver resolver, Uri uri) { - applyAutoRotationChanges(); + updateResources(); } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/BatteryTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/BatteryTile.java index 89fc546..3c3e206 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/BatteryTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/BatteryTile.java @@ -29,11 +29,6 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange super(context, inflater, container, qsc); mTileLayout = R.layout.quick_settings_tile_battery; - batteryLevels = (LevelListDrawable) mContext.getResources().getDrawable(R.drawable.qs_sys_battery); - chargingBatteryLevels = (LevelListDrawable) mContext.getResources().getDrawable(R.drawable.qs_sys_battery_charging); - - BatteryController controller = new BatteryController(mContext); - controller.addStateChangedCallback(this); mOnClick = new View.OnClickListener() { @Override @@ -45,7 +40,9 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange @Override void onPostCreate() { - applyBatteryChanges(); + updateTile(); + BatteryController controller = new BatteryController(mContext); + controller.addStateChangedCallback(this); super.onPostCreate(); } @@ -53,10 +50,18 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange public void onBatteryLevelChanged(int level, boolean pluggedIn) { batteryLevel = level; charging = pluggedIn; - applyBatteryChanges(); + updateResources(); } - void applyBatteryChanges() { + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + batteryLevels = (LevelListDrawable) mContext.getResources().getDrawable(R.drawable.qs_sys_battery); + chargingBatteryLevels = (LevelListDrawable) mContext.getResources().getDrawable(R.drawable.qs_sys_battery_charging); batteryIcon = charging ? chargingBatteryLevels : batteryLevels; @@ -68,9 +73,7 @@ public class BatteryTile extends QuickSettingsTile implements BatteryStateChange batteryLevel) : mContext.getString(R.string.status_bar_settings_battery_meter_format, batteryLevel); - } - updateQuickSettings(); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/BluetoothTile.java index db37294..ec8ed66 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/BluetoothTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/BluetoothTile.java @@ -2,10 +2,8 @@ package com.android.systemui.quicksettings; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter.BluetoothStateChangeCallback; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -55,18 +53,24 @@ public class BluetoothTile extends QuickSettingsTile implements BluetoothStateCh @Override public void onReceive(Context context, Intent intent) { + boolean update = false; if(intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)){ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); enabled = (state == BluetoothAdapter.STATE_ON); + update = true; } if(intent.getAction().equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)){ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.STATE_DISCONNECTED); connected = (state == BluetoothAdapter.STATE_CONNECTED); + update = true; + } + + if (update) { + updateResources(); } - applyBluetoothChanges(); } void checkBluetoothState() { @@ -74,7 +78,13 @@ public class BluetoothTile extends QuickSettingsTile implements BluetoothStateCh connected = mBluetoothAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED; } - private void applyBluetoothChanges(){ + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { if(enabled){ if(connected){ mDrawable = R.drawable.ic_qs_bluetooth_on; @@ -86,22 +96,21 @@ public class BluetoothTile extends QuickSettingsTile implements BluetoothStateCh mDrawable = R.drawable.ic_qs_bluetooth_off; mLabel = mContext.getString(R.string.quick_settings_bluetooth_off_label); } - updateQuickSettings(); } @Override void onPostCreate() { + checkBluetoothState(); + updateTile(); BluetoothController controller = new BluetoothController(mContext); controller.addStateChangedCallback(this); - checkBluetoothState(); - applyBluetoothChanges(); super.onPostCreate(); } @Override public void onBluetoothStateChange(boolean on) { this.enabled = on; - applyBluetoothChanges(); + updateResources(); } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/BrightnessTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/BrightnessTile.java index 90f0c7e..6549c06 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/BrightnessTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/BrightnessTile.java @@ -3,12 +3,12 @@ package com.android.systemui.quicksettings; import android.app.Dialog; import android.content.ContentResolver; import android.content.Context; -import android.content.DialogInterface; import android.net.Uri; import android.os.Handler; import android.os.RemoteException; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -16,21 +16,18 @@ import android.view.View.OnLongClickListener; import android.view.Window; import android.view.WindowManager; import android.view.WindowManagerGlobal; -import android.widget.ImageView; import com.android.systemui.R; import com.android.systemui.statusbar.phone.QuickSettingsController; import com.android.systemui.statusbar.phone.QuickSettingsContainerView; -import com.android.systemui.statusbar.policy.BrightnessController; import com.android.systemui.statusbar.policy.BrightnessController.BrightnessStateChangeCallback; -import com.android.systemui.statusbar.policy.ToggleSlider; public class BrightnessTile extends QuickSettingsTile implements BrightnessStateChangeCallback { + private static final String TAG = "BrightnessTile"; + private final int mBrightnessDialogLongTimeout; - private final int mBrightnessDialogShortTimeout; private Dialog mBrightnessDialog; - private BrightnessController mBrightnessController; private final Handler mHandler; private boolean autoBrightness = true; @@ -41,7 +38,6 @@ public class BrightnessTile extends QuickSettingsTile implements BrightnessState mHandler = handler; mBrightnessDialogLongTimeout = mContext.getResources().getInteger(R.integer.quick_settings_brightness_dialog_long_timeout); - mBrightnessDialogShortTimeout = mContext.getResources().getInteger(R.integer.quick_settings_brightness_dialog_short_timeout); mOnClick = new OnClickListener() { @@ -75,17 +71,6 @@ public class BrightnessTile extends QuickSettingsTile implements BrightnessState mBrightnessDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); mBrightnessDialog.setContentView(R.layout.quick_settings_brightness_dialog); mBrightnessDialog.setCanceledOnTouchOutside(true); - - mBrightnessController = new BrightnessController(mContext, - (ImageView) mBrightnessDialog.findViewById(R.id.brightness_icon), - (ToggleSlider) mBrightnessDialog.findViewById(R.id.brightness_slider)); - mBrightnessDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - mBrightnessController = null; - } - }); - mBrightnessDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); mBrightnessDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; @@ -117,7 +102,18 @@ public class BrightnessTile extends QuickSettingsTile implements BrightnessState }; @Override - public void onBrightnessLevelChanged() { + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { int mode; try { mode = Settings.System.getIntForUser(mContext.getContentResolver(), @@ -130,16 +126,17 @@ public class BrightnessTile extends QuickSettingsTile implements BrightnessState : R.drawable.ic_qs_brightness_auto_off; mLabel = mContext.getString(R.string.quick_settings_brightness_label); } catch (SettingNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - if(mTile != null){ - updateQuickSettings(); + Log.e(TAG, "Brightness setting not found", e); } } @Override + public void onBrightnessLevelChanged() { + updateResources(); + } + + @Override public void onChangeUri(ContentResolver resolver, Uri uri) { - onBrightnessLevelChanged(); + updateResources(); } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/BugReportTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/BugReportTile.java index 4ac1a0b..5dffbdb 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/BugReportTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/BugReportTile.java @@ -32,16 +32,8 @@ public class BugReportTile extends QuickSettingsTile{ super(context, inflater, container, qsc); mHandler = handler; - mLabel = mContext.getString(R.string.quick_settings_report_bug); - mDrawable = com.android.internal.R.drawable.stat_sys_adb; - - try { - enabled = (Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.BUGREPORT_IN_POWER_MENU) != 0); - } catch (SettingNotFoundException e) { - } mOnClick = new View.OnClickListener() { - @Override public void onClick(View v) { mQsc.mBar.collapseAllPanels(true); @@ -52,17 +44,34 @@ public class BugReportTile extends QuickSettingsTile{ } @Override - public void onChangeUri(ContentResolver resolver, Uri uri) { - onBugreportChanged(); + void onPostCreate() { + updateTile(); + super.onPostCreate(); } - public void onBugreportChanged() { + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mLabel = mContext.getString(R.string.quick_settings_report_bug); + mDrawable = com.android.internal.R.drawable.stat_sys_adb; final ContentResolver cr = mContext.getContentResolver(); try { enabled = (Settings.Secure.getInt(cr, Settings.Secure.BUGREPORT_IN_POWER_MENU) != 0); } catch (SettingNotFoundException e) { } - updateQuickSettings(); + } + + @Override + public void onChangeUri(ContentResolver resolver, Uri uri) { + updateResources(); + } + + public void onBugreportChanged() { + updateResources(); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/GPSTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/GPSTile.java index 04c950f..9c13e8b 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/GPSTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/GPSTile.java @@ -1,10 +1,8 @@ package com.android.systemui.quicksettings; -import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.location.LocationManager; import android.provider.Settings; import android.view.LayoutInflater; @@ -24,6 +22,8 @@ public class GPSTile extends QuickSettingsTile implements LocationGpsStateChange private boolean enabled = false; private boolean working = false; + private String mDescription = null; + ContentResolver mContentResolver; public GPSTile(Context context, LayoutInflater inflater, @@ -56,19 +56,22 @@ public class GPSTile extends QuickSettingsTile implements LocationGpsStateChange @Override public void onReceive(Context context, Intent intent) { enabled = Settings.Secure.isLocationProviderEnabled(mContentResolver, LocationManager.GPS_PROVIDER); - mLabel = mContext.getString(R.string.quick_settings_gps); - setGenericLabel(); - applyGPSChanges(); + updateResources(); } @Override void onPostCreate() { - setGenericLabel(); - applyGPSChanges(); + updateTile(); super.onPostCreate(); } - void applyGPSChanges() { + @Override + public void updateResources() { + updateTile(); + updateQuickSettings(); + } + + private synchronized void updateTile() { if (enabled && working) { mDrawable = R.drawable.ic_qs_location; } else if (enabled) { @@ -76,21 +79,21 @@ public class GPSTile extends QuickSettingsTile implements LocationGpsStateChange } else { mDrawable = R.drawable.ic_qs_gps_off; } - updateQuickSettings(); + setGenericLabel(); } @Override public void onLocationGpsStateChanged(boolean inUse, String description) { working = inUse; - if (description != null) { - mLabel = description; - } else { - setGenericLabel(); - } - applyGPSChanges(); + mDescription = description; + updateResources(); } private void setGenericLabel() { - mLabel = (enabled ? mContext.getString(R.string.quick_settings_gps) : mContext.getString(R.string.quick_settings_gps_off)); + if (mDescription != null) { + mLabel = mDescription; + } else { + mLabel = (enabled ? mContext.getString(R.string.quick_settings_gps) : mContext.getString(R.string.quick_settings_gps_off)); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/InputMethodTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/InputMethodTile.java index 1a7ed45..9cb6aec 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/InputMethodTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/InputMethodTile.java @@ -15,7 +15,6 @@ import android.view.View.OnClickListener; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; -import android.widget.TextView; import com.android.systemui.R; import com.android.systemui.statusbar.phone.QuickSettingsContainerView; @@ -23,6 +22,7 @@ import com.android.systemui.statusbar.phone.QuickSettingsController; public class InputMethodTile extends QuickSettingsTile { + private InputMethodManager mImm; private boolean showTile = false; private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; @@ -30,7 +30,7 @@ public class InputMethodTile extends QuickSettingsTile { QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - mDrawable = R.drawable.ic_qs_ime; + mImm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); mOnClick = new OnClickListener() { @@ -47,17 +47,6 @@ public class InputMethodTile extends QuickSettingsTile { } - public void toggleVisibility(boolean show) { - InputMethodManager imm = - (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); - List<InputMethodInfo> imis = imm.getInputMethodList(); - - showTile = (show && needsToShowImeSwitchOngoingNotification(imm)); - mLabel = getCurrentInputMethodName(mContext, mContext.getContentResolver(), - imm, imis, mContext.getPackageManager()); - updateQuickSettings(); - } - private static String getCurrentInputMethodName(Context context, ContentResolver resolver, InputMethodManager imm, List<InputMethodInfo> imis, PackageManager pm) { if (resolver == null || imis == null) return null; @@ -122,12 +111,33 @@ public class InputMethodTile extends QuickSettingsTile { } @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + @Override void updateQuickSettings() { - TextView tv = (TextView) mTile.findViewById(R.id.tile_textview); - tv.setText(mLabel); - tv.setCompoundDrawablesWithIntrinsicBounds(0, mDrawable, 0, 0); mTile.setVisibility(showTile ? View.VISIBLE : View.GONE); super.updateQuickSettings(); } + private synchronized void updateTile() { + List<InputMethodInfo> imis = mImm.getInputMethodList(); + mLabel = getCurrentInputMethodName(mContext, mContext.getContentResolver(), + mImm, imis, mContext.getPackageManager()); + mDrawable = R.drawable.ic_qs_ime; + } + + public void toggleVisibility(boolean show) { + showTile = (show && needsToShowImeSwitchOngoingNotification(mImm)); + updateResources(); + } + } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTile.java index 2338498..79a2a99 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTile.java @@ -20,16 +20,18 @@ import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChan public class MobileNetworkTile extends QuickSettingsTile implements NetworkSignalChangedCallback{ - private int mDataTypeIconId; + private static final int NO_OVERLAY = 0; + private static final int DISABLED_OVERLAY = -1; + + private boolean mEnabled; + private String mDescription; + private int mDataTypeIconId = NO_OVERLAY; private String dataContentDescription; private String signalContentDescription; private boolean wifiOn = false; private ConnectivityManager mCm; - private int NO_OVERLAY = 0; - private int DISABLED_OVERLAY = -1; - public MobileNetworkTile(Context context, LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); @@ -67,10 +69,27 @@ public class MobileNetworkTile extends QuickSettingsTile implements NetworkSigna void onPostCreate() { NetworkController controller = new NetworkController(mContext); controller.addNetworkSignalChangedCallback(this); + updateTile(); super.onPostCreate(); } @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + Resources r = mContext.getResources(); + dataContentDescription = mEnabled && (mDataTypeIconId > 0) && !wifiOn + ? dataContentDescription + : r.getString(R.string.accessibility_no_data); + mLabel = mEnabled + ? removeTrailingPeriod(mDescription) + : r.getString(R.string.quick_settings_rssi_emergency_only); + } + + @Override public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId, String wifitSignalContentDescriptionId, String description) { wifiOn = enabled; @@ -100,19 +119,15 @@ public class MobileNetworkTile extends QuickSettingsTile implements NetworkSigna mDataTypeIconId = NO_OVERLAY; } - dataContentDescription = enabled && (dataTypeIconId > 0) && !wifiOn - ? dataContentDescription - : r.getString(R.string.accessibility_no_data); - mLabel = enabled - ? removeTrailingPeriod(description) - : r.getString(R.string.quick_settings_rssi_emergency_only); - updateQuickSettings(); + mEnabled = enabled; + mDescription = description; + + updateResources(); } } @Override public void onAirplaneModeChanged(boolean enabled) { - // TODO Auto-generated method stub } boolean deviceSupportsTelephony() { diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTypeTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTypeTile.java index 7c00e0c..98d5aa6 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTypeTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/MobileNetworkTypeTile.java @@ -48,8 +48,6 @@ public class MobileNetworkTypeTile extends QuickSettingsTile implements NetworkS QuickSettingsController qsc) { super(context, inflater, container, qsc); - updateState(); - mOnClick = new OnClickListener() { @Override public void onClick(View v) { @@ -116,15 +114,24 @@ public class MobileNetworkTypeTile extends QuickSettingsTile implements NetworkS //need to clear intermediate states and update the tile mInternalState = networkModeToState(); - applyNetworkTypeChanges(); + updateResources(); + } + + @Override + void onPostCreate() { + NetworkController controller = new NetworkController(mContext); + controller.addNetworkSignalChangedCallback(this); + updateTile(); + super.onPostCreate(); } - private void applyNetworkTypeChanges(){ - updateState(); - updateQuickSettings(); + @Override + public void updateResources() { + updateTile(); + super.updateResources(); } - protected void updateState() { + private synchronized void updateTile() { mMode = get2G3G(mContext); mState = networkModeToState(); @@ -199,16 +206,8 @@ public class MobileNetworkTypeTile extends QuickSettingsTile implements NetworkS } @Override - void onPostCreate() { - NetworkController controller = new NetworkController(mContext); - controller.addNetworkSignalChangedCallback(this); - super.onPostCreate(); - } - - @Override public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId, String wifitSignalContentDescriptionId, String description) { - // TODO Auto-generated method stub } @Override @@ -216,11 +215,10 @@ public class MobileNetworkTypeTile extends QuickSettingsTile implements NetworkS int mobileSignalIconId, String mobileSignalContentDescriptionId, int dataTypeIconId, String dataTypeContentDescriptionId, String description) { - applyNetworkTypeChanges(); + updateResources(); } @Override public void onAirplaneModeChanged(boolean enabled) { - // TODO Auto-generated method stub } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/NfcTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/NfcTile.java index efbc9a0..7cf473d 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/NfcTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/NfcTile.java @@ -3,8 +3,6 @@ package com.android.systemui.quicksettings; import android.content.Context; import android.content.Intent; import android.nfc.NfcAdapter; -import android.nfc.NfcManager; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -15,7 +13,6 @@ import com.android.systemui.statusbar.phone.QuickSettingsController; public class NfcTile extends QuickSettingsTile { - private static String TAG = "NfcTile"; private static NfcAdapter mNfcAdapter; private static final int NFC_ADAPTER_UNKNOWN = -100; @@ -24,13 +21,11 @@ public class NfcTile extends QuickSettingsTile { QuickSettingsController qsc) { super(context, inflater, container, qsc); - setTileState(getNfcState()); - mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { toggleState(); - applyNfcChanges(); + updateResources(); } }; @@ -49,12 +44,19 @@ public class NfcTile extends QuickSettingsTile { } @Override + void onPostCreate() { + updateTile(getNfcState()); + super.onPostCreate(); + } + + @Override public void onReceive(Context context, Intent intent) { - applyNfcChanges(); + updateResources(); } - private void applyNfcChanges() { - setTileState(getNfcState()); + @Override + public void updateResources() { + updateTile(getNfcState()); updateQuickSettings(); } @@ -72,7 +74,7 @@ public class NfcTile extends QuickSettingsTile { } } - private void setTileState(int state) { + private synchronized void updateTile(int state) { switch (state) { case NfcAdapter.STATE_TURNING_ON: diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/PreferencesTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/PreferencesTile.java index fbfeb65..bfbf96b 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/PreferencesTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/PreferencesTile.java @@ -14,9 +14,6 @@ public class PreferencesTile extends QuickSettingsTile{ QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - mDrawable = R.drawable.ic_qs_settings; - mLabel = mContext.getString(R.string.quick_settings_settings_label); - mOnClick = new View.OnClickListener() { @Override @@ -26,4 +23,20 @@ public class PreferencesTile extends QuickSettingsTile{ }; } + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mDrawable = R.drawable.ic_qs_settings; + mLabel = mContext.getString(R.string.quick_settings_settings_label); + } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java index f65c204..e339505 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java @@ -19,11 +19,9 @@ package com.android.systemui.quicksettings; import android.app.AlertDialog; import android.app.Profile; import android.app.ProfileManager; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.IntentFilter; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; @@ -47,9 +45,6 @@ public class ProfileTile extends QuickSettingsTile { qsc.registerAction(ProfileManagerService.INTENT_ACTION_PROFILE_SELECTED, this); mProfileManager = (ProfileManager) mContext.getSystemService(Context.PROFILE_SERVICE); - mDrawable = R.drawable.ic_qs_profiles; - - mLabel = mProfileManager.getActiveProfile().getName(); mOnClick = new View.OnClickListener() { @Override @@ -68,9 +63,25 @@ public class ProfileTile extends QuickSettingsTile { } @Override - public void onReceive(Context context, Intent intent) { + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mDrawable = R.drawable.ic_qs_profiles; mLabel = mProfileManager.getActiveProfile().getName(); - updateQuickSettings(); + } + + @Override + public void onReceive(Context context, Intent intent) { + updateResources(); } // copied from com.android.internal.policy.impl.GlobalActions diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/QuickSettingsTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/QuickSettingsTile.java index 5f0538e..8a06d1d 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/QuickSettingsTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/QuickSettingsTile.java @@ -1,11 +1,9 @@ package com.android.systemui.quicksettings; import android.app.ActivityManagerNative; -import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.net.Uri; import android.os.RemoteException; import android.os.UserHandle; @@ -68,6 +66,12 @@ public class QuickSettingsTile implements OnClickListener { public void onChangeUri(ContentResolver resolver, Uri uri) {} + public void updateResources() { + if(mTile != null) { + updateQuickSettings(); + } + } + void updateQuickSettings(){ TextView tv = (TextView) mTile.findViewById(R.id.tile_textview); tv.setCompoundDrawablesWithIntrinsicBounds(0, mDrawable, 0, 0); diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/QuietHoursTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/QuietHoursTile.java index 52a1c4e..1897750 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/QuietHoursTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/QuietHoursTile.java @@ -20,7 +20,7 @@ public class QuietHoursTile extends QuickSettingsTile { public QuietHoursTile(Context context, LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - updateTileState(); + mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { @@ -41,12 +41,18 @@ public class QuietHoursTile extends QuickSettingsTile { } @Override - public void onChangeUri(ContentResolver resolver, Uri uri) { - updateTileState(); - updateQuickSettings(); + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); } - private void updateTileState() { + private synchronized void updateTile() { mEnabled = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.QUIET_HOURS_ENABLED, 0, UserHandle.USER_CURRENT) == 1; if (mEnabled) { @@ -58,4 +64,9 @@ public class QuietHoursTile extends QuickSettingsTile { } } + @Override + public void onChangeUri(ContentResolver resolver, Uri uri) { + updateResources(); + } + } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/RingerModeTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/RingerModeTile.java index 2a6139c..f9d389d 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/RingerModeTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/RingerModeTile.java @@ -1,13 +1,10 @@ package com.android.systemui.quicksettings; -import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.media.AudioManager; import android.net.Uri; -import android.os.Handler; import android.os.Vibrator; import android.provider.Settings; import android.text.TextUtils; @@ -39,27 +36,19 @@ public class RingerModeTile extends QuickSettingsTile { private int mRingerValuesIndex; private AudioManager mAudioManager; - private Handler mHandler; public RingerModeTile(Context context, LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); - mHandler = new Handler(); - - // Load the available ringer modes - updateSettings(mContext.getContentResolver()); - - // Make sure we show the initial state correctly - updateState(); // Tile actions mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { toggleState(); - applyVibrationChanges(); + updateResources(); } }; @@ -79,21 +68,33 @@ public class RingerModeTile extends QuickSettingsTile { @Override public void onReceive(Context context, Intent intent) { - applyVibrationChanges(); + updateResources(); } @Override public void onChangeUri(ContentResolver resolver, Uri uri) { updateSettings(mContext.getContentResolver()); - applyVibrationChanges(); + updateResources(); + } + + @Override + void onPostCreate() { + // Load the available ringer modes + updateSettings(mContext.getContentResolver()); + + // Make sure we show the initial state correctly + updateTile(); + + super.onPostCreate(); } - private void applyVibrationChanges(){ - updateState(); - updateQuickSettings(); + @Override + public void updateResources() { + updateTile(); + super.updateResources(); } - protected void updateState() { + private synchronized void updateTile() { // The title does not change mLabel = mContext.getString(R.string.quick_settings_ringer_normal); diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/ScreenTimeoutTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/ScreenTimeoutTile.java index b16b2b4..a5c5588 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/ScreenTimeoutTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/ScreenTimeoutTile.java @@ -3,16 +3,13 @@ package com.android.systemui.quicksettings; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.res.Resources; import android.net.Uri; import android.provider.Settings; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; -import android.widget.Toast; import com.android.systemui.R; import com.android.systemui.statusbar.phone.QuickSettingsController; @@ -35,13 +32,11 @@ public class ScreenTimeoutTile extends QuickSettingsTile { LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - updateTileState(); - mOnClick = new OnClickListener() { @Override public void onClick(View v) { toggleState(); - applyTimeoutChanges(); + updateResources(); } }; @@ -60,15 +55,22 @@ public class ScreenTimeoutTile extends QuickSettingsTile { @Override public void onChangeUri(ContentResolver resolver, Uri uri) { - applyTimeoutChanges(); + updateResources(); } - void applyTimeoutChanges() { - updateTileState(); - updateQuickSettings(); + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); } - protected void updateTileState() { + private synchronized void updateTile() { int timeout = getScreenTimeout(); mLabel = makeTimeoutSummaryString(mContext, timeout); mDrawable = R.drawable.ic_qs_screen_timeout_off; diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/SleepScreenTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/SleepScreenTile.java index 2daec1a..92507f5 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/SleepScreenTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/SleepScreenTile.java @@ -19,8 +19,6 @@ public class SleepScreenTile extends QuickSettingsTile { public SleepScreenTile(Context context, LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - mDrawable = R.drawable.ic_qs_sleep; - mLabel = mContext.getString(R.string.quick_settings_screen_sleep); pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mOnClick = new OnClickListener() { @Override @@ -38,4 +36,21 @@ public class SleepScreenTile extends QuickSettingsTile { }; } + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mDrawable = R.drawable.ic_qs_sleep; + mLabel = mContext.getString(R.string.quick_settings_screen_sleep); + } + } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/SyncTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/SyncTile.java index 4ba31e8..d7fa291 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/SyncTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/SyncTile.java @@ -21,13 +21,11 @@ public class SyncTile extends QuickSettingsTile { QuickSettingsController qsc) { super(context, inflater, container, qsc); - updateTileState(); - mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { toggleState(); - applySyncChanges(); + updateResources(); } }; @@ -45,6 +43,28 @@ public class SyncTile extends QuickSettingsTile { } @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + if (getSyncState()) { + mDrawable = R.drawable.ic_qs_sync_on; + mLabel = mContext.getString(R.string.quick_settings_sync); + } else { + mDrawable = R.drawable.ic_qs_sync_off; + mLabel = mContext.getString(R.string.quick_settings_sync_off); + } + } + + @Override public void setupQuickSettingsTile() { super.setupQuickSettingsTile(); @@ -59,11 +79,6 @@ public class SyncTile extends QuickSettingsTile { } } - private void applySyncChanges() { - updateTileState(); - updateQuickSettings(); - } - protected void toggleState() { // If ON turn OFF else turn ON if (getSyncState()) { @@ -73,17 +88,6 @@ public class SyncTile extends QuickSettingsTile { } } - private void updateTileState() { - - if (getSyncState()) { - mDrawable = R.drawable.ic_qs_sync_on; - mLabel = mContext.getString(R.string.quick_settings_sync); - } else { - mDrawable = R.drawable.ic_qs_sync_off; - mLabel = mContext.getString(R.string.quick_settings_sync_off); - } - } - private boolean getSyncState() { return ContentResolver.getMasterSyncAutomatically(); } @@ -94,7 +98,7 @@ public class SyncTile extends QuickSettingsTile { mHandler.post(new Runnable() { @Override public void run() { - applySyncChanges(); + updateResources(); } }); } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/ToggleLockscreenTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/ToggleLockscreenTile.java index ad8c774..712ce5c 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/ToggleLockscreenTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/ToggleLockscreenTile.java @@ -14,12 +14,12 @@ import com.android.systemui.statusbar.phone.QuickSettingsController; import com.android.systemui.statusbar.phone.QuickSettingsContainerView; import com.android.systemui.statusbar.powerwidget.PowerButton; +@SuppressWarnings("deprecation") public class ToggleLockscreenTile extends QuickSettingsTile { private KeyguardLock mLock = null; private static final String KEY_DISABLED = "lockscreen_disabled"; - private final KeyguardManager mKeyguardManager; private boolean mDisabledLockscreen; private SharedPreferences mPrefs; @@ -27,9 +27,6 @@ public class ToggleLockscreenTile extends QuickSettingsTile { LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); - mLabel = mContext.getString(R.string.quick_settings_lockscreen); - - mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); mPrefs = mContext.getSharedPreferences("PowerButton-" + PowerButton.BUTTON_LOCKSCREEN, Context.MODE_PRIVATE); mDisabledLockscreen = mPrefs.getBoolean(KEY_DISABLED, false); @@ -43,7 +40,7 @@ public class ToggleLockscreenTile extends QuickSettingsTile { editor.putBoolean(KEY_DISABLED, mDisabledLockscreen); editor.apply(); - applyLockscreenChanges(); + updateResources(); } }; @@ -59,11 +56,18 @@ public class ToggleLockscreenTile extends QuickSettingsTile { @Override void onPostCreate() { - applyLockscreenChanges(); + updateTile(); super.onPostCreate(); } - void applyLockscreenChanges() { + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + mLabel = mContext.getString(R.string.quick_settings_lockscreen); if (mLock == null) { KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); @@ -76,7 +80,6 @@ public class ToggleLockscreenTile extends QuickSettingsTile { mDrawable = R.drawable.ic_qs_lock_screen_on; mLock.reenableKeyguard(); } - updateQuickSettings(); } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/TorchTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/TorchTile.java index 5360b03..7e20265 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/TorchTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/TorchTile.java @@ -20,8 +20,6 @@ public class TorchTile extends QuickSettingsTile { QuickSettingsController qsc, Handler handler) { super(context, inflater, container, qsc); - updateTileState(); - mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { @@ -43,7 +41,19 @@ public class TorchTile extends QuickSettingsTile { qsc.registerObservedContent(Settings.System.getUriFor(Settings.System.TORCH_STATE), this); } - private void updateTileState() { + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { boolean enabled = Settings.System.getInt(mContext.getContentResolver(), Settings.System.TORCH_STATE, 0) == 1; @@ -58,7 +68,6 @@ public class TorchTile extends QuickSettingsTile { @Override public void onChangeUri(ContentResolver resolver, Uri uri) { - updateTileState(); - updateQuickSettings(); + updateResources(); } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/UsbTetherTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/UsbTetherTile.java index ed70aa8..3d262ac 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/UsbTetherTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/UsbTetherTile.java @@ -67,12 +67,12 @@ public class UsbTetherTile extends QuickSettingsTile { mMassStorageActive = false; } - updateTileState(); + updateResources(); } @Override void onPostCreate() { - updateTileState(); + updateTile(); super.onPostCreate(); } @@ -82,7 +82,13 @@ public class UsbTetherTile extends QuickSettingsTile { super.updateQuickSettings(); } - private void updateTileState() { + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { updateState(); if (mUsbConnected && !mMassStorageActive) { if (mUsbTethered) { @@ -96,9 +102,6 @@ public class UsbTetherTile extends QuickSettingsTile { mDrawable = R.drawable.ic_qs_usb_tether_off; mLabel = mContext.getString(R.string.quick_settings_usb_tether_off_label); } - if(mTile != null) { - updateQuickSettings(); - } } private void updateState() { diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/UserTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/UserTile.java index 2c7db9a..1cd7225 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/UserTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/UserTile.java @@ -1,10 +1,8 @@ package com.android.systemui.quicksettings; import android.app.ActivityManagerNative; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; import android.database.Cursor; @@ -26,7 +24,6 @@ import android.view.WindowManagerGlobal; import android.widget.ImageView; import android.widget.TextView; -import com.android.internal.widget.LockPatternUtils; import com.android.systemui.R; import com.android.systemui.statusbar.phone.QuickSettingsContainerView; import com.android.systemui.statusbar.phone.QuickSettingsController; @@ -80,6 +77,11 @@ public class UserTile extends QuickSettingsTile { } @Override + public void updateResources() { + queryForUserInformation(); + } + + @Override void updateQuickSettings() { ImageView iv = (ImageView) mTile.findViewById(R.id.user_imageview); TextView tv = (TextView) mTile.findViewById(R.id.user_textview); @@ -111,7 +113,6 @@ public class UserTile extends QuickSettingsTile { // The system needs some time to change the picture, if we try to load it when we receive the broadcast, we will load the old one Thread.sleep(50); } catch (InterruptedException e) { - // TODO Auto-generated catch block e.printStackTrace(); } final UserManager um = diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiDisplayTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiDisplayTile.java index 9becfa0..58ce66a 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiDisplayTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiDisplayTile.java @@ -1,9 +1,7 @@ package com.android.systemui.quicksettings; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.hardware.display.DisplayManager; import android.hardware.display.WifiDisplayStatus; import android.view.LayoutInflater; @@ -32,7 +30,6 @@ public class WiFiDisplayTile extends QuickSettingsTile{ } }; qsc.registerAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED, this); - applyWiFiDisplayChanges(); } @Override @@ -40,10 +37,22 @@ public class WiFiDisplayTile extends QuickSettingsTile{ WifiDisplayStatus status = (WifiDisplayStatus)intent.getParcelableExtra(DisplayManager.EXTRA_WIFI_DISPLAY_STATUS); enabled = status.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON; connected = status.getActiveDisplay() != null; - applyWiFiDisplayChanges(); + updateResources(); } - private void applyWiFiDisplayChanges() { + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { if(enabled && connected) { mLabel = mContext.getString(R.string.quick_settings_wifi_display_label); mDrawable = R.drawable.ic_qs_remote_display_connected; @@ -51,9 +60,6 @@ public class WiFiDisplayTile extends QuickSettingsTile{ mLabel = mContext.getString(R.string.quick_settings_wifi_display_no_connection_label); mDrawable = R.drawable.ic_qs_remote_display; } - if(mTile != null) { - updateQuickSettings(); - } } @Override diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiTile.java index 5e75970..038a445 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/WiFiTile.java @@ -14,6 +14,11 @@ import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChan public class WiFiTile extends QuickSettingsTile implements NetworkSignalChangedCallback{ + private boolean mWifiConnected; + private boolean mWifiNotConnected; + private int mWifiSignalIconId; + private String mDescription; + public WiFiTile(Context context, LayoutInflater inflater, QuickSettingsContainerView container, QuickSettingsController qsc) { super(context, inflater, container, qsc); @@ -39,25 +44,37 @@ public class WiFiTile extends QuickSettingsTile implements NetworkSignalChangedC void onPostCreate() { NetworkController controller = new NetworkController(mContext); controller.addNetworkSignalChangedCallback(this); + updateTile(); super.onPostCreate(); } @Override - public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId, - String wifitSignalContentDescriptionId, String description) { - boolean wifiConnected = enabled && (wifiSignalIconId > 0) && (description != null); - boolean wifiNotConnected = (wifiSignalIconId > 0) && (description == null); - if (wifiConnected) { - mDrawable = wifiSignalIconId; - mLabel = description.substring(1, description.length()-1); - } else if (wifiNotConnected) { + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { + if (mWifiConnected) { + mDrawable = mWifiSignalIconId; + mLabel = mDescription.substring(1, mDescription.length()-1); + } else if (mWifiNotConnected) { mDrawable = R.drawable.ic_qs_wifi_0; mLabel = mContext.getString(R.string.quick_settings_wifi_label); } else { mDrawable = R.drawable.ic_qs_wifi_no_network; mLabel = mContext.getString(R.string.quick_settings_wifi_off_label); } - updateQuickSettings(); + } + + @Override + public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId, + String wifiSignalContentDescriptionId, String description) { + mWifiConnected = enabled && (wifiSignalIconId > 0) && (description != null); + mWifiNotConnected = (wifiSignalIconId > 0) && (description == null); + mWifiSignalIconId = wifiSignalIconId; + mDescription = description; + updateResources(); } @Override @@ -65,14 +82,10 @@ public class WiFiTile extends QuickSettingsTile implements NetworkSignalChangedC int mobileSignalIconId, String mobileSignalContentDescriptionId, int dataTypeIconId, String dataTypeContentDescriptionId, String description) { - // TODO Auto-generated method stub - } @Override public void onAirplaneModeChanged(boolean enabled) { - // TODO Auto-generated method stub - } } diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/WifiAPTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/WifiAPTile.java index 48de8af..2f2fe7b 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/WifiAPTile.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/WifiAPTile.java @@ -1,10 +1,8 @@ package com.android.systemui.quicksettings; -import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.net.wifi.WifiManager; import android.provider.Settings; import android.view.LayoutInflater; @@ -24,7 +22,6 @@ public class WifiAPTile extends QuickSettingsTile { mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); - updateTileState(); mOnClick = new View.OnClickListener() { @Override public void onClick(View v) { @@ -55,11 +52,22 @@ public class WifiAPTile extends QuickSettingsTile { @Override public void onReceive(Context context, Intent intent) { - updateTileState(); - updateQuickSettings(); + updateResources(); } - private void updateTileState() { + @Override + void onPostCreate() { + updateTile(); + super.onPostCreate(); + } + + @Override + public void updateResources() { + updateTile(); + super.updateResources(); + } + + private synchronized void updateTile() { int state = mWifiManager.getWifiApState(); switch (state) { case WifiManager.WIFI_AP_STATE_ENABLING: diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 4fb2f4d..41e3ad8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -48,6 +48,7 @@ import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.inputmethodservice.InputMethodService; +import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.os.IPowerManager; @@ -707,7 +708,7 @@ public class PhoneStatusBar extends BaseStatusBar { } mQS.setService(this); mQS.setBar(mStatusBarView); - mQS.updateResources(); + mQS.setupQuickSettings(); // Start observing for changes mTilesChangedObserver = new TilesChangedObserver(mHandler); @@ -2910,8 +2911,13 @@ public class PhoneStatusBar extends BaseStatusBar { @Override public void onChange(boolean selfChange) { + onChange(selfChange, null); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { if (mSettingsContainer != null) { - mQS.updateResources(); + mQS.setupQuickSettings(); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsController.java index 8aed0c3..8ef8a56 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsController.java @@ -16,18 +16,42 @@ package com.android.systemui.statusbar.phone; -import java.util.ArrayList; -import java.util.HashMap; +import static com.android.internal.util.cm.QSConstants.TILES_DEFAULT; +import static com.android.internal.util.cm.QSConstants.TILE_AIRPLANE; +import static com.android.internal.util.cm.QSConstants.TILE_AUTOROTATE; +import static com.android.internal.util.cm.QSConstants.TILE_BATTERY; +import static com.android.internal.util.cm.QSConstants.TILE_BLUETOOTH; +import static com.android.internal.util.cm.QSConstants.TILE_BRIGHTNESS; +import static com.android.internal.util.cm.QSConstants.TILE_DELIMITER; +import static com.android.internal.util.cm.QSConstants.TILE_GPS; +import static com.android.internal.util.cm.QSConstants.TILE_LOCKSCREEN; +import static com.android.internal.util.cm.QSConstants.TILE_LTE; +import static com.android.internal.util.cm.QSConstants.TILE_MOBILEDATA; +import static com.android.internal.util.cm.QSConstants.TILE_NETWORKMODE; +import static com.android.internal.util.cm.QSConstants.TILE_NFC; +import static com.android.internal.util.cm.QSConstants.TILE_PROFILE; +import static com.android.internal.util.cm.QSConstants.TILE_QUIETHOURS; +import static com.android.internal.util.cm.QSConstants.TILE_RINGER; +import static com.android.internal.util.cm.QSConstants.TILE_SCREENTIMEOUT; +import static com.android.internal.util.cm.QSConstants.TILE_SETTINGS; +import static com.android.internal.util.cm.QSConstants.TILE_SLEEP; +import static com.android.internal.util.cm.QSConstants.TILE_SYNC; +import static com.android.internal.util.cm.QSConstants.TILE_TORCH; +import static com.android.internal.util.cm.QSConstants.TILE_USER; +import static com.android.internal.util.cm.QSConstants.TILE_WIFI; +import static com.android.internal.util.cm.QSConstants.TILE_WIFIAP; +import static com.android.internal.util.cm.QSConstants.TILE_WIMAX; +import static com.android.internal.util.cm.QSUtils.deviceSupportsBluetooth; +import static com.android.internal.util.cm.QSUtils.deviceSupportsTelephony; +import static com.android.internal.util.cm.QSUtils.deviceSupportsUsbTether; +import static com.android.internal.util.cm.QSUtils.systemProfilesEnabled; -import android.bluetooth.BluetoothAdapter; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.pm.PackageManager; import android.database.ContentObserver; -import android.net.ConnectivityManager; import android.net.Uri; import android.os.Handler; import android.provider.Settings; @@ -42,27 +66,30 @@ import com.android.systemui.quicksettings.BatteryTile; import com.android.systemui.quicksettings.BluetoothTile; import com.android.systemui.quicksettings.BrightnessTile; import com.android.systemui.quicksettings.BugReportTile; -import com.android.systemui.quicksettings.NfcTile; -import com.android.systemui.quicksettings.QuietHoursTile; -import com.android.systemui.quicksettings.ScreenTimeoutTile; -import com.android.systemui.quicksettings.TorchTile; import com.android.systemui.quicksettings.GPSTile; import com.android.systemui.quicksettings.InputMethodTile; import com.android.systemui.quicksettings.MobileNetworkTile; import com.android.systemui.quicksettings.MobileNetworkTypeTile; +import com.android.systemui.quicksettings.NfcTile; import com.android.systemui.quicksettings.PreferencesTile; import com.android.systemui.quicksettings.ProfileTile; import com.android.systemui.quicksettings.QuickSettingsTile; +import com.android.systemui.quicksettings.QuietHoursTile; import com.android.systemui.quicksettings.RingerModeTile; +import com.android.systemui.quicksettings.ScreenTimeoutTile; import com.android.systemui.quicksettings.SleepScreenTile; import com.android.systemui.quicksettings.SyncTile; import com.android.systemui.quicksettings.ToggleLockscreenTile; +import com.android.systemui.quicksettings.TorchTile; import com.android.systemui.quicksettings.UsbTetherTile; import com.android.systemui.quicksettings.UserTile; import com.android.systemui.quicksettings.WiFiDisplayTile; import com.android.systemui.quicksettings.WiFiTile; import com.android.systemui.quicksettings.WifiAPTile; +import java.util.ArrayList; +import java.util.HashMap; + public class QuickSettingsController { private static String TAG = "QuickSettingsController"; @@ -73,92 +100,15 @@ public class QuickSettingsController { public HashMap<Uri, ArrayList<QuickSettingsTile>> mObserverMap = new HashMap<Uri, ArrayList<QuickSettingsTile>>(); - /** - * START OF DATA MATCHING BLOCK - * - * THE FOLLOWING DATA MUST BE KEPT UP-TO-DATE WITH THE DATA IN - * com.android.settings.cyanogenmod.QuickSettingsUtil IN THE - * Settings PACKAGE. - */ - public static final String TILE_USER = "toggleUser"; - public static final String TILE_BATTERY = "toggleBattery"; - public static final String TILE_SETTINGS = "toggleSettings"; - public static final String TILE_WIFI = "toggleWifi"; - public static final String TILE_GPS = "toggleGPS"; - public static final String TILE_BLUETOOTH = "toggleBluetooth"; - public static final String TILE_BRIGHTNESS = "toggleBrightness"; - public static final String TILE_RINGER = "toggleSound"; - public static final String TILE_SYNC = "toggleSync"; - public static final String TILE_WIFIAP = "toggleWifiAp"; - public static final String TILE_SCREENTIMEOUT = "toggleScreenTimeout"; - public static final String TILE_MOBILEDATA = "toggleMobileData"; - public static final String TILE_LOCKSCREEN = "toggleLockScreen"; - public static final String TILE_NETWORKMODE = "toggleNetworkMode"; - public static final String TILE_AUTOROTATE = "toggleAutoRotate"; - public static final String TILE_AIRPLANE = "toggleAirplane"; - public static final String TILE_TORCH = "toggleFlashlight"; // Keep old string for compatibility - public static final String TILE_SLEEP = "toggleSleepMode"; - public static final String TILE_LTE = "toggleLte"; - public static final String TILE_WIMAX = "toggleWimax"; - public static final String TILE_PROFILE = "toggleProfile"; - public static final String TILE_NFC = "toggleNfc"; - public static final String TILE_USBTETHER = "toggleUsbTether"; - public static final String TILE_QUIETHOURS = "toggleQuietHours"; - - private static final String TILE_DELIMITER = "|"; - private static ArrayList<String> TILES_DEFAULT = new ArrayList<String>(); - - static { - TILES_DEFAULT.add(TILE_USER); - TILES_DEFAULT.add(TILE_BRIGHTNESS); - TILES_DEFAULT.add(TILE_SETTINGS); - TILES_DEFAULT.add(TILE_WIFI); - TILES_DEFAULT.add(TILE_MOBILEDATA); - TILES_DEFAULT.add(TILE_BATTERY); - TILES_DEFAULT.add(TILE_AIRPLANE); - TILES_DEFAULT.add(TILE_BLUETOOTH); - } - - /** - * END OF DATA MATCHING BLOCK - */ - private final Context mContext; + private ArrayList<QuickSettingsTile> mQuickSettingsTiles; public PanelBar mBar; private final QuickSettingsContainerView mContainerView; private final Handler mHandler; private BroadcastReceiver mReceiver; private ContentObserver mObserver; - private final ArrayList<Integer> mQuickSettings; public PhoneStatusBar mStatusBarService; - // Constants for use in switch statement - public static final int WIFI_TILE = 0; - public static final int MOBILE_NETWORK_TILE = 1; - public static final int AIRPLANE_MODE_TILE = 2; - public static final int BLUETOOTH_TILE = 3; - public static final int RINGER_TILE = 4; - public static final int SLEEP_TILE = 5; - public static final int TOGGLE_LOCKSCREEN_TILE = 6; - public static final int GPS_TILE = 7; - public static final int AUTO_ROTATION_TILE = 8; - public static final int BRIGHTNESS_TILE = 9; - public static final int MOBILE_NETWORK_TYPE_TILE = 10; - public static final int SETTINGS_TILE = 11; - public static final int BATTERY_TILE = 12; - public static final int IME_TILE = 13; - public static final int ALARM_TILE = 14; - public static final int BUG_REPORT_TILE = 15; - public static final int WIFI_DISPLAY_TILE = 16; - public static final int TORCH_TILE = 17; - public static final int WIFIAP_TILE = 18; - public static final int PROFILE_TILE = 19; - public static final int SYNC_TILE = 20; - public static final int NFC_TILE = 21; - public static final int SCREENTIMEOUT_TILE = 22; - public static final int USBTETHER_TILE = 23; - public static final int QUIET_HOURS_TILE = 24; - public static final int USER_TILE = 99; private InputMethodTile IMETile; public QuickSettingsController(Context context, QuickSettingsContainerView container, PhoneStatusBar statusBarService) { @@ -166,18 +116,19 @@ public class QuickSettingsController { mContainerView = container; mHandler = new Handler(); mStatusBarService = statusBarService; - mQuickSettings = new ArrayList<Integer>(); + mQuickSettingsTiles = new ArrayList<QuickSettingsTile>(); } void loadTiles() { // Filter items not compatible with device boolean bluetoothSupported = deviceSupportsBluetooth(); - boolean telephonySupported = deviceSupportsTelephony(); + boolean telephonySupported = deviceSupportsTelephony(mContext); if (!bluetoothSupported) { TILES_DEFAULT.remove(TILE_BLUETOOTH); } + if (!telephonySupported) { TILES_DEFAULT.remove(TILE_WIFIAP); TILES_DEFAULT.remove(TILE_MOBILEDATA); @@ -186,6 +137,7 @@ public class QuickSettingsController { // Read the stored list of tiles ContentResolver resolver = mContext.getContentResolver(); + LayoutInflater inflater = LayoutInflater.from(mContext); String tiles = Settings.System.getString(resolver, Settings.System.QUICK_SETTINGS_TILES); if (tiles == null) { Log.i(TAG, "Default tiles being loaded"); @@ -194,69 +146,61 @@ public class QuickSettingsController { Log.i(TAG, "Tiles list: " + tiles); - // Clear the list - mQuickSettings.clear(); - // Split out the tile names and add to the list for (String tile : tiles.split("\\|")) { + QuickSettingsTile qs = null; if (tile.equals(TILE_USER)) { - mQuickSettings.add(USER_TILE); + qs = new UserTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_BATTERY)) { - mQuickSettings.add(BATTERY_TILE); + qs = new BatteryTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_SETTINGS)) { - mQuickSettings.add(SETTINGS_TILE); + qs = new PreferencesTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_WIFI)) { - mQuickSettings.add(WIFI_TILE); + qs = new WiFiTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_GPS)) { - mQuickSettings.add(GPS_TILE); - } else if (tile.equals(TILE_BLUETOOTH)) { - if(bluetoothSupported) { - mQuickSettings.add(BLUETOOTH_TILE); - } + qs = new GPSTile(mContext, inflater, mContainerView, this); + } else if (tile.equals(TILE_BLUETOOTH) && bluetoothSupported) { + qs = new BluetoothTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_BRIGHTNESS)) { - mQuickSettings.add(BRIGHTNESS_TILE); + qs = new BrightnessTile(mContext, inflater, mContainerView, this, mHandler); } else if (tile.equals(TILE_RINGER)) { - mQuickSettings.add(RINGER_TILE); + qs = new RingerModeTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_SYNC)) { - mQuickSettings.add(SYNC_TILE); - } else if (tile.equals(TILE_WIFIAP)) { - if(telephonySupported) { - mQuickSettings.add(WIFIAP_TILE); - } + qs = new SyncTile(mContext, inflater, mContainerView, this); + } else if (tile.equals(TILE_WIFIAP) && telephonySupported) { + qs = new WifiAPTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_SCREENTIMEOUT)) { - mQuickSettings.add(SCREENTIMEOUT_TILE); - } else if (tile.equals(TILE_MOBILEDATA)) { - if(telephonySupported) { - mQuickSettings.add(MOBILE_NETWORK_TILE); - } + qs = new ScreenTimeoutTile(mContext, inflater, mContainerView, this); + } else if (tile.equals(TILE_MOBILEDATA) && telephonySupported) { + qs = new MobileNetworkTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_LOCKSCREEN)) { - mQuickSettings.add(TOGGLE_LOCKSCREEN_TILE); - } else if (tile.equals(TILE_NETWORKMODE)) { - if(telephonySupported) { - mQuickSettings.add(MOBILE_NETWORK_TYPE_TILE); - } + qs = new ToggleLockscreenTile(mContext, inflater, mContainerView, this); + } else if (tile.equals(TILE_NETWORKMODE) && telephonySupported) { + qs = new MobileNetworkTypeTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_AUTOROTATE)) { - mQuickSettings.add(AUTO_ROTATION_TILE); + qs = new AutoRotateTile(mContext, inflater, mContainerView, this, mHandler); } else if (tile.equals(TILE_AIRPLANE)) { - mQuickSettings.add(AIRPLANE_MODE_TILE); + qs = new AirplaneModeTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_TORCH)) { - mQuickSettings.add(TORCH_TILE); + qs = new TorchTile(mContext, inflater, mContainerView, this, mHandler); } else if (tile.equals(TILE_SLEEP)) { - mQuickSettings.add(SLEEP_TILE); - } else if (tile.equals(TILE_PROFILE)) { - if (systemProfilesEnabled(resolver)) { - mQuickSettings.add(PROFILE_TILE); - } + qs = new SleepScreenTile(mContext, inflater, mContainerView, this); + } else if (tile.equals(TILE_PROFILE) && systemProfilesEnabled(resolver)) { + qs = new ProfileTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_NFC)) { // User cannot add the NFC tile if the device does not support it // No need to check again here - mQuickSettings.add(NFC_TILE); + qs = new NfcTile(mContext, inflater, mContainerView, this); } else if (tile.equals(TILE_WIMAX)) { // Not available yet } else if (tile.equals(TILE_LTE)) { // Not available yet } else if (tile.equals(TILE_QUIETHOURS)) { - mQuickSettings.add(QUIET_HOURS_TILE); + qs = new QuietHoursTile(mContext, inflater, mContainerView, this); + } + if (qs != null) { + qs.setupQuickSettingsTile(); + mQuickSettingsTiles.add(qs); } } @@ -264,24 +208,35 @@ public class QuickSettingsController { // These toggles must be the last ones added to the view, as they will show // only when they are needed if (Settings.System.getInt(resolver, Settings.System.QS_DYNAMIC_ALARM, 1) == 1) { - mQuickSettings.add(ALARM_TILE); + QuickSettingsTile qs = new AlarmTile(mContext, inflater, mContainerView, this, mHandler); + qs.setupQuickSettingsTile(); + mQuickSettingsTiles.add(qs); } if (Settings.System.getInt(resolver, Settings.System.QS_DYNAMIC_BUGREPORT, 1) == 1) { - mQuickSettings.add(BUG_REPORT_TILE); + QuickSettingsTile qs = new BugReportTile(mContext, inflater, mContainerView, this, mHandler); + qs.setupQuickSettingsTile(); + mQuickSettingsTiles.add(qs); } if (Settings.System.getInt(resolver, Settings.System.QS_DYNAMIC_WIFI, 1) == 1) { - mQuickSettings.add(WIFI_DISPLAY_TILE); + QuickSettingsTile qs = new WiFiDisplayTile(mContext, inflater, mContainerView, this); + qs.setupQuickSettingsTile(); + mQuickSettingsTiles.add(qs); } if (Settings.System.getInt(resolver, Settings.System.QS_DYNAMIC_IME, 1) == 1) { - mQuickSettings.add(IME_TILE); + QuickSettingsTile qs = new InputMethodTile(mContext, inflater, mContainerView, this); + qs.setupQuickSettingsTile(); + mQuickSettingsTiles.add(qs); } - if (deviceSupportsUsbTether() && Settings.System.getInt(resolver, Settings.System.QS_DYNAMIC_USBTETHER, 1) == 1) { - mQuickSettings.add(USBTETHER_TILE); + if (deviceSupportsUsbTether(mContext) && Settings.System.getInt(resolver, Settings.System.QS_DYNAMIC_USBTETHER, 1) == 1) { + QuickSettingsTile qs = new UsbTetherTile(mContext, inflater, mContainerView, this); + qs.setupQuickSettingsTile(); + mQuickSettingsTiles.add(qs); } } - private void setupQuickSettings() { - LayoutInflater inflater = LayoutInflater.from(mContext); + protected void setupQuickSettings() { + mQuickSettingsTiles.clear(); + mContainerView.removeAllViews(); // Clear out old receiver if (mReceiver != null) { mContext.unregisterReceiver(mReceiver); @@ -295,7 +250,7 @@ public class QuickSettingsController { } mObserver = new QuickSettingsObserver(mHandler); mObserverMap.clear(); - addQuickSettings(inflater); + loadTiles(); setupBroadcastReceiver(); setupContentObserver(); } @@ -329,6 +284,7 @@ public class QuickSettingsController { mContext.registerReceiver(mReceiver, filter); } + @SuppressWarnings({ "rawtypes", "unchecked" }) private void registerInMap(Object item, QuickSettingsTile tile, HashMap map) { if (map.keySet().contains(item)) { ArrayList list = (ArrayList) map.get(item); @@ -361,122 +317,10 @@ public class QuickSettingsController { } }; - boolean deviceSupportsTelephony() { - PackageManager pm = mContext.getPackageManager(); - return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); - } - - boolean deviceSupportsBluetooth() { - return (BluetoothAdapter.getDefaultAdapter() != null); - } - - boolean deviceSupportsUsbTether() { - ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - return (cm.getTetherableUsbRegexs().length != 0); - } - - boolean systemProfilesEnabled(ContentResolver resolver) { - return (Settings.System.getInt(resolver, Settings.System.SYSTEM_PROFILES_ENABLED, 1) == 1); - } - void setBar(PanelBar bar) { mBar = bar; } - void addQuickSettings(LayoutInflater inflater){ - // Load the user configured tiles - loadTiles(); - - // Now add the actual tiles from the loaded list - for (Integer entry: mQuickSettings) { - QuickSettingsTile qs = null; - switch (entry) { - case WIFI_TILE: - qs = new WiFiTile(mContext, inflater, mContainerView, this); - break; - case MOBILE_NETWORK_TILE: - qs = new MobileNetworkTile(mContext, inflater, mContainerView, this); - break; - case AIRPLANE_MODE_TILE: - qs = new AirplaneModeTile(mContext, inflater, mContainerView, this); - break; - case BLUETOOTH_TILE: - qs = new BluetoothTile(mContext, inflater, mContainerView, this); - break; - case RINGER_TILE: - qs = new RingerModeTile(mContext, inflater, mContainerView, this); - break; - case SLEEP_TILE: - qs = new SleepScreenTile(mContext, inflater, mContainerView, this); - break; - case TOGGLE_LOCKSCREEN_TILE: - qs = new ToggleLockscreenTile(mContext, inflater, mContainerView, this); - break; - case GPS_TILE: - qs = new GPSTile(mContext, inflater, mContainerView, this); - break; - case AUTO_ROTATION_TILE: - qs = new AutoRotateTile(mContext, inflater, mContainerView, this, mHandler); - break; - case BRIGHTNESS_TILE: - qs = new BrightnessTile(mContext, inflater, mContainerView, this, mHandler); - break; - case MOBILE_NETWORK_TYPE_TILE: - qs = new MobileNetworkTypeTile(mContext, inflater, mContainerView, this); - break; - case ALARM_TILE: - qs = new AlarmTile(mContext, inflater, mContainerView, this, mHandler); - break; - case BUG_REPORT_TILE: - qs = new BugReportTile(mContext, inflater, mContainerView, this, mHandler); - break; - case WIFI_DISPLAY_TILE: - qs = new WiFiDisplayTile(mContext, inflater, mContainerView, this); - break; - case SETTINGS_TILE: - qs = new PreferencesTile(mContext, inflater, mContainerView, this); - break; - case BATTERY_TILE: - qs = new BatteryTile(mContext, inflater, mContainerView, this); - break; - case IME_TILE: - IMETile = new InputMethodTile(mContext, inflater, mContainerView, this); - qs = IMETile; - break; - case USER_TILE: - qs = new UserTile(mContext, inflater, mContainerView, this); - break; - case TORCH_TILE: - qs = new TorchTile(mContext, inflater, mContainerView, this, mHandler); - break; - case WIFIAP_TILE: - qs = new WifiAPTile(mContext, inflater, mContainerView, this); - break; - case PROFILE_TILE: - qs = new ProfileTile(mContext, inflater, mContainerView, this); - break; - case SYNC_TILE: - qs = new SyncTile(mContext, inflater, mContainerView, this); - break; - case NFC_TILE: - qs = new NfcTile(mContext, inflater, mContainerView, this); - break; - case SCREENTIMEOUT_TILE: - qs = new ScreenTimeoutTile(mContext, inflater, mContainerView, this); - break; - case USBTETHER_TILE: - qs = new UsbTetherTile(mContext, inflater, mContainerView, this); - break; - case QUIET_HOURS_TILE: - qs = new QuietHoursTile(mContext, inflater, mContainerView, this); - break; - } - if (qs != null) { - qs.setupQuickSettingsTile(); - } - } - } - public void setService(PhoneStatusBar phoneStatusBar) { mStatusBarService = phoneStatusBar; } @@ -489,8 +333,8 @@ public class QuickSettingsController { public void updateResources() { mContainerView.updateResources(); - mContainerView.removeAllViews(); - setupQuickSettings(); - mContainerView.requestLayout(); + for (QuickSettingsTile t : mQuickSettingsTiles) { + t.updateResources(); + } } } |