8000 12 29 by chrisws · Pull Request #244 · smallbasic/SmallBASIC · GitHub
[go: up one dir, main page]

Skip to content

12 29 #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jun 26, 2025
Merged

12 29 #244

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e1dab04
ANDROID: update USB api to allow setting baud rate and timeout
chrisws Mar 30, 2025
82c463c
ANDROID: experimental bluetooth support
chrisws Apr 5, 2025
1f9b998
ANDROID: fixed some intellij inspection issues
chrisws Apr 14, 2025
c7c3566
Removes IOIO-OTG support for now
chrisws Apr 14, 2025
2907bde
TEENSY: serial receive now takes buffer size arg
chrisws Apr 14, 2025
75438c3
TEENSY: update demo
chrisws Apr 14, 2025
a0b0784
ANDROID: update sound sample
chrisws Apr 19, 2025
e8e768e
COMMON: bump version
chrisws Apr 19, 2025
ac35055
ANDROID: update file UI dependencies
chrisws Apr 19, 2025
d978842
ANDROID: allow android.speak to take addtional non-string args
chrisws Apr 19, 2025
6c38f2b
ANDROID: update SOUND implementation to avoid skips
chrisws Apr 19, 2025
aad80fc
ANDROID: update SOUND implementation to avoid skips
chrisws Apr 19, 2025
cec6cb7
ANDROID: minor fix for PEN(3)
chrisws Apr 26, 2025
2c26e10
Merge branch 'smallbasic:master' into 12_29
chrisws May 3, 2025
fedfbcc
SDL: upgrade to SDL v 3.x
chrisws May 5, 2025
6d2bf2d
ANDROID: update bluetooth permissions for older android versions #242
chrisws May 6, 2025
c42cba8
ANDROID: updated file selection handling for new MUI grid version
chrisws May 6, 2025
9c9ae77
ANDROID: update bluetooth handling for older android devices
chrisws May 10, 2025
ad5a33b
COMMON: fix issue with space char before import 'c-module'
chrisws May 17, 2025
e46505d
ANDROID: implemented find command
chrisws May 18, 2025
ac23ca3
UI: update help display
chrisws May 24, 2025
77c221f
UI: update help display
chrisws May 24, 2025
bed7c3d
UI: update help display
chrisws May 24, 2025
740decc
UI: experimental keypad to replace android keypad
chrisws May 27, 2025
8955be7
UI: experimental keypad to replace android keypad
chrisws May 28, 2025
99742e9
UI: experimental keypad to replace android keypad
chrisws May 29, 2025
fb6b2c3
UI: experimental keypad to replace android keypad
chrisws Jun 5, 2025
02364ef
COMMON: resolved some compiler warnings
chrisws Jun 6, 2025
bd05aac
COMMON: update dependencies
chrisws Jun 6, 2025
230060f
SDL: added cmake build scripts for use with clion (free version)
chrisws Jun 7, 2025
1c22dfa
UI: experimental keypad to replace android keypad
chrisws Jun 7, 2025
2709c3f
UI: experimental keypad to replace android keypad
chrisws Jun 8, 2025
8c6752f
UI: experimental keypad to replace android keypad
chrisws Jun 11, 2025
da9d224
UI: experimental keypad to replace android keypad
chrisws Jun 13, 2025
05e366d
UI: experimental keypad to replace android keypad
chrisws Jun 14, 2025
6094d3a
UI: experimental keypad to replace android keypad
chrisws Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ANDROID: implemented find command
  • Loading branch information
chrisws committed May 18, 2025
commit e46505da9b4209056b9ee9ae4fd77d98759390c2
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package net.sourceforge.smallbasic;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

class FindBar {
private LinearLayout findBar;
private EditText findInput;
private Button findNext, findPrev, findClose;

public FindBar(Activity activity) {
FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();

// Create find bar layout
findBar = new LinearLayout(activity);
findBar.setOrientation(LinearLayout.HORIZONTAL);
findBar.setBackgroundColor(0xFFEEEEEE);
findBar.setPadding(8, 8, 8, 8);
findBar.setVisibility(View.GONE);

// Create EditText
findInput = new EditText(activity);
LinearLayout.LayoutParams lpInput = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
findInput.setLayoutParams(lpInput);
findInput.setHint("Find...");
findBar.addView(findInput);

// Create buttons
findPrev = new Button(activity);
findPrev.setText("↑");
findBar.addView(findPrev);

findNext = new Button(activity);
findNext.setText("↓");
findBar.addView(findNext);

findClose = new Button(activity);
findClose.setText("✕");
findBar.addView(findClose);

// Add find bar to decor view
FrameLayout.LayoutParams lp =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);
decor.addView(findBar, lp);

// Hook up buttons
findNext.setOnClickListener(v -> {
String query = findInput.getText().toString();
// TODO: call native method or Java function to highlight next
});

findPrev.setOnClickListener(v -> {
String query = findInput.getText().toString();
// TODO: call native method or Java function to highlight previous
});

findClose.setOnClickListener(v -> {
findBar.setVisibility(View.GONE);
//hideKeyboard(findInput);
});
}

// To show the find bar
public void show() {
findBar.setVisibility(View.VISIBLE);
findInput.requestFocus();
}
}
1 change: 1 addition & 0 deletions src/platform/android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ LOCAL_SRC_FILES := main.cpp \
runtime.cpp \
audio.cpp \
module.cpp \
editor.cpp \
../../../ui/screen.cpp \
../../../ui/ansiwidget.cpp \
../../../ui/window.cpp \
Expand Down
236 changes: 236 additions & 0 deletions src/platform/android/jni/editor.cpp
6D40
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
// This file is part of SmallBASIC
//
// Copyright(C) 2001-2025 Chris Warren-Smith.
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//

#include "config.h"

#include "ui/textedit.h"
#include "platform/android/jni/runtime.h"
#include "common/device.h"

extern Runtime *runtime;

void showHelpLineInput(TextEditHelpWidget *helpWidget, int width = 35) {
helpWidget->showPopup(width, 1);
}

void System::editSource(strlib::String loadPath, bool restoreOnExit) {
logEntered();

strlib::String fileName;
int i = loadPath.lastIndexOf('/', 0);
if (i != -1) {
fileName = loadPath.substring(i + 1);
} else {
fileName = loadPath;
}

strlib::String dirtyFile;
dirtyFile.append(" * ");
dirtyFile.append(fileName);
strlib::String cleanFile;
cleanFile.append(" - ");
cleanFile.append(fileName);

int w = _output->getWidth();
int h = _output->getHeight();
int charWidth = _output->getCharWidth();
int charHeight = _output->getCharHeight();
int prevScreenId = _output->selectScreen(SOURCE_SCREEN);
TextEditInput *editWidget;
if (_editor != nullptr) {
editWidget = _editor;
editWidget->_width = w;
editWidget->_height = h;
} else {
editWidget = new TextEditInput(_programSrc, charWidth, charHeight, 0, 0, w, h);
}
auto *helpWidget = new TextEditHelpWidget(editWidget, charWidth, charHeight, false);
auto *widget = editWidget;
_modifiedTime = getModifiedTime();
editWidget->updateUI(nullptr, nullptr);
editWidget->setLineNumbers();
editWidget->setFocus(true);

_output->clearScreen();
_output->addInput(editWidget);
_output->addInput(helpWidget);

if (gsb_last_line && isBreak()) {
String msg = "Break at line: ";
msg.append(gsb_last_line);
runtime->alert(msg);
} else if (gsb_last_error && !isBack()) {
// program stopped with an error
editWidget->setCursorRow(gsb_last_line + editWidget->getSelectionRow() - 1);
runtime->alert(gsb_last_errmsg);
}

bool showStatus = !editWidget->getScroll();
_srcRendered = false;
_output->setStatus(showStatus ? cleanFile : "");
_output->redraw();
_state = kEditState;
runtime->showKeypad(true);

while (_state == kEditState) {
MAEvent event = getNextEvent();
switch (event.type) {
case EVENT_TYPE_POINTER_PRESSED:
if (!showStatus && widget == editWidget && event.point.x < editWidget->getMarginWidth()) {
_output->setStatus(editWidget->isDirty() ? dirtyFile : cleanFile);
_output->redraw();
showStatus = true;
} else if (widget == helpWidget && helpWidget->searchMode()) {
// end searching
widget = editWidget;
helpWidget->hide();
helpWidget->cancelMode();
}
break;
case EVENT_TYPE_POINTER_RELEASED:
if (showStatus && event.point.x < editWidget->getMarginWidth() && editWidget->getScroll()) {
_output->setStatus("");
_output->redraw();
showStatus = false;
}
break;
case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
if (editWidget->isDirty() && !editWidget->getScroll()) {
_output->setStatus(dirtyFile);
_output->redraw();
}
break;
case EVENT_TYPE_KEY_PRESSED:
if (_userScreenId == -1) {
dev_clrkb();
int sw = _output->getScreenWidth();
bool redraw = true;
bool dirty = editWidget->isDirty();
char *text;

switch (event.key) {
case SB_KEY_F(2):
case SB_KEY_F(3):
case SB_KEY_F(4):
case SB_KEY_F(5):
case SB_KEY_F(6):
case SB_KEY_F(7):
case SB_KEY_F(8):
case SB_KEY_F(10):
case SB_KEY_F(11):
case SB_KEY_F(12):
case SB_KEY_MENU:
case SB_KEY_ESCAPE:
case SB_KEY_BREAK:
// unhandled keys
redraw = false;
break;
case SB_KEY_F(1):
widget = helpWidget;
helpWidget->createKeywordIndex();
helpWidget->showPopup(-4, -2);
helpWidget->setFocus(true);
runtime->showKeypad(false);
showStatus = false;
break;
case SB_KEY_F(9):
_state = kRunState;
if (editWidget->isDirty()) {
saveFile(editWidget, loadPath);
}
break;
case SB_KEY_CTRL('f'):
widget = helpWidget;
helpWidget->createSearch(false);
showHelpLineInput(helpWidget);
break;
case SB_KEY_CTRL('s'):
saveFile(editWidget, loadPath);
break;
case SB_KEY_CTRL('c'):
case SB_KEY_CTRL('x'):
text = widget->copy(event.key == (int)SB_KEY_CTRL('x'));
if (text) {
setClipboardText(text);
free(text);
}
break;
case SB_KEY_CTRL('v'):
text = getClipboardText();
widget->paste(text);
free(text);
break;
case SB_KEY_CTRL('o'):
_output->selectScreen(USER_SCREEN1);
showCompletion(true);
_output->redraw();
_state = kActiveState;
waitForBack();
runtime->showKeypad(true);
_output->selectScreen(SOURCE_SCREEN);
_state = kEditState;
break;
default:
redraw = widget->edit(event.key, sw, charWidth);
break;
}
if (editWidget->isDirty() != dirty && !editWidget->getScroll()) {
_output->setStatus(editWidget->isDirty() ? dirtyFile : cleanFile);
}
if (redraw) {
_output->redraw();
}
}
}

if (isBack() && widget == helpWidget) {
runtime->showKeypad(true);
widget = editWidget;
helpWidget->hide();
editWidget->setFocus(true);
_state = kEditState;
_output->redraw();
}

if (widget->isDirty()) {
int choice = -1;
if (isClosing()) {
choice = 0;
} else if (isBack()) {
const char *message = "The current file has not been saved.\n"
"Would you like to save it now?";
choice = ask("Save changes?", message, isBack());
}
if (choice == 0) {
widget->save(loadPath);
} else if (choice == 2) {
// cancel
_state = kEditState;
}
}
}

if (_state == kRunState) {
// allow the editor to be restored on return
if (!_output->removeInput(editWidget)) {
trace("Failed to remove editor input");
}
runtime->showKeypad(false);
_editor = editWidget;
_editor->setFocus(false);
} else {
_editor = nullptr;
}

// deletes editWidget unless it has been removed
_output->removeInputs();
if (!isClosing() && restoreOnExit) {
_output->selectScreen(prevScreenId);
}
logLeaving();
}
Loading
0