This commit is contained in:
Jon Atkins 2014-01-26 17:54:03 +00:00
commit 9754af9e67
4 changed files with 82 additions and 24 deletions

View File

@ -161,6 +161,11 @@ window.runOnSmartphonesAfterBoot = function() {
}); });
}); });
if(typeof android !== 'undefined' && android && android.setPermalink) {
window.map.on('moveend', window.setAndroidPermalink);
addHook('portalSelected', window.setAndroidPermalink);
}
// Force lower render limits for mobile // Force lower render limits for mobile
window.VIEWPORT_PAD_RATIO = 0.1; window.VIEWPORT_PAD_RATIO = 0.1;
window.MAX_DRAWN_PORTALS = 500; window.MAX_DRAWN_PORTALS = 500;
@ -168,6 +173,24 @@ window.runOnSmartphonesAfterBoot = function() {
window.MAX_DRAWN_FIELDS = 100; window.MAX_DRAWN_FIELDS = 100;
} }
window.setAndroidPermalink = function() {
var c = window.map.getCenter();
var lat = Math.round(c.lat*1E6)/1E6;
var lng = Math.round(c.lng*1E6)/1E6;
var href = '/intel?ll='+lat+','+lng+'&z=' + map.getZoom();
if(window.selectedPortal && window.portals[window.selectedPortal]) {
var p = window.portals[window.selectedPortal].getLatLng();
lat = Math.round(p.lat*1E6)/1E6;
lng = Math.round(p.lng*1E6)/1E6;
href += '&pll='+lat+','+lng;
}
href = $('<a>').prop('href', href).prop('href'); // to get absolute URI
android.setPermalink(href);
}
window.useAndroidPanes = function() { window.useAndroidPanes = function() {
// isSmartphone is important to disable panes in desktop mode // isSmartphone is important to disable panes in desktop mode
return (typeof android !== 'undefined' && android && android.addPane && window.isSmartphone()); return (typeof android !== 'undefined' && android && android.addPane && window.isSmartphone());

View File

@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application <application
@ -46,6 +47,7 @@
<!-- Handles the implicit intent to VIEW the www.ingress.com/intel URI --> <!-- Handles the implicit intent to VIEW the www.ingress.com/intel URI -->
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.VIEW"/>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.BROWSABLE"/>

View File

@ -17,14 +17,15 @@ public class IITC_JSInterface {
// context of main activity // context of main activity
private final IITC_Mobile mIitc; private final IITC_Mobile mIitc;
IITC_JSInterface(IITC_Mobile iitc) { IITC_JSInterface(final IITC_Mobile iitc) {
mIitc = iitc; mIitc = iitc;
} }
// open dialog to send geo intent for navigation apps like gmaps or waze etc... // open dialog to send geo intent for navigation apps like gmaps or waze etc...
@JavascriptInterface @JavascriptInterface
public void intentPosLink(double lat, double lng, int zoom, String title, boolean isPortal) { public void intentPosLink(
Intent intent = new Intent(mIitc, ShareActivity.class); final double lat, final double lng, final int zoom, final String title, final boolean isPortal) {
final Intent intent = new Intent(mIitc, ShareActivity.class);
intent.putExtra("lat", lat); intent.putExtra("lat", lat);
intent.putExtra("lng", lng); intent.putExtra("lng", lng);
intent.putExtra("zoom", zoom); intent.putExtra("zoom", zoom);
@ -35,8 +36,8 @@ public class IITC_JSInterface {
// share a string to the IITC share activity. only uses the share tab. // share a string to the IITC share activity. only uses the share tab.
@JavascriptInterface @JavascriptInterface
public void shareString(String str) { public void shareString(final String str) {
Intent intent = new Intent(mIitc, ShareActivity.class); final Intent intent = new Intent(mIitc, ShareActivity.class);
intent.putExtra("shareString", str); intent.putExtra("shareString", str);
intent.putExtra("onlyShare", true); intent.putExtra("onlyShare", true);
mIitc.startActivity(intent); mIitc.startActivity(intent);
@ -45,16 +46,15 @@ public class IITC_JSInterface {
// disable javascript injection while spinner is enabled // disable javascript injection while spinner is enabled
// prevent the spinner from closing automatically // prevent the spinner from closing automatically
@JavascriptInterface @JavascriptInterface
public void spinnerEnabled(boolean en) { public void spinnerEnabled(final boolean en) {
mIitc.getWebView().disableJS(en); mIitc.getWebView().disableJS(en);
} }
// copy link to specific portal to android clipboard // copy link to specific portal to android clipboard
@JavascriptInterface @JavascriptInterface
public void copy(String s) { public void copy(final String s) {
ClipboardManager clipboard = (ClipboardManager) mIitc final ClipboardManager clipboard = (ClipboardManager) mIitc.getSystemService(Context.CLIPBOARD_SERVICE);
.getSystemService(Context.CLIPBOARD_SERVICE); final ClipData clip = ClipData.newPlainText("Copied Text ", s);
ClipData clip = ClipData.newPlainText("Copied Text ", s);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Toast.makeText(mIitc, "copied to clipboard", Toast.LENGTH_SHORT).show(); Toast.makeText(mIitc, "copied to clipboard", Toast.LENGTH_SHORT).show();
} }
@ -63,10 +63,9 @@ public class IITC_JSInterface {
public int getVersionCode() { public int getVersionCode() {
int versionCode = 0; int versionCode = 0;
try { try {
PackageInfo pInfo = mIitc.getPackageManager() final PackageInfo pInfo = mIitc.getPackageManager().getPackageInfo(mIitc.getPackageName(), 0);
.getPackageInfo(mIitc.getPackageName(), 0);
versionCode = pInfo.versionCode; versionCode = pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) { } catch (final PackageManager.NameNotFoundException e) {
Log.w(e); Log.w(e);
} }
return versionCode; return versionCode;
@ -75,11 +74,11 @@ public class IITC_JSInterface {
@JavascriptInterface @JavascriptInterface
public String getVersionName() { public String getVersionName() {
String buildVersion = "unknown"; String buildVersion = "unknown";
PackageManager pm = mIitc.getPackageManager(); final PackageManager pm = mIitc.getPackageManager();
try { try {
PackageInfo info = pm.getPackageInfo(mIitc.getPackageName(), 0); final PackageInfo info = pm.getPackageInfo(mIitc.getPackageName(), 0);
buildVersion = info.versionName; buildVersion = info.versionName;
} catch (PackageManager.NameNotFoundException e) { } catch (final PackageManager.NameNotFoundException e) {
Log.w(e); Log.w(e);
} }
return buildVersion; return buildVersion;
@ -93,7 +92,7 @@ public class IITC_JSInterface {
Pane pane; Pane pane;
try { try {
pane = mIitc.getNavigationHelper().getPane(id); pane = mIitc.getNavigationHelper().getPane(id);
} catch (IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
pane = Pane.MAP; pane = Pane.MAP;
} }
@ -103,12 +102,12 @@ public class IITC_JSInterface {
} }
@JavascriptInterface @JavascriptInterface
public void dialogFocused(String id) { public void dialogFocused(final String id) {
mIitc.setFocusedDialog(id); mIitc.setFocusedDialog(id);
} }
@JavascriptInterface @JavascriptInterface
public void dialogOpened(String id, boolean open) { public void dialogOpened(final String id, final boolean open) {
mIitc.dialogOpened(id, open); mIitc.dialogOpened(id, open);
} }
@ -190,9 +189,9 @@ public class IITC_JSInterface {
@JavascriptInterface @JavascriptInterface
public boolean showZoom() { public boolean showZoom() {
PackageManager pm = mIitc.getPackageManager(); final PackageManager pm = mIitc.getPackageManager();
boolean hasMultitouch = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); final boolean hasMultitouch = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
boolean forcedZoom = mIitc.getPrefs().getBoolean("pref_user_zoom", false); final boolean forcedZoom = mIitc.getPrefs().getBoolean("pref_user_zoom", false);
return forcedZoom || !hasMultitouch; return forcedZoom || !hasMultitouch;
} }
@ -228,4 +227,9 @@ public class IITC_JSInterface {
public String getFileRequestUrlPrefix() { public String getFileRequestUrlPrefix() {
return mIitc.getFileManager().getFileRequestPrefix(); return mIitc.getFileManager().getFileRequestPrefix();
} }
@JavascriptInterface
public void setPermalink(final String href) {
mIitc.setPermalink(href);
}
} }

View File

@ -14,6 +14,10 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -44,7 +48,8 @@ import java.net.URISyntaxException;
import java.util.Stack; import java.util.Stack;
import java.util.Vector; import java.util.Vector;
public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener { public class IITC_Mobile extends Activity
implements OnSharedPreferenceChangeListener, NfcAdapter.CreateNdefMessageCallback {
private static final String mIntelUrl = "https://www.ingress.com/intel"; private static final String mIntelUrl = "https://www.ingress.com/intel";
private SharedPreferences mSharedPrefs; private SharedPreferences mSharedPrefs;
@ -68,6 +73,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
private boolean mIsLoading = true; private boolean mIsLoading = true;
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;
// 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>();
@ -142,6 +148,9 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
// afterwards install iitc update // afterwards install iitc update
registerReceiver(mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); registerReceiver(mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
final NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
if (nfc != null) nfc.setNdefPushMessageCallback(this, this);
handleIntent(getIntent(), true); handleIntent(getIntent(), true);
} }
@ -187,7 +196,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
private void handleIntent(final Intent intent, final boolean onCreate) { private void handleIntent(final Intent intent, final boolean onCreate) {
// load new iitc web view with ingress intel page // load new iitc web view with ingress intel page
final String action = intent.getAction(); final String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)) { if (Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
final Uri uri = intent.getData(); final Uri uri = intent.getData();
Log.d("intent received url: " + uri.toString()); Log.d("intent received url: " + uri.toString());
@ -777,4 +786,24 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
public interface ResponseHandler { public interface ResponseHandler {
void onActivityResult(int resultCode, Intent data); void onActivityResult(int resultCode, Intent data);
} }
public void setPermalink(final String href) {
mPermalink = href;
}
@Override
public NdefMessage createNdefMessage(final NfcEvent event) {
NdefRecord[] records;
if (mPermalink == null) { // no permalink yet, just provide AAR
records = new NdefRecord[] {
NdefRecord.createApplicationRecord(getPackageName())
};
} else {
records = new NdefRecord[] {
NdefRecord.createUri(mPermalink),
NdefRecord.createApplicationRecord(getPackageName())
};
}
return new NdefMessage(records);
}
} }