keymanapp / keymanapp/keyman

chore(android): stop returning valid values for invalid inputs -- across codebase

Open
#15,248 0 comments 0 reactions 1 assignee Claimed by @jahorton View on GitHub
android/ chore good first issue help wanted
Dominant language
Pascal
Stars
534
Forks
143
Avg merge
2d 10h
Merged PRs (30d)
113

Description

This is a pattern that is a bit of an issue across the Keyman for Android codebase. The orientation should only be landscape or portrait, and we should be restricting to those two values at the point of reading them from the Android system (whether that is by a parameter passed by Android to our function, or by calling an Android system function). We'd probably fallback to 'portrait' if the value is not either of those

Then, these lower level functions can assume that orientation will only ever be landscape or portrait, and we get away from having to check for the undefined result everywhere, which is part of what has caused us grief.

I am not saying we do this for this PR, but it's something we should be simplifying throughout. e.g. orientation, keyboardType, ...

So we change from things like this:

```java
public static int getKeyboardHeightMax(Context context, int orientation) {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
return (int) KMManager.KeyboardHeight_Context_Landscape_Default * 2;
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
return (int) KMManager.KeyboardHeight_Context_Portrait_Default * 2;
} else {
return KMManager.KeyboardHeight_Reset;
}
}
```

to:

```java
public static int getKeyboardHeightMax(Context context, int orientation) {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
return (int) KMManager.KeyboardHeight_Context_Landscape_Default * 2;
} else /* orientation == Configuration.ORIENTATION_PORTRAIT */ {
return (int) KMManager.KeyboardHeight_Context_Portrait_Default * 2;
}
}
```

_Originally posted by @mcdurdin in https://github.com/keymanapp/keyman/pull/13663#discussion_r2559006329_

We should be able to use enums for many of these cases.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.