From 250b8a6b7d2a32b9209c1cab8b2c2155582964b2 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Tue, 19 Sep 2023 09:40:41 +0700 Subject: [PATCH] chore(android): Remove popup code --- .../KMEA/app/src/main/assets/android-host.js | 52 --- .../com/keyman/engine/KMKeyPreviewView.java | 111 ------ .../java/com/keyman/engine/KMKeyboard.java | 359 ------------------ .../keyman/engine/KMKeyboardJSHandler.java | 8 - .../engine/KMKeyboardWebViewClient.java | 72 ---- .../java/com/keyman/engine/KMManager.java | 9 - .../app/src/main/res/layout/subkey_layout.xml | 10 - .../main/res/layout/subkeys_popup_layout.xml | 19 - .../KMEA/app/src/main/res/values/colors.xml | 4 - 9 files changed, 644 deletions(-) delete mode 100644 android/KMEA/app/src/main/java/com/keyman/engine/KMKeyPreviewView.java delete mode 100644 android/KMEA/app/src/main/res/layout/subkey_layout.xml delete mode 100644 android/KMEA/app/src/main/res/layout/subkeys_popup_layout.xml diff --git a/android/KMEA/app/src/main/assets/android-host.js b/android/KMEA/app/src/main/assets/android-host.js index 61e6c70d36e..afa2825e33d 100644 --- a/android/KMEA/app/src/main/assets/android-host.js +++ b/android/KMEA/app/src/main/assets/android-host.js @@ -229,58 +229,12 @@ function updateKMSelectionRange(start, end) { } var lastKeyTip = null; -function oskCreateKeyPreview(x,y,w,h,t) { - if(lastKeyTip && - lastKeyTip.t == t && - lastKeyTip.x == x && - lastKeyTip.y == y && - lastKeyTip.w == w && - lastKeyTip.h == h) { - return; - } - lastKeyTip = {x:x,y:y,w:w,h:h,t:t}; - - fragmentToggle = (fragmentToggle + 1) % 100; - var div = document.createElement('div'); - div.innerHTML = t; - var dt = div.firstChild.nodeValue; - window.location.hash = 'showKeyPreview-'+fragmentToggle+'+x='+x+'+y='+y+'+w='+w+'+h='+h+'+t='+toHex(dt); -} - -function oskClearKeyPreview() { - lastKeyTip = null; - fragmentToggle = (fragmentToggle + 1) % 100; - window.location.hash = 'dismissKeyPreview-'+fragmentToggle; -} function signalHelpBubbleDismissal() { fragmentToggle = (fragmentToggle + 1) % 100; window.location.hash = 'helpBubbleDismissed-'+fragmentToggle; } -function oskCreatePopup(obj,x,y) { - if(obj != null) { - var i; - var s = ''; - var shift = false; - var keyPos = x.toString() + ',' + y.toString(); - for(i=0; i> subKeysList = null; - public String[] subKeysWindowPos = {"0", "0"}; - // public something-something for the suggestion. public PopupWindow suggestionMenuWindow = null; public double[] suggestionWindowPos = {0, 0}; @@ -343,8 +337,6 @@ public void run() { } public void hideKeyboard() { - dismissKeyPreview(0); - dismissSubKeysWindow(); String jsString = "hideKeyboard()"; loadJavascript(jsString); @@ -372,18 +364,11 @@ public boolean onTouchEvent(MotionEvent event) { // suggestion banner longpresses - if so, it's not yet ready for proper integration... // and would need its own rung in this if-else ladder. if (true) { - if (event.getPointerCount() > 1) { - // Multiple points touch the screen at the same time, so dismiss any pending subkeys - dismissKeyPreview(0); - dismissSubKeysWindow(); - } gestureDetector.onTouchEvent(event); } if (action == MotionEvent.ACTION_UP) { // Cleanup popups. #6636 - dismissKeyPreview(0); - dismissSubKeysWindow(); } return super.onTouchEvent(event); @@ -402,23 +387,15 @@ public void onResume() { } public void onPause() { - dismissKeyPreview(0); - dismissSubKeysWindow(); - dismissHelpBubble(); } public void onDestroy() { - dismissKeyPreview(0); - dismissSubKeysWindow(); - dismissHelpBubble(); } public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - dismissKeyPreview(0); - dismissSubKeysWindow(); RelativeLayout.LayoutParams params = KMManager.getKeyboardLayoutParams(); this.setLayoutParams(params); @@ -436,9 +413,6 @@ public void onConfigurationChanged(Configuration newConfig) { } } - public void dismissSubKeysWindow() { - } - public void dismissSuggestionMenuWindow() { try { if (suggestionMenuWindow != null && suggestionMenuWindow.isShowing()) { @@ -946,234 +920,6 @@ public void onDismiss() { return; } - @SuppressLint({"InflateParams", "ClickableViewAccessibility"}) - private void showSubKeys(Context context) { - if (subKeysList == null || subKeysWindow != null) { - return; - } - - WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics metrics = new DisplayMetrics(); - wm.getDefaultDisplay().getMetrics(metrics); - float density = metrics.density; - - String[] pos = subKeysWindowPos; - int x = (int) (Float.valueOf(pos[0]) * density); - int y = (int) (Float.valueOf(pos[1]) * density); - - // Calculate desired size for subkey display, # of rows/cols, etc. - int kbWidth = getWidth(); - float pvWidth, pvHeight; - - float margin = getResources().getDimension(R.dimen.popup_margin); - int padding = getResources().getDimensionPixelSize(R.dimen.popup_padding); - int rows, columns; - float buttonWidth = getResources().getDimension(R.dimen.key_width); - float buttonHeight = getResources().getDimension(R.dimen.key_height); - float arrowWidth = getResources().getDimension(R.dimen.popup_arrow_width); - float arrowHeight = getResources().getDimension(R.dimen.popup_arrow_height); - float offset_y = getResources().getDimension(R.dimen.popup_offset_y); - - //int orientation = getResources().getConfiguration().orientation; - //columns = (orientation == Configuration.ORIENTATION_PORTRAIT)?6:10; - columns = (int) ((getWidth() - margin) / (buttonWidth + margin)); - int subKeysCount = subKeysList.size(); - if (subKeysCount <= columns) { - rows = 1; - pvWidth = (subKeysCount * (buttonWidth + padding)) + 2 * margin + padding; - pvHeight = (buttonHeight + padding) + 2 * margin + padding + arrowHeight; - } else { - rows = (subKeysCount / columns); - if (subKeysCount % columns > 0) { - rows++; - } - - if (subKeysCount % rows == 0) { - columns = subKeysCount / rows; - } else { - int s = (columns * rows - subKeysCount) / 2; - columns -= s / (rows - 1); - } - - pvWidth = (columns * (buttonWidth + padding)) + 2 * margin + padding; - pvHeight = (rows * (buttonHeight + padding)) + 2 * margin + padding + arrowHeight; - } - - // Construct from resources. - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View contentView = inflater.inflate(R.layout.subkeys_popup_layout, null, false); - - // Configure the popover view with desired size and construct its popup "arrow." - KMPopoverView popoverView = (KMPopoverView) contentView.findViewById(R.id.kmPopoverView); - popoverView.setSize((int) pvWidth, (int) pvHeight); - popoverView.setArrowSize(arrowWidth, arrowHeight); - - float px = x - pvWidth / 2.0f; - float py = y + offset_y - pvHeight; - if (px < 0) { - px = 0; - } else if ((px + pvWidth) > kbWidth) { - px = kbWidth - pvWidth; - } - - if (px == 0) { - popoverView.setArrowPosX(x); - } else if (px == (kbWidth - pvWidth)) { - popoverView.setArrowPosX(x - px); - } else { - popoverView.setArrowPosX(pvWidth / 2.0f); - } - - popoverView.redraw(); - - // Add needed subkeys to the popup view. - GridLayout grid = (GridLayout) contentView.findViewById(R.id.grid); - grid.setColumnCount(columns); - - for (int i = 0; i < subKeysCount; i++) { - Button button = (Button) inflater.inflate(R.layout.subkey_layout, null); - button.setId(i + 1); - button.setLayoutParams(new FrameLayout.LayoutParams((int) buttonWidth, (int) buttonHeight)); - // May as well set them here, keeping them in a closure than a prone-to-change field. - // Helps keep things from totally breaking when the event handler triggering subkey menu - // generation and the menu's event handler stop talking to each other. - final ArrayList> subkeyList = subKeysList; - button.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - int index = v.getId() - 1; - String keyId = subkeyList.get(index).get("keyId"); - String keyText = getSubkeyText(keyId, subkeyList.get(index).get("keyText")); - String jsFormat = "executePopupKey('%s','%s')"; - String jsString = KMString.format(jsFormat, keyId, keyText); - loadJavascript(jsString); - } - }); - button.setClickable(false); - - // Show existing text for subkeys. If subkey text is blank, get from id - String kId = subKeysList.get(i).get("keyId"); - String kText = getSubkeyText(kId, subKeysList.get(i).get("keyText")); - String title = convertKeyText(kText); - - // Disable Android's default uppercasing transformation on buttons. - button.setTransformationMethod(null); - button.setText(title); - - if (!specialOskFont.isEmpty()) { - button.setTypeface(KMManager.getFontTypeface(context, specialOSKFontFilename(specialOskFont))); - } else { - Typeface font = KMManager.getFontTypeface(context, (oskFont != null) ? oskFontFilename() : textFontFilename()); - if (font != null) { - button.setTypeface(font); - } else { - button.setTypeface(Typeface.SANS_SERIF); - } - } - - FrameLayout frame = new FrameLayout(context); - frame.setPadding(padding, padding, 0, 0); - frame.addView(button); - grid.addView(frame); - } - - grid.setOnTouchListener(new OnTouchListener() { - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouch(View v, MotionEvent event) { - int action = event.getAction(); - int tx = (int) event.getRawX(); - int ty = (int) event.getRawY(); - - if (action == MotionEvent.ACTION_UP) { - int count = ((ViewGroup) v).getChildCount(); - for (int i = 0; i < count; i++) { - FrameLayout frame = (FrameLayout) ((ViewGroup) v).getChildAt(i); - Button button = (Button) frame.getChildAt(0); - if (button.isPressed()) { - button.performClick(); - break; - } - } - dismissSubKeysWindow(); - return true; - } else if (action == MotionEvent.ACTION_MOVE) { - int count = ((ViewGroup) v).getChildCount(); - for (int i = 0; i < count; i++) { - FrameLayout frame = (FrameLayout) ((ViewGroup) v).getChildAt(i); - Button button = (Button) frame.getChildAt(0); - int[] pos = new int[2]; - button.getLocationOnScreen(pos); - Rect rect = new Rect(); - button.getDrawingRect(rect); - rect.offset(pos[0], pos[1]); - if (rect.contains(tx, ty)) { - button.setPressed(true); - } else { - button.setPressed(false); - } - } - return true; - } else if (action == MotionEvent.ACTION_DOWN) { - // Must return true if we want the others to properly process if and when this handler - // becomes decoupled from the keyboard's touch handler. - return true; - } - return false; - } - }); - - // Now to finalize the actual window. - subKeysWindow = new PopupWindow(contentView, (int) pvWidth, (int) pvHeight, false); - subKeysWindow.setTouchable(true); - subKeysWindow.setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss() { - subKeysList = null; - subKeysWindow = null; - String jsString = "popupVisible(0)"; - loadJavascript(jsString); - } - }); - - int posX, posY; - if (keyboardType == KeyboardType.KEYBOARD_TYPE_INAPP) { - int[] kbPos = new int[2]; - KMKeyboard.this.getLocationOnScreen(kbPos); - posX = (int) px; - posY = kbPos[1] + (int) py; - } else { - int[] kbPos = new int[2]; - KMKeyboard.this.getLocationInWindow(kbPos); - posX = (int) px; - posY = kbPos[1] + (int) py; - } - - dismissHelpBubble(); - this.setShouldShowHelpBubble(false); - dismissKeyPreview(0); - //subKeysWindow.setAnimationStyle(R.style.PopupAnim); - - // And now to actually display it. - subKeysWindow.showAtLocation(KMKeyboard.this, Gravity.TOP | Gravity.LEFT, posX, posY); - String jsString = "popupVisible(1)"; - loadJavascript(jsString); - } - - // Attempt to get the subkey text. - // If the subkey popup text is empty, parse the ID - private String getSubkeyText(String keyID, String keyText) { - String text = keyText; - if (text.isEmpty()) { - if(keyID.indexOf("U_") != -1 && keyID.indexOf("+") != -1 ) { - // Chop off any appended '+____' portion of the key ID. - keyID = keyID.substring(0, keyID.indexOf("+")); - } - text = keyID.replaceAll("U_", "\\\\u"); - } - return text; - } - /** * Take a font JSON object and adjust to pass to JS * 1. Replace "source" keys for "files" keys @@ -1233,111 +979,6 @@ private JSONObject makeFontPaths(String font) { return null; } - @SuppressLint("InflateParams") - protected void showKeyPreview(Context context, int px, int py, RectF baseKeyFrame, String text) { - WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics metrics = new DisplayMetrics(); - wm.getDefaultDisplay().getMetrics(metrics); - float density = metrics.density; - - if (keyPreviewWindow != null && keyPreviewWindow.isShowing()) { - View contentView = keyPreviewWindow.getContentView(); - KMKeyPreviewView keyPreview = (KMKeyPreviewView) contentView.findViewById(R.id.kmKeyPreviewView); - TextView textView = (TextView) contentView.findViewById(R.id.textView1); - textView.setText(text); - Typeface font = KMManager.getFontTypeface(context, (oskFont != null) ? oskFontFilename() : textFontFilename()); - if (font != null) { - textView.setTypeface(font); - } else { - textView.setTypeface(Typeface.SANS_SERIF); - } - - int w = (int)getResources().getDimension(R.dimen.key_width); - int h = (int)getResources().getDimension(R.dimen.key_height); - RectF frame = keyPreview.setKeySize(w, h); - keyPreview.redraw(); - - float offset_y = getResources().getDimension(R.dimen.popup_offset_y); - int posX, posY; - if (keyboardType == KeyboardType.KEYBOARD_TYPE_INAPP) { - int[] kbPos = new int[2]; - KMKeyboard.this.getLocationOnScreen(kbPos); - posX = (int) (px * density - frame.width() / 2.0f); - posY = kbPos[1] + (int) (py * density - frame.height() + offset_y); - } else { - int[] kbPos = new int[2]; - KMKeyboard.this.getLocationInWindow(kbPos); - posX = (int) (px * density - frame.width() / 2.0f); - posY = kbPos[1] + (int) (py * density - frame.height() + offset_y); - } - - keyPreviewWindow.update(posX, posY, (int) frame.width(), (int) frame.height()); - return; - } - - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View contentView = inflater.inflate(R.layout.key_preview_layout, null, false); - KMKeyPreviewView keyPreview = (KMKeyPreviewView) contentView.findViewById(R.id.kmKeyPreviewView); - TextView textView = (TextView) contentView.findViewById(R.id.textView1); - textView.setText(text); - Typeface font = KMManager.getFontTypeface(context, (oskFont != null) ? oskFontFilename() : textFontFilename()); - if (font != null) { - textView.setTypeface(font); - } else { - textView.setTypeface(Typeface.SANS_SERIF); - } - - int w = (int)getResources().getDimension(R.dimen.key_width); - int h = (int)getResources().getDimension(R.dimen.key_height); - RectF frame = keyPreview.setKeySize(w, h); - keyPreview.redraw(); - keyPreviewWindow = new PopupWindow(contentView, (int) frame.width(), (int) frame.height(), false); - keyPreviewWindow.setTouchable(true); - keyPreviewWindow.setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss() { - keyPreviewWindow = null; - } - }); - - float offset_y = getResources().getDimension(R.dimen.popup_offset_y); - int posX, posY; - if (keyboardType == KeyboardType.KEYBOARD_TYPE_INAPP) { - int[] kbPos = new int[2]; - KMKeyboard.this.getLocationOnScreen(kbPos); - posX = (int) (px * density - frame.width() / 2.0f); - posY = kbPos[1] + (int) (py * density - frame.height() + offset_y); - } else { - int[] kbPos = new int[2]; - KMKeyboard.this.getLocationInWindow(kbPos); - posX = (int) (px * density - frame.width() / 2.0f); - posY = kbPos[1] + (int) (py * density - frame.height() + offset_y); - } - - dismissHelpBubble(); - this.setShouldShowHelpBubble(false); - //keyPreviewWindow.setAnimationStyle(R.style.KeyPreviewAnim); - if (keyPreviewWindow != null) { - keyPreviewWindow.showAtLocation(KMKeyboard.this, Gravity.TOP | Gravity.LEFT, posX, posY); - } - } - - protected void dismissKeyPreview(long delay) { - // dismiss after delay - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - try { - if (keyPreviewWindow != null && keyPreviewWindow.isShowing()) - keyPreviewWindow.dismiss(); - } catch (Exception e) { - KMLog.LogException(TAG, "", e); - } - } - }, delay); - } - protected void showHelpBubble() { if(keyboardType == KeyboardType.KEYBOARD_TYPE_SYSTEM) { return; // Help bubble is disabled for System-wide keyboard diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardJSHandler.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardJSHandler.java index 2e939d15ba9..6c959b0056c 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardJSHandler.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardJSHandler.java @@ -92,10 +92,6 @@ public void run() { return; } - if (k.subKeysWindow != null) { - return; - } - if (!isInappKMTextViewValid(k.keyboardType)) { return; } @@ -204,10 +200,6 @@ public void run() { return; } - if (k.subKeysWindow != null) { - return; - } - if (!isInappKMTextViewValid(k.keyboardType)) { return; } diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardWebViewClient.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardWebViewClient.java index 7ea366f0d12..e7188a94f96 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardWebViewClient.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboardWebViewClient.java @@ -163,78 +163,6 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { // The user has begun interacting with the keyboard; we'll disable the help bubble // for the rest of the lifetime of this keyboard instance. kmKeyboard.setShouldShowHelpBubble(false); - } else if (url.indexOf("showKeyPreview") >= 0) { - String deviceType = context.getResources().getString(R.string.device_type); - if (deviceType.equals("AndroidTablet")) { - return false; - } - - if (kmKeyboard.subKeysWindow != null) { - return false; - } - - int start = url.indexOf("x=") + 2; - int end = url.indexOf("+y="); - float x = Float.valueOf(url.substring(start, end)); - - start = url.indexOf("y=") + 2; - end = url.indexOf("+w="); - float y = Float.valueOf(url.substring(start, end)); - - start = url.indexOf("w=") + 2; - end = url.indexOf("+h="); - float w = Float.valueOf(url.substring(start, end)); - - start = url.indexOf("h=") + 2; - end = url.indexOf("+t="); - float h = Float.valueOf(url.substring(start, end)); - - start = url.indexOf("t=") + 2; - String t = url.substring(start); - String text = kmKeyboard.convertKeyText(t); - - float left = x - w / 2.0f; - float right = left + w; - float top = y - 1; - float bottom = top + h; - - RectF keyFrame = new RectF(left, top, right, bottom); - kmKeyboard.showKeyPreview(context, (int) x, (int) y, keyFrame, text); - } else if (url.indexOf("dismissKeyPreview") >= 0) { - kmKeyboard.dismissKeyPreview(100); - } else if (url.indexOf("showMore") >= 0) { - if (kmKeyboard.subKeysWindow != null && kmKeyboard.subKeysWindow.isShowing()) { - return false; - } - - int start = url.indexOf("keyPos=") + 7; - int end = url.indexOf("+keys="); - kmKeyboard.subKeysWindowPos = url.substring(start, end).split("\\,"); - - start = end + 6; - end = url.indexOf("+font="); - if (end < 0) { - end = url.length(); - kmKeyboard.specialOskFont = ""; - } else { - kmKeyboard.specialOskFont = KMManager.KMFilename_Osk_Ttf_Font; - } - - String keys = url.substring(start, end); - - String[] keyList = keys.split("\\;"); - int klCount = keyList.length; - kmKeyboard.subKeysList = new ArrayList>(); - for (int i = 0; i < klCount; i++) { - String[] values = keyList[i].split("\\:"); - String keyId = (values.length > 0) ? values[0] : ""; - String keyText = (values.length > 1) ? values[1] : ""; - - HashMap hashMap = new HashMap(); - hashMap.put("keyId", keyId); - hashMap.put("keyText", keyText); - kmKeyboard.subKeysList.add(hashMap); - } } else if (url.indexOf("refreshBannerHeight") >= 0) { int start = url.indexOf("change=") + 7; String change = url.substring(start); diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 6777de81339..cbcb28053a1 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2153,15 +2153,6 @@ private static boolean isLocked() { * @param keyboardType KeyboardType KEYBOARD_TYPE_INAPP or KEYBOARD_TYPE_SYSTEM */ public static void handleGlobeKeyAction(Context context, boolean globeKeyDown, KeyboardType keyboardType) { - // Clear preview and subkeys - if (keyboardType == KeyboardType.KEYBOARD_TYPE_INAPP) { - InAppKeyboard.dismissKeyPreview(0); - InAppKeyboard.dismissSubKeysWindow(); - } else if (keyboardType == KeyboardType.KEYBOARD_TYPE_SYSTEM) { - SystemKeyboard.dismissKeyPreview(0); - SystemKeyboard.dismissSubKeysWindow(); - } - // Update globeKeyState if (globeKeyState != GlobeKeyState.GLOBE_KEY_STATE_LONGPRESS) { globeKeyState = globeKeyDown ? GlobeKeyState.GLOBE_KEY_STATE_DOWN : GlobeKeyState.GLOBE_KEY_STATE_UP; diff --git a/android/KMEA/app/src/main/res/layout/subkey_layout.xml b/android/KMEA/app/src/main/res/layout/subkey_layout.xml deleted file mode 100644 index 547400e3d07..00000000000 --- a/android/KMEA/app/src/main/res/layout/subkey_layout.xml +++ /dev/null @@ -1,10 +0,0 @@ - - diff --git a/android/KMEA/app/src/main/res/layout/subkeys_popup_layout.xml b/android/KMEA/app/src/main/res/layout/subkeys_popup_layout.xml deleted file mode 100644 index 4cdd7356fd3..00000000000 --- a/android/KMEA/app/src/main/res/layout/subkeys_popup_layout.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - diff --git a/android/KMEA/app/src/main/res/values/colors.xml b/android/KMEA/app/src/main/res/values/colors.xml index 86ce5e004ec..497d9ca3500 100644 --- a/android/KMEA/app/src/main/res/values/colors.xml +++ b/android/KMEA/app/src/main/res/values/colors.xml @@ -6,9 +6,5 @@ #ff282828 #ff000000 #ff282828 - - #ff838383 - #ff333333 - #ff737373