Skip to content

Commit

Permalink
BatteryStyle: fixed layout in StatusBar Header on OxygenOS
Browse files Browse the repository at this point in the history
  • Loading branch information
C3C0 committed Jun 6, 2021
1 parent db6bdf0 commit e7da2ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void initPreferences(XSharedPreferences prefs) {
mBatteryPercentTextEnabledSb = prefs.getBoolean(
GravityBoxSettings.PREF_KEY_BATTERY_PERCENT_TEXT_STATUSBAR, false);
mBatteryPercentTextEnabledSbHeader = prefs.getBoolean(
GravityBoxSettings.PREF_KEY_BATTERY_PERCENT_TEXT_STATUSBAR_HEADER, false);
GravityBoxSettings.PREF_KEY_BATTERY_PERCENT_TEXT_STATUSBAR_HEADER, false) && !Utils.isOxygenOsRom();
mBatteryPercentTextKgMode = KeyguardMode.valueOf(prefs.getString(
GravityBoxSettings.PREF_KEY_BATTERY_PERCENT_TEXT_KEYGUARD, "DEFAULT"));
mBatteryPercentTextOnRight = "RIGHT".equals(prefs.getString(
Expand All @@ -152,8 +152,7 @@ private void initLayout() throws Throwable {
ColorStateList headerFillColor = null;

int bIconIndex = mSystemIcons.getChildCount();
int bIconMarginStart = gbRes.getDimensionPixelSize(R.dimen.circle_battery_padding_left);
int bIconMarginEnd = gbRes.getDimensionPixelSize(R.dimen.circle_battery_padding_right);
ViewGroup.LayoutParams bLayoutParams = null;

// determine fill color in header
if (mContainerType == ContainerType.HEADER) {
Expand All @@ -171,19 +170,20 @@ private void initLayout() throws Throwable {
res.getIdentifier(batteryResName, "id", PACKAGE_NAME));
if (stockBatteryView != null) {
bIconIndex = mSystemIcons.indexOfChild(stockBatteryView);
bIconMarginStart = ((MarginLayoutParams) stockBatteryView.getLayoutParams()).getMarginStart();
bIconMarginEnd = ((MarginLayoutParams) stockBatteryView.getLayoutParams()).getMarginEnd();
bLayoutParams = stockBatteryView.getLayoutParams();
mStockBattery = new StatusbarBattery(stockBatteryView);
}

// inject circle battery view
mCircleBattery = new CmCircleBattery(mContext, this);
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lParams.gravity = Gravity.CENTER_VERTICAL;
lParams.setMarginStart(bIconMarginStart);
lParams.setMarginEnd(bIconMarginEnd);
mCircleBattery.setLayoutParams(lParams);
if (bLayoutParams != null) {
mCircleBattery.setLayoutParams(bLayoutParams);
} else {
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lParams.gravity = Gravity.CENTER_VERTICAL;
mCircleBattery.setLayoutParams(lParams);
}
mCircleBattery.setVisibility(View.GONE);
if (mContainerType == ContainerType.HEADER) {
mCircleBattery.setOnClickListener(v -> startPowerUsageSummary());
Expand All @@ -196,7 +196,7 @@ private void initLayout() throws Throwable {

// inject percent text
TextView percentTextView = new TextView(mContext);
lParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
percentTextView.setLayoutParams(lParams);
percentTextView.setPadding(
Expand Down Expand Up @@ -456,7 +456,7 @@ public void onBroadcastReceived(Context context, Intent intent) {
}
if (intent.hasExtra(GravityBoxSettings.EXTRA_BATTERY_PERCENT_TEXT_STATUSBAR_HEADER)) {
mBatteryPercentTextEnabledSbHeader = intent.getBooleanExtra(
GravityBoxSettings.EXTRA_BATTERY_PERCENT_TEXT_STATUSBAR_HEADER, false);
GravityBoxSettings.EXTRA_BATTERY_PERCENT_TEXT_STATUSBAR_HEADER, false) && !Utils.isOxygenOsRom();
if (DEBUG) log("mBatteryPercentTextEnabledSbHeader changed to: " + mBatteryPercentTextEnabledSbHeader);
}
if (intent.hasExtra(GravityBoxSettings.EXTRA_BATTERY_PERCENT_TEXT_KEYGUARD)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ public static class PrefsFragment extends PreferenceFragment
private ListPreference mPrefBatteryTileTempUnit;
private EditTextPreference mPrefPowerCameraVp;
private Preference mPrefTuner;
private PreferenceScreen mPrefCatBatteryPercentText;

private String mSearchQuery;
private int mDonateUrlResId;
Expand All @@ -1347,6 +1348,7 @@ public void onCreate(Bundle savedInstanceState) {
// Force update tile service components
TileOrderActivity.updateServiceComponents(getActivity());

mPrefCatBatteryPercentText = (PreferenceScreen) findPreference(PREF_CAT_KEY_BATTERY_PERCENT_TEXT);
mBatteryStyle = (ListPreference) findPreference(PREF_KEY_BATTERY_STYLE);
mPrefBatteryPercentSize = (ListPreference) findPreference(PREF_KEY_BATTERY_PERCENT_TEXT_SIZE);
mPrefBatteryPercentStyle = (ListPreference) findPreference(PREF_KEY_BATTERY_PERCENT_TEXT_STYLE);
Expand Down Expand Up @@ -1668,6 +1670,8 @@ public void onCreate(Bundle savedInstanceState) {
lp.setEntries(actionEntries);
lp.setEntryValues(actionEntryValues);
}
p = findPreference(PREF_KEY_BATTERY_PERCENT_TEXT_STATUSBAR_HEADER);
if (p != null) mPrefCatBatteryPercentText.removePreference(p);
} else {
Preference p = findPreference(PREF_KEY_OOS_CALL_RECORDING);
if (p != null) mPrefCatPhoneTelephony.removePreference(p);
Expand Down

0 comments on commit e7da2ed

Please sign in to comment.