mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-22 07:37:40 +00:00
Initial pred. text longpress support (Android)
This commit is contained in:
parent
d0fb13f768
commit
6eb59e5bd7
5 changed files with 118 additions and 10 deletions
|
|
@ -235,6 +235,23 @@
|
|||
}
|
||||
}
|
||||
|
||||
function suggestionPopup(obj,custom,x,y,w,h) {
|
||||
if(obj != null) {
|
||||
var i;
|
||||
var s = JSON.stringify(obj);
|
||||
var shift = false;
|
||||
var pos = x.toString() + ',' + y.toString();
|
||||
var size = w.toString() + ',' + h.toString();
|
||||
|
||||
|
||||
fragmentToggle=(fragmentToggle+1) % 100;
|
||||
var hash = 'suggestPopup-' + fragmentToggle + '+pos=' + pos + '+size=' + size + '+suggestion=' + s;
|
||||
hash = hash + '+custom=' + custom;
|
||||
|
||||
window.location.hash = hash;
|
||||
}
|
||||
}
|
||||
|
||||
function showMenu() {
|
||||
fragmentToggle = (fragmentToggle + 1) % 100;
|
||||
window.location.hash = 'globeKeyAction' + fragmentToggle;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
|
@ -162,4 +163,16 @@ public final class JSONParser {
|
|||
public JSONObject getJSONObjectFromUrl(String urlStr) {
|
||||
return getJSONObjectFromUrl(urlStr, JSONObject.class);
|
||||
}
|
||||
|
||||
public JSONObject getJSONObjectFromString(String str) {
|
||||
return getJSONObjectFromReader(new BufferedReader(new StringReader(str)));
|
||||
}
|
||||
|
||||
public JSONObject getJSONObjectFromURIString(String str) {
|
||||
try {
|
||||
return getJSONObjectFromString(java.net.URLDecoder.decode(str, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1371,6 +1371,36 @@ public final class KMManager {
|
|||
currentBanner = (change.equals("loaded")) ? "suggestion" : "blank";
|
||||
RelativeLayout.LayoutParams params = getKeyboardLayoutParams();
|
||||
InAppKeyboard.setLayoutParams(params);
|
||||
} else if (url.indexOf("suggestPopup") >= 0) {
|
||||
int start = url.indexOf("pos=") + 4;
|
||||
int end = url.indexOf("size=");
|
||||
|
||||
String posData[] = url.substring(start, end).split("\\,");
|
||||
|
||||
start = end + 5;
|
||||
end = url.indexOf("suggestion=");
|
||||
|
||||
String sizeData[] = url.substring(start, end).split("\\,");
|
||||
|
||||
start = end + 11;
|
||||
end = url.indexOf("custom=");
|
||||
|
||||
String suggestionJSON = url.substring(start, end);
|
||||
|
||||
start = end + 7;
|
||||
|
||||
String isCustomStr = url.substring(start);
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject obj = parser.getJSONObjectFromURIString(suggestionJSON);
|
||||
|
||||
try {
|
||||
Log.v("KMEA", "Suggestion display: " + obj.getString("displayAs"));
|
||||
} catch (JSONException e) {
|
||||
//e.printStackTrace();
|
||||
Log.v("KMEA", "JSON parsing error: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1547,8 +1577,37 @@ public final class KMManager {
|
|||
currentBanner = (change.equals("loaded")) ? "suggestion" : "blank";
|
||||
RelativeLayout.LayoutParams params = getKeyboardLayoutParams();
|
||||
SystemKeyboard.setLayoutParams(params);
|
||||
}
|
||||
return false;
|
||||
} else if (url.indexOf("suggestPopup") >= 0) {
|
||||
int start = url.indexOf("pos=") + 4;
|
||||
int end = url.indexOf("size=");
|
||||
|
||||
String posData[] = url.substring(start, end).split("\\,");
|
||||
|
||||
start = end + 5;
|
||||
end = url.indexOf("suggestion=");
|
||||
|
||||
String sizeData[] = url.substring(start, end).split("\\,");
|
||||
|
||||
start = end + 11;
|
||||
end = url.indexOf("custom=");
|
||||
|
||||
String suggestionJSON = url.substring(start, end);
|
||||
|
||||
start = end + 7;
|
||||
|
||||
String isCustomStr = url.substring(start);
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject obj = parser.getJSONObjectFromURIString(suggestionJSON);
|
||||
|
||||
try {
|
||||
Log.v("KMEA", "Suggestion display: " + obj.getString("displayAs"));
|
||||
} catch (JSONException e) {
|
||||
//e.printStackTrace();
|
||||
Log.v("KMEA", "JSON parsing error: " + e.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,6 +186,18 @@ namespace com.keyman.osk {
|
|||
|
||||
return true;
|
||||
};
|
||||
|
||||
SuggestionManager.prototype.platformHold = function(this: SuggestionManager, suggestionObj: BannerSuggestion, isCustom: boolean) {
|
||||
// Parallels VisualKeyboard.prototype.touchHold, but for predictive suggestions instead of keystrokes.
|
||||
let suggestionEle = suggestionObj.div;
|
||||
|
||||
// Need to know if it's a <keep> option or not!
|
||||
|
||||
var xBase = dom.Utils.getAbsoluteX(suggestionEle) - dom.Utils.getAbsoluteX(suggestionEle.parentElement) + suggestionEle.offsetWidth/2,
|
||||
yBase = dom.Utils.getAbsoluteY(suggestionEle) - dom.Utils.getAbsoluteY(suggestionEle.parentElement);
|
||||
|
||||
window['suggestionPopup'](suggestionObj.suggestion, isCustom, xBase, yBase, suggestionEle.offsetWidth, suggestionEle.offsetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
namespace com.keyman.text {
|
||||
|
|
|
|||
|
|
@ -407,9 +407,11 @@ namespace com.keyman.osk {
|
|||
}
|
||||
}
|
||||
|
||||
class SuggestionManager extends dom.UITouchHandlerBase<HTMLDivElement> {
|
||||
export class SuggestionManager extends dom.UITouchHandlerBase<HTMLDivElement> {
|
||||
private selected: BannerSuggestion;
|
||||
|
||||
platformHold: (suggestion: BannerSuggestion, isCustom: boolean) => void;
|
||||
|
||||
//#region Touch handling implementation
|
||||
findTargetFrom(e: HTMLElement): HTMLDivElement {
|
||||
let keyman = com.keyman.singleton;
|
||||
|
|
@ -459,11 +461,16 @@ namespace com.keyman.osk {
|
|||
|
||||
//#region Long-press support
|
||||
protected hold(t: HTMLDivElement): void {
|
||||
// Temp, pending implementation of suggestion longpress submenus
|
||||
// - nothing worth doing with a hold yet -
|
||||
let suggestionObj = t['suggestion'] as BannerSuggestion;
|
||||
|
||||
// Should have separate native + embedded mode branches.
|
||||
// Embedded mode should pass any info needed to show a submenu IMMEDIATELY.
|
||||
// Is this the <keep> suggestion? It's never in this.currentSuggestions, so check against that.
|
||||
let isCustom = this.currentSuggestions.indexOf(suggestionObj.suggestion) == -1;
|
||||
|
||||
if(this.platformHold) {
|
||||
// Implemented separately for native + embedded mode branches.
|
||||
// Embedded mode should pass any info needed to show a submenu IMMEDIATELY.
|
||||
this.platformHold(suggestionObj, isCustom); // No implementation yet for native.
|
||||
}
|
||||
}
|
||||
protected clearHolds(): void {
|
||||
// Temp, pending implementation of suggestion longpress submenus
|
||||
|
|
@ -471,12 +478,12 @@ namespace com.keyman.osk {
|
|||
|
||||
// only really used in native-KMW
|
||||
}
|
||||
|
||||
protected hasModalPopup(): boolean {
|
||||
// Temp, pending implementation of suggestion longpress submenus
|
||||
|
||||
// Utilized by the mobile apps; allows them to 'take over' touch handling,
|
||||
// blocking it within KMW when the apps are already managing an ongoing touch-hold.
|
||||
return false;
|
||||
let keyman = com.keyman.singleton;
|
||||
return keyman['osk'].vkbd.popupVisible;
|
||||
}
|
||||
|
||||
protected dealiasSubTarget(target: HTMLDivElement): HTMLDivElement {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue