diff options
author | Adrian Roos <roosa@google.com> | 2014-08-12 17:28:58 +0200 |
---|---|---|
committer | Adrian Roos <roosa@google.com> | 2014-08-12 17:27:41 +0000 |
commit | 5fd872e8ea44ffcd4fce1d1196736dca4f270508 (patch) | |
tree | 88ddf296a41c3b3ee9d962f52f911c0907236a8c /packages/SystemUI/src/com/android | |
parent | 14690b0aa380697179eb0432939a8ce96e6561f0 (diff) | |
download | frameworks_base-5fd872e8ea44ffcd4fce1d1196736dca4f270508.zip frameworks_base-5fd872e8ea44ffcd4fce1d1196736dca4f270508.tar.gz frameworks_base-5fd872e8ea44ffcd4fce1d1196736dca4f270508.tar.bz2 |
Hide panel while changing brightness
Bug: 15408618
Change-Id: Ic1f934f9ddbb582453b4b52a4b4402c71ac79654
Diffstat (limited to 'packages/SystemUI/src/com/android')
5 files changed, 164 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index cbf6e29..6d88214 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -35,6 +35,7 @@ import com.android.systemui.qs.QSTile.DetailAdapter; import com.android.systemui.settings.BrightnessController; import com.android.systemui.settings.ToggleSlider; import com.android.systemui.statusbar.phone.QSTileHost; +import com.android.systemui.statusbar.policy.BrightnessMirrorController; import java.util.ArrayList; import java.util.Collection; @@ -105,6 +106,14 @@ public class QSPanel extends ViewGroup { }); } + public void setBrightnessMirror(BrightnessMirrorController c) { + super.onFinishInflate(); + ToggleSlider brightnessSlider = (ToggleSlider) findViewById(R.id.brightness_slider); + ToggleSlider mirror = (ToggleSlider) c.getMirror().findViewById(R.id.brightness_slider); + brightnessSlider.setMirror(mirror); + brightnessSlider.setMirrorController(c); + } + public void setCallback(Callback callback) { mCallback = callback; } diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java index 108c8df..2113c68 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java +++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java @@ -188,6 +188,7 @@ public class BrightnessController implements ToggleSlider.Listener { mListening = false; } + @Override public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) { updateIcon(mAutomatic); if (!mAutomatic) { diff --git a/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java b/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java index 4b78072..acfeb4f 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java +++ b/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java @@ -29,6 +29,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import com.android.systemui.R; +import com.android.systemui.statusbar.policy.BrightnessMirrorController; public class ToggleSlider extends RelativeLayout { public interface Listener { @@ -43,6 +44,9 @@ public class ToggleSlider extends RelativeLayout { private SeekBar mSlider; private TextView mLabel; + private ToggleSlider mMirror; + private BrightnessMirrorController mMirrorController; + public ToggleSlider(Context context) { this(context, null); } @@ -72,6 +76,18 @@ public class ToggleSlider extends RelativeLayout { a.recycle(); } + public void setMirror(ToggleSlider toggleSlider) { + mMirror = toggleSlider; + if (mMirror != null) { + mMirror.mToggle.setChecked(mToggle.isChecked()); + mMirror.mSlider.setProgress(mSlider.getProgress()); + } + } + + public void setMirrorController(BrightnessMirrorController c) { + mMirrorController = c; + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -109,6 +125,10 @@ public class ToggleSlider extends RelativeLayout { mListener.onChanged( ToggleSlider.this, mTracking, checked, mSlider.getProgress()); } + + if (mMirror != null) { + mMirror.mToggle.setChecked(checked); + } } }; @@ -119,6 +139,10 @@ public class ToggleSlider extends RelativeLayout { mListener.onChanged( ToggleSlider.this, mTracking, mToggle.isChecked(), progress); } + + if (mMirror != null) { + mMirror.mSlider.setProgress(progress); + } } @Override @@ -131,6 +155,15 @@ public class ToggleSlider extends RelativeLayout { } mToggle.setChecked(false); + + if (mMirror != null) { + mMirror.mSlider.setPressed(true); + } + + if (mMirrorController != null) { + mMirrorController.showMirror(); + mMirrorController.setLocation((View) getParent()); + } } @Override @@ -141,6 +174,14 @@ public class ToggleSlider extends RelativeLayout { mListener.onChanged( ToggleSlider.this, mTracking, mToggle.isChecked(), mSlider.getProgress()); } + + if (mMirror != null) { + mMirror.mSlider.setPressed(false); + } + + if (mMirrorController != null) { + mMirrorController.hideMirror(); + } } }; } 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 ad60cc8..f8319c2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -133,6 +133,7 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; import com.android.systemui.statusbar.policy.BluetoothControllerImpl; +import com.android.systemui.statusbar.policy.BrightnessMirrorController; import com.android.systemui.statusbar.policy.CastControllerImpl; import com.android.systemui.statusbar.policy.FlashlightController; import com.android.systemui.statusbar.policy.HeadsUpNotificationView; @@ -229,6 +230,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, UserSwitcherController mUserSwitcherController; NextAlarmController mNextAlarmController; KeyguardMonitor mKeyguardMonitor; + BrightnessMirrorController mBrightnessMirrorController; int mNaturalBarHeight = -1; int mIconSize = -1; @@ -819,6 +821,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mSecurityController); mQSPanel.setHost(qsh); mQSPanel.setTiles(qsh.getTiles()); + mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindow); + mQSPanel.setBrightnessMirror(mBrightnessMirrorController); mHeader.setQSPanel(mQSPanel); qsh.setCallback(new QSTileHost.Callback() { @Override @@ -3048,6 +3052,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (mHeadsUpNotificationView != null) { mHeadsUpNotificationView.updateResources(); } + if (mBrightnessMirrorController != null) { + mBrightnessMirrorController.updateResources(); + } } protected void loadDimens() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java new file mode 100644 index 0000000..7bd2e5c --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2014 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.policy; + +import com.android.systemui.R; +import com.android.systemui.statusbar.phone.PhoneStatusBar; +import com.android.systemui.statusbar.phone.StatusBarWindowView; + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewPropertyAnimator; +import android.widget.FrameLayout; + +/** + * Controls showing and hiding of the brightness mirror. + */ +public class BrightnessMirrorController { + + public long TRANSITION_DURATION_OUT = 150; + public long TRANSITION_DURATION_IN = 200; + + private final View mScrimBehind; + private final View mBrightnessMirror; + private final View mPanelHolder; + private final int[] mInt2Cache = new int[2]; + + public BrightnessMirrorController(StatusBarWindowView statusBarWindow) { + mScrimBehind = statusBarWindow.findViewById(R.id.scrim_behind); + mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror); + mPanelHolder = statusBarWindow.findViewById(R.id.panel_holder); + } + + public void showMirror() { + mBrightnessMirror.setVisibility(View.VISIBLE); + outAnimation(mScrimBehind.animate()); + outAnimation(mPanelHolder.animate()) + .withLayer(); + } + + public void hideMirror() { + inAnimation(mScrimBehind.animate()); + inAnimation(mPanelHolder.animate()) + .withLayer() + .withEndAction(new Runnable() { + @Override + public void run() { + mBrightnessMirror.setVisibility(View.GONE); + } + }); + } + + private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) { + return a.alpha(0.0f) + .setDuration(TRANSITION_DURATION_OUT) + .setInterpolator(PhoneStatusBar.ALPHA_OUT); + } + private ViewPropertyAnimator inAnimation(ViewPropertyAnimator a) { + return a.alpha(1.0f) + .setDuration(TRANSITION_DURATION_IN) + .setInterpolator(PhoneStatusBar.ALPHA_IN); + } + + + public void setLocation(View original) { + original.getLocationInWindow(mInt2Cache); + int originalY = mInt2Cache[1]; + mBrightnessMirror.getLocationInWindow(mInt2Cache); + int mirrorY = mInt2Cache[1]; + + mBrightnessMirror.setTranslationY(mBrightnessMirror.getTranslationY() + + originalY - mirrorY); + } + + public View getMirror() { + return mBrightnessMirror; + } + + public void updateResources() { + FrameLayout.LayoutParams lp = + (FrameLayout.LayoutParams) mBrightnessMirror.getLayoutParams(); + lp.width = mBrightnessMirror.getResources().getDimensionPixelSize( + R.dimen.notification_panel_width); + lp.gravity = mBrightnessMirror.getResources().getInteger( + R.integer.notification_panel_layout_gravity); + mBrightnessMirror.setLayoutParams(lp); + + int padding = mBrightnessMirror.getResources().getDimensionPixelSize( + R.dimen.notification_side_padding); + mBrightnessMirror.setPadding(padding, mBrightnessMirror.getPaddingTop(), + padding, mBrightnessMirror.getPaddingBottom()); + } +} |