Panagiotis Triantafyllou

added geo scheme handler to webview

......@@ -3,20 +3,7 @@
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="R58M42EM7YT" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-07-26T14:53:01.900442Z" />
</State>
<State />
</entry>
</value>
</component>
......
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.5.4r33'
PUBLISH_VERSION = '4.5.5.4r34'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -122,6 +122,9 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
private static final String URL_ACTION_MAIL = "mailto";
private static final String URL_ACTION_MARKET = "market";
private static final String URL_ACTION_INTENT = "intent";
private static final String URL_ACTION_MAPS = "geo";
private static final String URL_FALLBACK_MAPS = "https://www.google.com/maps/search/?api=1&query=";
private static final String URL_ACTION_MARKET_AUTHORITY = "play.google.com";
// ===========================================================
......@@ -230,6 +233,39 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
}
}
private void actionMap(String strUrl) {
try {
Uri webpage = Uri.parse(strUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
getContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
// String tempUrl = strUrl.split("q=")[1];
// Find the start index after "geo:"
int startIndex = strUrl.indexOf("geo:") + 4;
// Find the index of "?" to ignore everything after it
int endIndex = strUrl.indexOf("?");
// If there is no "?", set the endIndex to the length of the string
if (endIndex == -1) {
endIndex = strUrl.length();
}
// Extract the latitude and longitude part
String tempUrl = strUrl.substring(startIndex, endIndex);
if (!TextUtils.isEmpty(tempUrl)) {
Uri webpage = Uri.parse(URL_FALLBACK_MAPS + tempUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
getContext().startActivity(intent);
}
}
}
private void actionTel(Uri uri) {
try {
......@@ -905,6 +941,9 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
} catch (URISyntaxException e) {
return true;
}
} else if (scheme.equals(URL_ACTION_MAPS)) {
actionMap(strUrl);
return true;
}
return false;
}
......