Add an option to ignore navigation bar height.

This commit is contained in:
Alex Ning 2020-04-19 13:03:33 +08:00
parent 2d60b732a9
commit 499f507f88
5 changed files with 33 additions and 1 deletions

View File

@ -207,6 +207,10 @@ public abstract class BaseActivity extends AppCompatActivity {
}
public int getNavBarHeight() {
if (getSharedPreferences().getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY, false)) {
return 0;
}
Resources resources = getResources();
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {

View File

@ -30,6 +30,7 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
setPreferencesFromResource(R.xml.interface_preference, rootKey);
SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY);
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
@ -37,15 +38,32 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES);
if (immersiveInterfaceSwitch != null) {
if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
immersiveInterfaceSwitch.setVisible(true);
immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
if ((Boolean) newValue) {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
} else {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
}
EventBus.getDefault().post(new RecreateActivityEvent());
return true;
});
if (immersiveInterfaceSwitch.isChecked()) {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
} else {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
}
immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent());
return true;
});
} else {
immersiveInterfaceSwitch.setVisible(false);
immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
}
}

View File

@ -31,6 +31,7 @@ public class SharedPreferencesUtils {
public static final String CONTENT_FONT_SIZE_KEY = "content_font_size";
public static final String AMOLED_DARK_KEY = "amoled_dark";
public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface";
public static final String IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY = "immersive_interface_ignore_nav_bar";
public static final String BOTTOM_APP_BAR_KEY = "bottom_app_bar";
public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right";

View File

@ -312,6 +312,8 @@
<string name="settings_gestures_and_buttons_title">Gestures &amp; Buttons</string>
<string name="settings_open_link_in_app_title">Open Link In App</string>
<string name="settings_immersive_interface_title">Immersive Interface</string>
<string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string>
<string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string>
<string name="settings_enable_bottom_app_bar_title">Enable Bottom Navigation</string>
<string name="settings_enable_bottom_app_bar_summary">Has No Effect in Anonymous Mode</string>
<string name="settings_vote_buttons_on_the_right_title">Vote Buttons on the Right</string>

View File

@ -13,6 +13,13 @@
app:title="@string/settings_immersive_interface_title"
app:isPreferenceVisible="false" />
<SwitchPreference
app:defaultValue="false"
app:key="immersive_interface_ignore_nav_bar"
app:title="@string/settings_immersive_interface_ignore_nav_bar_title"
app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary"
app:isPreferenceVisible="false" />
<SwitchPreference
app:defaultValue="false"
app:key="bottom_app_bar"