Skip to content

Commit

Permalink
enabled width and alignment adjustment for all layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
sspanak committed Feb 2, 2025
1 parent b340058 commit 78e559f
Show file tree
Hide file tree
Showing 27 changed files with 204 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ItemDropDown populate() {

void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setEnabled(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setEnabled(mainViewLayout != SettingsStore.LAYOUT_STEALTH);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ItemDropDown populate() {

void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setEnabled(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setEnabled(mainViewLayout != SettingsStore.LAYOUT_STEALTH);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.graphics.Insets;
import android.os.Build;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
Expand Down Expand Up @@ -135,7 +137,73 @@ boolean setHeight(int height) {
}


void setWidth(int widthPercent) {}
/**
* Adjusts the width of the keyboard to the given percentage of the screen width.
*/
private void setKeyboardWidth(int widthPercent) {
View keyboard = view != null ? view.findViewById(R.id.keyboard_container) : null;
if (keyboard == null) {
return;
}

LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) keyboard.getLayoutParams();
if (layout != null) {
layout.weight = widthPercent;
keyboard.setLayoutParams(layout);
}
}


/**
* Adjust the padding on both sides of the keyboard to make it centered, or aligned to the
* left or right.
*/
private void setBumperWidth(int widthPercent, int gravity) {
View leftBumper = view.findViewById(R.id.bumper_left);
View rightBumper = view.findViewById(R.id.bumper_right);
if (leftBumper == null || rightBumper == null) {
return;
}

int leftPadding = 0;
int rightPadding = 0;

switch (gravity) {
case Gravity.CENTER_HORIZONTAL:
leftPadding = rightPadding = (100 - widthPercent) / 2;
break;

case Gravity.START:
rightPadding = 100 - widthPercent;
break;

case Gravity.END:
leftPadding = 100 - widthPercent;
break;
}

LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) leftBumper.getLayoutParams();
if (layout != null) {
layout.weight = leftPadding;
leftBumper.setLayoutParams(layout);
}

layout = (LinearLayout.LayoutParams) rightBumper.getLayoutParams();
if (layout != null) {
layout.weight = rightPadding;
rightBumper.setLayoutParams(layout);
}
}


void setWidth(int widthPercent, int gravity) {
if (view == null || widthPercent <= 0 || widthPercent > 100) {
return;
}

setBumperWidth(widthPercent, gravity);
setKeyboardWidth(widthPercent);
}


abstract void showCommandPalette();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.sspanak.tt9.ui.main;

import android.content.res.Resources;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -164,87 +162,6 @@ int getHeight(boolean forceRecalculate) {
}


/**
* Adjusts the width of the keyboard to the given percentage of the screen width.
*/
private void setKeyboardWidth(int widthPercent) {
View keyboard = view != null ? view.findViewById(R.id.numpad_container) : null;
if (keyboard == null) {
return;
}

LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) keyboard.getLayoutParams();
if (layout != null) {
layout.weight = widthPercent;
keyboard.setLayoutParams(layout);
}
}


/**
* Adjust the padding on both sides of the keyboard to make it centered, or aligned to the
* left or right.
*/
private void setBumperWidth(int widthPercent, int gravity) {
View leftBumper = view.findViewById(R.id.numpad_bumper_left);
View rightBumper = view.findViewById(R.id.numpad_bumper_right);
if (leftBumper == null || rightBumper == null) {
return;
}

int leftPadding = 0;
int rightPadding = 0;

switch (gravity) {
case Gravity.CENTER_HORIZONTAL:
leftPadding = rightPadding = (100 - widthPercent) / 2;
break;

case Gravity.START:
rightPadding = 100 - widthPercent;
break;

case Gravity.END:
leftPadding = 100 - widthPercent;
break;
}

LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) leftBumper.getLayoutParams();
if (layout != null) {
layout.weight = leftPadding;
leftBumper.setLayoutParams(layout);
}

layout = (LinearLayout.LayoutParams) rightBumper.getLayoutParams();
if (layout != null) {
layout.weight = rightPadding;
rightBumper.setLayoutParams(layout);
}
}


void setWidth(int widthPercent, int gravity) {
if (view == null || widthPercent <= 0 || widthPercent > 100) {
return;
}

setBumperWidth(widthPercent, gravity);
setKeyboardWidth(widthPercent);
}


@Override
void render() {
getView();
setKeyHeight(getKeyHeightCompat());
setWidth(tt9.getSettings().getNumpadWidthPercent(), tt9.getSettings().getNumpadAlignment());
enableClickHandlers();
for (SoftKey key : getKeys()) {
key.render();
}
}


@Override
protected void enableClickHandlers() {
super.enableClickHandlers();
Expand Down Expand Up @@ -307,4 +224,16 @@ protected ArrayList<SoftKey> getKeys() {

return keys;
}


@Override
void render() {
getView();
setKeyHeight(getKeyHeightCompat());
setWidth(tt9.getSettings().getNumpadWidthPercent(), tt9.getSettings().getNumpadAlignment());
enableClickHandlers();
for (SoftKey key : getKeys()) {
key.render();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class MainLayoutStealth extends BaseMainLayout {
}
@Override void hideTextEditingPalette() { isTextEditingPaletteShown = false; }
@Override boolean isTextEditingPaletteShown() { return isTextEditingPaletteShown; }

@Override void setWidth(int w, int g) {}
@Override void render() {}
}
21 changes: 11 additions & 10 deletions app/src/main/java/io/github/sspanak/tt9/ui/main/MainLayoutTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ boolean isTextEditingPaletteShown() {
return view != null && view.findViewById(R.id.text_editing_container).getVisibility() == LinearLayout.VISIBLE;
}

@Override
void render() {
getView();
enableClickHandlers();
setSoftKeysVisibility();
for (SoftKey key : getKeys()) {
key.render();
}
}

@NonNull
@Override
protected ArrayList<SoftKey> getKeys() {
Expand All @@ -91,4 +81,15 @@ protected ArrayList<SoftKey> getKeys() {
}
return keys;
}

@Override
void render() {
getView();
setSoftKeysVisibility();
setWidth(tt9.getSettings().getNumpadWidthPercent(), tt9.getSettings().getNumpadAlignment());
enableClickHandlers();
for (SoftKey key : getKeys()) {
key.render();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public void removeListeners() {
}
}

@Override public void onViewAttachedToWindow(@NonNull View v) {
setHeight(height, heightSmall, heightNumpad);
main.setWidth(tt9.getSettings().getNumpadWidthPercent());
}
@Override public void onViewAttachedToWindow(@NonNull View v) { setHeight(height, heightSmall, heightNumpad); }
@Override public void onViewDetachedFromWindow(@NonNull View v) {}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.DividerItemDecoration;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class SuggestionsBar {

private final ResizableMainView mainView;
private final Runnable onItemClick;
private final RecyclerView mView;
@Nullable private final RecyclerView mView;
private final SettingsStore settings;
private SuggestionsAdapter mSuggestionsAdapter;
private Vibration vibration;
Expand Down Expand Up @@ -65,6 +66,10 @@ public SuggestionsBar(@NonNull SettingsStore settings, @NonNull ResizableMainVie


private void configureAnimation() {
if (mView == null) {
return;
}

DefaultItemAnimator animator = new DefaultItemAnimator();

animator.setMoveDuration(SettingsStore.SUGGESTIONS_SELECT_ANIMATION_DURATION);
Expand All @@ -77,20 +82,29 @@ private void configureAnimation() {


private void initDataAdapter(Context context) {
if (mView == null) {
return;
}

mSuggestionsAdapter = new SuggestionsAdapter(
context,
this::handleItemClick,
settings.isMainLayoutNumpad() ? R.layout.suggestion_list_numpad : R.layout.suggestion_list,
R.id.suggestion_list_item,
suggestions
);

mView.setAdapter(mSuggestionsAdapter);

setDarkTheme();
}


private void initSeparator(Context context) {
if (mView == null) {
return;
}

// Extra XML is required instead of a ColorDrawable object, because setting the highlight color
// erases the borders defined using the ColorDrawable.
Drawable separatorDrawable = ContextCompat.getDrawable(context, R.drawable.suggestion_separator);
Expand Down Expand Up @@ -144,7 +158,9 @@ public String getSuggestion(int id) {


public void setRTL(boolean yes) {
mView.setLayoutDirection(yes ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
if (mView != null) {
mView.setLayoutDirection(yes ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
}
}


Expand Down Expand Up @@ -275,6 +291,10 @@ private void scrollToIndex() {
* to set the selected index in the adapter.
*/
private void scrollView() {
if (mView == null) {
return;
}

if (containsStem() && selectedIndex == 1) {
mView.scrollToPosition(0);
} else {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/main_numpad.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/TTheme.FullScreenContainer"
android:id="@+id/full_screen_container">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/TTheme.FullScreenContainer">

<LinearLayout style="@style/TTheme.FullScreenContainer.SideBumper" android:id="@+id/numpad_bumper_left" />
<LinearLayout style="@style/TTheme.FullScreenContainer.SideBumper" android:id="@+id/bumper_left" />

<LinearLayout style="@style/TTheme.Numpad" android:id="@+id/numpad_container">
<LinearLayout style="@style/TTheme.Numpad" android:id="@+id/keyboard_container">
<View style="@style/TTheme.Keyboard.TopSeparator" />
<include layout="@layout/panel_numpad_status_bar" />

Expand All @@ -22,6 +22,6 @@
</LinearLayout>
</LinearLayout>

<LinearLayout style="@style/TTheme.FullScreenContainer.SideBumper" android:id="@+id/numpad_bumper_right" />
<LinearLayout style="@style/TTheme.FullScreenContainer.SideBumper" android:id="@+id/bumper_right" />

</LinearLayout>
Loading

0 comments on commit 78e559f

Please sign in to comment.