Add Android Beam (NFC) support
This commit is contained in:
parent
6b7525836d
commit
23a092f187
@ -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
|
||||
window.VIEWPORT_PAD_RATIO = 0.1;
|
||||
window.MAX_DRAWN_PORTALS = 500;
|
||||
@ -168,6 +173,24 @@ window.runOnSmartphonesAfterBoot = function() {
|
||||
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() {
|
||||
// isSmartphone is important to disable panes in desktop mode
|
||||
return (typeof android !== 'undefined' && android && android.addPane && window.isSmartphone());
|
||||
|
@ -16,6 +16,7 @@
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.NFC"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
|
@ -227,4 +227,9 @@ public class IITC_JSInterface {
|
||||
public String getFileRequestUrlPrefix() {
|
||||
return mIitc.getFileManager().getFileRequestPrefix();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void setPermalink(final String href) {
|
||||
mIitc.setPermalink(href);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.res.Configuration;
|
||||
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.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -44,7 +48,8 @@ import java.net.URISyntaxException;
|
||||
import java.util.Stack;
|
||||
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 SharedPreferences mSharedPrefs;
|
||||
@ -68,6 +73,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
private boolean mIsLoading = true;
|
||||
private boolean mShowMapInDebug = false;
|
||||
private final Stack<String> mDialogStack = new Stack<String>();
|
||||
private String mPermalink = null;
|
||||
|
||||
// Used for custom back stack handling
|
||||
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
|
||||
registerReceiver(mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||
|
||||
final NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
|
||||
nfc.setNdefPushMessageCallback(this, this);
|
||||
|
||||
handleIntent(getIntent(), true);
|
||||
}
|
||||
|
||||
@ -777,4 +786,19 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
public interface ResponseHandler {
|
||||
void onActivityResult(int resultCode, Intent data);
|
||||
}
|
||||
|
||||
public void setPermalink(final String href) {
|
||||
mPermalink = href;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NdefMessage createNdefMessage(final NfcEvent event) {
|
||||
if (mPermalink == null) { // no permalink yet, just provide AAR
|
||||
return new NdefMessage(NdefRecord.createApplicationRecord(getPackageName()));
|
||||
}
|
||||
|
||||
return new NdefMessage(
|
||||
NdefRecord.createUri(mPermalink),
|
||||
NdefRecord.createApplicationRecord(getPackageName()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user