Skip to content
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

Update:Android:GUI/Internal: Show contextual GUI menu when receiving geo intent #987

Open
wants to merge 30 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
65d9d1c
Sample working internal GUI coordinates option menu on QR code scan (…
lains Apr 5, 2020
24196b9
Fixing sanity check
lains Apr 6, 2020
7d11904
Fixing line length
lains Apr 19, 2020
083049f
Fixing renamed function
lains Apr 19, 2020
b564028
Making NavitGraphics.getCoordForPoint() static
lains Apr 19, 2020
a352997
Disabling overlays before showing coord action menu
lains Apr 19, 2020
100ac78
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Apr 19, 2020
30a5445
Updating native prototype following switch to static method
lains Apr 20, 2020
cd16a5a
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
jkoan Apr 26, 2020
94663d1
Refactoring gui_internal_show_coord_actions()
lains Apr 27, 2020
87e360e
Using overlay disable before running graphics_overlay_disable()
lains Apr 27, 2020
80c01fa
Fixing contextual internal menu display
lains Apr 27, 2020
46259e9
Removing call to graphics_overlay_disable() as this is done by gui_in…
lains Apr 27, 2020
8248a15
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Jun 5, 2020
65403f2
Delaying geo: intent processing and adding probe for gui_show_coord_a…
lains Jul 16, 2020
6b48a55
Fixing indentation
lains Jul 17, 2020
b52939c
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Jul 17, 2020
d11f1c5
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Aug 22, 2020
1417419
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
jkoan Sep 6, 2020
cdc2c3e
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
jkoan Nov 19, 2020
90e8a56
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Jan 4, 2021
14f9089
Fixing processing geo: intent when navit is not started
lains Jan 5, 2021
51c864f
Merge branch 'geo-coord-show-actions-on-internal-gui' of https://gith…
lains Jan 5, 2021
0b61705
Removing trailing spaces for sanity check
lains Jan 8, 2021
93f73aa
Applying astyle
lains Jan 11, 2021
5c11a9e
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Jul 30, 2022
3ef645e
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Jul 30, 2022
e61a0dc
Fixing sailfish build
lains Aug 3, 2022
9eeee8b
Fixing show_coord_actions (disabled) callback for sailfish
lains Aug 3, 2022
db97e5b
Merge branch 'trunk' into geo-coord-show-actions-on-internal-gui
lains Nov 30, 2022
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
26 changes: 17 additions & 9 deletions navit/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ JNIEXPORT jstring JNICALL Java_org_navitproject_navit_NavitGraphics_getCoordForP
return return_string;
}


JNIEXPORT jobject JNICALL Java_org_navitproject_navit_NavitCallbackHandler_callbackCmdChannel( JNIEnv* env,
jclass thiz, jint command) {

Expand Down Expand Up @@ -493,29 +492,30 @@ JNIEXPORT jint JNICALL Java_org_navitproject_navit_NavitCallbackHandler_callback
dbg(lvl_debug,"Setting destination to %s",coord_str);
// start navigation asynchronous
navit_set_destination(attr.u.navit, &pc, coord_str, 1);
ret = 1;
}
break;
case 3: {
// navigate to geo position
char *name;
case 8: /* Show contextual actions for a geo position */
case 3: { /* Navigate to geo position */
s = (*env)->GetStringUTFChars(env, str, NULL);
char *name;
char parse_str[strlen(s) + 1];
strcpy(parse_str, s);
(*env)->ReleaseStringUTFChars(env, str, s);
dbg(lvl_debug, "*****string=%s", s);

// set destination to (lat#lon#title)
/* Parse coordinates from argument string (lat#lon#title) */
struct coord_geo g;
char *p;
char *stopstring;

// latitude
// extract latitude
p = strtok (parse_str,"#");
g.lat = strtof(p, &stopstring);
// longitude
// extract longitude
p = strtok (NULL, "#");
g.lng = strtof(p, &stopstring);
// description/name of the place identified by lat and long
// extract description/name of the place identified by lat and long (if any)
name = strtok (NULL, "#");

dbg(lvl_debug, "lat=%f", g.lat);
Expand All @@ -534,8 +534,16 @@ JNIEXPORT jint JNICALL Java_org_navitproject_navit_NavitCallbackHandler_callback
pcoord_format_degree_short(&pc, coord_str, sizeof(coord_str), " ");
name = coord_str;
}
// start navigation asynchronous

if (channel == 8) {
graphics_overlay_disable(navit_get_graphics(attr.u.navit), 1); /* Disable OSD items before showing menu */
ret = gui_show_coord_actions(navit_get_gui(attr.u.navit), c, "" /* description */);
}
if (ret)
break;
/* else fallback to default action navigate asynchrnous as when called with channel 3 */
navit_set_destination(attr.u.navit, &pc, name, 1);
ret = 1;
}
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion navit/android/src/org/navitproject/navit/Navit.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void handleIntent(Intent intent) {
} else if (naviScheme.equals("geo")
&& intent.getAction().equals("android.intent.action.VIEW")) {
invokeCallbackOnGeo(intent.getData().getSchemeSpecificPart(),
NavitCallbackHandler.MsgType.CLB_SET_DESTINATION, "");
NavitCallbackHandler.MsgType.CLB_COORD_ACTIONS, "");
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions navit/android/src/org/navitproject/navit/NavitCallbackHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,40 @@ static void sendCommand(CmdType command) {


enum MsgType {
CLB_SET_DESTINATION, CLB_SET_DISPLAY_DESTINATION, CLB_CALL_CMD, CLB_LOAD_MAP, CLB_UNLOAD_MAP,
/* Set the current navigation destination to geographical coordinates */
CLB_SET_DESTINATION,
/* Set current navigation destination to a given position on the current graphical display */
CLB_SET_DISPLAY_DESTINATION,
/* Open a contextual menu with possible actions related to the provided geographical coordinates */
CLB_COORD_ACTIONS,
/* Call a custom internal command (like in the GUI scripts) */
CLB_CALL_CMD,
/* Load a map */
CLB_LOAD_MAP,
/* Unload a map */
CLB_UNLOAD_MAP,
/* Unload a map and delete it from the storage */
CLB_DELETE_MAP
}


static class CallBackHandler extends Handler {
public void handleMessage(Message msg) {
switch (msg_values[msg.what]) {
case CLB_SET_DESTINATION:
case CLB_SET_DESTINATION: {
String lat = Float.toString(msg.getData().getFloat("lat"));
String lon = Float.toString(msg.getData().getFloat("lon"));
String q = msg.getData().getString(("q"));
callbackMessageChannel(3, lat + "#" + lon + "#" + q);
break;
}
break;
case CLB_COORD_ACTIONS: {
String lat = Float.toString(msg.getData().getFloat("lat"));
String lon = Float.toString(msg.getData().getFloat("lon"));
String q = msg.getData().getString(("q"));
callbackMessageChannel(8, lat + "#" + lon + "#" + q);
}
break;
case CLB_SET_DISPLAY_DESTINATION:
int x = msg.arg1;
int y = msg.arg2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ private void setmActivity(final Navit navit) {

private native void motionCallback(long id, int x, int y);

private native String getCoordForPoint(int x, int y, boolean absoluteCoord);
private static native String getCoordForPoint(int x, int y, boolean absoluteCoord);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can you give a motivation for this, does it solve or change anything ? thx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I searched a bit further and you have a point in changing it to static when it comes to MIM as described here #964. Just if you change it to static you will have to change jobject to jclass in the signature there https://github.com/navit-gps/navit/blob/trunk/navit/android.c#L325 for consistency, thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yes, that was the reason for this change. This method does not access any member of the class.
I agree it has nothing to do with the feature in this PR. I just fixed this on the way while browsing through the code I wrote earlier in the previously related PR #794.

But you're right, this is not required to implement the feature described in this current PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, I've just changed this.


static native String[][] getAllCountries();

Expand Down
11 changes: 11 additions & 0 deletions navit/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ int gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description) {
return ret;
}

int gui_show_coord_actions(struct gui *gui, struct pcoord *c, char *description) {
int ret;
dbg(lvl_info,"enter");
if (! gui->meth.show_coord_actions)
return 0;
ret=gui->meth.show_coord_actions(gui->priv, c, description);

dbg(lvl_info,"ret=%d", ret);
return ret;
}

int gui_set_graphics(struct gui *this_, struct graphics *gra) {
if (! this_->meth.set_graphics) {
dbg(lvl_error, "cannot set graphics, method 'set_graphics' not available");
Expand Down
2 changes: 2 additions & 0 deletions navit/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct gui_methods {
int (*run_main_loop)(struct gui_priv *priv);
struct datawindow_priv *(*datawindow_new)(struct gui_priv *priv, const char *name, struct callback *click, struct callback *close, struct datawindow_methods *meth);
int (*add_bookmark)(struct gui_priv *priv, struct pcoord *c, char *description);
int (*show_coord_actions)(struct gui_priv *priv, struct pcoord *c, char *description);
void (*disable_suspend)(struct gui_priv *priv);
int (*get_attr)(struct gui_priv *priv, enum attr_type type, struct attr *attr);
int (*add_attr)(struct gui_priv *priv, struct attr *attr);
Expand All @@ -64,6 +65,7 @@ struct menu *gui_menubar_new(struct gui *gui);
struct menu *gui_popup_new(struct gui *gui);
struct datawindow *gui_datawindow_new(struct gui *gui, const char *name, struct callback *click, struct callback *close);
int gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description);
int gui_show_coord_actions(struct gui *this_, struct pcoord *c, char *description);
int gui_set_graphics(struct gui *this_, struct graphics *gra);
void gui_disable_suspend(struct gui *this_);
int gui_has_main_loop(struct gui *this_);
Expand Down
5 changes: 3 additions & 2 deletions navit/gui/gtk/gui_gtk_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,13 @@ static int gui_gtk_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *de
}

struct gui_methods gui_gtk_methods = {
NULL,
NULL, // gui_gtk_menubar_new
gui_gtk_popup_new,
gui_gtk_set_graphics,
NULL,
NULL, // gui_gtk_run_main_loop
gui_gtk_datawindow_new,
gui_gtk_add_bookmark,
NULL, // gui_gtk_show_coord_actions
};

static gboolean gui_gtk_delete(GtkWidget *widget, GdkEvent *event, struct navit *nav) {
Expand Down
16 changes: 11 additions & 5 deletions navit/gui/internal/gui_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,6 +2893,11 @@ static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra
return 0;
}

static int gui_internal_show_coord_actions(struct gui_priv *this, struct pcoord *c, char *description) {
gui_internal_cmd2_show_geopos_actions(this, c, description);
return 1;
}

static void gui_internal_disable_suspend(struct gui_priv *this) {
if (this->win->disable_suspend)
this->win->disable_suspend(this->win);
Expand All @@ -2904,12 +2909,13 @@ static void gui_internal_disable_suspend(struct gui_priv *this) {
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
struct gui_methods gui_internal_methods = {
NULL,
NULL,
NULL, // gui_internal_menubar_new
NULL, // gui_internal_popup_new
gui_internal_set_graphics,
NULL,
NULL,
NULL,
NULL, // gui_internal_run_main_loop
NULL, // gui_internal_datawindow_new
NULL, // gui_internal_add_bookmark
gui_internal_show_coord_actions,
gui_internal_disable_suspend,
gui_internal_get_attr,
gui_internal_add_attr,
Expand Down
24 changes: 24 additions & 0 deletions navit/gui/internal/gui_internal_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,27 @@ static void gui_internal_onclick(struct attr ***in, char **onclick, char *set) {
return;
}

void gui_internal_cmd2_show_geopos_actions(struct gui_priv *this, struct pcoord *c, char *description) {
struct widget w;
const char *name=NULL;

dbg(lvl_debug,"enter");
/*
if (!in || !in[0])
dbg(lvl_error, "No arg");
if (in[0] && ATTR_IS_STRING(in[0]->type)) {
name=in[1]->u.str;
dbg(lvl_error, "1st arg is string \"%s\"", name)
}
*/

w.name = "Location from QR code";
w.text = g_strdup("1.583471 15.340001");
pcoord_parse(w.text, projection_mg, &(w.c));
gui_internal_cmd_position(this, &w, (void*)8);
g_free(w.text);
}

static int gui_internal_cmd_img(struct gui_priv * this, char *function, struct attr **in, struct attr ***out) {
char *str=g_strdup("<img"),*suffix=NULL,*onclick=g_strdup(""),*html;

Expand Down Expand Up @@ -1173,6 +1194,8 @@ static int gui_internal_cmd2(struct gui_priv *this, char *function, struct attr
gui_internal_cmd2_waypoints(this, function, in, out);
else if(!strcmp(function, "about"))
gui_internal_cmd2_about(this, function, in, out);
//else if(!strcmp(function, "geopos_actions"))
// gui_internal_cmd2_show_geopos_actions(this, function, in, out);

if(entering)
graphics_draw_mode(this->gra, draw_mode_end);
Expand Down Expand Up @@ -1209,6 +1232,7 @@ static struct command_table commands[] = {
{"waypoints",command_cast(gui_internal_cmd2)},
{"write",command_cast(gui_internal_cmd_write)},
{"about",command_cast(gui_internal_cmd2)},
//{"geopos_actions",command_cast(gui_internal_cmd2_show_geopos_actions)},
#if HAS_IFADDRS
{"network_info",command_cast(gui_internal_cmd2)},
#endif
Expand Down
3 changes: 2 additions & 1 deletion navit/gui/internal/gui_internal_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
struct attr;
struct gui_priv;
struct pcoord;
char *gui_internal_coordinates(struct pcoord *pc, char sep);
int gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out);
void gui_internal_command_init(struct gui_priv *this, struct attr **attrs);
//void gui_internal_cmd2_show_geopos_actions(struct gui_priv *this, char *function, struct attr **in, struct attr ***out);
void gui_internal_cmd2_show_geopos_actions(struct gui_priv *this, struct pcoord *c, char *description);
/* end of prototypes */
3 changes: 2 additions & 1 deletion navit/gui/win32/gui_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,10 @@ struct gui_methods win32_gui_methods = {
NULL, // win32_gui_menubar_new,
win32_gui_popup_new,
win32_gui_set_graphics,
NULL,
NULL, // win32_gui_run_main_loop
NULL, // win32_gui_datawindow_new,
win32_gui_add_bookmark,
NULL, // win32_gui_show_coord_actions
};


Expand Down