-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
477367d
commit 16af8ef
Showing
9 changed files
with
120 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
VolumePluginCommon/src/co/potatoproject/plugin/volume/common/PanelSideAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |