From bd2b1ecd6c9e214f3235fc6f4b59632691f6dba6 Mon Sep 17 00:00:00 2001 From: Aadin Date: Mon, 23 Nov 2026 03:44:44 +0530 Subject: [PATCH 1/2] ci: add GitHub Actions workflow to build APK --- .github/workflows/build-apk.yml | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/build-apk.yml diff --git a/.github/workflows/build-apk.yml b/.github/workflows/build-apk.yml new file mode 100644 index 000000000..701b14c41 --- /dev/null +++ b/.github/workflows/build-apk.yml @@ -0,0 +1,37 @@ +name: Build APK + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Install deps + run: | + npm install + npm install -g cordova + npm run setup + + - name: Enable MANAGE_EXTERNAL_STORAGE and build + run: | + node utils/storage_manager.mjs y + npm run build paid dev apk + + - uses: actions/upload-artifact@v4 + with: + name: acode-apk + path: platforms/android/app/build/outputs/apk/debug/app-debug.apk From 69709da55d400fea185a23e696988066019e3b98 Mon Sep 17 00:00:00 2001 From: Aadin Date: Mon, 23 Nov 2026 03:44:45 +0530 Subject: [PATCH 2/2] feat(browser): preview cursor with adjustable speed/size, trackpad area and hideable controls Adds a virtual cursor to the in-app browser preview: - Cursor toggle in the browser menu (off by default, not persisted) - Trackpad-style movement with adjustable speed and size - Cursor shapes follow CSS cursor and hover is emulated - Drawn cursor icon for the menu, eye-slash icon to hide controls --- .../android/com/foxdebug/browser/Browser.java | 602 ++++++++++++++++++ .../com/foxdebug/browser/Emulator.java | 57 ++ .../android/com/foxdebug/browser/Menu.java | 19 + .../android/com/foxdebug/system/Ui.java | 65 ++ 4 files changed, 743 insertions(+) diff --git a/src/plugins/browser/android/com/foxdebug/browser/Browser.java b/src/plugins/browser/android/com/foxdebug/browser/Browser.java index bd0d4ab93..5b0280bf0 100644 --- a/src/plugins/browser/android/com/foxdebug/browser/Browser.java +++ b/src/plugins/browser/android/com/foxdebug/browser/Browser.java @@ -49,6 +49,14 @@ import android.widget.Toast; import android.os.Handler; import android.os.Looper; +import android.app.Dialog; +import android.graphics.drawable.ColorDrawable; +import android.view.MotionEvent; +import android.view.ViewConfiguration; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.SeekBar; @@ -71,6 +79,30 @@ public class Browser extends LinearLayout { public boolean emulator = false; public boolean console = false; public boolean desktopMode = false; + // Virtual cursor overlay. Intentionally NOT persisted: it is off every + // time the browser is launched. + public boolean cursor = false; + // How far the cursor moves per unit of finger movement (trackpad speed). + // Adjusted with the "Cursor Settings" slider (continuous), saved in prefs. + public float cursorSpeed = 1.5f; + // Cursor size multiplier (1 = default size). Also set in "Cursor Settings". + public float cursorSize = 1f; + // Cursor size at 1x, in dp, independent of preview zoom / device preset. + private static final float CURSOR_BASE_DP = 12f; + private static final float SPEED_MIN = 0.2f; + private static final float SPEED_MAX = 6f; + private static final float SIZE_MIN = 0.4f; + private static final float SIZE_MAX = 2.5f; + private static final int SEEK_STEPS = 200; + + private Dialog cursorDialog; + // Native trackpad state, used for the area around/under the preview. + private float padX; + private float padY; + private float padDownX; + private float padDownY; + private long padDownTime; + private boolean padMoved; private String url = ""; private String title = "Browser"; @@ -95,6 +127,7 @@ public Browser(Context context, Ui.Theme theme, Boolean onlyConsole) { this.imageSize = Ui.dpToPixels(context, 35); this.titleHeight = Ui.dpToPixels(context, 45); this.titleTextHeight = Ui.dpToPixels(context, 35); + loadCursorPrefs(); this.init(); } @@ -220,6 +253,7 @@ public void onDownloadStart(String url, String userAgent, ); webViewContainer.setBackgroundColor(theme.get("primaryColor")); webViewContainer.addView(webView); + installTrackpad(webViewContainer); setOrientation(LinearLayout.VERTICAL); setFocusableInTouchMode(true); @@ -237,6 +271,11 @@ private void createMenu() { menu.addItem(Ui.Icons.DEVICES, "Devices", false); menu.addItem(Ui.Icons.NO_CACHE, "Disable Cache", false); menu.addItem(Ui.Icons.TERMINAL, "Console", false); + menu.addItem(Ui.Icons.CURSOR, "Cursor", false); + menu.addItem(Ui.Icons.TUNE, "Cursor Settings"); + menu.setVisible("Cursor Settings", false); + menu.addItem(Ui.Icons.DEVICES, "Preview Controls", true); + menu.setVisible("Preview Controls", false); menu.addItem(Ui.Icons.TUNE, "Set as Default"); menu.addItem(Ui.Icons.REFRESH, "Clear Default"); menu.setVisible("Set as Default", false); @@ -262,6 +301,7 @@ public void onSelect(String action, Boolean checked) { menu.setChecked("Console", false); menu.setVisible("Console", false); addView(deviceEmulator); + onEmulatorShown(); fitWebViewTo( deviceEmulator.getWidthProgress(), deviceEmulator.getHeightProgress(), @@ -270,6 +310,7 @@ public void onSelect(String action, Boolean checked) { } else { menu.setVisible("Console", true); removeView(deviceEmulator); + menu.setVisible("Preview Controls", false); fitWebViewTo(0, 0, 1); webView .getViewTreeObserver() @@ -290,6 +331,20 @@ public void onGlobalLayout() { case "Console": setConsoleVisible(checked); break; + case "Cursor": + cursor = checked; + menu.setVisible("Cursor Settings", checked); + if (!checked && cursorDialog != null) { + cursorDialog.dismiss(); + } + applyCursor(); + break; + case "Cursor Settings": + showCursorSettings(); + break; + case "Preview Controls": + setControlsVisible(checked); + break; case "Set as Default": if (deviceEmulator != null) { deviceEmulator.saveAsDefault(); @@ -334,6 +389,322 @@ public void onGlobalLayout() { ); } + private float density() { + return context.getResources().getDisplayMetrics().density; + } + + private static float clampf(float v, float lo, float hi) { + return Math.max(lo, Math.min(hi, v)); + } + + private static int toProgress(float v, float lo, float hi) { + return Math.round(((v - lo) / (hi - lo)) * SEEK_STEPS); + } + + private static float fromProgress(int p, float lo, float hi) { + return lo + ((hi - lo) * p) / (float) SEEK_STEPS; + } + + private void loadCursorPrefs() { + android.content.SharedPreferences prefs = context.getSharedPreferences( + "acode_browser", + Context.MODE_PRIVATE + ); + cursorSpeed = clampf(prefs.getFloat("cursor_speed", 1.5f), SPEED_MIN, SPEED_MAX); + cursorSize = clampf(prefs.getFloat("cursor_size", 1f), SIZE_MIN, SIZE_MAX); + } + + private void saveCursorPrefs() { + context + .getSharedPreferences("acode_browser", Context.MODE_PRIVATE) + .edit() + .putFloat("cursor_speed", cursorSpeed) + .putFloat("cursor_size", cursorSize) + .apply(); + } + + private String speedText() { + return String.format("Cursor speed: %.2fx", cursorSpeed); + } + + private String sizeText() { + return String.format("Cursor size: %.2fx", cursorSize); + } + + /** + * On-screen width (in real pixels, including the preview scale) of the page + * area. The cursor script uses it to know how many screen pixels one CSS + * pixel is, so the cursor keeps the same physical size and the same + * sensitivity on every device preset / zoom level. + */ + private float previewScreenWidth() { + int w = webView.getWidth(); + if (w <= 0 && webView.getParent() != null) { + w = ((View) webView.getParent()).getWidth(); + } + return w * webView.getScaleX(); + } + + /** Pushes the current speed/size into an already injected cursor. */ + private void pushCursorSettings(float screenWidth) { + if (!cursor) return; + webView.evaluateJavascript( + "window.__acodeCursorSet&&window.__acodeCursorSet(" + + cursorSpeed + "," + cursorSize + "," + screenWidth + "," + + (CURSOR_BASE_DP * density()) + ");", + null + ); + } + + private void moveCursorBy(float dx, float dy) { + webView.evaluateJavascript( + "window.__acodeCursorMove&&window.__acodeCursorMove(" + dx + "," + dy + ");", + null + ); + } + + private void clickCursor() { + webView.evaluateJavascript( + "window.__acodeCursorClick&&window.__acodeCursorClick();", + null + ); + } + + /** + * Makes the whole area around the preview (the empty space above/below it, + * e.g. under a desktop-sized preview) act as a trackpad: drag to move the + * cursor, quick tap to click. Touches on the page itself are handled by the + * injected script, so both behave the same. + */ + @SuppressWarnings("ClickableViewAccessibility") + private void installTrackpad(View area) { + final int slop = ViewConfiguration.get(context).getScaledTouchSlop(); + area.setOnTouchListener( + new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent e) { + if (!cursor) return false; + + switch (e.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + padX = padDownX = e.getX(); + padY = padDownY = e.getY(); + padDownTime = e.getEventTime(); + padMoved = false; + return true; + case MotionEvent.ACTION_MOVE: + float x = e.getX(); + float y = e.getY(); + if ( + !padMoved && + Math.abs(x - padDownX) + Math.abs(y - padDownY) > slop + ) { + padMoved = true; + padX = padDownX; + padY = padDownY; + } + if (padMoved) { + moveCursorBy(x - padX, y - padY); + } + padX = x; + padY = y; + return true; + case MotionEvent.ACTION_UP: + if (!padMoved && e.getEventTime() - padDownTime < 300) { + clickCursor(); + } + return true; + default: + return true; + } + } + } + ); + } + + /** Shows or hides the bottom Width/Height/Scale/device panel. */ + private void setControlsVisible(boolean visible) { + if (deviceEmulator != null) { + deviceEmulator.setVisibility(visible ? View.VISIBLE : View.GONE); + } + } + + /** Called whenever the device panel is added, so it starts out visible. */ + private void onEmulatorShown() { + setControlsVisible(true); + menu.setVisible("Preview Controls", true); + menu.setChecked("Preview Controls", true); + } + + /** + * Floating panel with live sliders for cursor speed and size. It does not + * dim or block the screen, so the cursor can be dragged around while tuning. + */ + private void showCursorSettings() { + if (cursorDialog != null && cursorDialog.isShowing()) return; + + final int pad = Ui.dpToPixels(context, 14); + final int textColor = theme.get("primaryTextColor"); + final float radius = Ui.dpToPixels(context, 14); + + LinearLayout panel = new LinearLayout(context); + panel.setOrientation(LinearLayout.VERTICAL); + panel.setPadding(pad, pad, pad, pad); + GradientDrawable background = new GradientDrawable(); + background.setColor(theme.get("primaryColor")); + background.setCornerRadii( + new float[] { radius, radius, radius, radius, 0, 0, 0, 0 } + ); + panel.setBackgroundDrawable(background); + + final TextView speedLabel = new TextView(context); + speedLabel.setTextColor(textColor); + speedLabel.setText(speedText()); + + final SeekBar speedBar = new SeekBar(context); + speedBar.setMax(SEEK_STEPS); + speedBar.setProgress(toProgress(cursorSpeed, SPEED_MIN, SPEED_MAX)); + speedBar.setOnSeekBarChangeListener( + new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) { + if (!fromUser) return; + cursorSpeed = fromProgress(progress, SPEED_MIN, SPEED_MAX); + speedLabel.setText(speedText()); + pushCursorSettings(previewScreenWidth()); + } + + @Override + public void onStartTrackingTouch(SeekBar bar) {} + + @Override + public void onStopTrackingTouch(SeekBar bar) { + saveCursorPrefs(); + } + } + ); + + final TextView sizeLabel = new TextView(context); + sizeLabel.setTextColor(textColor); + sizeLabel.setText(sizeText()); + + final SeekBar sizeBar = new SeekBar(context); + sizeBar.setMax(SEEK_STEPS); + sizeBar.setProgress(toProgress(cursorSize, SIZE_MIN, SIZE_MAX)); + sizeBar.setOnSeekBarChangeListener( + new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) { + if (!fromUser) return; + cursorSize = fromProgress(progress, SIZE_MIN, SIZE_MAX); + sizeLabel.setText(sizeText()); + pushCursorSettings(previewScreenWidth()); + } + + @Override + public void onStartTrackingTouch(SeekBar bar) {} + + @Override + public void onStopTrackingTouch(SeekBar bar) { + saveCursorPrefs(); + } + } + ); + + LinearLayout buttons = new LinearLayout(context); + buttons.setOrientation(LinearLayout.HORIZONTAL); + buttons.setGravity(Gravity.END); + + Button reset = new Button(context); + reset.setText("Reset"); + Button done = new Button(context); + done.setText("Done"); + buttons.addView(reset); + buttons.addView(done); + + panel.addView(speedLabel); + panel.addView(speedBar); + panel.addView(sizeLabel); + panel.addView(sizeBar); + panel.addView(buttons); + + final Dialog dialog = new Dialog(context); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setContentView(panel); + + reset.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + cursorSpeed = 1.5f; + cursorSize = 1f; + speedBar.setProgress(toProgress(cursorSpeed, SPEED_MIN, SPEED_MAX)); + sizeBar.setProgress(toProgress(cursorSize, SIZE_MIN, SIZE_MAX)); + speedLabel.setText(speedText()); + sizeLabel.setText(sizeText()); + pushCursorSettings(previewScreenWidth()); + saveCursorPrefs(); + } + } + ); + + done.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + } + } + ); + + dialog.setOnDismissListener( + new android.content.DialogInterface.OnDismissListener() { + @Override + public void onDismiss(android.content.DialogInterface d) { + saveCursorPrefs(); + cursorDialog = null; + } + } + ); + + Window window = dialog.getWindow(); + if (window != null) { + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); + // Let touches outside the panel through so the cursor can be moved + // while the sliders are open. + window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); + window.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ); + window.setGravity(Gravity.BOTTOM); + } + + cursorDialog = dialog; + dialog.show(); + } + + /** + * Shows or hides a virtual cursor (arrow) inside the page, driven like a + * trackpad. Safe to call repeatedly; any previous cursor is removed first + * (its position is kept). Called when the menu toggle or speed changes and + * after every page load, because navigating wipes the injected overlay. + */ + public void applyCursor() { + // The injected script lives in CursorScript (bottom of this file). + webView.evaluateJavascript( + CursorScript.build( + cursor, + cursorSpeed, + cursorSize, + previewScreenWidth(), + CURSOR_BASE_DP * density() + ), + null + ); + } + private void updateDefaultItems(boolean emulatorOn) { menu.setVisible("Set as Default", emulatorOn); menu.setVisible( @@ -396,6 +767,7 @@ public void run() { menu.setChecked("Console", false); menu.setVisible("Console", false); addView(deviceEmulator); + onEmulatorShown(); // The emulator sets up its sliders on a later layout pass and then // applies the saved size itself, so the webview is not resized here. } @@ -407,6 +779,15 @@ private void createDeviceEmulatorLayout() { Browser browser = this; deviceEmulator = new Emulator(context, theme); deviceEmulator.setReference(webView); + deviceEmulator.setHideListener( + new Runnable() { + @Override + public void run() { + setControlsVisible(false); + menu.setChecked("Preview Controls", false); + } + } + ); deviceEmulator.setChangeListener( new Emulator.Callback() { @Override @@ -530,6 +911,13 @@ private void fitWebViewTo(int width, int height, float scale) { if (width > 0 && height > 0) { updateViewportDimension(width, height); } + + if (cursor && webView.getParent() != null) { + int shownWidth = width == 0 + ? ((View) webView.getParent()).getWidth() + : width; + pushCursorSettings(shownWidth * scale); + } } private void styleIcon(ImageView view) { @@ -697,6 +1085,215 @@ public void exit() { } } +/** + * JavaScript injected into the page while the "Cursor" menu toggle is on. + * + * Behaviour: + * - A virtual mouse cursor (the Acode arrow) is drawn over the page. Its + * shape follows the CSS `cursor` of whatever is under it (pointer hand, + * text I-beam, grab, not-allowed, resize arrows, ...). + * - Dragging a finger moves the cursor like a trackpad, multiplied by SPEED. + * - A quick tap clicks at the cursor. + * - Hover is emulated: mouseover/mouseenter/mousemove events are fired and + * :hover rules from same-origin stylesheets are mirrored onto a helper + * class, so hover effects and hover-dependent cursors work. + * - Normal one-finger touch, scrolling and taps on the page are blocked, but + * two-finger pinch zoom is still allowed. + */ +class CursorScript { + + static String build( + boolean on, + float speed, + float size, + float screenW, + float basePx + ) { + String[] js = { + "(function(on,SPEED,SIZE,SW,BASE){", + "if(window.__acodeCursorCleanup){window.__acodeCursorCleanup();window.__acodeCursorCleanup=null;}", + "if(!on)return;", + "var root=document.documentElement;if(!root)return;", + "var NS='http://www.w3.org/2000/svg';", + "var HV='__acode_hv';", + "var cur='',hot=[0,0],hv=null,gesture=false;", + // live config: speed, size multiplier, on-screen px width of the page, base cursor px + "var cfg={speed:SPEED,size:SIZE,sw:SW,base:BASE};", + "var t0=0,sx=0,sy=0,lx=0,ly=0,moved=false,active=false;", + // visible area, so the cursor also behaves while pinch-zoomed + "function bounds(){var v=window.visualViewport;", + "if(v)return{x0:v.offsetLeft,y0:v.offsetTop,x1:v.offsetLeft+v.width,y1:v.offsetTop+v.height,s:v.scale||1};", + "return{x0:0,y0:0,x1:window.innerWidth,y1:window.innerHeight,s:1};}", + // copy every :hover rule to a helper class we can toggle ourselves + "function rulesToCss(rules){var out='';", + "for(var i=0;i-1){", + "out+=r.selectorText.replace(/:hover/g,'.'+HV)+'{'+r.style.cssText+'}';}}", + "else if(r.cssRules&&(r.type===4||r.type===12)){", + "var inner=rulesToCss(r.cssRules);", + "if(inner){out+=(r.type===4?'@media '+r.media.mediaText:'@supports '+r.conditionText)+'{'+inner+'}';}}", + "}catch(err){}}", + "return out;}", + "function hoverCss(){var css='';", + "for(var i=0;i shape + "var MAP={pointer:'hand',grab:'grab',grabbing:'grabbing',text:'text','vertical-text':'text',crosshair:'cross',cell:'cross',wait:'wait',progress:'wait','not-allowed':'no','no-drop':'no',move:'move','all-scroll':'move',help:'help','ew-resize':'ew','col-resize':'ew','e-resize':'ew','w-resize':'ew','ns-resize':'ns','row-resize':'ns','n-resize':'ns','s-resize':'ns','nesw-resize':'nesw','ne-resize':'nesw','sw-resize':'nesw','nwse-resize':'nwse','nw-resize':'nwse','se-resize':'nwse'};", + "function mk(tag,attrs){var e=document.createElementNS(NS,tag);for(var k in attrs)e.setAttribute(k,attrs[k]);return e;}", + "function build(shape){", + "var svg=mk('svg',{width:24,height:24,viewBox:'0 0 24 24'});", + "svg.style.cssText='position:absolute;left:0;top:0;overflow:visible;';", + "var g=mk('g',shape.g?{transform:shape.g}:{});svg.appendChild(g);", + "for(var pass=0;pass<2;pass++){", + "for(var i=0;i0&&w>0)?cfg.sw/w:1;}", + "function M(){return (cfg.base*cfg.size)/(24*K());}", + "function draw(){window.__acodeCursorPos=[cx,cy];var m=M();", + "c.style.transform='translate('+(cx-hot[0]*m)+'px,'+(cy-hot[1]*m)+'px) scale('+m+')';}", + "function nudge(dx,dy){var b=bounds();", + "cx=Math.max(b.x0,Math.min(b.x1-1,cx+dx));", + "cy=Math.max(b.y0,Math.min(b.y1-1,cy+dy));draw();}", + "function setShape(k){if(k===cur)return;cur=k;", + "while(c.firstChild)c.removeChild(c.firstChild);", + "if(k==='none'){c.style.visibility='hidden';return;}", + "c.style.visibility='visible';", + "var s=SHAPES[k]||SHAPES.arrow;hot=[s.hx,s.hy];c.appendChild(build(s));draw();}", + // which shape does the page want here? + "function isText(el){var n=el.nodeName;if(n==='TEXTAREA')return true;", + "if(n==='INPUT'){var t=(el.type||'text').toLowerCase();", + "return ['button','submit','reset','checkbox','radio','range','color','file','image'].indexOf(t)<0;}", + "return !!el.isContentEditable;}", + "function kindOf(el){if(!el)return 'arrow';var v='auto';", + "try{v=getComputedStyle(el).cursor||'auto';}catch(err){}", + "var m=v.match(/([a-z-]+)\\s*$/);v=m?m[1]:'auto';", + "if(v==='none')return 'none';", + "if(v==='auto')return isText(el)?'text':'arrow';", + "return MAP[v]||'arrow';}", + // synthetic mouse events + "function fire(el,type,bub){", + "var o={bubbles:!!bub,cancelable:true,view:window,clientX:cx,clientY:cy,button:0,", + "buttons:(type==='mousedown'||type==='pointerdown')?1:0};", + "try{if(type.indexOf('pointer')===0&&window.PointerEvent){o.pointerType='mouse';o.isPrimary=true;el.dispatchEvent(new PointerEvent(type,o));}", + "else el.dispatchEvent(new MouseEvent(type,o));}catch(err){}}", + "function hover(moved){var el=document.elementFromPoint(cx,cy);", + "if(el!==hv){", + "if(hv){fire(hv,'pointerout',1);fire(hv,'mouseout',1);fire(hv,'pointerleave',0);fire(hv,'mouseleave',0);}", + "for(var n=hv;n;n=n.parentElement)if(n.classList)n.classList.remove(HV);", + "for(var m=el;m;m=m.parentElement)if(m.classList)m.classList.add(HV);", + "hv=el;", + "if(el){fire(el,'pointerover',1);fire(el,'mouseover',1);fire(el,'pointerenter',0);fire(el,'mouseenter',0);}}", + "if(moved&&el){fire(el,'pointermove',1);fire(el,'mousemove',1);}", + "setShape(kindOf(el));}", + "function clickAtCursor(){hover(false);var el=hv;if(!el)return;", + "['pointerdown','mousedown','pointerup','mouseup','click'].forEach(function(n){fire(el,n,1);});", + "if(el.focus){try{el.focus();}catch(err){}}}", + // touch handling: one finger drives the cursor, two fingers are left to the browser (pinch zoom) + "function onTS(e){if(e.touches.length>1){gesture=true;return;}", + "var t=e.touches[0];if(!t)return;", + "gesture=false;active=true;moved=false;t0=Date.now();sx=lx=t.clientX;sy=ly=t.clientY;}", + "function onTM(e){if(gesture||e.touches.length>1){gesture=true;return;}", + "var t=e.touches[0];if(!t)return;", + "if(!moved&&Math.abs(t.clientX-sx)+Math.abs(t.clientY-sy)>10){moved=true;lx=sx;ly=sy;}", + "if(moved){nudge((t.clientX-lx)*cfg.speed,(t.clientY-ly)*cfg.speed);hover(true);}", + "lx=t.clientX;ly=t.clientY;}", + "function onTE(e){if(e.touches.length>0)return;", + "if(active&&!moved&&!gesture&&Date.now()-t0<300)clickAtCursor();", + "active=false;gesture=false;}", + // keep every real (trusted) input event away from the page's own handlers + "var types=['touchstart','touchmove','touchend','touchcancel','pointerdown','pointermove',", + "'pointerup','pointercancel','mousedown','mousemove','mouseup','click','dblclick',", + "'contextmenu','wheel'];", + "var o={capture:true,passive:false};", + "function block(e){if(!e.isTrusted)return;var ty=e.type;", + "if(ty==='touchstart')onTS(e);", + "else if(ty==='touchmove')onTM(e);", + "else if(ty==='touchend')onTE(e);", + "else if(ty==='touchcancel'){active=false;gesture=false;}", + "if(ty.indexOf('touch')!==0&&e.cancelable)e.preventDefault();", + "e.stopImmediatePropagation();}", + "types.forEach(function(t){window.addEventListener(t,block,o);});", + "var vv=window.visualViewport;", + "function vp(){nudge(0,0);}", + "if(vv){vv.addEventListener('resize',vp);vv.addEventListener('scroll',vp);}", + // layout can change under a resting cursor (after a click, animations) + "var iv=setInterval(function(){hover(false);draw();},250);", + // hooks called from Java: native trackpad (area outside the page) and settings sliders + "window.__acodeCursorMove=function(dx,dy){var f=cfg.speed/K();nudge(dx*f,dy*f);hover(true);};", + "window.__acodeCursorClick=function(){clickAtCursor();};", + "window.__acodeCursorSet=function(sp,sz,sw,bs){cfg.speed=sp;cfg.size=sz;cfg.sw=sw;cfg.base=bs;draw();};", + "window.__acodeCursorCleanup=function(){", + "window.__acodeCursorMove=null;window.__acodeCursorClick=null;window.__acodeCursorSet=null;", + "clearInterval(iv);", + "types.forEach(function(t){window.removeEventListener(t,block,o);});", + "if(vv){vv.removeEventListener('resize',vp);vv.removeEventListener('scroll',vp);}", + "for(var n=hv;n;n=n.parentElement)if(n.classList)n.classList.remove(HV);", + "if(c.parentNode)c.parentNode.removeChild(c);", + "if(st.parentNode)st.parentNode.removeChild(st);};", + "setShape('arrow');hover(false);", + "})", + }; + + StringBuilder sb = new StringBuilder(); + for (String line : js) { + sb.append(line).append('\n'); + } + sb + .append('(') + .append(on) + .append(',') + .append(speed) + .append(',') + .append(size) + .append(',') + .append(screenW) + .append(',') + .append(basePx) + .append(");"); + return sb.toString(); + } +} + class BrowserChromeClient extends WebChromeClient { Browser browser; @@ -784,6 +1381,11 @@ public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); browser.setProgressBarVisible(false); + // Navigation wipes injected overlays, so re-apply the cursor if enabled. + if (browser.cursor) { + browser.applyCursor(); + } + // Inject console for external sites // this is not a good solution but for now its good, later we'll improve this if (!url.startsWith("http://localhost")) { diff --git a/src/plugins/browser/android/com/foxdebug/browser/Emulator.java b/src/plugins/browser/android/com/foxdebug/browser/Emulator.java index 25f0d70ea..38d3d6cee 100644 --- a/src/plugins/browser/android/com/foxdebug/browser/Emulator.java +++ b/src/plugins/browser/android/com/foxdebug/browser/Emulator.java @@ -3,6 +3,7 @@ import android.content.Context; import android.graphics.Typeface; import android.util.Log; +import android.view.Gravity; import android.view.View; import android.view.ViewTreeObserver; import android.widget.ImageView; @@ -22,6 +23,7 @@ public class Emulator extends LinearLayout { private View reference; private Context context; private Callback listener; + private Runnable hideListener; private Device customDevice; private Device selectedDevice; private boolean initialized = false; @@ -115,11 +117,66 @@ public void onSelect(Device device) { addControl("width", 50, "Width"); addControl("height", 50, "Height"); addControl("scale", 50, "Scale"); + // Thin tappable handle on top of the panel that hides the whole panel. + LinearLayout handle = new LinearLayout(context); + handle.setOrientation(LinearLayout.HORIZONTAL); + handle.setGravity(Gravity.CENTER_VERTICAL | Gravity.START); + handle.setPadding( + Ui.dpToPixels(context, 12), + 0, + Ui.dpToPixels(context, 12), + 0 + ); + handle.setBackgroundColor(theme.get("primaryColor")); + handle.setClickable(true); + + ImageView hideIcon = new ImageView(context); + hideIcon.setImageBitmap( + Ui.Icons.get(context, Ui.Icons.VISIBILITY_OFF, theme.get("primaryTextColor")) + ); + hideIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); + hideIcon.setLayoutParams( + new LinearLayout.LayoutParams( + Ui.dpToPixels(context, 18), + Ui.dpToPixels(context, 18) + ) + ); + + TextView hideLabel = new TextView(context); + hideLabel.setText("Hide controls"); + hideLabel.setTextSize(12); + hideLabel.setTextColor(theme.get("primaryTextColor")); + hideLabel.setPadding(Ui.dpToPixels(context, 8), 0, 0, 0); + + handle.addView(hideIcon); + handle.addView(hideLabel); + handle.setLayoutParams( + new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + Ui.dpToPixels(context, 28) + ) + ); + handle.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + if (hideListener != null) { + hideListener.run(); + } + } + } + ); + + addView(handle); addView(border); addView(main); setOrientation(LinearLayout.VERTICAL); } + public void setHideListener(Runnable listener) { + this.hideListener = listener; + } + public void setChangeListener(Callback listener) { this.listener = listener; } diff --git a/src/plugins/browser/android/com/foxdebug/browser/Menu.java b/src/plugins/browser/android/com/foxdebug/browser/Menu.java index 8b5bbb544..4a9fdb224 100644 --- a/src/plugins/browser/android/com/foxdebug/browser/Menu.java +++ b/src/plugins/browser/android/com/foxdebug/browser/Menu.java @@ -114,6 +114,17 @@ public void setChecked(String action, Boolean checked) { } } + /** Changes the visible label of an item without changing its action id. */ + public void setLabel(String action, String text) { + for (int i = 0; i < list.getChildCount(); i++) { + MenuItem menuItem = (MenuItem) list.getChildAt(i); + if (menuItem.action.equals(action)) { + menuItem.setLabel(text); + break; + } + } + } + public void setVisible(String action, Boolean visible) { for (int i = 0; i < list.getChildCount(); i++) { MenuItem menuItem = (MenuItem) list.getChildAt(i); @@ -214,6 +225,14 @@ public void setText(String text, int color) { addView(textView, 1); } + public void setLabel(String text) { + // Children are laid out as [icon, label, ...], see Menu.addItem(). + View label = getChildAt(1); + if (label instanceof TextView) { + ((TextView) label).setText(text); + } + } + public void setChecked(boolean checked) { this.checked = checked; if (checkBox != null) { diff --git a/src/plugins/system/android/com/foxdebug/system/Ui.java b/src/plugins/system/android/com/foxdebug/system/Ui.java index 4cdf19c63..ec3a73d1f 100644 --- a/src/plugins/system/android/com/foxdebug/system/Ui.java +++ b/src/plugins/system/android/com/foxdebug/system/Ui.java @@ -5,6 +5,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Path; import android.graphics.Typeface; import android.util.Log; import android.util.TypedValue; @@ -32,6 +33,14 @@ public static class Icons { public static final String LAPTOP = "\uE90D"; public static final String TV = "\uE929"; + // Not a glyph in icon.ttf: this code is intercepted in get() and the + // cursor arrow is drawn directly with a Canvas instead. + public static final String CURSOR = "\uF8FF"; + + // Also not a glyph in icon.ttf: drawn with a Canvas in get() (eye with a + // slash, like a "hide password" icon). + public static final String VISIBILITY_OFF = "\uF8FE"; + private static Paint paint; private static int size = 24; private static int color = Color.parseColor("#FFFFFF"); @@ -43,6 +52,14 @@ public static Bitmap get( int size, int color ) { + if (CURSOR.equals(code)) { + return drawCursor(color); + } + + if (VISIBILITY_OFF.equals(code)) { + return drawEyeOff(color); + } + if (paint == null) { paint = new Paint(); paint.setAntiAlias(true); @@ -69,6 +86,54 @@ public static Bitmap get( return bitmap; } + /** Draws an eye with a slash through it (like a "hide password" icon). */ + private static Bitmap drawEyeOff(int color) { + int px = 96; + Bitmap bitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); + p.setColor(color); + p.setStyle(Paint.Style.STROKE); + p.setStrokeWidth(7f); + p.setStrokeCap(Paint.Cap.ROUND); + p.setStrokeJoin(Paint.Join.ROUND); + + Path eye = new Path(); + eye.moveTo(8f, 48f); + eye.quadTo(48f, 4f, 88f, 48f); + eye.quadTo(48f, 92f, 8f, 48f); + canvas.drawPath(eye, p); + canvas.drawCircle(48f, 48f, 14f, p); + canvas.drawLine(18f, 14f, 78f, 82f, p); + return bitmap; + } + + /** Draws the cursor arrow (same shape as the in-page cursor). */ + private static Bitmap drawCursor(int color) { + int px = 96; + // The arrow outline is 357 x 475 units; fit it into the bitmap. + float s = (px * 0.9f) / 475f; + float ox = (px - 357f * s) / 2f; + float oy = (px - 475f * s) / 2f; + + Bitmap bitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); + p.setColor(color); + p.setStyle(Paint.Style.FILL_AND_STROKE); + p.setStrokeJoin(Paint.Join.ROUND); + p.setStrokeWidth(30f * s); + + Path path = new Path(); + path.moveTo(ox, oy); + path.lineTo(ox + 357f * s, oy + 335f * s); + path.lineTo(ox + 152f * s, oy + 345f * s); + path.lineTo(ox, oy + 475f * s); + path.close(); + canvas.drawPath(path, p); + return bitmap; + } + public static Bitmap get( Context context, String code,