Skip to content

Commit

Permalink
Merge pull request #12410 from keymanapp/fix/android/cleanup-longpres…
Browse files Browse the repository at this point in the history
…s-api

fix(android): Add gating to setLongpressDelay()
  • Loading branch information
darcywong00 committed Sep 13, 2024
2 parents bcd8f1c + eaec494 commit 86feb8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class AdjustLongpressDelayActivity extends BaseActivity {
// Keeps track of the adjusted longpress delay time for saving.
// Internally use milliseconds, but GUI displays seconds
private static int currentDelayTimeMS = KMManager.KMDefault_LongpressDelay; // ms
private static int minLongpressTime = 300; // ms
private static int maxLongpressTime = 1500; // ms
private static int delayTimeIncrement = 200; // ms

/**
Expand Down Expand Up @@ -112,7 +110,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
findViewById(R.id.delayTimeDownButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currentDelayTimeMS > minLongpressTime) {
if (currentDelayTimeMS > KMManager.KMMinimum_LongpressDelay) {
currentDelayTimeMS -= delayTimeIncrement;
seekBar.setProgress(delayTimeToProgress());
}
Expand All @@ -122,7 +120,7 @@ public void onClick(View v) {
findViewById(R.id.delayTimeUpButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currentDelayTimeMS < maxLongpressTime) {
if (currentDelayTimeMS < KMManager.KMMaximum_LongpressDelay) {
currentDelayTimeMS += delayTimeIncrement;
seekBar.setProgress(delayTimeToProgress());
}
Expand Down
15 changes: 13 additions & 2 deletions android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ public enum EnterModeType {
public static final String KMDefault_DictionaryVersion = "0.1.4";
public static final String KMDefault_DictionaryKMP = KMDefault_DictionaryPackageID + FileUtils.MODELPACKAGE;

// Default KeymanWeb longpress delay in milliseconds
// Default KeymanWeb longpress delay constants in milliseconds
public static final int KMDefault_LongpressDelay = 500;
public static final int KMMinimum_LongpressDelay = 300;
public static final int KMMaximum_LongpressDelay = 1500;


// Keyman files
protected static final String KMFilename_KeyboardHtml = "keyboard.html";
Expand Down Expand Up @@ -2097,14 +2100,22 @@ public static int getLongpressDelay() {

/**
* Set the longpress delay (in milliseconds) as a stored preference.
* Valid range is 300 ms to 1500 ms. Returns true if the preference is successfully stored.
* @param longpressDelay - int longpress delay in milliseconds
* @return boolean
*/
public static void setLongpressDelay(int longpressDelay) {
public static boolean setLongpressDelay(int longpressDelay) {
if (longpressDelay < KMMinimum_LongpressDelay || longpressDelay > KMMaximum_LongpressDelay) {
return false;
}

SharedPreferences prefs = appContext.getSharedPreferences(
appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(KMKey_LongpressDelay, longpressDelay);
editor.commit();

return true;
}

/**
Expand Down

0 comments on commit 86feb8c

Please sign in to comment.