Skip to content

Commit 7f9759a

Browse files
committed
ANDROID: fix POINT
1 parent d48421c commit 7f9759a

File tree

10 files changed

+66
-14
lines changed

10 files changed

+66
-14
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [0.12.4])
10+
AC_INIT([smallbasic], [0.12.5])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

ide/android/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="net.sourceforge.smallbasic"
44
android:installLocation="preferExternal"
5-
android:versionCode="18"
6-
android:versionName="0.12.4">
5+
android:versionCode="19"
6+
android:versionName="0.12.5">
77
<!-- This is the platform API where NativeActivity was introduced. -->
88
<uses-sdk android:minSdkVersion="9"/>
99

@@ -64,5 +64,6 @@
6464
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6565
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6666
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
67+
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
6768
</manifest>
6869

ide/android/assets/main.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sub do_about()
5555
print "(_ ._ _ _.|||_) /\ (_ |/ "
5656
print "__)| | |(_||||_)/--\__)|\_"
5757
print
58-
print "Version 0.12.4"
58+
print "Version 0.12.5"
5959
print
6060
print "Copyright (c) 2002-2015 Chris Warren-Smith"
6161
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)

src/platform/android/jni/runtime.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ Runtime::~Runtime() {
177177
pthread_mutex_destroy(&_mutex);
178178
}
179179

180+
void Runtime::addShortcut(const char *path) {
181+
JNIEnv *env;
182+
_app->activity->vm->AttachCurrentThread(&env, NULL);
183+
jclass clazz = env->GetObjectClass(_app->activity->clazz);
184+
jstring pathString = env->NewStringUTF(path);
185+
jmethodID methodId = env->GetMethodID(clazz, "addShortcut",
186+
"(Ljava/lang/String;)V");
187+
env->CallVoidMethod(_app->activity->clazz, methodId, pathString);
188+
env->DeleteLocalRef(clazz);
189+
env->DeleteLocalRef(pathString);
190+
_app->activity->vm->DetachCurrentThread();
191+
}
192+
180193
void Runtime::alert(const char *title, const char *message) {
181194
logEntered();
182195

@@ -818,6 +831,9 @@ void System::editSource(strlib::String &loadPath) {
818831
saveFile(editWidget, loadPath);
819832
}
820833
break;
834+
case SB_KEY_F(10):
835+
runtime->addShortcut(loadPath.c_str());
836+
break;
821837
case SB_KEY_CTRL('s'):
822838
saveFile(editWidget, loadPath);
823839
break;

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Runtime : public System {
2121
Runtime(android_app *app);
2222
virtual ~Runtime();
2323

24+
void addShortcut(const char *path);
2425
void alert(const char *title, const char *message);
2526
void alert(const char *title, bool longDuration=true);
2627
int ask(const char *title, const char *prompt, bool cancel);

src/platform/android/src/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ public class MainActivity extends NativeActivity {
8484
public static native void onResize(int width, int height);
8585
public static native void runFile(String fileName);
8686

87+
public void addShortcut(final String path) {
88+
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
89+
intent.setAction(Intent.ACTION_MAIN);
90+
Intent addIntent = new Intent();
91+
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
92+
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SmallBASIC");
93+
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
94+
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
95+
R.drawable.ic_launcher));
96+
addIntent.putExtra("duplicate", false);
97+
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
98+
getApplicationContext().sendBroadcast(addIntent);
99+
showToast("The shortcut was created and has been placed on your home screen", true);
100+
}
101+
87102
public int ask(final String title, final String prompt, final boolean cancel) {
88103
final AskResult result = new AskResult();
89104
final Activity activity = this;

src/platform/sdl/editor.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "config.h"
1010

1111
#include "common/sbapp.h"
12+
#include "common/fs_socket_client.h"
1213
#include "ui/textedit.h"
1314
#include "platform/sdl/runtime.h"
1415
#include "platform/sdl/settings.h"
@@ -64,23 +65,24 @@ void showRecentFiles(TextEditHelpWidget *helpWidget, String &loadPath) {
6465
}
6566

6667
void exportBuffer(AnsiWidget *out, const char *text, String &dest, String &token) {
67-
int handle = 1;
6868
char buffer[PATH_MAX];
69+
dev_file_t f;
70+
memset(&f, 0, sizeof(dev_file_t));
6971

70-
sprintf(buffer, "SOCL:%s\n", dest.c_str());
71-
if (dev_fopen(handle, buffer, DEV_FILE_OUTPUT)) {
72+
sprintf(f.name, "SOCL:%s\n", dest.c_str());
73+
if (dest.indexOf(':', 0) != -1 && sockcl_open(&f)) {
7274
sprintf(buffer, "# %s\n", token.c_str());
73-
dev_fwrite(handle, (byte *)buffer, strlen(buffer));
74-
if (!dev_fwrite(handle, (byte *)text, strlen(text))) {
75+
sockcl_write(&f, (byte *)buffer, strlen(buffer));
76+
if (!sockcl_write(&f, (byte *)text, strlen(text))) {
7577
sprintf(buffer, "Failed to write: %s", dest.c_str());
7678
} else {
7779
sprintf(buffer, "Exported file to %s", dest.c_str());
7880
}
81+
sockcl_close(&f);
7982
} else {
8083
sprintf(buffer, "Failed to open: %s", dest.c_str());
8184
}
8285
out->setStatus(buffer);
83-
dev_fclose(handle);
8486
}
8587

8688
void System::editSource(String &loadPath) {
@@ -193,6 +195,12 @@ void System::editSource(String &loadPath) {
193195
redraw = false;
194196
onlineHelp((Runtime *)this, editWidget);
195197
break;
198+
case SB_KEY_F(4):
199+
if (editWidget->getTextLength() && g_exportAddr.length() && g_exportToken.length()) {
200+
exportBuffer(_output, editWidget->getText(), g_exportAddr, g_exportToken);
201+
break;
202+
}
203+
// else fallthru to F3 handler
196204
case SB_KEY_F(3):
197205
if (editWidget->getTextLength()) {
198206
saveFile(editWidget, loadPath);
@@ -313,8 +321,6 @@ void System::editSource(String &loadPath) {
313321
_output->setStatus("Enter token. Esc=Close");
314322
break;
315323
case kExportToken:
316-
_output->setStatus("Sending ...");
317-
_output->redraw();
318324
g_exportToken = helpWidget->getText();
319325
inputMode = kInit;
320326
widget = editWidget;

src/ui/graphics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ int Graphics::getPixel(Canvas *canvas, int posX, int posY) {
314314
&& posY < canvas->_h - 1) {
315315
pixel_t *line = canvas->getLine(posY);
316316
result = line[posX];
317+
#if defined(PIXELFORMAT_RGBA8888)
318+
uint8_t r,g,b;
319+
GET_RGB2(result, r, g, b);
320+
result = SET_RGB(r, g, b);
321+
#endif
317322
}
318323
return result;
319324
}

src/ui/system.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#define MENU_DEBUG 18
4242
#define MENU_OUTPUT 19
4343
#define MENU_HELP 20
44-
#define MENU_SIZE 21
44+
#define MENU_SHORTCUT 21
45+
#define MENU_SIZE 22
4546
#define MENU_COMPETION_0 (MENU_SIZE + 1)
4647
#define MENU_COMPETION_1 (MENU_SIZE + 2)
4748
#define MENU_COMPETION_2 (MENU_SIZE + 3)
@@ -342,6 +343,10 @@ void System::handleMenu(MAEvent &event) {
342343
event.type = EVENT_TYPE_KEY_PRESSED;
343344
event.key = SB_KEY_F(1);
344345
break;
346+
case MENU_SHORTCUT:
347+
event.type = EVENT_TYPE_KEY_PRESSED;
348+
event.key = SB_KEY_F(10);
349+
break;
345350
case MENU_COMPETION_0:
346351
completeKeyword(0);
347352
break;
@@ -834,6 +839,9 @@ void System::showMenu() {
834839
sprintf(buffer, "Control Mode [%s]", (controlMode ? "ON" : "OFF"));
835840
items->add(new String(buffer));
836841
_systemMenu[index++] = MENU_CTRL_MODE;
842+
} else {
843+
items->add(new String("Desktop Shortcut"));
844+
_systemMenu[index++] = MENU_SHORTCUT;
837845
}
838846
#endif
839847
} else {

src/ui/textedit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const char *helpText =
108108
"TAB indent line\n"
109109
"F1,A-h keyword help\n"
110110
"F2 online help\n"
111-
"F3 export\n"
111+
"F3,F4 export\n"
112112
"F5 debug\n"
113113
"F9, C-r run\n";
114114

0 commit comments

Comments
 (0)