Enable IITC to receive geo: intents
This commit is contained in:
parent
3e18e5bea1
commit
663a8f0dbc
@ -50,13 +50,24 @@
|
||||
<data
|
||||
android:host="www.ingress.com"
|
||||
android:scheme="https"
|
||||
android:pathPrefix="/intel"></data>
|
||||
android:pathPrefix="/intel"/>
|
||||
<data
|
||||
android:host="www.ingress.com"
|
||||
android:scheme="http"
|
||||
android:pathPrefix="/intel"></data>
|
||||
android:pathPrefix="/intel"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Handles geo: URIs -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
|
||||
<data android:scheme="geo"/>
|
||||
</intent-filter>
|
||||
|
||||
|
||||
<!-- Points to searchable meta data. -->
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
@ -65,8 +76,7 @@
|
||||
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
||||
android:theme="@style/AppBaseTheme"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize">
|
||||
</activity>
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"/>
|
||||
|
||||
<!-- START Used for Samsung Multi-Window support -->
|
||||
<uses-library
|
||||
|
@ -2,8 +2,10 @@ package com.cradle.iitc_mobile;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.SearchManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
@ -17,7 +19,6 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.StrictMode;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@ -30,6 +31,7 @@ import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class IITC_Mobile extends Activity {
|
||||
@ -169,13 +171,39 @@ public class IITC_Mobile extends Activity {
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Uri uri = intent.getData();
|
||||
String url = uri.toString();
|
||||
Log.d("iitcm", "intent received url: " + url);
|
||||
if (url.contains("ingress.com")) {
|
||||
Log.d("iitcm", "loading url...");
|
||||
this.loadUrl(url);
|
||||
Log.d("iitcm", "intent received url: " + uri.toString());
|
||||
|
||||
if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {
|
||||
if (uri.getHost() != null
|
||||
&& (uri.getHost().equals("ingress.com") || uri.getHost().endsWith(".ingress.com"))) {
|
||||
Log.d("iitcm", "loading url...");
|
||||
this.loadUrl(uri.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (Intent.ACTION_SEARCH.equals(action)) {
|
||||
|
||||
if (uri.getScheme().equals("geo")) {
|
||||
try {
|
||||
handleGeoUri(uri);
|
||||
return;
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Address could not be opened")
|
||||
.setMessage(e.getReason())
|
||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Intent.ACTION_SEARCH.equals(action)) {
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
query = query.replace("'", "''");
|
||||
final SearchView searchView =
|
||||
@ -185,11 +213,59 @@ public class IITC_Mobile extends Activity {
|
||||
actionBar.setTitle(getString(R.string.app_name));
|
||||
backStackUpdate(android.R.id.home);
|
||||
iitc_view.loadUrl("javascript:search('" + query + "');");
|
||||
} else if (onCreate) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (onCreate) {
|
||||
this.loadUrl(intel_url);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGeoUri(Uri uri) throws URISyntaxException {
|
||||
String[] parts = uri.getSchemeSpecificPart().split("\\?", 2);
|
||||
Double lat, lon;
|
||||
Integer z = null;
|
||||
|
||||
// parts[0] may contain an 'uncertainty' parameter, delimited by a semicolon
|
||||
String[] pos = parts[0].split(";", 2)[0].split(",", 2);
|
||||
if (pos.length != 2)
|
||||
throw new URISyntaxException(uri.toString(), "URI does not contain a valid position");
|
||||
|
||||
try {
|
||||
lat = Double.valueOf(pos[0]);
|
||||
lon = Double.valueOf(pos[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
URISyntaxException use = new URISyntaxException(uri.toString(), "position could not be parsed");
|
||||
use.initCause(e);
|
||||
throw use;
|
||||
}
|
||||
|
||||
if (parts.length > 1) // query string present
|
||||
{
|
||||
// search for z=
|
||||
for (String param : parts[1].split("&")) {
|
||||
if (param.startsWith("z="))
|
||||
{
|
||||
try
|
||||
{
|
||||
z = Integer.valueOf(param.substring(2));
|
||||
} catch (NumberFormatException e)
|
||||
{
|
||||
URISyntaxException use = new URISyntaxException(uri.toString(), "could not parse zoom level");
|
||||
use.initCause(e);
|
||||
throw use;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String url = "http://www.ingress.com/intel?ll=" + lat + "," + lon;
|
||||
if (z != null)
|
||||
url += "&z=" + z;
|
||||
this.loadUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
Loading…
x
Reference in New Issue
Block a user