From 3a6052c03fe14d4983f7fd6c649ca1155e389d77 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Wed, 25 Aug 2021 19:39:45 +0500 Subject: [PATCH] Added: Allow users to adjust terminal horizontal and vertical margin The `terminal-margin-horizontal` key can be used to adjust the terminal left/right margin and the `terminal-margin-vertical` can be used to adjust the terminal top/bottom margin. This will also affect drawer. The user can set an integer value between `0` and `100` as `dp` units. The default value is still `3` for horizontal and `0` for vertical margin. So adding an entry like `terminal-margin-horizontal=10` to `termux.properties` file will allow users to set a horizontal margin of `10dp`. After updating the value, either restart termux or run `termux-reload-settings` for changes to take effect. This was added since for some users text on edges would not be shown on the screen or they had screen protectors/cases that covered screen edges (Of course, that would require fixing every single app and android system UI itself, so kinda stupid to use). Moreover, horizontal margin of like `10dp` may be helpful with peek-and-slide for people having gesture navigation enabled on android `10+` since they won't be to touch at exactly the edge of the screen to trigger peek (#1325). Closes #2210 --- .../java/com/termux/app/TermuxActivity.java | 12 +++++ app/src/main/res/layout/activity_termux.xml | 5 +- .../properties/TermuxPropertyConstants.java | 21 +++++++- .../properties/TermuxSharedProperties.java | 48 +++++++++++++++++++ .../com/termux/shared/view/ViewUtils.java | 15 ++++++ 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 254b3bc50f..11b066f366 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -29,6 +29,7 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; +import android.widget.RelativeLayout; import android.widget.Toast; import com.termux.R; @@ -49,6 +50,7 @@ import com.termux.shared.interact.TextInputDialogUtils; import com.termux.shared.logger.Logger; import com.termux.shared.termux.TermuxUtils; +import com.termux.shared.view.ViewUtils; import com.termux.terminal.TerminalSession; import com.termux.terminal.TerminalSessionClient; import com.termux.app.utils.CrashUtils; @@ -204,6 +206,8 @@ public void onCreate(Bundle savedInstanceState) { return; } + setMargins(); + mTermuxActivityRootView = findViewById(R.id.activity_termux_root_view); mTermuxActivityRootView.setActivity(this); mTermuxActivityBottomSpaceView = findViewById(R.id.activity_termux_bottom_space_view); @@ -416,6 +420,13 @@ private void setDrawerTheme() { } } + private void setMargins() { + RelativeLayout relativeLayout = findViewById(R.id.activity_termux_root_relative_layout); + int marginHorizontal = mProperties.getTerminalMarginHorizontal(); + int marginVertical = mProperties.getTerminalMarginVertical(); + ViewUtils.setLayoutMarginsInDp(relativeLayout, marginHorizontal, marginVertical, marginHorizontal, marginVertical); + } + public void addTermuxActivityRootViewGlobalLayoutListener() { @@ -873,6 +884,7 @@ private void reloadActivityStyling() { } } + setMargins(); setTerminalToolbarHeight(); if (mTermuxTerminalSessionClient != null) diff --git a/app/src/main/res/layout/activity_termux.xml b/app/src/main/res/layout/activity_termux.xml index c659f57711..144e846c51 100644 --- a/app/src/main/res/layout/activity_termux.xml +++ b/app/src/main/res/layout/activity_termux.xml @@ -6,9 +6,12 @@ android:fitsSystemWindows="true">