Skip to content

Commit 9cc05bd

Browse files
committed
ANDROID: add shortcut option
1 parent 7f9759a commit 9cc05bd

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2016-02-11
22
Added export to mobile command (SDL)
3+
Added Desktop shortcut command (android)
34

45
2015-12-05
56
Implemented loading recent files via ALT+1 .. ALT+9

src/platform/android/jni/runtime.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_r
139139

140140
extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_onResize
141141
(JNIEnv *env, jclass jclazz, jint width, jint height) {
142-
if (runtime != NULL && runtime->isActive() && os_graphics) {
142+
if (runtime != NULL && !runtime->isClosing() && runtime->isActive() && os_graphics) {
143143
runtime->onResize(width, height);
144144
}
145145
}
@@ -831,9 +831,6 @@ void System::editSource(strlib::String &loadPath) {
831831
saveFile(editWidget, loadPath);
832832
}
833833
break;
834-
case SB_KEY_F(10):
835-
runtime->addShortcut(loadPath.c_str());
836-
break;
837834
case SB_KEY_CTRL('s'):
838835
saveFile(editWidget, loadPath);
839836
break;

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,21 @@ public class MainActivity extends NativeActivity {
8585
public static native void runFile(String fileName);
8686

8787
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);
88+
Intent shortcut = new Intent(getApplicationContext(), MainActivity.class);
89+
shortcut.setAction(Intent.ACTION_MAIN);
90+
shortcut.setData(Uri.parse("smallbasic://" + path));
91+
Intent intent = new Intent();
92+
int index = path.lastIndexOf('/');
93+
String name = (index == -1) ? path : path.substring(index + 1);
94+
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
95+
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
96+
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
97+
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
98+
R.drawable.ic_launcher));
99+
intent.putExtra("duplicate", false);
100+
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
101+
getApplicationContext().sendBroadcast(intent);
102+
showToast("The shortcut " + name + " was created and has been placed on your home screen", true);
100103
}
101104

102105
public int ask(final String title, final String prompt, final boolean cancel) {

src/platform/sdl/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(SDL_Window *window);
2222
virtual ~Runtime();
2323

24+
void addShortcut(const char *) {}
2425
void alert(const char *title, const char *message);
2526
int ask(const char *title, const char *prompt, bool cancel);
2627
void browseFile(const char *url);

src/ui/system.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,9 @@ void System::handleMenu(MAEvent &event) {
344344
event.key = SB_KEY_F(1);
345345
break;
346346
case MENU_SHORTCUT:
347-
event.type = EVENT_TYPE_KEY_PRESSED;
348-
event.key = SB_KEY_F(10);
347+
if (_activeFile.length() > 0) {
348+
addShortcut(_activeFile.c_str());
349+
}
349350
break;
350351
case MENU_COMPETION_0:
351352
completeKeyword(0);
@@ -839,9 +840,6 @@ void System::showMenu() {
839840
sprintf(buffer, "Control Mode [%s]", (controlMode ? "ON" : "OFF"));
840841
items->add(new String(buffer));
841842
_systemMenu[index++] = MENU_CTRL_MODE;
842-
} else {
843-
items->add(new String("Desktop Shortcut"));
844-
_systemMenu[index++] = MENU_SHORTCUT;
845843
}
846844
#endif
847845
} else {
@@ -879,6 +877,11 @@ void System::showMenu() {
879877
#if defined(_SDL)
880878
items->add(new String("Back"));
881879
_systemMenu[index++] = MENU_BACK;
880+
#else
881+
if (!_mainBas && _activeFile.length() > 0) {
882+
items->add(new String("Desktop Shortcut"));
883+
_systemMenu[index++] = MENU_SHORTCUT;
884+
}
882885
#endif
883886
}
884887
optionsBox(items);

src/ui/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct System {
5353
kHand, kArrow, kIBeam
5454
};
5555

56+
virtual void addShortcut(const char *path) = 0;
5657
virtual void alert(const char *title, const char *message) = 0;
5758
virtual int ask(const char *title, const char *prompt, bool cancel=true) = 0;
5859
virtual void debugStart(TextEditInput *edit, const char *file) = 0;

0 commit comments

Comments
 (0)