Skip to content

Commit e1b254c

Browse files
authored
Merge pull request #2 from RaXorX/max_master
Max master
2 parents c9fa62f + 9818221 commit e1b254c

19 files changed

+578
-208
lines changed

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## Patches from Pulya Max ##
2+
Removed signature check on main thread
3+
4+
Added ctrl+backspace hotkey
5+
6+
Fixed switch-case: constant expression required error.
7+
8+
Fixed build in Android Studio 2024.
9+
10+
(For multiply lanuages) Force english when modifier keys pressed.
11+
12+
Settings Tab Hack(Tab enters DNS server writed in code)
13+
114
## Overview ##
215

316
**WARNING:** *This is a rather ancient project that was originally developed back in 2011 based on the Android 2.3 (Gingerbread) AOSP keyboard. While it still works as-is for many users, it would need some major rewrites to work with newer APIs, and some features such as language switching or popup keys don't work right on modern Android systems. I'm not currently planning on significant updates, and it's possible that it will stop working on modern devices or will no longer be updateable via the Google Play store due to minimum API level requirements. Play Store requires targeting API level 29 (Android 10), while the code was written for API level 9 (Android 2.3) from 2011.*

‎app/build.gradle‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4+
namespace 'org.pocketworkstation.pckeyboard'
45
compileSdkVersion 26
56
defaultConfig {
67
applicationId 'org.pocketworkstation.pckeyboard'
7-
minSdkVersion 14
8+
minSdkVersion 21
89
targetSdkVersion 26
910
versionCode 1041001
1011
versionName "v1.41.1"
@@ -19,6 +20,10 @@ android {
1920
release {
2021
minifyEnabled false
2122
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23+
debuggable true
24+
}
25+
debug {
26+
debuggable true
2227
}
2328
}
2429
externalNativeBuild {

‎app/src/main/java/org/pocketworkstation/pckeyboard/CandidateView.java‎

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public class CandidateView extends View {
4646

4747
private LatinIME mService;
4848
private final ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>();
49+
50+
51+
52+
private ArrayList<CharSequence> mSuggestions_fullText = null;
4953
private boolean mShowingCompletions;
5054
private CharSequence mSelectedString;
5155
private int mSelectedIndex;
@@ -62,11 +66,15 @@ public class CandidateView extends View {
6266
private int mCurrentWordIndex;
6367
private Drawable mDivider;
6468

65-
private static final int MAX_SUGGESTIONS = 32;
69+
private static final int MAX_SUGGESTIONS = 10;
70+
/**
71+
*Length of R.array.suggested_commands
72+
*/
73+
private static final int COMMANDS_COUNT = 1;
6674
private static final int SCROLL_PIXELS = 20;
6775

68-
private final int[] mWordWidth = new int[MAX_SUGGESTIONS];
69-
private final int[] mWordX = new int[MAX_SUGGESTIONS];
76+
private final int[] mWordWidth = new int[MAX_SUGGESTIONS+COMMANDS_COUNT];
77+
private final int[] mWordX = new int[MAX_SUGGESTIONS+COMMANDS_COUNT];
7078
private int mPopupPreviewX;
7179
private int mPopupPreviewY;
7280

@@ -320,6 +328,7 @@ private void scrollToTarget() {
320328

321329
public void setSuggestions(List<CharSequence> suggestions, boolean completions,
322330
boolean typedWordValid, boolean haveMinimalSuggestion) {
331+
mSuggestions_fullText=null;
323332
clear();
324333
if (suggestions != null) {
325334
int insertCount = Math.min(suggestions.size(), MAX_SUGGESTIONS);
@@ -329,6 +338,30 @@ public void setSuggestions(List<CharSequence> suggestions, boolean completions,
329338
break;
330339
}
331340
}
341+
mSuggestions.addAll(Arrays.asList(getResources().getStringArray(R.array.suggested_commands)));
342+
mShowingCompletions = completions;
343+
mTypedWordValid = typedWordValid;
344+
scrollTo(0, getScrollY());
345+
mTargetScrollX = 0;
346+
mHaveMinimalSuggestion = haveMinimalSuggestion;
347+
// Compute the total width
348+
onDraw(null);
349+
invalidate();
350+
requestLayout();
351+
}
352+
public void setSuggestions(List<CharSequence> suggestions,List<CharSequence> suggestions_FullText, boolean completions,
353+
boolean typedWordValid, boolean haveMinimalSuggestion) {
354+
mSuggestions_fullText=new ArrayList<>();
355+
clear();
356+
if (suggestions != null) {
357+
int insertCount = Math.min(suggestions.size(), MAX_SUGGESTIONS);
358+
for (int i=0;i<insertCount;i++) {
359+
mSuggestions.add(suggestions.get(i));
360+
mSuggestions_fullText.add(suggestions_FullText.get(i));
361+
}
362+
}
363+
mSuggestions.addAll(Arrays.asList(getResources().getStringArray(R.array.suggested_commands)));
364+
mSuggestions_fullText.addAll(Arrays.asList(getResources().getStringArray(R.array.suggested_commands)));
332365
mShowingCompletions = completions;
333366
mTypedWordValid = typedWordValid;
334367
scrollTo(0, getScrollY());
@@ -361,6 +394,7 @@ public boolean dismissAddToDictionaryHint() {
361394
/* package */ List<CharSequence> getSuggestions() {
362395
return mSuggestions;
363396
}
397+
/* package */ ArrayList<CharSequence> getSuggestions_fullText() {return mSuggestions_fullText;}
364398

365399
public void clear() {
366400
// Don't call mSuggestions.clear() because it's being used for logging
@@ -403,7 +437,7 @@ public boolean onTouchEvent(MotionEvent me) {
403437
//TextEntryState.acceptedSuggestion(mSuggestions.get(0), mSelectedString);
404438
//TextEntryState.manualTyped(mSelectedString);
405439
}
406-
mService.pickSuggestionManually(mSelectedIndex, mSelectedString);
440+
mService.pickSuggestionManually(mSelectedIndex);
407441
mSelectedString = null;
408442
mSelectedIndex = -1;
409443
}
@@ -420,7 +454,7 @@ public boolean onTouchEvent(MotionEvent me) {
420454
//TextEntryState.acceptedSuggestion(mSuggestions.get(0), mSelectedString);
421455
//TextEntryState.manualTyped(mSelectedString);
422456
}
423-
mService.pickSuggestionManually(mSelectedIndex, mSelectedString);
457+
mService.pickSuggestionManually(mSelectedIndex);
424458
}
425459
}
426460
}

‎app/src/main/java/org/pocketworkstation/pckeyboard/EditingUtil.java‎

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ public static void appendText(InputConnection connection, String newText) {
6363

6464
connection.setComposingText(newText, 1);
6565
}
66+
//*//Added by Pulya Max
67+
public static void SetText(InputConnection connection, String newText) {
68+
if (connection == null) {
69+
return;
70+
}
71+
72+
// Commit the composing text
73+
connection.finishComposingText();
74+
75+
// Deletes text if the field already has text.
76+
CharSequence charBeforeCursor = connection.getTextBeforeCursor(1, 0);
77+
if (charBeforeCursor != null
78+
&& !charBeforeCursor.equals(" ")
79+
&& (charBeforeCursor.length() > 0)) {
80+
deleteWordAtCursor(connection,"",false);
81+
}
82+
83+
connection.setComposingText(newText, 1);
84+
}
6685

6786
private static int getCursorPosition(InputConnection connection) {
6887
ExtractedText extracted = connection.getExtractedText(
@@ -73,6 +92,16 @@ private static int getCursorPosition(InputConnection connection) {
7392
return extracted.startOffset + extracted.selectionStart;
7493
}
7594

95+
public static boolean textViewIsEmpty(InputConnection connection) {
96+
if (connection==null) return true;
97+
CharSequence before = connection.getTextBeforeCursor(1, 0);
98+
CharSequence after = connection.getTextAfterCursor(1, 0);
99+
String text = "";
100+
if(before!=null) text += before;
101+
if(after!=null) text += after;
102+
return text.isEmpty();
103+
104+
}
76105
/**
77106
* @param connection connection to the current text field.
78107
* @param separators characters which may separate words
@@ -83,18 +112,29 @@ private static int getCursorPosition(InputConnection connection) {
83112
*/
84113
public static String getWordAtCursor(
85114
InputConnection connection, String separators, Range range) {
86-
Range r = getWordRangeAtCursor(connection, separators, range);
115+
Range r = getWordOrSeparatorsRangeAtCursor(connection, separators, range,false);
87116
return (r == null) ? null : r.word;
88117
}
118+
//*//Added by Pulya Max. Used for ctrl+backspace hotkey
119+
/**
120+
* Removes the word surrounding the cursor and separators. Parameters are identical to
121+
* getWordAtCursor.
122+
*/
123+
public static void deleteWordAndSeparatorAtCursor(
124+
InputConnection connection, String separators) {
125+
deleteWordAtCursor(connection,separators,true);
126+
deleteWordAtCursor(connection,separators,false);
127+
}
89128

90129
/**
91130
* Removes the word surrounding the cursor. Parameters are identical to
92131
* getWordAtCursor.
93132
*/
133+
//*// edited by Maxim Pulya
94134
public static void deleteWordAtCursor(
95-
InputConnection connection, String separators) {
135+
InputConnection connection, String separators,boolean deleteSeparators) {
96136

97-
Range range = getWordRangeAtCursor(connection, separators, null);
137+
Range range = getWordOrSeparatorsRangeAtCursor(connection, separators, null,deleteSeparators);
98138
if (range == null) return;
99139

100140
connection.finishComposingText();
@@ -105,6 +145,7 @@ public static void deleteWordAtCursor(
105145
connection.deleteSurroundingText(0, range.charsBefore + range.charsAfter);
106146
}
107147

148+
108149
/**
109150
* Represents a range of text, relative to the current cursor position.
110151
*/
@@ -133,8 +174,8 @@ public Range(int charsBefore, int charsAfter, String word) {
133174
}
134175
}
135176

136-
private static Range getWordRangeAtCursor(
137-
InputConnection connection, String sep, Range range) {
177+
private static Range getWordOrSeparatorsRangeAtCursor(
178+
InputConnection connection, String sep, Range range,boolean getSeparatorsRange) {
138179
if (connection == null || sep == null) {
139180
return null;
140181
}
@@ -146,7 +187,8 @@ private static Range getWordRangeAtCursor(
146187

147188
// Find first word separator before the cursor
148189
int start = before.length();
149-
while (start > 0 && !isWhitespace(before.charAt(start - 1), sep)) start--;
190+
if(!getSeparatorsRange) while (start > 0 && !isWhitespace(before.charAt(start - 1), sep)) start--;
191+
else while (start > 0 && isWhitespace(before.charAt(start - 1), sep)) start--;
150192

151193
// Find last word separator after the cursor
152194
int end = -1;

‎app/src/main/java/org/pocketworkstation/pckeyboard/KeyboardSwitcher.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ private static class KeyboardId {
226226
/** A KEYBOARDMODE_XXX value */
227227
public final boolean mEnableShiftLock;
228228
public final boolean mHasVoice;
229-
public final float mKeyboardHeightPercent;
229+
public float mKeyboardHeightPercent;
230+
//*//Pulya Max. Size of keyboard is dynamic.
231+
//*// Used by Big pin keyboard option
230232
public final boolean mUsingExtension;
231233

232234
private final int mHashCode;
@@ -307,11 +309,13 @@ private void setKeyboardMode(int mode, int imeOptions, boolean enableVoice,
307309

308310
KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
309311
LatinKeyboard keyboard = null;
312+
//*// Added by Maxim Pulya
313+
//*// I made pin keyboard bigger
314+
if (mode == MODE_PHONE && mInputMethodService.isPortrait())id.mKeyboardHeightPercent*=1.4;
315+
310316
keyboard = getKeyboard(id);
311317

312-
if (mode == MODE_PHONE) {
313-
mInputView.setPhoneKeyboard(keyboard);
314-
}
318+
if (mode == MODE_PHONE)mInputView.setPhoneKeyboard(keyboard);
315319

316320
mCurrentId = id;
317321
mInputView.setKeyboard(keyboard);
@@ -644,7 +648,8 @@ private void changeLatinKeyboardView(int newLayout, boolean forceReset) {
644648
mInputMethodService.mHandler.post(new Runnable() {
645649
public void run() {
646650
if (mInputView != null) {
647-
mInputMethodService.setInputView(mInputView);
651+
//*//Edited by Pulya Max to fix candidates
652+
mInputMethodService.setInputView(mInputMethodService.mCandidateViewAndKeyboardView);
648653
}
649654
mInputMethodService.updateInputViewShown();
650655
}

‎app/src/main/java/org/pocketworkstation/pckeyboard/LanguageSwitcher.java‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ public class LanguageSwitcher {
3636
private String[] mSelectedLanguageArray;
3737
private String mSelectedLanguages;
3838
private int mCurrentIndex = 0;
39+
private int mPreviousIndex = 0;
40+
private int mEnglishIndex = 0;
3941
private String mDefaultInputLanguage;
4042
private Locale mDefaultInputLocale;
4143
private Locale mSystemLocale;
4244

45+
//*// added by Pulya Max //*//
46+
private boolean mLangChangedByUser=false;
4347
public LanguageSwitcher(LatinIME ime) {
4448
mIme = ime;
4549
mLocales = new Locale[0];
@@ -87,6 +91,13 @@ public boolean loadLocales(SharedPreferences sp) {
8791
}
8892
// If we didn't find the index, use the first one
8993
}
94+
95+
//*//Added by Pulya Max
96+
for (int i=0;i<mSelectedLanguageArray.length;i++){
97+
if (mSelectedLanguageArray[i].equals("en"))mEnglishIndex=i;
98+
}
99+
//*//
100+
90101
return true;
91102
}
92103

@@ -196,21 +207,33 @@ public Locale getPrevInputLocale() {
196207
}
197208

198209
public void reset() {
210+
mLangChangedByUser=true;
199211
mCurrentIndex = 0;
200212
mSelectedLanguages = "";
201213
loadLocales(PreferenceManager.getDefaultSharedPreferences(mIme));
202214
}
203215

204216
public void next() {
217+
mLangChangedByUser=true;
205218
mCurrentIndex++;
206219
if (mCurrentIndex >= mLocales.length) mCurrentIndex = 0; // Wrap around
207220
}
208221

209222
public void prev() {
223+
mLangChangedByUser=true;
210224
mCurrentIndex--;
211225
if (mCurrentIndex < 0) mCurrentIndex = mLocales.length - 1; // Wrap around
212226
}
213-
227+
//*// Added by Pulya Max
228+
public void p_max_force_en(){
229+
mLangChangedByUser=false;
230+
mPreviousIndex=mCurrentIndex;
231+
mCurrentIndex=mEnglishIndex;
232+
}
233+
public void p_max_previous_lang(){
234+
if(!mLangChangedByUser)mCurrentIndex=mPreviousIndex;
235+
}
236+
//*//
214237
public void persist() {
215238
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mIme);
216239
Editor editor = sp.edit();

0 commit comments

Comments
 (0)