Skip to content

Commit f9be01f

Browse files
committed
Move Keyboard.Row to its own class Row
1 parent 3c66864 commit f9be01f

3 files changed

Lines changed: 156 additions & 127 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public class Key {
6262
// Key meta-properties
6363
private final Keyboard grandparentKeyboard;
6464

65-
public Key(final Keyboard.Row parentRow) {
65+
public Key(final Row parentRow) {
6666
grandparentKeyboard = parentRow.parentKeyboard;
6767
width = parentRow.keyWidth;
6868
height = parentRow.keyHeight;
6969
}
7070

7171
public Key(
72-
final Keyboard.Row parentRow,
72+
final Row parentRow,
7373
final int x,
7474
final int y,
7575
final Resources resources,

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

Lines changed: 11 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,21 @@ public class Keyboard {
5151
private static final int DEFAULT_KEY_TEXT_SIZE_SP = 32;
5252
private final int defaultKeyTextSizePx;
5353

54-
private static final int DEFAULT_OFFSET_X = 0;
5554
private static final int DEFAULT_KEYBOARD_FILL_COLOUR = Color.BLACK;
5655
public static final int KEYBOARD_GUTTER_HEIGHT_PX = 1;
5756

5857
// Key properties
59-
private boolean keysAreShiftable;
60-
private int keyWidth;
61-
private int keyHeight;
62-
private int keyFillColour;
63-
private int keyBorderColour;
64-
private int keyBorderThickness;
65-
private int keyTextColour;
66-
private int keyTextSwipeColour;
67-
private int keyTextSize;
68-
private int keyTextOffsetX;
69-
private int keyTextOffsetY;
58+
public boolean keysAreShiftable;
59+
public int keyWidth;
60+
public int keyHeight;
61+
public int keyFillColour;
62+
public int keyBorderColour;
63+
public int keyBorderThickness;
64+
public int keyTextColour;
65+
public int keyTextSwipeColour;
66+
public int keyTextSize;
67+
public int keyTextOffsetX;
68+
public int keyTextOffsetY;
7069

7170
// Keyboard properties
7271
private int width;
@@ -102,119 +101,6 @@ public List<Key> getKeyList() {
102101
return keyList;
103102
}
104103

105-
/*
106-
A container that holds keys.
107-
*/
108-
public static class Row {
109-
110-
// Key properties
111-
public final boolean keysAreShiftable;
112-
public final int keyWidth;
113-
public final int keyHeight;
114-
public final int keyFillColour;
115-
public final int keyBorderColour;
116-
public final int keyBorderThickness;
117-
public final int keyTextColour;
118-
public final int keyTextSwipeColour;
119-
public final int keyTextSize;
120-
public final int keyTextOffsetX;
121-
public final int keyTextOffsetY;
122-
123-
// Row properties
124-
public final Keyboard parentKeyboard;
125-
private final int offsetX;
126-
127-
public Row(
128-
final Keyboard parentKeyboard,
129-
final Resources resources,
130-
final XmlResourceParser xmlResourceParser
131-
)
132-
{
133-
this.parentKeyboard = parentKeyboard;
134-
135-
final TypedArray attributesArray =
136-
resources.obtainAttributes(
137-
Xml.asAttributeSet(xmlResourceParser),
138-
R.styleable.Keyboard
139-
);
140-
141-
offsetX =
142-
getDimensionOrFraction(
143-
attributesArray,
144-
R.styleable.Keyboard_offsetX,
145-
parentKeyboard.screenWidth,
146-
DEFAULT_OFFSET_X
147-
);
148-
149-
keysAreShiftable =
150-
attributesArray.getBoolean(
151-
R.styleable.Keyboard_isShiftable,
152-
parentKeyboard.keysAreShiftable
153-
);
154-
155-
keyWidth =
156-
getDimensionOrFraction(
157-
attributesArray,
158-
R.styleable.Keyboard_keyWidth,
159-
parentKeyboard.screenWidth,
160-
parentKeyboard.keyWidth
161-
);
162-
keyHeight =
163-
getDimensionOrFraction(
164-
attributesArray,
165-
R.styleable.Keyboard_keyHeight,
166-
parentKeyboard.screenHeight,
167-
parentKeyboard.keyHeight
168-
);
169-
170-
keyFillColour =
171-
attributesArray.getColor(
172-
R.styleable.Keyboard_keyFillColour,
173-
parentKeyboard.keyFillColour
174-
);
175-
keyBorderColour =
176-
attributesArray.getColor(
177-
R.styleable.Keyboard_keyBorderColour,
178-
parentKeyboard.keyBorderColour
179-
);
180-
keyBorderThickness =
181-
attributesArray.getDimensionPixelSize(
182-
R.styleable.Keyboard_keyBorderThickness,
183-
parentKeyboard.keyBorderThickness
184-
);
185-
186-
keyTextColour =
187-
attributesArray.getColor(
188-
R.styleable.Keyboard_keyTextColour,
189-
parentKeyboard.keyTextColour
190-
);
191-
keyTextSwipeColour =
192-
attributesArray.getColor(
193-
R.styleable.Keyboard_keyTextSwipeColour,
194-
parentKeyboard.keyTextSwipeColour
195-
);
196-
keyTextSize =
197-
attributesArray.getDimensionPixelSize(
198-
R.styleable.Keyboard_keyTextSize,
199-
parentKeyboard.keyTextSize
200-
);
201-
202-
keyTextOffsetX =
203-
attributesArray.getDimensionPixelSize(
204-
R.styleable.Keyboard_keyTextOffsetX,
205-
parentKeyboard.keyTextOffsetX
206-
);
207-
keyTextOffsetY =
208-
attributesArray.getDimensionPixelSize(
209-
R.styleable.Keyboard_keyTextOffsetY,
210-
parentKeyboard.keyTextOffsetY
211-
);
212-
213-
attributesArray.recycle();
214-
}
215-
216-
}
217-
218104
public int getWidth() {
219105
return width;
220106
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
Copyright 2021 Conway
3+
Licensed under the GNU General Public License v3.0 (GPL-3.0-only).
4+
This is free software with NO WARRANTY etc. etc.,
5+
see LICENSE or <https://www.gnu.org/licenses/>.
6+
*/
7+
/*
8+
This file contains bytes copied from the deprecated `Keyboard` class,
9+
i.e. `core/java/android/inputmethodservice/Keyboard.java`
10+
from <https://android.googlesource.com/platform/frameworks/base>,
11+
which is licensed under the Apache License 2.0,
12+
see <https://www.apache.org/licenses/LICENSE-2.0.html>.
13+
---
14+
Take your pick from the following out-of-date notices:
15+
In `core/java/android/inputmethodservice/Keyboard.java`:
16+
Copyright (C) 2008-2009 Google Inc.
17+
In `NOTICE`:
18+
Copyright 2005-2008 The Android Open Source Project
19+
*/
20+
21+
package io.github.yawnoc.strokeinput;
22+
23+
import android.content.res.Resources;
24+
import android.content.res.TypedArray;
25+
import android.content.res.XmlResourceParser;
26+
import android.util.Xml;
27+
28+
import static io.github.yawnoc.strokeinput.Keyboard.getDimensionOrFraction;
29+
30+
/*
31+
A container that holds keys.
32+
*/
33+
public class Row {
34+
35+
private static final int DEFAULT_OFFSET_X = 0;
36+
37+
// Key properties
38+
public final boolean keysAreShiftable;
39+
public final int keyWidth;
40+
public final int keyHeight;
41+
public final int keyFillColour;
42+
public final int keyBorderColour;
43+
public final int keyBorderThickness;
44+
public final int keyTextColour;
45+
public final int keyTextSwipeColour;
46+
public final int keyTextSize;
47+
public final int keyTextOffsetX;
48+
public final int keyTextOffsetY;
49+
50+
// Row properties
51+
public final Keyboard parentKeyboard;
52+
public final int offsetX;
53+
54+
public Row(
55+
final Keyboard parentKeyboard,
56+
final Resources resources,
57+
final XmlResourceParser xmlResourceParser
58+
)
59+
{
60+
this.parentKeyboard = parentKeyboard;
61+
62+
final TypedArray attributesArray =
63+
resources.obtainAttributes(
64+
Xml.asAttributeSet(xmlResourceParser),
65+
R.styleable.Keyboard
66+
);
67+
68+
offsetX =
69+
getDimensionOrFraction(
70+
attributesArray,
71+
R.styleable.Keyboard_offsetX,
72+
parentKeyboard.screenWidth,
73+
DEFAULT_OFFSET_X
74+
);
75+
76+
keysAreShiftable =
77+
attributesArray.getBoolean(
78+
R.styleable.Keyboard_isShiftable,
79+
parentKeyboard.keysAreShiftable
80+
);
81+
82+
keyWidth =
83+
getDimensionOrFraction(
84+
attributesArray,
85+
R.styleable.Keyboard_keyWidth,
86+
parentKeyboard.screenWidth,
87+
parentKeyboard.keyWidth
88+
);
89+
keyHeight =
90+
getDimensionOrFraction(
91+
attributesArray,
92+
R.styleable.Keyboard_keyHeight,
93+
parentKeyboard.screenHeight,
94+
parentKeyboard.keyHeight
95+
);
96+
97+
keyFillColour =
98+
attributesArray.getColor(
99+
R.styleable.Keyboard_keyFillColour,
100+
parentKeyboard.keyFillColour
101+
);
102+
keyBorderColour =
103+
attributesArray.getColor(
104+
R.styleable.Keyboard_keyBorderColour,
105+
parentKeyboard.keyBorderColour
106+
);
107+
keyBorderThickness =
108+
attributesArray.getDimensionPixelSize(
109+
R.styleable.Keyboard_keyBorderThickness,
110+
parentKeyboard.keyBorderThickness
111+
);
112+
113+
keyTextColour =
114+
attributesArray.getColor(
115+
R.styleable.Keyboard_keyTextColour,
116+
parentKeyboard.keyTextColour
117+
);
118+
keyTextSwipeColour =
119+
attributesArray.getColor(
120+
R.styleable.Keyboard_keyTextSwipeColour,
121+
parentKeyboard.keyTextSwipeColour
122+
);
123+
keyTextSize =
124+
attributesArray.getDimensionPixelSize(
125+
R.styleable.Keyboard_keyTextSize,
126+
parentKeyboard.keyTextSize
127+
);
128+
129+
keyTextOffsetX =
130+
attributesArray.getDimensionPixelSize(
131+
R.styleable.Keyboard_keyTextOffsetX,
132+
parentKeyboard.keyTextOffsetX
133+
);
134+
keyTextOffsetY =
135+
attributesArray.getDimensionPixelSize(
136+
R.styleable.Keyboard_keyTextOffsetY,
137+
parentKeyboard.keyTextOffsetY
138+
);
139+
140+
attributesArray.recycle();
141+
}
142+
143+
}

0 commit comments

Comments
 (0)