diff --git a/packages/SystemUI/res/drawable-hdpi/stat_sys_sync_error.png b/packages/SystemUI/res/drawable-hdpi/stat_sys_sync_error.png deleted file mode 100644 index 70f839f903dfb..0000000000000 Binary files a/packages/SystemUI/res/drawable-hdpi/stat_sys_sync_error.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable-mdpi/stat_sys_sync_error.png b/packages/SystemUI/res/drawable-mdpi/stat_sys_sync_error.png deleted file mode 100644 index 6db607dd452a7..0000000000000 Binary files a/packages/SystemUI/res/drawable-mdpi/stat_sys_sync_error.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable-xhdpi/stat_sys_sync_error.png b/packages/SystemUI/res/drawable-xhdpi/stat_sys_sync_error.png deleted file mode 100644 index 6276f47c8bf26..0000000000000 Binary files a/packages/SystemUI/res/drawable-xhdpi/stat_sys_sync_error.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable-xxhdpi/stat_sys_sync_error.png b/packages/SystemUI/res/drawable-xxhdpi/stat_sys_sync_error.png deleted file mode 100644 index 2f6a4c0a2725f..0000000000000 Binary files a/packages/SystemUI/res/drawable-xxhdpi/stat_sys_sync_error.png and /dev/null differ diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index 1165b8d50e4fb..6a0f6e3e3107b 100755 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -29,11 +29,12 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.BatteryManager; +import android.os.Bundle; import android.provider.Settings; import android.util.AttributeSet; import android.view.View; -public class BatteryMeterView extends View { +public class BatteryMeterView extends View implements DemoMode { public static final String TAG = BatteryMeterView.class.getSimpleName(); public static final String ACTION_LEVEL_TEST = "com.android.systemui.BATTERY_LEVEL_TEST"; @@ -204,7 +205,6 @@ public class BatteryMeterView extends View { } private int getColorForLevel(int percent) { - if (mTracker.plugged) return mChargeColor; int thresh, color = 0; for (int i=0; i= FULL) { @@ -270,16 +271,16 @@ public class BatteryMeterView extends View { final float x = mWidth * 0.5f; final float y = (mHeight + mWarningTextHeight) * 0.48f; c.drawText(mWarningString, x, y, mWarningTextPaint); - } else if (mTracker.plugged) { + } else if (tracker.plugged) { final Rect r = new Rect( (int)frame.left + width / 4, (int)frame.top + height / 5, (int)frame.right - width / 4, (int)frame.bottom - height / 6); mLightning.setBounds(r); mLightning.draw(c); - } else if (mShowPercent && !(mTracker.level == 100 && !SHOW_100_PERCENT)) { + } else if (mShowPercent && !(tracker.level == 100 && !SHOW_100_PERCENT)) { mTextPaint.setTextSize(height * (SINGLE_DIGIT_PERCENT ? 0.75f - : (mTracker.level == 100 ? 0.38f : 0.5f))); + : (tracker.level == 100 ? 0.38f : 0.5f))); mTextHeight = -mTextPaint.getFontMetrics().ascent; final String str = String.valueOf(SINGLE_DIGIT_PERCENT ? (pct/10) : pct); @@ -302,4 +303,29 @@ public class BatteryMeterView extends View { // c.drawRect(1, 1, mWidth, mHeight, pt); } } + + private boolean mDemoMode; + private BatteryTracker mDemoTracker = new BatteryTracker(); + + @Override + public void dispatchDemoCommand(String command, Bundle args) { + if (!mDemoMode && command.equals(COMMAND_ENTER)) { + mDemoMode = true; + mDemoTracker.level = mTracker.level; + mDemoTracker.plugged = mTracker.plugged; + } else if (mDemoMode && command.equals(COMMAND_EXIT)) { + mDemoMode = false; + postInvalidate(); + } else if (mDemoMode && command.equals(COMMAND_BATTERY)) { + String level = args.getString("level"); + String plugged = args.getString("plugged"); + if (level != null) { + mDemoTracker.level = Math.min(Math.max(Integer.parseInt(level), 0), 100); + } + if (plugged != null) { + mDemoTracker.plugged = Boolean.parseBoolean(plugged); + } + postInvalidate(); + } + } } diff --git a/packages/SystemUI/src/com/android/systemui/DemoMode.java b/packages/SystemUI/src/com/android/systemui/DemoMode.java new file mode 100644 index 0000000000000..8d271e488ecab --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/DemoMode.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui; + +import android.os.Bundle; + +public interface DemoMode { + + void dispatchDemoCommand(String command, Bundle args); + + public static final String ACTION_DEMO = "com.android.systemui.demo"; + + public static final String COMMAND_ENTER = "enter"; + public static final String COMMAND_EXIT = "exit"; + public static final String COMMAND_CLOCK = "clock"; + public static final String COMMAND_BATTERY = "battery"; + public static final String COMMAND_NETWORK = "network"; + public static final String COMMAND_BARS = "bars"; + public static final String COMMAND_STATUS = "status"; +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java new file mode 100644 index 0000000000000..aba7afa16249b --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.phone; + +import android.os.Bundle; +import android.os.UserHandle; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import com.android.internal.statusbar.StatusBarIcon; +import com.android.systemui.DemoMode; +import com.android.systemui.R; +import com.android.systemui.statusbar.StatusBarIconView; +import com.android.systemui.statusbar.policy.LocationController; + +public class DemoStatusIcons extends LinearLayout implements DemoMode { + private final LinearLayout mStatusIcons; + private final int mIconSize; + + private boolean mDemoMode; + + public DemoStatusIcons(LinearLayout statusIcons, int iconSize) { + super(statusIcons.getContext()); + mStatusIcons = statusIcons; + mIconSize = iconSize; + + setLayoutParams(mStatusIcons.getLayoutParams()); + setOrientation(mStatusIcons.getOrientation()); + setGravity(Gravity.CENTER_VERTICAL); // no LL.getGravity() + ViewGroup p = (ViewGroup) mStatusIcons.getParent(); + p.addView(this, p.indexOfChild(mStatusIcons)); + } + + @Override + public void dispatchDemoCommand(String command, Bundle args) { + if (!mDemoMode && command.equals(COMMAND_ENTER)) { + mDemoMode = true; + mStatusIcons.setVisibility(View.GONE); + setVisibility(View.VISIBLE); + } else if (mDemoMode && command.equals(COMMAND_EXIT)) { + mDemoMode = false; + mStatusIcons.setVisibility(View.VISIBLE); + setVisibility(View.GONE); + } else if (mDemoMode && command.equals(COMMAND_STATUS)) { + String volume = args.getString("volume"); + if (volume != null) { + int iconId = volume.equals("silent") ? R.drawable.stat_sys_ringer_silent + : volume.equals("vibrate") ? R.drawable.stat_sys_ringer_vibrate + : 0; + updateSlot("volume", null, iconId); + } + String bt = args.getString("bluetooth"); + if (bt != null) { + int iconId = bt.equals("disconnected") ? R.drawable.stat_sys_data_bluetooth + : bt.equals("connected") ? R.drawable.stat_sys_data_bluetooth_connected + : 0; + updateSlot("bluetooth", null, iconId); + } + String location = args.getString("location"); + if (location != null) { + int iconId = location.equals("show") ? LocationController.LOCATION_STATUS_ICON_ID + : 0; + updateSlot(LocationController.LOCATION_STATUS_ICON_PLACEHOLDER, null, iconId); + } + String alarm = args.getString("alarm"); + if (alarm != null) { + int iconId = alarm.equals("show") ? R.drawable.stat_sys_alarm + : 0; + updateSlot("alarm_clock", null, iconId); + } + String sync = args.getString("sync"); + if (sync != null) { + int iconId = sync.equals("show") ? R.drawable.stat_sys_sync + : 0; + updateSlot("sync_active", null, iconId); + } + String tty = args.getString("tty"); + if (tty != null) { + int iconId = tty.equals("show") ? R.drawable.stat_sys_tty_mode + : 0; + updateSlot("tty", null, iconId); + } + String eri = args.getString("eri"); + if (eri != null) { + int iconId = eri.equals("show") ? R.drawable.stat_sys_roaming_cdma_0 + : 0; + updateSlot("cdma_eri", null, iconId); + } + String mute = args.getString("mute"); + if (mute != null) { + int iconId = mute.equals("show") ? android.R.drawable.stat_notify_call_mute + : 0; + updateSlot("mute", null, iconId); + } + String speakerphone = args.getString("speakerphone"); + if (speakerphone != null) { + int iconId = speakerphone.equals("show") ? android.R.drawable.stat_sys_speakerphone + : 0; + updateSlot("speakerphone", null, iconId); + } + } + } + + private void updateSlot(String slot, String iconPkg, int iconId) { + if (!mDemoMode) return; + int removeIndex = -1; + for (int i = 0; i < getChildCount(); i++) { + StatusBarIconView v = (StatusBarIconView) getChildAt(i); + if (slot.equals(v.getTag())) { + if (iconId == 0) { + removeIndex = i; + break; + } else { + StatusBarIcon icon = v.getStatusBarIcon(); + icon.iconPackage = iconPkg; + icon.iconId = iconId; + v.set(icon); + v.updateDrawable(); + return; + } + } + } + if (iconId == 0) { + if (removeIndex != -1) { + removeViewAt(removeIndex); + return; + } + } + StatusBarIcon icon = new StatusBarIcon(iconPkg, UserHandle.CURRENT, iconId, 0, 0, "Demo"); + StatusBarIconView v = new StatusBarIconView(mContext, null); + v.setTag(slot); + v.set(icon); + addView(v, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize)); + } +} \ No newline at end of file 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 bde3795dc4cab..01e6c842b2dc7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -47,6 +47,7 @@ import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.inputmethodservice.InputMethodService; +import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; @@ -79,6 +80,7 @@ import android.widget.ScrollView; import android.widget.TextView; import com.android.internal.statusbar.StatusBarIcon; +import com.android.systemui.DemoMode; import com.android.systemui.EventLogTags; import com.android.systemui.R; import com.android.systemui.statusbar.BaseStatusBar; @@ -102,7 +104,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; -public class PhoneStatusBar extends BaseStatusBar { +public class PhoneStatusBar extends BaseStatusBar implements DemoMode { static final String TAG = "PhoneStatusBar"; public static final boolean DEBUG = BaseStatusBar.DEBUG; public static final boolean SPEW = false; @@ -363,7 +365,6 @@ public class PhoneStatusBar extends BaseStatusBar { mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar); mStatusBarView.setBar(this); - PanelHolder holder = (PanelHolder) mStatusBarWindow.findViewById(R.id.panel_holder); mStatusBarView.setPanelHolder(holder); @@ -605,18 +606,13 @@ public class PhoneStatusBar extends BaseStatusBar { } } -// final ImageView wimaxRSSI = -// (ImageView)sb.findViewById(R.id.wimax_signal); -// if (wimaxRSSI != null) { -// mNetworkController.addWimaxIconView(wimaxRSSI); -// } - // receive broadcasts IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); + filter.addAction(ACTION_DEMO); context.registerReceiver(mBroadcastReceiver, filter); // listen for USER_SETUP_COMPLETE setting (per-user) @@ -1874,6 +1870,7 @@ public class PhoneStatusBar extends BaseStatusBar { } private void checkBarModes() { + if (mDemoMode) return; checkBarMode(mStatusBarMode, mStatusBarWindowState, mStatusBarView.getBarTransitions()); if (mNavigationBarView != null) { checkBarMode(mNavigationBarMode, @@ -2447,6 +2444,19 @@ public class PhoneStatusBar extends BaseStatusBar { repositionNavigationBar(); notifyNavigationBarScreenOn(true); } + else if (ACTION_DEMO.equals(action)) { + Bundle bundle = intent.getExtras(); + if (bundle != null) { + String command = bundle.getString("command", "").trim().toLowerCase(); + if (command.length() > 0) { + try { + dispatchDemoCommand(command, bundle); + } catch (Throwable t) { + Log.w(TAG, "Error running demo command, intent=" + intent, t); + } + } + } + } } }; @@ -2676,4 +2686,66 @@ public class PhoneStatusBar extends BaseStatusBar { } mContext.unregisterReceiver(mBroadcastReceiver); } + + private boolean mDemoModeAllowed; + private boolean mDemoMode; + private DemoStatusIcons mDemoStatusIcons; + + @Override + public void dispatchDemoCommand(String command, Bundle args) { + if (!mDemoModeAllowed) { + mDemoModeAllowed = Settings.Global.getInt(mContext.getContentResolver(), + "sysui_demo_allowed", 0) != 0; + } + if (!mDemoModeAllowed) return; + if (command.equals(COMMAND_ENTER)) { + mDemoMode = true; + } else if (command.equals(COMMAND_EXIT)) { + mDemoMode = false; + checkBarModes(); + } else if (!mDemoMode) { + // automatically enter demo mode on first demo command + dispatchDemoCommand(COMMAND_ENTER, new Bundle()); + } + boolean modeChange = command.equals(COMMAND_ENTER) || command.equals(COMMAND_EXIT); + if (modeChange || command.equals(COMMAND_CLOCK)) { + dispatchDemoCommandToView(command, args, R.id.clock); + } + if (modeChange || command.equals(COMMAND_BATTERY)) { + dispatchDemoCommandToView(command, args, R.id.battery); + } + if (modeChange || command.equals(COMMAND_STATUS)) { + if (mDemoStatusIcons == null) { + mDemoStatusIcons = new DemoStatusIcons(mStatusIcons, mIconSize); + } + mDemoStatusIcons.dispatchDemoCommand(command, args); + } + if (mNetworkController != null && (modeChange || command.equals(COMMAND_NETWORK))) { + mNetworkController.dispatchDemoCommand(command, args); + } + if (command.equals(COMMAND_BARS)) { + String mode = args.getString("mode"); + int barMode = "opaque".equals(mode) ? MODE_OPAQUE : + "transparent".equals(mode) ? MODE_TRANSPARENT : + "semi-transparent".equals(mode) ? MODE_SEMI_TRANSPARENT : + -1; + if (barMode != -1) { + boolean animate = true; + if (mStatusBarView != null) { + mStatusBarView.getBarTransitions().transitionTo(barMode, animate); + } + if (mNavigationBarView != null) { + mNavigationBarView.getBarTransitions().transitionTo(barMode, animate); + } + } + } + } + + private void dispatchDemoCommandToView(String command, Bundle args, int id) { + if (mStatusBarView == null) return; + View v = mStatusBarView.findViewById(id); + if (v instanceof DemoMode) { + ((DemoMode)v).dispatchDemoCommand(command, args); + } + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index 4ee2a4b98bcc0..159bc62cfb8bf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -157,9 +157,8 @@ public class PhoneStatusBarPolicy { // Sync state mService.setIcon("sync_active", R.drawable.stat_sys_sync, 0, null); - mService.setIcon("sync_failing", R.drawable.stat_sys_sync_error, 0, null); mService.setIconVisibility("sync_active", false); - mService.setIconVisibility("sync_failing", false); + // "sync_failing" is obsolete: b/1297963 // volume mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0, null); @@ -175,10 +174,7 @@ public class PhoneStatusBarPolicy { private final void updateSyncState(Intent intent) { if (!SHOW_SYNC_ICON) return; boolean isActive = intent.getBooleanExtra("active", false); - boolean isFailing = intent.getBooleanExtra("failing", false); mService.setIconVisibility("sync_active", isActive); - // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never" - //mService.setIconVisibility("sync_failing", isFailing && !isActive); } private final void updateSimState(Intent intent) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java index fece57ee06c0a..0e53f0d6eda46 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java @@ -23,10 +23,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.view.View; -import android.widget.ImageView; - -import com.android.systemui.R; import java.util.ArrayList; import java.util.HashSet; @@ -35,11 +31,6 @@ import java.util.Set; public class BluetoothController extends BroadcastReceiver { private static final String TAG = "StatusBar.BluetoothController"; - private Context mContext; - private ArrayList mIconViews = new ArrayList(); - - private int mIconId = R.drawable.stat_sys_data_bluetooth; - private int mContentDescriptionId = 0; private boolean mEnabled = false; private Set mBondedDevices = new HashSet(); @@ -48,7 +39,6 @@ public class BluetoothController extends BroadcastReceiver { new ArrayList(); public BluetoothController(Context context) { - mContext = context; IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); @@ -59,16 +49,11 @@ public class BluetoothController extends BroadcastReceiver { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null) { handleAdapterStateChange(adapter.getState()); - handleConnectionStateChange(adapter.getConnectionState()); } - refreshViews(); + fireCallbacks(); updateBondedBluetoothDevices(); } - public void addIconView(ImageView v) { - mIconViews.add(v); - } - public void addStateChangedCallback(BluetoothStateChangeCallback cb) { mChangeCallbacks.add(cb); } @@ -84,14 +69,8 @@ public class BluetoothController extends BroadcastReceiver { if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { handleAdapterStateChange( intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)); - } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { - handleConnectionStateChange( - intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, - BluetoothAdapter.STATE_DISCONNECTED)); - } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) { - // Fall through and update bonded devices and refresh view } - refreshViews(); + fireCallbacks(); updateBondedBluetoothDevices(); } @@ -111,31 +90,11 @@ public class BluetoothController extends BroadcastReceiver { } } - public void handleAdapterStateChange(int adapterState) { + private void handleAdapterStateChange(int adapterState) { mEnabled = (adapterState == BluetoothAdapter.STATE_ON); } - public void handleConnectionStateChange(int connectionState) { - final boolean connected = (connectionState == BluetoothAdapter.STATE_CONNECTED); - if (connected) { - mIconId = R.drawable.stat_sys_data_bluetooth_connected; - mContentDescriptionId = R.string.accessibility_bluetooth_connected; - } else { - mIconId = R.drawable.stat_sys_data_bluetooth; - mContentDescriptionId = R.string.accessibility_bluetooth_disconnected; - } - } - - public void refreshViews() { - int N = mIconViews.size(); - for (int i=0; i