[IITCm] new feature: share a screenshot of the current view
This commit is contained in:
parent
13893546a4
commit
b30c1e4aa3
@ -36,6 +36,11 @@
|
||||
android:orderInCategory="130"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/menu_clear_cookies"/>
|
||||
<item
|
||||
android:id="@+id/menu_send_screenshot"
|
||||
android:orderInCategory="140"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/menu_send_screenshot"/>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="200"
|
||||
|
@ -161,6 +161,7 @@
|
||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_debug">Debug</string>
|
||||
<string name="menu_send_screenshot">Send screenshot</string>
|
||||
<string name="menu_plugins_add">Add external plugins</string>
|
||||
<string name="choose_account_to_login">Choose account to login</string>
|
||||
<string name="login_failed">Login failed.</string>
|
||||
|
@ -3,7 +3,6 @@ package com.cradle.iitc_mobile;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Environment;
|
||||
@ -30,22 +29,13 @@ public class IITC_JSInterface {
|
||||
@JavascriptInterface
|
||||
public void intentPosLink(
|
||||
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("lng", lng);
|
||||
intent.putExtra("zoom", zoom);
|
||||
intent.putExtra("title", title);
|
||||
intent.putExtra("isPortal", isPortal);
|
||||
mIitc.startActivity(intent);
|
||||
mIitc.startActivity(ShareActivity.forPosition(mIitc, lat, lng, zoom, title, isPortal));
|
||||
}
|
||||
|
||||
// share a string to the IITC share activity. only uses the share tab.
|
||||
@JavascriptInterface
|
||||
public void shareString(final String str) {
|
||||
final Intent intent = new Intent(mIitc, ShareActivity.class);
|
||||
intent.putExtra("shareString", str);
|
||||
intent.putExtra("onlyShare", true);
|
||||
mIitc.startActivity(intent);
|
||||
mIitc.startActivity(ShareActivity.forString(mIitc, str));
|
||||
}
|
||||
|
||||
// disable javascript injection while spinner is enabled
|
||||
|
@ -13,6 +13,8 @@ import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
@ -38,11 +40,13 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
||||
import com.cradle.iitc_mobile.share.ShareActivity;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Stack;
|
||||
@ -571,6 +575,9 @@ public class IITC_Mobile extends Activity
|
||||
final CookieManager cm = CookieManager.getInstance();
|
||||
cm.removeAllCookie();
|
||||
return true;
|
||||
case R.id.menu_send_screenshot:
|
||||
sendScreenshot();
|
||||
return true;
|
||||
case R.id.menu_debug:
|
||||
mDebugging = !mDebugging;
|
||||
updateViews();
|
||||
@ -842,6 +849,26 @@ public class IITC_Mobile extends Activity
|
||||
mPermalink = href;
|
||||
}
|
||||
|
||||
private void sendScreenshot() {
|
||||
mIitcWebView.setDrawingCacheEnabled(true);
|
||||
final Bitmap bitmap = mIitcWebView.getDrawingCache();
|
||||
if (bitmap == null) {
|
||||
Log.e("getDrawingCache() returned null!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final File cache = getExternalCacheDir();
|
||||
final File file = File.createTempFile("IITC screenshot", ".png", cache);
|
||||
if (!Bitmap.createBitmap(bitmap).compress(CompressFormat.PNG, 100, new FileOutputStream(file))) {
|
||||
// quality is ignored by PNG
|
||||
throw new IOException("Could not compress bitmap!");
|
||||
}
|
||||
startActivity(ShareActivity.forFile(this, file, "image/png"));
|
||||
} catch (final IOException e) {
|
||||
Log.e("Could not generate screenshot", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NdefMessage createNdefMessage(final NfcEvent event) {
|
||||
NdefRecord[] records;
|
||||
|
@ -140,8 +140,8 @@ public class IntentGenerator {
|
||||
final Intent intent = new Intent(Intent.ACTION_SEND)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
|
||||
.setType("text/plain")
|
||||
.putExtra(Intent.EXTRA_TEXT, text)
|
||||
.putExtra(Intent.EXTRA_SUBJECT, title);
|
||||
.putExtra(Intent.EXTRA_SUBJECT, title)
|
||||
.putExtra(Intent.EXTRA_TEXT, text);
|
||||
|
||||
final ArrayList<Intent> targets = resolveTargets(intent);
|
||||
|
||||
@ -154,4 +154,12 @@ public class IntentGenerator {
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
public ArrayList<Intent> getShareIntents(final String title, final Uri uri, final String type) {
|
||||
return resolveTargets(new Intent(Intent.ACTION_SEND)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
|
||||
.setType(type)
|
||||
.putExtra(Intent.EXTRA_SUBJECT, title)
|
||||
.putExtra(Intent.EXTRA_STREAM, uri));
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package com.cradle.iitc_mobile.share;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
@ -11,20 +13,49 @@ import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.cradle.iitc_mobile.Log;
|
||||
import com.cradle.iitc_mobile.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ShareActivity extends FragmentActivity implements ActionBar.TabListener {
|
||||
private static final String EXTRA_TYPE = "share-type";
|
||||
private static final String TYPE_FILE = "file";
|
||||
private static final String TYPE_PERMALINK = "permalink";
|
||||
private static final String TYPE_PORTAL_LINK = "portal_link";
|
||||
private static final String TYPE_STRING = "string";
|
||||
|
||||
public static Intent forFile(final Context context, final File file, final String type) {
|
||||
return new Intent(context, ShareActivity.class)
|
||||
.putExtra(EXTRA_TYPE, TYPE_FILE)
|
||||
.putExtra("uri", Uri.fromFile(file))
|
||||
.putExtra("type", type);
|
||||
}
|
||||
|
||||
public static Intent forPosition(final Context context, final double lat, final double lng, final int zoom,
|
||||
final String title, final boolean isPortal) {
|
||||
return new Intent(context, ShareActivity.class)
|
||||
.putExtra(EXTRA_TYPE, isPortal ? TYPE_PORTAL_LINK : TYPE_PERMALINK)
|
||||
.putExtra("lat", lat)
|
||||
.putExtra("lng", lng)
|
||||
.putExtra("zoom", zoom)
|
||||
.putExtra("title", title)
|
||||
.putExtra("isPortal", isPortal);
|
||||
}
|
||||
|
||||
public static Intent forString(final Context context, final String str) {
|
||||
return new Intent(context, ShareActivity.class)
|
||||
.putExtra(EXTRA_TYPE, TYPE_STRING)
|
||||
.putExtra("shareString", str);
|
||||
}
|
||||
|
||||
private IntentComparator mComparator;
|
||||
private FragmentAdapter mFragmentAdapter;
|
||||
private IntentGenerator mGenerator;
|
||||
private boolean mIsPortal;
|
||||
private String mLl;
|
||||
private SharedPreferences mSharedPrefs = null;
|
||||
private String mTitle;
|
||||
private ViewPager mViewPager;
|
||||
private int mZoom;
|
||||
|
||||
private void addTab(final ArrayList<Intent> intents, final int label, final int icon) {
|
||||
final IntentListFragment fragment = new IntentListFragment();
|
||||
@ -36,10 +67,10 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
|
||||
mFragmentAdapter.add(fragment);
|
||||
}
|
||||
|
||||
private String getIntelUrl() {
|
||||
String url = "http://www.ingress.com/intel?ll=" + mLl + "&z=" + mZoom;
|
||||
if (mIsPortal) {
|
||||
url += "&pll=" + mLl;
|
||||
private String getIntelUrl(final String ll, final int zoom, final boolean isPortal) {
|
||||
String url = "http://www.ingress.com/intel?ll=" + ll + "&z=" + zoom;
|
||||
if (isPortal) {
|
||||
url += "&pll=" + ll;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
@ -68,29 +99,41 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final String type = intent.getStringExtra(EXTRA_TYPE);
|
||||
// from portallinks/permalinks we build 3 intents (share / geo / vanilla-intel-link)
|
||||
if (!intent.getBooleanExtra("onlyShare", false)) {
|
||||
if (TYPE_PERMALINK.equals(type) || TYPE_PORTAL_LINK.equals(type)) {
|
||||
mTitle = intent.getStringExtra("title");
|
||||
mLl = intent.getDoubleExtra("lat", 0) + "," + intent.getDoubleExtra("lng", 0);
|
||||
mZoom = intent.getIntExtra("zoom", 0);
|
||||
mIsPortal = intent.getBooleanExtra("isPortal", false);
|
||||
final String ll = intent.getDoubleExtra("lat", 0) + "," + intent.getDoubleExtra("lng", 0);
|
||||
final int zoom = intent.getIntExtra("zoom", 0);
|
||||
final String url = getIntelUrl(ll, zoom, TYPE_PORTAL_LINK.equals(type));
|
||||
|
||||
actionBar.setTitle(mTitle);
|
||||
|
||||
addTab(mGenerator.getShareIntents(mTitle, getIntelUrl()),
|
||||
addTab(mGenerator.getShareIntents(mTitle, url),
|
||||
R.string.tab_share,
|
||||
R.drawable.ic_action_share);
|
||||
addTab(mGenerator.getGeoIntents(mTitle, mLl, mZoom),
|
||||
addTab(mGenerator.getGeoIntents(mTitle, ll, zoom),
|
||||
R.string.tab_map,
|
||||
R.drawable.ic_action_place);
|
||||
addTab(mGenerator.getBrowserIntents(mTitle, getIntelUrl()),
|
||||
addTab(mGenerator.getBrowserIntents(mTitle, url),
|
||||
R.string.tab_browser,
|
||||
R.drawable.ic_action_web_site);
|
||||
} else {
|
||||
} else if (TYPE_STRING.equals(type)) {
|
||||
mTitle = getString(R.string.app_name);
|
||||
final String shareString = intent.getStringExtra("shareString");
|
||||
|
||||
addTab(mGenerator.getShareIntents(mTitle, shareString), R.string.tab_share, R.drawable.ic_action_share);
|
||||
} else if (TYPE_FILE.equals(type)) {
|
||||
mTitle = "Screenshot";
|
||||
|
||||
final Uri uri = intent.getParcelableExtra("uri");
|
||||
final String mime = intent.getStringExtra("type");
|
||||
|
||||
addTab(mGenerator.getShareIntents(mTitle, uri, mime), R.string.tab_share, R.drawable.ic_action_share);
|
||||
} else {
|
||||
Log.w("Unknown sharing type: " + type);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
|
Loading…
x
Reference in New Issue
Block a user