Skip to content

Commit 3c84290

Browse files
committed
Merge branch 'target-sdk-35' (closes #17)
- Implements keyboard edge-to-edge padding (bottom spacer) - Opts out of Main Activity edge-to-edge
2 parents 274917a + 31d09f1 commit 3c84290

10 files changed

Lines changed: 89 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
## [Unreleased]
55

6+
- Upgraded Android SDK to Level 35
7+
- Implemented keyboard edge-to-edge padding (bottom spacer)
8+
- Opted out of Main Activity edge-to-edge
9+
- Fixed buggy key preview initialisation in landscape mode
610
- Changed Help/About link colour to blue
711

812

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android
99
{
1010
applicationId "io.github.yawnoc.strokeinput"
1111
minSdkVersion 24
12-
compileSdk 34
13-
targetSdkVersion 34
12+
compileSdk 35
13+
targetSdkVersion 35
1414
versionCode 65
1515
versionName "1.3.1"
1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -40,6 +40,6 @@ dependencies
4040
{
4141
implementation 'com.google.android.material:material:1.12.0'
4242
testImplementation 'junit:junit:4.13.2'
43-
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
44-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
43+
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
4545
}

app/src/main/java/io/github/yawnoc/strokeinput/InputContainer.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
package io.github.yawnoc.strokeinput;
99

1010
import android.content.Context;
11+
import android.graphics.Insets;
1112
import android.graphics.Typeface;
13+
import android.os.Build;
1214
import android.util.AttributeSet;
1315
import android.view.View;
16+
import android.view.ViewGroup;
1417
import android.view.ViewTreeObserver;
18+
import android.view.WindowInsets;
1519
import android.widget.FrameLayout;
1620

21+
import androidx.core.view.WindowInsetsCompat;
22+
1723
import java.util.List;
1824

1925
/*
@@ -23,6 +29,7 @@
2329
- Stroke sequence bar
2430
- Candidates view
2531
- Keyboard view
32+
- Bottom spacer (needed in API level 35+ due to edge-to-edge)
2633
2. Key preview plane (overlaid)
2734
*/
2835
public class InputContainer
@@ -34,6 +41,23 @@ public class InputContainer
3441
private CandidatesView candidatesView;
3542
private CandidatesViewAdapter candidatesViewAdapter;
3643
private KeyboardView keyboardView;
44+
private View bottomSpacer;
45+
46+
@Override
47+
public WindowInsets onApplyWindowInsets(WindowInsets insets)
48+
{
49+
super.onApplyWindowInsets(insets);
50+
51+
if (Build.VERSION.SDK_INT >= 35) // bottom spacing for edge-to-edge
52+
{
53+
final Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
54+
ViewGroup.LayoutParams layoutParameters = bottomSpacer.getLayoutParams();
55+
layoutParameters.height = systemBars.bottom;
56+
bottomSpacer.setLayoutParams(layoutParameters);
57+
}
58+
59+
return insets;
60+
}
3761

3862
public InputContainer(final Context context, final AttributeSet attributes)
3963
{
@@ -70,6 +94,11 @@ public void initialiseKeyboardView(
7094
keyboardView.setKeyboard(keyboard);
7195
}
7296

97+
public void initialiseBottomSpacer()
98+
{
99+
bottomSpacer = findViewById(R.id.bottom_spacer);
100+
}
101+
73102
public void setPopupRecessLayout(final boolean isFullscreen)
74103
{
75104
if (isFullscreen)
@@ -141,6 +170,7 @@ public void setKeyRepeatIntervalMilliseconds(final int milliseconds)
141170

142171
public void redrawKeyboard()
143172
{
173+
keyboardView.requestLayout();
144174
keyboardView.invalidate();
145175
}
146176
}

app/src/main/java/io/github/yawnoc/strokeinput/Key.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class Key
4545
public String valueTextShifted; // overrides displayText drawn when shifted
4646

4747
// Key dimensions
48-
public int width;
48+
public int width, naturalWidth;
4949
public int height, naturalHeight;
5050

5151
// Key styles
@@ -55,13 +55,13 @@ public class Key
5555
public int textColour;
5656
public int textSwipeColour;
5757
public int textSize;
58-
public int textOffsetX;
58+
public int textOffsetX, naturalTextOffsetX;
5959
public int textOffsetY, naturalTextOffsetY;
6060
public float previewMagnification;
6161
public int previewMarginY, naturalPreviewMarginY;
6262

6363
// Key position
64-
public int x;
64+
public int x, naturalX;
6565
public int y, naturalY;
6666

6767
// Key meta-properties
@@ -70,7 +70,7 @@ public class Key
7070
public Key(final Row parentRow)
7171
{
7272
grandparentKeyboard = parentRow.parentKeyboard;
73-
width = parentRow.keyWidth;
73+
width = naturalWidth = parentRow.keyWidth;
7474
height = naturalHeight = parentRow.keyHeight;
7575
}
7676

@@ -83,7 +83,7 @@ public Key(final Row parentRow,
8383
{
8484
this(parentRow);
8585

86-
this.x = x;
86+
this.x = naturalX = x;
8787
this.y = naturalY = y;
8888

8989
final TypedArray attributesArray =
@@ -114,7 +114,7 @@ else if (valueTextShifted == null)
114114
valueTextShifted = displayText;
115115
}
116116

117-
width =
117+
width = naturalWidth =
118118
Valuey.getDimensionOrFraction(
119119
attributesArray,
120120
R.styleable.Key_keyWidth,
@@ -139,7 +139,8 @@ else if (valueTextShifted == null)
139139
textColour = attributesArray.getColor(R.styleable.Key_keyTextColour, parentRow.keyTextColour);
140140
textSwipeColour = attributesArray.getColor(R.styleable.Key_keyTextSwipeColour, parentRow.keyTextSwipeColour);
141141
textSize = attributesArray.getDimensionPixelSize(R.styleable.Key_keyTextSize, parentRow.keyTextSize);
142-
textOffsetX = attributesArray.getDimensionPixelSize(R.styleable.Key_keyTextOffsetX, parentRow.keyTextOffsetX);
142+
textOffsetX = naturalTextOffsetX =
143+
attributesArray.getDimensionPixelSize(R.styleable.Key_keyTextOffsetX, parentRow.keyTextOffsetX);
143144
textOffsetY = naturalTextOffsetY =
144145
attributesArray.getDimensionPixelSize(R.styleable.Key_keyTextOffsetY, parentRow.keyTextOffsetY);
145146

app/src/main/java/io/github/yawnoc/strokeinput/Keyboard.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public class Keyboard
9494

9595
public Keyboard(final Context context, final int layoutResourceId)
9696
{
97-
final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
97+
final Resources resources = context.getResources();
98+
final DisplayMetrics displayMetrics = resources.getDisplayMetrics();
9899
applicationContext = context.getApplicationContext();
99100

100101
screenWidth = displayMetrics.widthPixels;
@@ -108,7 +109,7 @@ public Keyboard(final Context context, final int layoutResourceId)
108109

109110
keyList = new ArrayList<>();
110111

111-
makeKeyboard(context, context.getResources().getXml(layoutResourceId));
112+
makeKeyboard(context, resources.getXml(layoutResourceId));
112113
adjustKeyboardHeight();
113114
}
114115

@@ -206,6 +207,17 @@ else if (inRow)
206207
}
207208
}
208209

210+
public void correctKeyboardWidth(int inputContainerWidth)
211+
{
212+
final float correctionFactor = ((float) inputContainerWidth) / screenWidth;
213+
for (final Key key : keyList)
214+
{
215+
key.x = (int) (key.naturalX * correctionFactor);
216+
key.width = (int) (key.naturalWidth * correctionFactor);
217+
key.textOffsetX = (int) (key.naturalTextOffsetX * correctionFactor);
218+
}
219+
}
220+
209221
public void adjustKeyboardHeight()
210222
{
211223
final int userAdjustmentProgress = MainActivity.loadSavedKeyboardHeightAdjustmentProgress(applicationContext);

app/src/main/java/io/github/yawnoc/strokeinput/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class MainActivity
6161
protected void onCreate(final Bundle savedInstanceState)
6262
{
6363
super.onCreate(savedInstanceState);
64+
getTheme().applyStyle(R.style.NoEdgeToEdge, false);
6465
setTitle(R.string.label__main_activity__welcome);
6566
setContentView(R.layout.main_activity);
6667

app/src/main/java/io/github/yawnoc/strokeinput/StrokeInputService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public View onCreateInputView()
196196
inputContainer.initialiseStrokeSequenceBar(this);
197197
inputContainer.initialiseCandidatesView(this);
198198
inputContainer.initialiseKeyboardView(this, loadSavedKeyboard());
199+
inputContainer.initialiseBottomSpacer();
199200

200201
return inputContainer;
201202
}
@@ -404,6 +405,18 @@ public void onStartInputView(final EditorInfo editorInfo, final boolean isRestar
404405
{
405406
super.onStartInputView(editorInfo, isRestarting);
406407

408+
inputContainer.post( // await layout so that width is available
409+
() ->
410+
{
411+
final int inputContainerWidth = inputContainer.getWidth();
412+
for (final Keyboard keyboard : keyboardSet)
413+
{
414+
keyboard.correctKeyboardWidth(inputContainerWidth); // needed in API level 35+ due to edge-to-edge breakage
415+
}
416+
inputContainer.redrawKeyboard(); // key preview plane initialisation is buggy in landscape mode
417+
}
418+
);
419+
407420
for (final Keyboard keyboard : keyboardSet)
408421
{
409422
keyboard.adjustKeyboardHeight();

app/src/main/res/layout/input_container.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
android:layout_width="wrap_content"
5353
android:layout_height="wrap_content"
5454
/>
55+
<View
56+
android:id="@+id/bottom_spacer"
57+
android:layout_width="match_parent"
58+
android:layout_height="0dp"
59+
android:background="@android:color/black"
60+
/>
5561
</LinearLayout>
5662
<io.github.yawnoc.strokeinput.KeyPreviewPlane
5763
android:id="@+id/key_preview_plane"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="NoEdgeToEdge">
4+
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
5+
</style>
6+
</resources>

app/src/main/res/values/styles.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3+
<style name="NoEdgeToEdge">
4+
<!-- API 34 or earlier does not need `android:windowOptOutEdgeToEdgeEnforcement` -->
5+
</style>
36
<style name="MainActivityText">
47
<item name="android:layout_height">match_parent</item>
58
<item name="android:layout_width">match_parent</item>

0 commit comments

Comments
 (0)