Merge branch 'intents' of git://github.com/fkloft/ingress-intel-total-conversion into fkloft-intents

Conflicts:
	mobile/res/values/strings.xml
This commit is contained in:
Philipp Schaefer 2013-07-27 11:23:51 +02:00
commit ab164cfde5
24 changed files with 547 additions and 29 deletions

View File

@ -52,7 +52,6 @@ window.renderPortalDetails = function(guid) {
var poslinks = 'window.showPortalPosLinks('+lat+','+lng+',\''+escapeJavascriptString(d.portalV2.descriptiveText.TITLE)+'\')';
var portalDetailObj = window.getPortalDescriptionFromDetailsExtended(d);
var portalDetailedDescription = '';
if(portalDetailObj) {
@ -101,8 +100,12 @@ window.renderPortalDetails = function(guid) {
+ randDetails
+ resoDetails
+ '<div class="linkdetails">'
+ '<aside><a href="'+perma+'" onclick="return androidCopy(this.href)" title="Create a URL link to this portal" >Portal link</a></aside>'
+ (
typeof android !== 'undefined' && android && android.intentPosLink // Android handles both links via a dialog
? '<aside><a onclick="'+poslinks+'" title="Create a URL link to this portal" >Portal link</a></aside>'
: '<aside><a href="'+perma+'" onclick="return androidCopy(this.href)" title="Create a URL link to this portal" >Portal link</a></aside>'
+ '<aside><a onclick="'+poslinks+'" title="Link to alternative maps (Google, etc)">Map links</a></aside>'
)
+ '<aside><a onclick="window.reportPortalIssue()" title="Report issues with this portal to Niantic/Google">Report issue</a></aside>'
+ '</div>'
);

View File

@ -176,7 +176,7 @@ window.showPortalPosLinks = function(lat, lng, name) {
}
if (typeof android !== 'undefined' && android && android.intentPosLink) {
android.intentPosLink(lat, lng, encoded_name);
android.intentPosLink(lat, lng, map.getZoom(), name, true);
} else {
var qrcode = '<div id="qrcode"></div>';
var script = '<script>$(\'#qrcode\').qrcode({text:\'GEO:'+lat+','+lng+'\'});</script>';
@ -200,6 +200,15 @@ window.androidCopy = function(text) {
return false;
}
window.androidPermalink = function() {
if(typeof android === 'undefined' || !android || !android.copy)
return true; // i.e. execute other actions
var center = map.getCenter();
android.intentPosLink(center.lat, center.lng, map.getZoom(), "Intel Map", false);
return false;
}
window.reportPortalIssue = function(info) {
var t = 'Redirecting you to a Google Help Page.\n\nThe text box contains all necessary information. Press CTRL+C to copy it.';
var d = window.portals[window.selectedPortal].options.details;

View File

@ -96,7 +96,7 @@ document.getElementsByTagName('body')[0].innerHTML = ''
// redeeming removed from stock site, so commented out for now. it may return...
// + ' <input id="redeem" placeholder="Redeem code…" type="text"/>'
+ ' <div id="toolbox">'
+ ' <a onmouseover="setPermaLink(this)" onclick="setPermaLink(this);return androidCopy(this.href)" title="URL link to this map view">Permalink</a>'
+ ' <a onmouseover="setPermaLink(this)" onclick="setPermaLink(this);return androidPermalink()" title="URL link to this map view">Permalink</a>'
+ ' <a onclick="window.aboutIITC()" style="cursor: help">About IITC</a>'
+ ' </div>'
+ ' </div>'

View File

@ -50,22 +50,58 @@
<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" />
</activity>
<activity
android:name="com.cradle.iitc_mobile.IITC_Settings"
android:theme="@style/AppBaseTheme"
android:label="@string/app_name"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize">
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"/>
<activity
android:name=".share.ShareActivity"
android:label="@string/app_name"
android:noHistory="true"
android:parentActivityName="com.cradle.iitc_mobile.IITC_Mobile"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.cradle.iitc_mobile.IITC_Mobile"/>
</activity>
<activity
android:name=".share.SendToClipboard"
android:enabled="true"
android:excludeFromRecents="true"
android:exported="false"
android:label="Copy to clipboard"
android:noHistory="false">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<!-- START Used for Samsung Multi-Window support -->
@ -76,7 +112,6 @@
<meta-data
android:name="com.sec.android.support.multiwindow"
android:value="true"/>
<meta-data
android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W"
android:resource="@dimen/app_defaultsize_w"/>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,6 @@
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ShareActivity"/>

View File

@ -8,4 +8,6 @@
<dimen name="app_minimumsize_w">400dip</dimen>
<dimen name="app_minimumsize_h">200dip</dimen>
<dimen name="icon_margin">8dp</dimen>
</resources>

View File

@ -61,8 +61,14 @@
<string name="menu_faction">Faction</string>
<string name="menu_info">Info</string>
<string name="menu_debug">Debug</string>
<string name="menu_search">Search</string>
<string name="choose_account_to_login">Choose account to login</string>
<string name="login_failed">Login failed.</string>
<string name="search_hint">Search Locations</string>
<string name="menu_search">Search</string>
<string name="intent_error">Address could not be opened</string>
<string name="msg_copied">Copied to clipboard…</string>
<string name="tab_map">Map</string>
<string name="tab_share">Share</string>
<string name="tab_browser">Browser</string>
</resources>

View File

@ -1,5 +1,10 @@
package com.cradle.iitc_mobile;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
@ -8,16 +13,12 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.HashMap;
import com.cradle.iitc_mobile.share.ShareActivity;
// provide communication between IITC script and android app
public class IITC_JSInterface {
@ -36,12 +37,15 @@ public class IITC_JSInterface {
context = c;
}
// 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
public void intentPosLink(String lat, String lng, String portal_name) {
String uri = "geo:" + lat + "," + lng + "?q=" + lat + "," + lng;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(uri));
public void intentPosLink(double lat, double lng, int zoom, String title, boolean isPortal) {
Intent intent = new Intent(context, ShareActivity.class);
intent.putExtra("lat", lat);
intent.putExtra("lng", lng);
intent.putExtra("zoom", zoom);
intent.putExtra("title", title);
intent.putExtra("isPortal", isPortal);
context.startActivity(intent);
}

View File

@ -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;
@ -31,6 +32,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 {
@ -170,13 +172,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", "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(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(R.string.intent_error)
.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 =
@ -186,11 +214,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();

View File

@ -0,0 +1,59 @@
package com.cradle.iitc_mobile.share;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
public class IntentFragment extends Fragment implements OnScrollListener, OnItemClickListener {
private Intent mIntent;
private IntentListView mListView;
private int mScrollIndex, mScrollTop;
public int getIcon() {
return getArguments().getInt("icon");
}
public String getTitle() {
return getArguments().getString("title");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle args = getArguments();
mIntent = args.getParcelable("intent");
mListView = new IntentListView(getActivity());
mListView.setIntent(mIntent);
if (mScrollIndex != -1 && mScrollTop != -1)
mListView.setSelectionFromTop(mScrollIndex, mScrollTop);
mListView.setOnScrollListener(this);
mListView.setOnItemClickListener(this);
return mListView;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = mListView.getTargetIntent(position);
startActivity(intent);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mScrollIndex = mListView.getFirstVisiblePosition();
View v = mListView.getChildAt(0);
mScrollTop = (v == null) ? 0 : v.getTop();
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}

View File

@ -0,0 +1,37 @@
package com.cradle.iitc_mobile.share;
import java.util.ArrayList;
import java.util.List;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class IntentFragmentAdapter extends FragmentPagerAdapter {
private List<IntentFragment> mTabs;
public IntentFragmentAdapter(FragmentManager fm) {
super(fm);
mTabs = new ArrayList<IntentFragment>();
}
public void add(IntentFragment fragment) {
mTabs.add(fragment);
}
@Override
public int getCount() {
return mTabs.size();
}
@Override
public Fragment getItem(int position) {
return mTabs.get(position);
}
@Override
public CharSequence getPageTitle(int position) {
return mTabs.get(position).getTitle();
}
}

View File

@ -0,0 +1,134 @@
package com.cradle.iitc_mobile.share;
import java.util.List;
import com.cradle.iitc_mobile.R;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class IntentListView extends ListView {
private class IntentAdapter extends ArrayAdapter<ResolveInfo>
{
private IntentAdapter()
{
super(IntentListView.this.getContext(), android.R.layout.simple_list_item_1);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
TextView view = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
ActivityInfo info = getItem(position).activityInfo;
CharSequence label = info.loadLabel(mPackageManager);
Drawable icon = info.loadIcon(mPackageManager);
view.setText(label);
view.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.icon_margin));
view.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null);
return view;
}
}
private IntentAdapter mAdapter;
private PackageManager mPackageManager;
private Intent mIntent = null;
public IntentListView(Context context) {
super(context);
init();
}
public IntentListView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public IntentListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mPackageManager = getContext().getPackageManager();
mAdapter = new IntentAdapter();
setAdapter(mAdapter);
}
public ResolveInfo getItem(int position) {
return mAdapter.getItem(position);
}
public void setIntent(Intent intent)
{
mIntent = intent;
mAdapter.setNotifyOnChange(false);
mAdapter.clear();
String packageName = getContext().getPackageName();
List<ResolveInfo> activities = mPackageManager.queryIntentActivities(intent, 0);
ResolveInfo defaultTarget = mPackageManager.resolveActivity(intent, 0);
boolean hasCopyIntent = false;
for (ResolveInfo resolveInfo : activities) { // search for "Copy to clipboard" target, provided by Drive
if (resolveInfo.activityInfo.name.equals("com.google.android.apps.docs.app.SendTextToClipboardActivity")
&& resolveInfo.activityInfo.packageName.equals("com.google.android.apps.docs"))
hasCopyIntent = true;
}
for (int i = 0; i < activities.size(); i++) { // use traditional loop since List may change during interation
ResolveInfo info = activities.get(i);
ActivityInfo activity = info.activityInfo;
// remove all IITCm intents, except for SendToClipboard in case Drive is not installed
if (activity.packageName.equals(packageName))
{
if (hasCopyIntent || !activity.name.equals(SendToClipboard.class.getCanonicalName()))
{
activities.remove(i);
i--;
continue;
}
}
// move default Intent to top
if (info.activityInfo.packageName.equals(defaultTarget.activityInfo.packageName)
&& info.activityInfo.name.equals(defaultTarget.activityInfo.name))
{
activities.remove(i);
activities.add(0, info);
}
}
mAdapter.addAll(activities);
mAdapter.setNotifyOnChange(true);
mAdapter.notifyDataSetChanged();
}
public Intent getTargetIntent(int position) {
ActivityInfo activity = mAdapter.getItem(position).activityInfo;
Intent intent = new Intent(mIntent)
.setComponent(new ComponentName(activity.packageName, activity.name))
.setPackage(activity.packageName);
return intent;
}
}

View File

@ -0,0 +1,29 @@
package com.cradle.iitc_mobile.share;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.cradle.iitc_mobile.R;
public class SendToClipboard extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Copied Text ", text);
clipboard.setPrimaryClip(clip);
Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show();
finish();
setResult(RESULT_OK);
}
}

View File

@ -0,0 +1,118 @@
package com.cradle.iitc_mobile.share;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;
import com.cradle.iitc_mobile.R;
public class ShareActivity extends FragmentActivity implements ActionBar.TabListener {
private boolean mIsPortal;
private String mLl;
private String mTitle;
private int mZoom;
IntentFragmentAdapter mFragmentAdapter;
ViewPager mViewPager;
private void addTab(Intent intent, int label, int icon)
{
IntentFragment fragment = new IntentFragment();
Bundle args = new Bundle();
args.putParcelable("intent", intent);
args.putString("title", getString(label));
args.putInt("icon", icon);
fragment.setArguments(args);
mFragmentAdapter.add(fragment);
}
private String getUrl() {
String url = "http://www.ingress.com/intel?ll=" + mLl + "&z=" + mZoom;
if (mIsPortal)
url += "&pll=" + mLl;
return url;
}
private void setupIntents() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, getUrl());
intent.putExtra(Intent.EXTRA_SUBJECT, mTitle);
addTab(intent, R.string.tab_share, R.drawable.share);
String geoUri = "geo:" + mLl;
intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(geoUri));
addTab(intent, R.string.tab_map, R.drawable.location_map);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getUrl()));
addTab(intent, R.string.tab_browser, R.drawable.browser);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
Intent intent = getIntent();
mTitle = intent.getStringExtra("title");
mLl = intent.getDoubleExtra("lat", 0) + "," + intent.getDoubleExtra("lng", 0);
mZoom = intent.getIntExtra("zoom", 0);
mIsPortal = intent.getBooleanExtra("isPortal", false);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayHomeAsUpEnabled(true);
mFragmentAdapter = new IntentFragmentAdapter(getSupportFragmentManager());
setupIntents();
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mFragmentAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mFragmentAdapter.getCount(); i++) {
IntentFragment fragment = (IntentFragment) mFragmentAdapter.getItem(i);
actionBar.addTab(actionBar
.newTab()
.setText(fragment.getTitle())
.setIcon(fragment.getIcon())
.setTabListener(this));
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
}