diff options
| author | HrX03 <dn.bianco03@gmail.com> | 2020-12-11 18:02:09 +0000 |
|---|---|---|
| committer | Kshitij Gupta <kshitijgm@gmail.com> | 2020-12-21 09:22:31 +0000 |
| commit | 16af8ef1adfe2ae98aa1df6d9bbf350d755dd0a4 (patch) | |
| tree | 76f36e315e9d334cbe24cada3689509027892821 | |
| parent | 477367d0e8d041179d880c5bf82bc682790d724b (diff) | |
plugins: Make panels side aware at runtime
[ @HrX03 - POSP ]
The panels will now change side based on a setting + they will default to the old resource so that maintainers can still define the default side
Change-Id: I729d8082f64756751a7cb27c0dc347686c472137
9 files changed, 120 insertions, 24 deletions
diff --git a/AospPanel/res/layout/volume_dialog_aosp.xml b/AospPanel/res/layout/volume_dialog_aosp.xml index a4ddcf5..aa4eb2c 100644 --- a/AospPanel/res/layout/volume_dialog_aosp.xml +++ b/AospPanel/res/layout/volume_dialog_aosp.xml @@ -54,7 +54,7 @@ android:layout_height="match_parent" android:scaleType="fitCenter" android:padding="@dimen/volume_dialog_ringer_icon_padding" - android:tint="@color/accent_tint_color_selector" + android:tint="?android:attr/colorAccent" android:layout_gravity="center" android:soundEffectsEnabled="false" /> diff --git a/AospPanel/res/layout/volume_dialog_aosp_row.xml b/AospPanel/res/layout/volume_dialog_aosp_row.xml index c425423..9251b00 100644 --- a/AospPanel/res/layout/volume_dialog_aosp_row.xml +++ b/AospPanel/res/layout/volume_dialog_aosp_row.xml @@ -62,7 +62,7 @@ android:layout_height="@dimen/volume_dialog_tap_target_size" android:background="@drawable/ripple_drawable_20dp" android:layout_marginBottom="@dimen/volume_dialog_row_margin_bottom" - android:tint="@color/accent_tint_color_selector" + android:tint="?android:attr/colorAccent" android:soundEffectsEnabled="false" /> </LinearLayout> diff --git a/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java b/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java index 5b57d95..1a5f6c5 100644 --- a/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java +++ b/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java @@ -123,7 +123,7 @@ import java.util.List; @Requires(target = VolumeDialog.Callback.class, version = VolumeDialog.Callback.VERSION) @Requires(target = VolumeDialogController.class, version = VolumeDialogController.VERSION) @Requires(target = ActivityStarter.class, version = ActivityStarter.VERSION) -public class VolumeDialogImpl implements VolumeDialog { +public class VolumeDialogImpl extends PanelSideAware implements VolumeDialog { private static final String TAG = Utils.logTag(VolumeDialogImpl.class); public static final String ACTION_MEDIA_OUTPUT = "com.android.settings.panel.action.MEDIA_OUTPUT"; @@ -185,8 +185,6 @@ public class VolumeDialogImpl implements VolumeDialog { private boolean mExpanded; - private boolean mLeftVolumeRocker; - public VolumeDialogImpl() {} @Override @@ -202,7 +200,7 @@ public class VolumeDialogImpl implements VolumeDialog { mShowActiveStreamOnly = showActiveStreamOnly(); mHasSeenODICaptionsTooltip = Prefs.getBoolean(sysuiContext, Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, false); - mLeftVolumeRocker = mSysUIContext.getResources().getBoolean(mSysUIR.bool("config_audioPanelOnLeftSide")); + initObserver(pluginContext, sysuiContext); } public void init(int windowType, Callback callback) { @@ -215,6 +213,11 @@ public class VolumeDialogImpl implements VolumeDialog { } @Override + protected void onSideChange() { + initDialog(); + } + + @Override public void destroy() { mController.removeCallback(mControllerCallbackH); mHandler.removeCallbacksAndMessages(null); @@ -1593,7 +1596,7 @@ public class VolumeDialogImpl implements VolumeDialog { } private boolean isAudioPanelOnLeftSide() { - return mLeftVolumeRocker; + return mPanelOnLeftSide; } private static class VolumeRow { diff --git a/CompactPanel/res/layout/volume_dialog_compact.xml b/CompactPanel/res/layout/volume_dialog_compact.xml index b9bf4a8..d173ba8 100644 --- a/CompactPanel/res/layout/volume_dialog_compact.xml +++ b/CompactPanel/res/layout/volume_dialog_compact.xml @@ -159,7 +159,7 @@ android:layout_height="match_parent" android:scaleType="fitCenter" android:padding="@dimen/volume_dialog_ringer_icon_padding" - android:tint="@color/accent_tint_color_selector" + android:tint="?android:attr/colorAccent" android:layout_gravity="center" android:soundEffectsEnabled="false" /> @@ -200,4 +200,4 @@ android:layout_marginRight="@dimen/volume_tool_tip_right_margin" android:layout_marginBottom="@dimen/volume_tool_tip_bottom_margin"/> -</FrameLayout>
\ No newline at end of file +</FrameLayout> diff --git a/CompactPanel/res/layout/volume_dialog_compact_row.xml b/CompactPanel/res/layout/volume_dialog_compact_row.xml index 61a0d33..fa50bec 100644 --- a/CompactPanel/res/layout/volume_dialog_compact_row.xml +++ b/CompactPanel/res/layout/volume_dialog_compact_row.xml @@ -36,7 +36,7 @@ android:layout_height="@dimen/volume_dialog_tap_target_size" android:background="@drawable/ripple_drawable_20dp" android:layout_marginTop="@dimen/volume_dialog_row_margin_bottom" - android:tint="@color/accent_tint_color_selector" + android:tint="?android:attr/colorAccent" android:visibility="gone" android:soundEffectsEnabled="false" /> @@ -71,4 +71,4 @@ <include layout="@layout/volume_dnd_icon"/> -</FrameLayout>
\ No newline at end of file +</FrameLayout> diff --git a/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java b/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java index 044e950..f474b9d 100644 --- a/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java +++ b/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java @@ -123,7 +123,7 @@ import java.util.List; @Requires(target = VolumeDialog.Callback.class, version = VolumeDialog.Callback.VERSION) @Requires(target = VolumeDialogController.class, version = VolumeDialogController.VERSION) @Requires(target = ActivityStarter.class, version = ActivityStarter.VERSION) -public class VolumeDialogImpl implements VolumeDialog { +public class VolumeDialogImpl extends PanelSideAware implements VolumeDialog { private static final String TAG = Utils.logTag(VolumeDialogImpl.class); public static final String ACTION_MEDIA_OUTPUT = "com.android.settings.panel.action.MEDIA_OUTPUT"; @@ -186,7 +186,6 @@ public class VolumeDialogImpl implements VolumeDialog { private ViewStub mODICaptionsTooltipViewStub; private View mODICaptionsTooltipView = null; - private boolean mLeftVolumeRocker; private PanelMode mPanelMode = PanelMode.MINI; public VolumeDialogImpl() {} @@ -204,7 +203,7 @@ public class VolumeDialogImpl implements VolumeDialog { mShowActiveStreamOnly = showActiveStreamOnly(); mHasSeenODICaptionsTooltip = Prefs.getBoolean(sysuiContext, Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, false); - mLeftVolumeRocker = mSysUIContext.getResources().getBoolean(mSysUIR.bool("config_audioPanelOnLeftSide")); + initObserver(pluginContext, sysuiContext); } @Override @@ -215,15 +214,20 @@ public class VolumeDialogImpl implements VolumeDialog { mController.addCallback(mControllerCallbackH, mHandler); mController.getState(); - } + @Override public void destroy() { mController.removeCallback(mControllerCallbackH); mHandler.removeCallbacksAndMessages(null); } + @Override + protected void onSideChange() { + initDialog(); + } + private void initDialog() { mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); @@ -1674,7 +1678,7 @@ public class VolumeDialogImpl implements VolumeDialog { } private boolean isAudioPanelOnLeftSide() { - return mLeftVolumeRocker; + return mPanelOnLeftSide; } private static class VolumeRow { diff --git a/OreoPanel/res/layout/volume_dialog_oreo.xml b/OreoPanel/res/layout/volume_dialog_oreo.xml index 942704d..3fdf573 100644 --- a/OreoPanel/res/layout/volume_dialog_oreo.xml +++ b/OreoPanel/res/layout/volume_dialog_oreo.xml @@ -41,7 +41,7 @@ android:layout_height="match_parent" android:scaleType="fitCenter" android:padding="@dimen/volume_dialog_ringer_icon_padding" - android:tint="@color/accent_tint_color_selector" + android:tint="?android:attr/colorAccent" android:layout_gravity="center" android:soundEffectsEnabled="false" /> @@ -96,4 +96,4 @@ </FrameLayout> </FrameLayout> </LinearLayout> -</FrameLayout>
\ No newline at end of file +</FrameLayout> diff --git a/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java b/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java index 68b1c9a..f2b0162 100644 --- a/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java +++ b/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java @@ -127,7 +127,7 @@ import java.util.List; @Requires(target = VolumeDialog.Callback.class, version = VolumeDialog.Callback.VERSION) @Requires(target = VolumeDialogController.class, version = VolumeDialogController.VERSION) @Requires(target = ActivityStarter.class, version = ActivityStarter.VERSION) -public class VolumeDialogImpl implements VolumeDialog { +public class VolumeDialogImpl extends PanelSideAware implements VolumeDialog { private static final String TAG = Utils.logTag(VolumeDialogImpl.class); public static final String ACTION_MEDIA_OUTPUT = "com.android.settings.panel.action.MEDIA_OUTPUT"; @@ -188,7 +188,6 @@ public class VolumeDialogImpl implements VolumeDialog { private ViewStub mODICaptionsTooltipViewStub; private View mODICaptionsTooltipView = null; - private boolean mLeftVolumeRocker; private Drawable mSwitchStreamSelectedDrawable; private boolean mActiveStreamManuallyModified = false; @@ -207,7 +206,7 @@ public class VolumeDialogImpl implements VolumeDialog { mShowActiveStreamOnly = showActiveStreamOnly(); mHasSeenODICaptionsTooltip = Prefs.getBoolean(sysuiContext, Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, false); - mLeftVolumeRocker = false;//mSysUIContext.getResources().getBoolean(mSysUIR.bool("config_audioPanelOnLeftSide")); + initObserver(pluginContext, sysuiContext); } public void init(int windowType, Callback callback) { @@ -220,6 +219,13 @@ public class VolumeDialogImpl implements VolumeDialog { } @Override + protected void onSideChange() { + initDialog(); + mConfigurableTexts.update(); + mController.getState(); + } + + @Override public void destroy() { mController.removeCallback(mControllerCallbackH); mHandler.removeCallbacksAndMessages(null); @@ -353,7 +359,8 @@ public class VolumeDialogImpl implements VolumeDialog { mActiveStreamManuallyModified = false; updateRowsH(getActiveRow()); - initOutputSwitcherH(); + updateSwitchStreamButtonsH(getActiveRow()); + initOutputSwitcherH(); initRingerH(); initODICaptionsH(); } @@ -468,7 +475,6 @@ public class VolumeDialogImpl implements VolumeDialog { private VolumeRow findRow(int stream) { for (VolumeRow row : mRows) { - Log.d("Le cringe 2", String.valueOf(row.stream)); if (row.stream == stream) return row; } return null; @@ -1678,7 +1684,7 @@ public class VolumeDialogImpl implements VolumeDialog { } private boolean isAudioPanelOnLeftSide() { - return mLeftVolumeRocker; + return mPanelOnLeftSide; } private static class VolumeRow { diff --git a/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/PanelSideAware.java b/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/PanelSideAware.java new file mode 100644 index 0000000..567c569 --- /dev/null +++ b/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/PanelSideAware.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2020 The Potato Open Sauce 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 co.potatoproject.plugin.volume.common; + +import android.content.ContentResolver; +import android.content.Context; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; +import android.os.Looper; +import android.os.UserHandle; +import android.provider.Settings; + +public abstract class PanelSideAware { + protected boolean mPanelOnLeftSide = false; + + protected void initObserver(Context sysUIContext, Context localContext) { + SideObserver observer = new SideObserver(sysUIContext, localContext); + observer.observe(); + } + + private class SideObserver extends ContentObserver { + private Context mSysUIContext; + private Context mLocalContext; + private SysUIR mSysUIR; + + SideObserver(Context sysUIContext, Context localContext) { + super(new Handler(Looper.getMainLooper())); + mSysUIContext = sysUIContext; + mLocalContext = localContext; + mSysUIR = new SysUIR(localContext); + updateSideVar(); + } + + public void observe() { + ContentResolver resolver = mLocalContext.getContentResolver(); + resolver.registerContentObserver(Settings.System.getUriFor( + "volume_panel_on_left"), + false, this, UserHandle.USER_CURRENT); + } + + private void updateSideVar() { + int defaultValue; + + try { + defaultValue = mSysUIContext.getResources().getBoolean( + mSysUIR.bool("config_audioPanelOnLeftSide")) ? 1 : 0; + } catch(Exception e) { + defaultValue = 0; + } + + int panelOnLeftSide = Settings.System.getIntForUser( + mLocalContext.getContentResolver(), + "volume_panel_on_left", defaultValue, + UserHandle.USER_CURRENT); + + mPanelOnLeftSide = panelOnLeftSide == 1; + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + if (uri.equals(Settings.System.getUriFor("volume_panel_on_left"))) { + updateSideVar(); + onSideChange(); + } + } + } + + abstract protected void onSideChange(); +} |
