Merge "The return and fixing of demo mode" into nyc-dev
This commit is contained in:
@@ -238,6 +238,19 @@
|
|||||||
android:value="com.android.settings.category.system" />
|
android:value="com.android.settings.category.system" />
|
||||||
</activity>
|
</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 used by secondary users to register themselves with the system user. -->
|
||||||
<service android:name=".recents.RecentsSystemUserService"
|
<service android:name=".recents.RecentsSystemUserService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import android.provider.Settings;
|
|||||||
|
|
||||||
import com.android.systemui.statusbar.policy.BatteryController;
|
import com.android.systemui.statusbar.policy.BatteryController;
|
||||||
|
|
||||||
public class BatteryMeterDrawable extends Drawable implements DemoMode,
|
public class BatteryMeterDrawable extends Drawable implements
|
||||||
BatteryController.BatteryStateChangeCallback {
|
BatteryController.BatteryStateChangeCallback {
|
||||||
|
|
||||||
private static final float ASPECT_RATIO = 9.5f / 14.5f;
|
private static final float ASPECT_RATIO = 9.5f / 14.5f;
|
||||||
@@ -184,14 +184,12 @@ public class BatteryMeterDrawable extends Drawable implements DemoMode,
|
|||||||
mContext.getContentResolver().registerContentObserver(
|
mContext.getContentResolver().registerContentObserver(
|
||||||
Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
|
Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
|
||||||
updateShowPercent();
|
updateShowPercent();
|
||||||
if (mDemoMode) return;
|
|
||||||
mBatteryController.addStateChangedCallback(this);
|
mBatteryController.addStateChangedCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopListening() {
|
public void stopListening() {
|
||||||
mListening = false;
|
mListening = false;
|
||||||
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
|
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
|
||||||
if (mDemoMode) return;
|
|
||||||
mBatteryController.removeStateChangedCallback(this);
|
mBatteryController.removeStateChangedCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,35 +505,6 @@ public class BatteryMeterDrawable extends Drawable implements DemoMode,
|
|||||||
return 0;
|
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 {
|
private final class SettingObserver extends ContentObserver {
|
||||||
public SettingObserver() {
|
public SettingObserver() {
|
||||||
super(new Handler());
|
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
|
@Override
|
||||||
public boolean isPowerSave() {
|
public boolean isPowerSave() {
|
||||||
// Power save is not valid for the car, so always return false.
|
// 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);
|
dispatchDemoCommandToView(command, args, R.id.clock);
|
||||||
}
|
}
|
||||||
if (modeChange || command.equals(COMMAND_BATTERY)) {
|
if (modeChange || command.equals(COMMAND_BATTERY)) {
|
||||||
dispatchDemoCommandToView(command, args, R.id.battery);
|
mBatteryController.dispatchDemoCommand(command, args);
|
||||||
}
|
}
|
||||||
if (modeChange || command.equals(COMMAND_STATUS)) {
|
if (modeChange || command.equals(COMMAND_STATUS)) {
|
||||||
mIconController.dispatchDemoCommand(command, args);
|
mIconController.dispatchDemoCommand(command, args);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (mNetworkController != null && (modeChange || command.equals(COMMAND_NETWORK))) {
|
if (mNetworkController != null && (modeChange || command.equals(COMMAND_NETWORK))) {
|
||||||
mNetworkController.dispatchDemoCommand(command, args);
|
mNetworkController.dispatchDemoCommand(command, args);
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
package com.android.systemui.statusbar.policy;
|
package com.android.systemui.statusbar.policy;
|
||||||
|
|
||||||
|
import com.android.systemui.DemoMode;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
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}.
|
* 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.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import com.android.systemui.DemoMode;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
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 ArrayList<BatteryController.BatteryStateChangeCallback> mChangeCallbacks = new ArrayList<>();
|
||||||
private final PowerManager mPowerManager;
|
private final PowerManager mPowerManager;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
protected int mLevel;
|
protected int mLevel;
|
||||||
protected boolean mPluggedIn;
|
protected boolean mPluggedIn;
|
||||||
@@ -52,17 +55,21 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
|||||||
private boolean mTestmode = false;
|
private boolean mTestmode = false;
|
||||||
|
|
||||||
public BatteryControllerImpl(Context context) {
|
public BatteryControllerImpl(Context context) {
|
||||||
|
mContext = context;
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
|
|
||||||
|
registerReceiver();
|
||||||
|
updatePowerSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerReceiver() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||||
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
|
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
|
||||||
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGING);
|
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGING);
|
||||||
filter.addAction(ACTION_LEVEL_TEST);
|
filter.addAction(ACTION_LEVEL_TEST);
|
||||||
context.registerReceiver(this, filter);
|
mContext.registerReceiver(this, filter);
|
||||||
|
|
||||||
updatePowerSave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,4 +183,28 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
|||||||
mChangeCallbacks.get(i).onPowerSaveChanged(mPowerSave);
|
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);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (getFragmentManager().findFragmentByTag(TAG_TUNER) == null) {
|
if (getFragmentManager().findFragmentByTag(TAG_TUNER) == null) {
|
||||||
|
boolean showDemoMode = getIntent().getAction().equals(
|
||||||
|
"com.android.settings.action.DEMO_MODE");
|
||||||
boolean showNightMode = getIntent().getBooleanExtra(
|
boolean showNightMode = getIntent().getBooleanExtra(
|
||||||
NightModeFragment.EXTRA_SHOW_NIGHT_MODE, false);
|
NightModeFragment.EXTRA_SHOW_NIGHT_MODE, false);
|
||||||
|
final PreferenceFragment fragment = showNightMode ? new NightModeFragment()
|
||||||
|
: showDemoMode ? new DemoModeFragment()
|
||||||
|
: new TunerFragment();
|
||||||
getFragmentManager().beginTransaction().replace(R.id.content_frame,
|
getFragmentManager().beginTransaction().replace(R.id.content_frame,
|
||||||
showNightMode ? new NightModeFragment() : new TunerFragment(),
|
fragment, TAG_TUNER).commit();
|
||||||
TAG_TUNER).commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user