Improved support for geo: intents
This commit is contained in:
parent
09b0fc7297
commit
c9d0c8141a
@ -47,6 +47,8 @@ import java.io.IOException;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class IITC_Mobile extends Activity
|
public class IITC_Mobile extends Activity
|
||||||
implements OnSharedPreferenceChangeListener, NfcAdapter.CreateNdefMessageCallback {
|
implements OnSharedPreferenceChangeListener, NfcAdapter.CreateNdefMessageCallback {
|
||||||
@ -74,6 +76,7 @@ public class IITC_Mobile extends Activity
|
|||||||
private boolean mShowMapInDebug = false;
|
private boolean mShowMapInDebug = false;
|
||||||
private final Stack<String> mDialogStack = new Stack<String>();
|
private final Stack<String> mDialogStack = new Stack<String>();
|
||||||
private String mPermalink = null;
|
private String mPermalink = null;
|
||||||
|
private String mSearchTerm = null;
|
||||||
|
|
||||||
// Used for custom back stack handling
|
// Used for custom back stack handling
|
||||||
private final Stack<Pane> mBackStack = new Stack<IITC_NavigationHelper.Pane>();
|
private final Stack<Pane> mBackStack = new Stack<IITC_NavigationHelper.Pane>();
|
||||||
@ -258,20 +261,20 @@ public class IITC_Mobile extends Activity
|
|||||||
|
|
||||||
private void handleGeoUri(final Uri uri) throws URISyntaxException {
|
private void handleGeoUri(final Uri uri) throws URISyntaxException {
|
||||||
final String[] parts = uri.getSchemeSpecificPart().split("\\?", 2);
|
final String[] parts = uri.getSchemeSpecificPart().split("\\?", 2);
|
||||||
Double lat, lon;
|
Double lat = null, lon = null;
|
||||||
Integer z = null;
|
Integer z = null;
|
||||||
|
String search = null;
|
||||||
|
|
||||||
// parts[0] may contain an 'uncertainty' parameter, delimited by a semicolon
|
// parts[0] may contain an 'uncertainty' parameter, delimited by a semicolon
|
||||||
final String[] pos = parts[0].split(";", 2)[0].split(",", 2);
|
final 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");
|
if (pos.length == 2) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lat = Double.valueOf(pos[0]);
|
lat = Double.valueOf(pos[0]);
|
||||||
lon = Double.valueOf(pos[1]);
|
lon = Double.valueOf(pos[1]);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
final URISyntaxException use = new URISyntaxException(uri.toString(), "position could not be parsed");
|
lat = null;
|
||||||
use.initCause(e);
|
lon = null;
|
||||||
throw use;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts.length > 1) { // query string present
|
if (parts.length > 1) { // query string present
|
||||||
@ -281,21 +284,47 @@ public class IITC_Mobile extends Activity
|
|||||||
try {
|
try {
|
||||||
z = Integer.valueOf(param.substring(2));
|
z = Integer.valueOf(param.substring(2));
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
final URISyntaxException use = new URISyntaxException(
|
|
||||||
uri.toString(), "could not parse zoom level");
|
|
||||||
use.initCause(e);
|
|
||||||
throw use;
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
if (param.startsWith("q=")) {
|
||||||
|
search = param.substring(2);
|
||||||
|
final Pattern pattern = Pattern.compile("^(-?\\d+(\\.\\d+)?),(-?\\d+(\\.\\d+)?)\\s*\\(.+\\)");
|
||||||
|
final Matcher matcher = pattern.matcher(search);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
try {
|
||||||
|
lat = Double.valueOf(matcher.group(1));
|
||||||
|
lon = Double.valueOf(matcher.group(3));
|
||||||
|
search = null; // if we have a position, we don't need the search term
|
||||||
|
} catch (final NumberFormatException e) {
|
||||||
|
lat = null;
|
||||||
|
lon = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = "http://www.ingress.com/intel?ll=" + lat + "," + lon;
|
if (lat != null && lon != null) {
|
||||||
|
String url = mIntelUrl + "?ll=" + lat + "," + lon;
|
||||||
if (z != null) {
|
if (z != null) {
|
||||||
url += "&z=" + z;
|
url += "&z=" + z;
|
||||||
}
|
}
|
||||||
loadUrl(url);
|
loadUrl(url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (search != null) {
|
||||||
|
if (mIsLoading) {
|
||||||
|
mSearchTerm = search;
|
||||||
|
loadUrl(mIntelUrl);
|
||||||
|
} else {
|
||||||
|
switchToPane(Pane.MAP);
|
||||||
|
mIitcWebView.loadUrl("javascript:search('" + search + "');");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new URISyntaxException(uri.toString(), "position could not be parsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -447,8 +476,7 @@ public class IITC_Mobile extends Activity
|
|||||||
// Get the SearchView and set the searchable configuration
|
// Get the SearchView and set the searchable configuration
|
||||||
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||||
mSearchMenuItem = menu.findItem(R.id.menu_search);
|
mSearchMenuItem = menu.findItem(R.id.menu_search);
|
||||||
final SearchView searchView =
|
final SearchView searchView = (SearchView) mSearchMenuItem.getActionView();
|
||||||
(SearchView) mSearchMenuItem.getActionView();
|
|
||||||
// Assumes current activity is the searchable activity
|
// Assumes current activity is the searchable activity
|
||||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
||||||
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
|
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
|
||||||
@ -458,8 +486,8 @@ public class IITC_Mobile extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(final Menu menu) {
|
public boolean onPrepareOptionsMenu(final Menu menu) {
|
||||||
boolean visible = false;
|
boolean visible = false;
|
||||||
if (mNavigationHelper != null)
|
if (mNavigationHelper != null) visible = !mNavigationHelper.isDrawerOpened();
|
||||||
visible = !mNavigationHelper.isDrawerOpened();
|
if (mIsLoading) visible = false;
|
||||||
|
|
||||||
for (int i = 0; i < menu.size(); i++) {
|
for (int i = 0; i < menu.size(); i++) {
|
||||||
final MenuItem item = menu.getItem(i);
|
final MenuItem item = menu.getItem(i);
|
||||||
@ -475,6 +503,7 @@ public class IITC_Mobile extends Activity
|
|||||||
|
|
||||||
case R.id.locate:
|
case R.id.locate:
|
||||||
item.setVisible(visible);
|
item.setVisible(visible);
|
||||||
|
item.setEnabled(!mIsLoading);
|
||||||
item.setIcon(mUserLocation.isFollowing()
|
item.setIcon(mUserLocation.isFollowing()
|
||||||
? R.drawable.ic_action_location_follow
|
? R.drawable.ic_action_location_follow
|
||||||
: R.drawable.ic_action_location_found);
|
: R.drawable.ic_action_location_found);
|
||||||
@ -658,10 +687,20 @@ public class IITC_Mobile extends Activity
|
|||||||
|
|
||||||
public void setLoadingState(final boolean isLoading) {
|
public void setLoadingState(final boolean isLoading) {
|
||||||
mIsLoading = isLoading;
|
mIsLoading = isLoading;
|
||||||
|
|
||||||
mNavigationHelper.onLoadingStateChanged();
|
mNavigationHelper.onLoadingStateChanged();
|
||||||
|
invalidateOptionsMenu();
|
||||||
updateViews();
|
updateViews();
|
||||||
|
|
||||||
|
if (mSearchTerm != null && !isLoading) {
|
||||||
|
new Handler().postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// switchToPane(Pane.MAP);
|
||||||
|
mIitcWebView.loadUrl("javascript:search('" + mSearchTerm + "');");
|
||||||
|
mSearchTerm = null;
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateViews() {
|
private void updateViews() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user