Skip to content

Commit

Permalink
plugins: Make panels side aware at runtime
Browse files Browse the repository at this point in the history
[ @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
  • Loading branch information
HrX03 authored and AgentFabulous committed Dec 21, 2020
1 parent 477367d commit 16af8ef
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 24 deletions.
2 changes: 1 addition & 1 deletion AospPanel/res/layout/volume_dialog_aosp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
2 changes: 1 addition & 1 deletion AospPanel/res/layout/volume_dialog_aosp_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
@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";
Expand Down Expand Up @@ -185,8 +185,6 @@ public class VolumeDialogImpl implements VolumeDialog {

private boolean mExpanded;

private boolean mLeftVolumeRocker;

public VolumeDialogImpl() {}

@Override
Expand All @@ -202,7 +200,7 @@ public void onCreate(Context sysuiContext, Context pluginContext) {
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) {
Expand All @@ -214,6 +212,11 @@ public void init(int windowType, Callback callback) {
mController.getState();
}

@Override
protected void onSideChange() {
initDialog();
}

@Override
public void destroy() {
mController.removeCallback(mControllerCallbackH);
Expand Down Expand Up @@ -1593,7 +1596,7 @@ public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
}

private boolean isAudioPanelOnLeftSide() {
return mLeftVolumeRocker;
return mPanelOnLeftSide;
}

private static class VolumeRow {
Expand Down
4 changes: 2 additions & 2 deletions CompactPanel/res/layout/volume_dialog_compact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down Expand Up @@ -200,4 +200,4 @@
android:layout_marginRight="@dimen/volume_tool_tip_right_margin"
android:layout_marginBottom="@dimen/volume_tool_tip_bottom_margin"/>

</FrameLayout>
</FrameLayout>
4 changes: 2 additions & 2 deletions CompactPanel/res/layout/volume_dialog_compact_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down Expand Up @@ -71,4 +71,4 @@

<include layout="@layout/volume_dnd_icon"/>

</FrameLayout>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
@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";
Expand Down Expand Up @@ -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() {}
Expand All @@ -204,7 +203,7 @@ public void onCreate(Context sysuiContext, Context pluginContext) {
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
Expand All @@ -215,15 +214,20 @@ public void init(int windowType, Callback callback) {

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);

Expand Down Expand Up @@ -1674,7 +1678,7 @@ public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
}

private boolean isAudioPanelOnLeftSide() {
return mLeftVolumeRocker;
return mPanelOnLeftSide;
}

private static class VolumeRow {
Expand Down
4 changes: 2 additions & 2 deletions OreoPanel/res/layout/volume_dialog_oreo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down Expand Up @@ -96,4 +96,4 @@
</FrameLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
@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";
Expand Down Expand Up @@ -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;

Expand All @@ -207,7 +206,7 @@ public void onCreate(Context sysuiContext, Context pluginContext) {
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) {
Expand All @@ -219,6 +218,13 @@ public void init(int windowType, Callback callback) {
mController.getState();
}

@Override
protected void onSideChange() {
initDialog();
mConfigurableTexts.update();
mController.getState();
}

@Override
public void destroy() {
mController.removeCallback(mControllerCallbackH);
Expand Down Expand Up @@ -353,7 +359,8 @@ private void initDialog() {
mActiveStreamManuallyModified = false;

updateRowsH(getActiveRow());
initOutputSwitcherH();
updateSwitchStreamButtonsH(getActiveRow());
initOutputSwitcherH();
initRingerH();
initODICaptionsH();
}
Expand Down Expand Up @@ -468,7 +475,6 @@ private VolumeRow getActiveRow() {

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;
Expand Down Expand Up @@ -1678,7 +1684,7 @@ public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
}

private boolean isAudioPanelOnLeftSide() {
return mLeftVolumeRocker;
return mPanelOnLeftSide;
}

private static class VolumeRow {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 16af8ef

Please sign in to comment.