diff --git a/code/smartphone.js b/code/smartphone.js index c9133aab..d39b6a03 100644 --- a/code/smartphone.js +++ b/code/smartphone.js @@ -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 = $('').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()); diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 47e1ad36..74eeaef1 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -16,6 +16,7 @@ --> + mDialogStack = new Stack(); + private String mPermalink = null; // Used for custom back stack handling private final Stack mBackStack = new Stack(); @@ -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())); + } }