Merge "The return and fixing of demo mode" into nyc-dev
am: 8af20ef
* commit '8af20ef6a885a50694805a066f02fc643e80b837':
The return and fixing of demo mode
Change-Id: I34d6d6dba5797b926a9ce61bd9670ea910f3e7b7
This commit is contained in:
@@ -238,6 +238,19 @@
|
||||
android:value="com.android.settings.category.system" />
|
||||
</activity>
|
||||
|
||||
<activity-alias android:name=".DemoMode"
|
||||
android:targetActivity=".tuner.TunerActivity"
|
||||
android:icon="@drawable/tuner"
|
||||
android:theme="@style/TunerSettings"
|
||||
android:label="@string/demo_mode"
|
||||
android:process=":tuner"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.DEMO_MODE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<!-- Service used by secondary users to register themselves with the system user. -->
|
||||
<service android:name=".recents.RecentsSystemUserService"
|
||||
android:exported="false"
|
||||
|
||||
@@ -37,7 +37,7 @@ import android.provider.Settings;
|
||||
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
|
||||
public class BatteryMeterDrawable extends Drawable implements DemoMode,
|
||||
public class BatteryMeterDrawable extends Drawable implements
|
||||
BatteryController.BatteryStateChangeCallback {
|
||||
|
||||
private static final float ASPECT_RATIO = 9.5f / 14.5f;
|
||||
@@ -184,14 +184,12 @@ public class BatteryMeterDrawable extends Drawable implements DemoMode,
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
|
||||
updateShowPercent();
|
||||
if (mDemoMode) return;
|
||||
mBatteryController.addStateChangedCallback(this);
|
||||
}
|
||||
|
||||
public void stopListening() {
|
||||
mListening = false;
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
|
||||
if (mDemoMode) return;
|
||||
mBatteryController.removeStateChangedCallback(this);
|
||||
}
|
||||
|
||||
@@ -507,35 +505,6 @@ public class BatteryMeterDrawable extends Drawable implements DemoMode,
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean mDemoMode;
|
||||
|
||||
@Override
|
||||
public void dispatchDemoCommand(String command, Bundle args) {
|
||||
if (!mDemoMode && command.equals(COMMAND_ENTER)) {
|
||||
mBatteryController.removeStateChangedCallback(this);
|
||||
mDemoMode = true;
|
||||
if (mListening) {
|
||||
mBatteryController.removeStateChangedCallback(this);
|
||||
}
|
||||
} else if (mDemoMode && command.equals(COMMAND_EXIT)) {
|
||||
mDemoMode = false;
|
||||
postInvalidate();
|
||||
if (mListening) {
|
||||
mBatteryController.addStateChangedCallback(this);
|
||||
}
|
||||
} else if (mDemoMode && command.equals(COMMAND_BATTERY)) {
|
||||
String level = args.getString("level");
|
||||
String plugged = args.getString("plugged");
|
||||
if (level != null) {
|
||||
mLevel = Math.min(Math.max(Integer.parseInt(level), 0), 100);
|
||||
}
|
||||
if (plugged != null) {
|
||||
mPluggedIn = Boolean.parseBoolean(plugged);
|
||||
}
|
||||
postInvalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private final class SettingObserver extends ContentObserver {
|
||||
public SettingObserver() {
|
||||
super(new Handler());
|
||||
|
||||
@@ -239,6 +239,11 @@ public class CarBatteryController extends BroadcastReceiver implements BatteryCo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchDemoCommand(String command, Bundle args) {
|
||||
// TODO: Car demo mode.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerSave() {
|
||||
// Power save is not valid for the car, so always return false.
|
||||
|
||||
@@ -3595,11 +3595,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
dispatchDemoCommandToView(command, args, R.id.clock);
|
||||
}
|
||||
if (modeChange || command.equals(COMMAND_BATTERY)) {
|
||||
dispatchDemoCommandToView(command, args, R.id.battery);
|
||||
mBatteryController.dispatchDemoCommand(command, args);
|
||||
}
|
||||
if (modeChange || command.equals(COMMAND_STATUS)) {
|
||||
mIconController.dispatchDemoCommand(command, args);
|
||||
|
||||
}
|
||||
if (mNetworkController != null && (modeChange || command.equals(COMMAND_NETWORK))) {
|
||||
mNetworkController.dispatchDemoCommand(command, args);
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package com.android.systemui.statusbar.policy;
|
||||
|
||||
import com.android.systemui.DemoMode;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public interface BatteryController {
|
||||
public interface BatteryController extends DemoMode {
|
||||
/**
|
||||
* Prints the current state of the {@link BatteryController} to the given {@link PrintWriter}.
|
||||
*/
|
||||
|
||||
@@ -21,9 +21,11 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
import com.android.systemui.DemoMode;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
@@ -43,6 +45,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
||||
private final ArrayList<BatteryController.BatteryStateChangeCallback> mChangeCallbacks = new ArrayList<>();
|
||||
private final PowerManager mPowerManager;
|
||||
private final Handler mHandler;
|
||||
private final Context mContext;
|
||||
|
||||
protected int mLevel;
|
||||
protected boolean mPluggedIn;
|
||||
@@ -52,17 +55,21 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
||||
private boolean mTestmode = false;
|
||||
|
||||
public BatteryControllerImpl(Context context) {
|
||||
mContext = context;
|
||||
mHandler = new Handler();
|
||||
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
registerReceiver();
|
||||
updatePowerSave();
|
||||
}
|
||||
|
||||
private void registerReceiver() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
|
||||
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGING);
|
||||
filter.addAction(ACTION_LEVEL_TEST);
|
||||
context.registerReceiver(this, filter);
|
||||
|
||||
updatePowerSave();
|
||||
mContext.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,4 +183,28 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
||||
mChangeCallbacks.get(i).onPowerSaveChanged(mPowerSave);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mDemoMode;
|
||||
|
||||
@Override
|
||||
public void dispatchDemoCommand(String command, Bundle args) {
|
||||
if (!mDemoMode && command.equals(COMMAND_ENTER)) {
|
||||
mDemoMode = true;
|
||||
mContext.unregisterReceiver(this);
|
||||
} else if (mDemoMode && command.equals(COMMAND_EXIT)) {
|
||||
mDemoMode = false;
|
||||
registerReceiver();
|
||||
updatePowerSave();
|
||||
} else if (mDemoMode && command.equals(COMMAND_BATTERY)) {
|
||||
String level = args.getString("level");
|
||||
String plugged = args.getString("plugged");
|
||||
if (level != null) {
|
||||
mLevel = Math.min(Math.max(Integer.parseInt(level), 0), 100);
|
||||
}
|
||||
if (plugged != null) {
|
||||
mPluggedIn = Boolean.parseBoolean(plugged);
|
||||
}
|
||||
fireBatteryLevelChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,15 @@ public class TunerActivity extends SettingsDrawerActivity implements
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getFragmentManager().findFragmentByTag(TAG_TUNER) == null) {
|
||||
boolean showDemoMode = getIntent().getAction().equals(
|
||||
"com.android.settings.action.DEMO_MODE");
|
||||
boolean showNightMode = getIntent().getBooleanExtra(
|
||||
NightModeFragment.EXTRA_SHOW_NIGHT_MODE, false);
|
||||
final PreferenceFragment fragment = showNightMode ? new NightModeFragment()
|
||||
: showDemoMode ? new DemoModeFragment()
|
||||
: new TunerFragment();
|
||||
getFragmentManager().beginTransaction().replace(R.id.content_frame,
|
||||
showNightMode ? new NightModeFragment() : new TunerFragment(),
|
||||
TAG_TUNER).commit();
|
||||
fragment, TAG_TUNER).commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user