diff options
12 files changed, 206 insertions, 11 deletions
diff --git a/packages/SystemUI/res/drawable/bg_qs_brightness_auto_off.xml b/packages/SystemUI/res/drawable/bg_qs_brightness_auto_off.xml new file mode 100644 index 000000000000..36a1cacb6153 --- /dev/null +++ b/packages/SystemUI/res/drawable/bg_qs_brightness_auto_off.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <corners android:radius="24dp" /> + <solid android:color="?attr/offStateColor" /> + <size android:width="48dp" android:height="48dp" /> +</shape> diff --git a/packages/SystemUI/res/drawable/bg_qs_brightness_auto_on.xml b/packages/SystemUI/res/drawable/bg_qs_brightness_auto_on.xml new file mode 100644 index 000000000000..7e1a9a0d282f --- /dev/null +++ b/packages/SystemUI/res/drawable/bg_qs_brightness_auto_on.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <corners android:radius="24dp" /> + <solid android:color="?android:attr/colorAccent" /> + <size android:width="48dp" android:height="48dp" /> +</shape> diff --git a/packages/SystemUI/res/drawable/ic_qs_brightness_auto_off.xml b/packages/SystemUI/res/drawable/ic_qs_brightness_auto_off.xml new file mode 100644 index 000000000000..4823216e91e2 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_brightness_auto_off.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="22dp" + android:height="22dp" + android:viewportWidth="22" + android:viewportHeight="22" + android:tint="?android:attr/textColorPrimary"> + + <path + android:pathData="M 19.31 8 L 19.31 3.31 L 14.62 3.31 L 11.31 0 L 8 3.31 L 3.31 3.31 L 3.31 8 L 0 11.31 L 3.31 14.62 L 3.31 19.31 L 8 19.31 L 11.31 22.62 L 14.62 19.31 L 19.31 19.31 L 19.31 14.62 L 22.62 11.31 Z M 2.83 11.31 L 5.31 8.83 L 5.31 5.31 L 8.83 5.31 L 11.31 2.83 L 13.79 5.31 L 15.68 5.31 L 12.93 8.06 L 12.31 6.31 L 10.31 6.31 L 7.9 13.09 L 5.31 15.68 L 5.31 13.79 Z M 12.46 11.96 L 11.71 11.96 L 12.28 11.39 Z M 10.68 10.31 L 11.31 8.31 L 11.64 9.31 Z M 17.31 13.79 L 17.31 17.31 L 13.79 17.31 L 11.31 19.79 L 8.83 17.31 L 6.36 17.31 L 8.36 15.31 L 9 15.31 L 9.35 14.31 L 10.35 13.31 L 12.9 13.31 L 13.6 15.31 L 15.5 15.31 L 13.63 10 L 17.31 6.32 L 17.31 8.83 L 19.79 11.31 Z" + android:fillColor="#ffffff" + android:strokeWidth="1"/> +</vector> diff --git a/packages/SystemUI/res/drawable/ic_qs_brightness_auto_on.xml b/packages/SystemUI/res/drawable/ic_qs_brightness_auto_on.xml new file mode 100644 index 000000000000..fd104d099385 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_brightness_auto_on.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="36.0dip" + android:height="48.0dip" + android:viewportWidth="36.0" + android:viewportHeight="48.0" + android:tint="?android:attr/textColorPrimaryInverse"> + + <path android:fillColor="#FFFFFFFF" + android:pathData="m 17,19 -3.2,9 h 1.9 l 0.7,-2 h 3.2 l 0.7,2 h 1.9 L 19,19 Z M 16.85,24.65 18,21 19.15,24.65 Z M 26,20.69 V 16 H 21.31 L 18,12.69 14.69,16 H 10 v 4.69 L 6.69,24 10,27.31 V 32 h 4.69 L 18,35.31 21.31,32 H 26 V 27.31 L 29.31,24 Z m -2,5.79 V 30 H 20.48 L 18,32.48 15.52,30 H 12 V 26.48 L 9.52,24 12,21.52 V 18 h 3.52 L 18,15.52 20.48,18 H 24 v 3.52 L 26.48,24 Z" /> +</vector> diff --git a/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml b/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml index e95c6a79733c..f89ccb40ad04 100644 --- a/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml +++ b/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml @@ -13,20 +13,22 @@ See the License for the specific language governing permissions and limitations under the License. --> - <com.android.systemui.settings.brightness.BrightnessSliderView +<com.android.systemui.settings.brightness.BrightnessSliderView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/brightness_slider" android:layout_width="match_parent" android:layout_height="@dimen/brightness_mirror_height" android:layout_gravity="center" android:contentDescription="@string/accessibility_brightness" + android:orientation="horizontal" android:importantForAccessibility="no" > <com.android.systemui.settings.brightness.ToggleSeekBar android:id="@+id/slider" - android:layout_width="match_parent" + android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:layout_weight="1" android:minHeight="48dp" android:thumb="@null" android:background="@null" @@ -35,4 +37,15 @@ android:progressDrawable="@drawable/brightness_progress_drawable" android:splitTrack="false" /> - </com.android.systemui.settings.brightness.BrightnessSliderView> + + <ImageButton + android:id="@+id/brightness_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:background="@drawable/bg_qs_brightness_auto_on" + android:src="@drawable/ic_qs_brightness_auto_on" + android:contentDescription="@null" + android:layout_marginStart="8dp" /> + +</com.android.systemui.settings.brightness.BrightnessSliderView> diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java index ae0f5104d20f..29adcf0fa051 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java @@ -116,7 +116,8 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> { mBrightnessSlider = mBrightnessSliderFactory.create(getContext(), mView); mView.setBrightnessView(mBrightnessSlider.getRootView()); - mBrightnessController = brightnessControllerFactory.create(mBrightnessSlider); + mBrightnessController = brightnessControllerFactory.create( + mBrightnessSlider.getIconView(), mBrightnessSlider); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java index 1ad253e7f867..57a7766bccd3 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java @@ -42,12 +42,15 @@ import android.service.vr.IVrManager; import android.service.vr.IVrStateCallbacks; import android.util.Log; import android.util.MathUtils; +import android.view.View; +import android.widget.ImageView; import com.android.internal.display.BrightnessSynchronizer; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.systemui.Dependency; +import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.settings.CurrentUserTracker; @@ -59,6 +62,7 @@ public class BrightnessController implements ToggleSlider.Listener { private static final String TAG = "StatusBar.BrightnessController"; private static final int SLIDER_ANIMATION_DURATION = 3000; + private static final int MSG_UPDATE_ICON = 0; private static final int MSG_UPDATE_SLIDER = 1; private static final int MSG_ATTACH_LISTENER = 2; private static final int MSG_DETACH_LISTENER = 3; @@ -72,6 +76,9 @@ public class BrightnessController implements ToggleSlider.Listener { private final float mMinimumBacklightForVr; private final float mMaximumBacklightForVr; + private final ImageView mIcon; + private boolean mAutomaticAvailable; + private final int mDisplayId; private final Context mContext; private final ToggleSlider mControl; @@ -223,6 +230,7 @@ public class BrightnessController implements ToggleSlider.Listener { Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT); mAutomatic = automatic != Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL; + mHandler.obtainMessage(MSG_UPDATE_ICON, mAutomatic ? 1 : 0).sendToTarget(); } }; @@ -261,6 +269,9 @@ public class BrightnessController implements ToggleSlider.Listener { mExternalChange = true; try { switch (msg.what) { + case MSG_UPDATE_ICON: + updateIcon(mAutomatic); + break; case MSG_UPDATE_SLIDER: updateSlider(Float.intBitsToFloat(msg.arg1), msg.arg2 != 0); break; @@ -282,9 +293,10 @@ public class BrightnessController implements ToggleSlider.Listener { } }; - public BrightnessController(Context context, ToggleSlider control, + public BrightnessController(Context context, ImageView icon, ToggleSlider control, BroadcastDispatcher broadcastDispatcher) { mContext = context; + mIcon = icon; mControl = control; mControl.setMax(GAMMA_SPACE_MAX); mBackgroundHandler = new Handler((Looper) Dependency.get(Dependency.BG_LOOPER)); @@ -307,6 +319,26 @@ public class BrightnessController implements ToggleSlider.Listener { mDisplayManager = context.getSystemService(DisplayManager.class); mVrManager = IVrManager.Stub.asInterface(ServiceManager.getService( Context.VR_SERVICE)); + mAutomaticAvailable = context.getResources().getBoolean( + com.android.internal.R.bool.config_automatic_brightness_available); + + if (mIcon != null) { + if (mAutomaticAvailable) { + mIcon.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int newMode = mAutomatic ? Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL : Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; + setMode(newMode); + } + }); + } + } + } + + private void setMode(int mode) { + Settings.System.putIntForUser(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE, mode, + mUserTracker.getCurrentUserId()); } public void addStateChangedCallback(BrightnessStateChangeCallback cb) { @@ -389,6 +421,17 @@ public class BrightnessController implements ToggleSlider.Listener { mDisplayManager.setTemporaryBrightness(mDisplayId, brightness); } + private void updateIcon(boolean automatic) { + if (mIcon != null) { + mIcon.setImageResource(automatic ? + R.drawable.ic_qs_brightness_auto_on : + R.drawable.ic_qs_brightness_auto_off); + mIcon.setBackgroundResource(automatic ? + R.drawable.bg_qs_brightness_auto_on : + R.drawable.bg_qs_brightness_auto_off); + } + } + private void updateVrMode(boolean isEnabled) { if (mIsVrModeEnabled != isEnabled) { mIsVrModeEnabled = isEnabled; @@ -458,8 +501,8 @@ public class BrightnessController implements ToggleSlider.Listener { } /** Create a {@link BrightnessController} */ - public BrightnessController create(ToggleSlider toggleSlider) { - return new BrightnessController(mContext, toggleSlider, mBroadcastDispatcher); + public BrightnessController create(ImageView icon, ToggleSlider toggleSlider) { + return new BrightnessController(mContext, icon, toggleSlider, mBroadcastDispatcher); } } diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java index 0f97e43c466b..220f766a73ee 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java @@ -76,7 +76,8 @@ public class BrightnessDialog extends Activity { controller.init(); frame.addView(controller.getRootView(), MATCH_PARENT, WRAP_CONTENT); - mBrightnessController = new BrightnessController(this, controller, mBroadcastDispatcher); + mBrightnessController = new BrightnessController(this, controller.getIconView(), + controller, mBroadcastDispatcher); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java index 0ff6216ea87e..50ae7d1d6ba1 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java @@ -21,6 +21,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.SeekBar; import androidx.annotation.Nullable; @@ -51,6 +52,7 @@ public class BrightnessSlider extends ViewController<BrightnessSliderView> imple private BrightnessMirrorController mMirrorController; private boolean mTracking; private final FalsingManager mFalsingManager; + private ImageView mIconView; private final Gefingerpoken mOnInterceptListener = new Gefingerpoken() { @Override @@ -71,8 +73,10 @@ public class BrightnessSlider extends ViewController<BrightnessSliderView> imple BrightnessSlider( BrightnessSliderView brightnessSliderView, + ImageView icon, FalsingManager falsingManager) { super(brightnessSliderView); + mIconView = icon; mFalsingManager = falsingManager; } @@ -83,6 +87,9 @@ public class BrightnessSlider extends ViewController<BrightnessSliderView> imple return mView; } + public ImageView getIconView() { + return mIconView; + } @Override protected void onViewAttached() { @@ -240,7 +247,8 @@ public class BrightnessSlider extends ViewController<BrightnessSliderView> imple int layout = getLayout(); BrightnessSliderView root = (BrightnessSliderView) LayoutInflater.from(context) .inflate(layout, viewRoot, false); - return new BrightnessSlider(root, mFalsingManager); + ImageView icon = (ImageView) root.findViewById(R.id.brightness_icon); + return new BrightnessSlider(root, icon, mFalsingManager); } /** Get the layout to inflate based on what slider to use */ diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java index 15aa2b730adf..a8a79cf5e22f 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java @@ -25,6 +25,7 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; +import android.widget.LinearLayout; import android.widget.SeekBar.OnSeekBarChangeListener; import androidx.annotation.NonNull; @@ -38,7 +39,7 @@ import com.android.systemui.R; * {@code FrameLayout} used to show and manipulate a {@link ToggleSeekBar}. * */ -public class BrightnessSliderView extends FrameLayout { +public class BrightnessSliderView extends LinearLayout { @NonNull private ToggleSeekBar mSlider; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 85b39ee94b03..133b00164337 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1308,6 +1308,7 @@ public class StatusBar extends SystemUI implements DemoMode, .withDefault(this::createDefaultQSFragment) .build()); mBrightnessMirrorController = new BrightnessMirrorController( + mContext, mNotificationShadeWindowView, mNotificationPanelViewController, mNotificationShadeDepthControllerLazy.get(), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java index 1e5251196379..de2c6dd4d65f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java @@ -18,12 +18,16 @@ package com.android.systemui.statusbar.policy; import android.annotation.NonNull; import android.content.Context; +import android.content.ContentResolver; import android.content.res.Resources; +import android.os.UserHandle; +import android.provider.Settings; import android.util.ArraySet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; +import android.widget.ImageView; import com.android.systemui.R; import com.android.systemui.settings.brightness.BrightnessSlider; @@ -53,11 +57,15 @@ public class BrightnessMirrorController private int mBrightnessMirrorBackgroundPadding; private int mLastBrightnessSliderWidth = -1; - public BrightnessMirrorController(NotificationShadeWindowView statusBarWindow, + private ImageView mIcon; + private Context mContext; + + public BrightnessMirrorController(Context context, NotificationShadeWindowView statusBarWindow, NotificationPanelViewController notificationPanelViewController, NotificationShadeDepthController notificationShadeDepthController, BrightnessSlider.Factory factory, @NonNull Consumer<Boolean> visibilityCallback) { + mContext = context; mStatusBarWindow = statusBarWindow; mToggleSliderFactory = factory; mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror_container); @@ -68,9 +76,12 @@ public class BrightnessMirrorController mBrightnessMirror.setVisibility(View.INVISIBLE); }); mVisibilityCallback = visibilityCallback; + mIcon = (ImageView) mBrightnessMirror.findViewById(R.id.brightness_icon); + mIcon.setVisibility(View.VISIBLE); } public void showMirror() { + updateIcon(); mBrightnessMirror.setVisibility(View.VISIBLE); mVisibilityCallback.accept(true); mNotificationPanel.setPanelAlpha(0, true /* animate */); @@ -177,4 +188,22 @@ public class BrightnessMirrorController public interface BrightnessMirrorListener { void onBrightnessMirrorReinflated(View brightnessMirror); } + + private void updateIcon() { + if (mIcon == null) { + return; + } + // enable the auto brightness icon + mIcon = (ImageView) mBrightnessMirror.findViewById(R.id.brightness_icon); + boolean automatic = Settings.System.getIntForUser(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE, + Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, + UserHandle.USER_CURRENT) != Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL; + mIcon.setImageResource(automatic ? + R.drawable.ic_qs_brightness_auto_on : + R.drawable.ic_qs_brightness_auto_off); + mIcon.setBackgroundResource(automatic ? + R.drawable.bg_qs_brightness_auto_on : + R.drawable.bg_qs_brightness_auto_off); + } } |