Small changes to make VolumePanel more testable.
- Put a zen call requiring status_bar_service behind the controller. - Make the dialog window params overridable by subclasses. Bug: 19260237 Change-Id: I2b75cde8a2f7efcd8ac001f181c151597bb7a978
This commit is contained in:
@@ -31,6 +31,7 @@ public interface ZenModeController {
|
||||
void setUserId(int userId);
|
||||
boolean isZenAvailable();
|
||||
ComponentName getEffectsSuppressor();
|
||||
boolean isCountdownConditionSupported();
|
||||
|
||||
public static class Callback {
|
||||
public void onZenChanged(int zen) {}
|
||||
|
||||
@@ -169,6 +169,12 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
return NotificationManager.from(mContext).getEffectsSuppressor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCountdownConditionSupported() {
|
||||
return NotificationManager.from(mContext)
|
||||
.isSystemConditionProviderEnabled(ZenModeConfig.COUNTDOWN_PATH);
|
||||
}
|
||||
|
||||
private void fireNextAlarmChanged() {
|
||||
for (Callback cb : mCallbacks) {
|
||||
cb.onNextAlarmChanged();
|
||||
|
||||
@@ -350,6 +350,17 @@ public class VolumePanel extends Handler implements DemoMode {
|
||||
};
|
||||
}
|
||||
|
||||
protected LayoutParams getDialogLayoutParams(Window window, Resources res) {
|
||||
final LayoutParams lp = window.getAttributes();
|
||||
lp.token = null;
|
||||
lp.y = res.getDimensionPixelOffset(com.android.systemui.R.dimen.volume_panel_top);
|
||||
lp.type = LayoutParams.TYPE_STATUS_BAR_PANEL;
|
||||
lp.format = PixelFormat.TRANSLUCENT;
|
||||
lp.windowAnimations = com.android.systemui.R.style.VolumePanelAnimation;
|
||||
lp.setTitle(TAG);
|
||||
return lp;
|
||||
}
|
||||
|
||||
public VolumePanel(Context context, ZenModeController zenController) {
|
||||
mTag = String.format("%s.%08x", TAG, hashCode());
|
||||
mContext = context;
|
||||
@@ -408,14 +419,7 @@ public class VolumePanel extends Handler implements DemoMode {
|
||||
|
||||
mDialog.create();
|
||||
|
||||
final LayoutParams lp = window.getAttributes();
|
||||
lp.token = null;
|
||||
lp.y = res.getDimensionPixelOffset(com.android.systemui.R.dimen.volume_panel_top);
|
||||
lp.type = LayoutParams.TYPE_STATUS_BAR_PANEL;
|
||||
lp.format = PixelFormat.TRANSLUCENT;
|
||||
lp.windowAnimations = com.android.systemui.R.style.VolumePanelAnimation;
|
||||
lp.setTitle(TAG);
|
||||
window.setAttributes(lp);
|
||||
window.setAttributes(getDialogLayoutParams(window, res));
|
||||
|
||||
updateWidth();
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.systemui.volume;
|
||||
import android.animation.LayoutTransition;
|
||||
import android.animation.LayoutTransition.TransitionListener;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -85,10 +84,6 @@ public class ZenModePanel extends LinearLayout {
|
||||
private final int mSubheadWarningColor;
|
||||
private final int mSubheadColor;
|
||||
private final Interpolator mInterpolator;
|
||||
private final int mMaxConditions;
|
||||
private final int mMaxOptionalConditions;
|
||||
private final boolean mCountdownConditionSupported;
|
||||
private final int mFirstConditionIndex;
|
||||
private final TransitionHelper mTransitionHelper = new TransitionHelper();
|
||||
private final Uri mForeverId;
|
||||
|
||||
@@ -103,6 +98,10 @@ public class ZenModePanel extends LinearLayout {
|
||||
|
||||
private Callback mCallback;
|
||||
private ZenModeController mController;
|
||||
private boolean mCountdownConditionSupported;
|
||||
private int mMaxConditions;
|
||||
private int mMaxOptionalConditions;
|
||||
private int mFirstConditionIndex;
|
||||
private boolean mRequestingConditions;
|
||||
private Condition mExitCondition;
|
||||
private String mExitConditionText;
|
||||
@@ -127,14 +126,6 @@ public class ZenModePanel extends LinearLayout {
|
||||
mSubheadColor = res.getColor(R.color.qs_subhead);
|
||||
mInterpolator = AnimationUtils.loadInterpolator(mContext,
|
||||
com.android.internal.R.interpolator.fast_out_slow_in);
|
||||
mCountdownConditionSupported = NotificationManager.from(mContext)
|
||||
.isSystemConditionProviderEnabled(ZenModeConfig.COUNTDOWN_PATH);
|
||||
final int countdownDelta = mCountdownConditionSupported ? 1 : 0;
|
||||
mFirstConditionIndex = COUNTDOWN_CONDITION_INDEX + countdownDelta;
|
||||
final int minConditions = 1 /*forever*/ + countdownDelta;
|
||||
mMaxConditions = MathUtils.constrain(res.getInteger(R.integer.zen_mode_max_conditions),
|
||||
minConditions, 100);
|
||||
mMaxOptionalConditions = mMaxConditions - minConditions;
|
||||
mForeverId = Condition.newId(mContext).appendPath("forever").build();
|
||||
if (DEBUG) Log.d(mTag, "new ZenModePanel");
|
||||
}
|
||||
@@ -192,9 +183,6 @@ public class ZenModePanel extends LinearLayout {
|
||||
Interaction.register(mMoreSettings, mInteractionCallback);
|
||||
|
||||
mZenConditions = (LinearLayout) findViewById(R.id.zen_conditions);
|
||||
for (int i = 0; i < mMaxConditions; i++) {
|
||||
mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false));
|
||||
}
|
||||
|
||||
setLayoutTransition(newLayoutTransition(mTransitionHelper));
|
||||
}
|
||||
@@ -306,6 +294,16 @@ public class ZenModePanel extends LinearLayout {
|
||||
|
||||
public void init(ZenModeController controller) {
|
||||
mController = controller;
|
||||
mCountdownConditionSupported = mController.isCountdownConditionSupported();
|
||||
final int countdownDelta = mCountdownConditionSupported ? 1 : 0;
|
||||
mFirstConditionIndex = COUNTDOWN_CONDITION_INDEX + countdownDelta;
|
||||
final int minConditions = 1 /*forever*/ + countdownDelta;
|
||||
mMaxConditions = MathUtils.constrain(mContext.getResources()
|
||||
.getInteger(R.integer.zen_mode_max_conditions), minConditions, 100);
|
||||
mMaxOptionalConditions = mMaxConditions - minConditions;
|
||||
for (int i = 0; i < mMaxConditions; i++) {
|
||||
mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false));
|
||||
}
|
||||
setExitCondition(mController.getExitCondition());
|
||||
refreshExitConditionText();
|
||||
mSessionZen = getSelectedZen(-1);
|
||||
|
||||
Reference in New Issue
Block a user