Skip to content

Commit

Permalink
android: Make back button return to system home when on Movian's home…
Browse files Browse the repository at this point in the history
… screen
  • Loading branch information
andoma committed Aug 21, 2018
1 parent 16106b9 commit 2317659
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
11 changes: 11 additions & 0 deletions android/src/com/lonelycoder/mediaplayer/GLWActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,15 @@ public void run() {
});
}

@Override
public void sysHome() {
runOnUiThread(new Runnable() {
public void run() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ interface VideoRendererProvider {

public void disableScreenSaver();
public void enableScreenSaver();
public void sysHome();
}
24 changes: 24 additions & 0 deletions src/arch/android/android_glw.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ dis_screensaver_callback(void *opaque, int value)
(*env)->CallVoidMethod(env, agr->agr_vrp, mid);
}


static void
nav_eventsink(void *opaque, event_t *e)
{
android_glw_root_t *agr = opaque;
JNIEnv *env;
(*JVM)->GetEnv(JVM, (void **)&env, JNI_VERSION_1_6);

jclass class = (*env)->GetObjectClass(env, agr->agr_vrp);
if(event_is_action(e, ACTION_SYSTEM_HOME)) {
jmethodID mid = (*env)->GetMethodID(env, class, "sysHome", "()V");
(*env)->CallVoidMethod(env, agr->agr_vrp, mid);
}
}

JNIEXPORT jint JNICALL
Java_com_lonelycoder_mediaplayer_Core_glwCreate(JNIEnv *env,
jobject obj,
Expand All @@ -78,6 +93,14 @@ Java_com_lonelycoder_mediaplayer_Core_glwCreate(JNIEnv *env,
PROP_TAG_COURIER, agr->gr.gr_courier,
NULL);

agr->agr_nav_eventsink_sub =
prop_subscribe(0,
PROP_TAG_CALLBACK_EVENT, nav_eventsink, agr,
PROP_TAG_NAME("nav", "eventSink"),
PROP_TAG_NAMED_ROOT, android_nav, "nav",
PROP_TAG_COURIER, agr->gr.gr_courier,
NULL);

glw_load_universe(&agr->gr);
return (intptr_t)agr;
}
Expand Down Expand Up @@ -124,6 +147,7 @@ Java_com_lonelycoder_mediaplayer_Core_glwDestroy(JNIEnv *env,
glw_root_t *gr = &agr->gr;

prop_unsubscribe(agr->agr_disable_screensaver_sub);
prop_unsubscribe(agr->agr_nav_eventsink_sub);

glw_lock(gr);
while(agr->agr_running == 1)
Expand Down
3 changes: 2 additions & 1 deletion src/arch/android/android_glw.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ typedef struct android_glw_root {

lphelper_t agr_dpad_center;


prop_sub_t *agr_disable_screensaver_sub;

prop_sub_t *agr_nav_eventsink_sub;

} android_glw_root_t;


1 change: 1 addition & 0 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ static struct strtab actionnames[] = {
{ "Select", ACTION_SELECT },
{ "MediaStats", ACTION_SHOW_MEDIA_STATS },
{ "Home", ACTION_HOME },
{ "SysHome", ACTION_SYSTEM_HOME },
{ "Reset", ACTION_RESET },
{ "Copy", ACTION_COPY },
{ "Paste", ACTION_PASTE },
Expand Down
1 change: 1 addition & 0 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef enum {
ACTION_SELECT,
ACTION_SHOW_MEDIA_STATS,
ACTION_HOME,
ACTION_SYSTEM_HOME,
ACTION_RESET,

ACTION_SWITCH_VIEW,
Expand Down
6 changes: 6 additions & 0 deletions src/navigator.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,12 @@ nav_back(navigator_t *nav)

if(doclose)
nav_close(np, 1);
} else {
event_t *e = event_create_action(ACTION_SYSTEM_HOME);
prop_t *eventsink = prop_create_r(nav->nav_prop_root, "eventSink");
prop_send_ext_event(eventsink, e);
prop_ref_dec(eventsink);
event_release(e);
}
}

Expand Down

0 comments on commit 2317659

Please sign in to comment.