Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
@ -80,8 +80,8 @@
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
|
||||
<data android:mimeType="application/x-javascript" />
|
||||
<data android:mimeType="text/javascript" />
|
||||
<data android:mimeType="application/x-javascript"/>
|
||||
<data android:mimeType="text/javascript"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
@ -92,23 +92,20 @@
|
||||
|
||||
<data
|
||||
android:host="*"
|
||||
android:scheme="file"
|
||||
android:pathPattern=".*\\.user.js"/>
|
||||
|
||||
android:pathPattern=".*\\.user.js"
|
||||
android:scheme="file"/>
|
||||
<data
|
||||
android:host="*"
|
||||
android:scheme="content"
|
||||
android:pathPattern=".*\\.user.js"/>
|
||||
|
||||
android:pathPattern=".*\\.user.js"
|
||||
android:scheme="content"/>
|
||||
<data
|
||||
android:host="*"
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*\\.user.js"/>
|
||||
|
||||
android:pathPattern=".*\\.user.js"
|
||||
android:scheme="http"/>
|
||||
<data
|
||||
android:host="*"
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*\\.user.js"/>
|
||||
android:pathPattern=".*\\.user.js"
|
||||
android:scheme="https"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Points to searchable meta data. -->
|
||||
@ -149,6 +146,15 @@
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.cradle.iitc_mobile.share.SaveToFile"
|
||||
android:enabled="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:exported="false"
|
||||
android:icon="@drawable/ic_action_save"
|
||||
android:label="@string/activity_save_to_file"
|
||||
android:noHistory="false"
|
||||
android:theme="@android:style/Theme.Holo.Dialog"/>
|
||||
|
||||
<!-- START Used for Samsung Multi-Window support -->
|
||||
<uses-library
|
||||
|
BIN
mobile/res/drawable-hdpi/ic_action_save.png
Normal file
BIN
mobile/res/drawable-hdpi/ic_action_save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 394 B |
BIN
mobile/res/drawable-mdpi/ic_action_save.png
Normal file
BIN
mobile/res/drawable-mdpi/ic_action_save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 362 B |
BIN
mobile/res/drawable-xhdpi/ic_action_save.png
Normal file
BIN
mobile/res/drawable-xhdpi/ic_action_save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 441 B |
BIN
mobile/res/drawable-xxhdpi/ic_action_save.png
Normal file
BIN
mobile/res/drawable-xxhdpi/ic_action_save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 495 B |
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"/>
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ShareActivity"/>
|
||||
|
@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/progressBarLoading"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:id="@+id/progressBarLoading"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"/>
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -7,7 +6,7 @@
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="48dp"
|
||||
android:paddingRight="?android:attr/scrollbarSize" >
|
||||
android:paddingRight="?android:attr/scrollbarSize">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dip"
|
||||
@ -16,7 +15,7 @@
|
||||
android:layout_marginLeft="6dip"
|
||||
android:layout_marginRight="6dip"
|
||||
android:layout_marginTop="6dip"
|
||||
android:layout_weight="1" >
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/plug_pref_title"
|
||||
@ -25,7 +24,7 @@
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/plug_pref_summary"
|
||||
@ -34,7 +33,7 @@
|
||||
android:layout_below="@android:id/title"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
@ -36,6 +37,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"
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
@ -8,7 +9,10 @@
|
||||
<dimen name="app_minimumsize_w">400dip</dimen>
|
||||
<dimen name="app_minimumsize_h">200dip</dimen>
|
||||
|
||||
<!-- margin around app icons in share activity -->
|
||||
<dimen name="icon_margin">8dp</dimen>
|
||||
|
||||
<!-- button size for debug views -->
|
||||
<dimen name="button_size">36dp</dimen>
|
||||
|
||||
</resources>
|
@ -8,6 +8,7 @@
|
||||
<string name="activity_plugins">IITC Plugins</string>
|
||||
<string name="activity_share">Share using…</string>
|
||||
<string name="activity_share_to_clipboard">Copy to clipboard</string>
|
||||
<string name="activity_save_to_file">Save to file</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="drawer_open">Show navigation menu</string>
|
||||
<string name="drawer_close">Hide navigation menu</string>
|
||||
@ -161,6 +162,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>
|
||||
@ -184,4 +186,4 @@
|
||||
Are you sure you want to proceed?]]>
|
||||
</string>
|
||||
|
||||
</resources>
|
||||
</resources>
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
@ -19,6 +20,4 @@
|
||||
|
||||
<color name="drawer_background">#99111111</color>
|
||||
|
||||
<dimen name="button_size">36dp</dimen>
|
||||
|
||||
</resources>
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PreferenceScreen>
|
||||
<!-- empty...we will build the prefs in PluginsFragment -->
|
||||
|
||||
<!-- empty...we will build the prefs in PluginsFragment -->
|
||||
|
||||
</PreferenceScreen>
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_ui_cat"
|
||||
android:title="@string/pref_ui_cat">
|
||||
@ -36,8 +37,8 @@
|
||||
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
||||
android:key="pref_plugins"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_plugins"
|
||||
android:summary="@string/pref_plugins_sum">
|
||||
android:summary="@string/pref_plugins_sum"
|
||||
android:title="@string/pref_plugins">
|
||||
<intent
|
||||
android:targetClass="com.cradle.iitc_mobile.IITC_PluginPreferenceActivity"
|
||||
android:targetPackage="com.cradle.iitc_mobile"/>
|
||||
@ -60,18 +61,19 @@
|
||||
android:title="@string/pref_press_twice_to_exit"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_mics"
|
||||
android:title="@string/pref_misc_cat">
|
||||
android:key="pref_mics"
|
||||
android:title="@string/pref_misc_cat">
|
||||
<PreferenceScreen
|
||||
android:key="pref_developer_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_advanced_options"
|
||||
android:summary="@string/pref_advanced_options_sum">
|
||||
android:summary="@string/pref_advanced_options_sum"
|
||||
android:title="@string/pref_advanced_options">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_dev_checkbox"
|
||||
android:summary="@string/pref_enable_dev_mode_sum"
|
||||
android:title="@string/pref_enable_dev_mode"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_advanced_ui_cat"
|
||||
android:title="@string/pref_ui_cat">
|
||||
@ -106,4 +108,4 @@
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_name"
|
||||
android:hint="@string/search_hint"
|
||||
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
|
||||
android:voiceLanguageModel="web_search"
|
||||
android:voiceMaxResults="1">
|
||||
</searchable>
|
||||
android:hint="@string/search_hint"
|
||||
android:label="@string/app_name"
|
||||
android:voiceLanguageModel="web_search"
|
||||
android:voiceMaxResults="1"
|
||||
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"/>
|
||||
|
@ -63,8 +63,7 @@ public class IITC_FileManager {
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copyStream(final InputStream inStream, final OutputStream outStream, final boolean closeOutput)
|
||||
throws IOException
|
||||
{
|
||||
throws IOException {
|
||||
// in case Android includes Apache commons IO in the future, this function should be replaced by IOUtils.copy
|
||||
final int bufferSize = 4096;
|
||||
final byte[] buffer = new byte[bufferSize];
|
||||
@ -94,20 +93,20 @@ public class IITC_FileManager {
|
||||
map.put("name", "unknown");
|
||||
map.put("description", "");
|
||||
map.put("category", "Misc");
|
||||
BufferedReader reader = new BufferedReader(new StringReader(header));
|
||||
final BufferedReader reader = new BufferedReader(new StringReader(header));
|
||||
String headerLine;
|
||||
try {
|
||||
while ((headerLine = reader.readLine()) != null) {
|
||||
if (headerLine.matches("//.*@.*")) {
|
||||
// get start of key name (first @ in line)
|
||||
String[] keyStart = headerLine.split("@", 2);
|
||||
final String[] keyStart = headerLine.split("@", 2);
|
||||
// split key value
|
||||
String[] keyValue = keyStart[1].split(" ", 2);
|
||||
final String[] keyValue = keyStart[1].split(" ", 2);
|
||||
// remove whitespaces from string begin and end and push to map
|
||||
map.put(keyValue[0].trim(), keyValue[1].trim());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
}
|
||||
return map;
|
||||
@ -279,7 +278,7 @@ public class IITC_FileManager {
|
||||
InputStream is;
|
||||
String fileName;
|
||||
if (uri.getScheme().contains("http")) {
|
||||
URLConnection conn = new URL(url).openConnection();
|
||||
final URLConnection conn = new URL(url).openConnection();
|
||||
is = conn.getInputStream();
|
||||
fileName = uri.getLastPathSegment();
|
||||
} else {
|
||||
@ -335,7 +334,7 @@ public class IITC_FileManager {
|
||||
|
||||
// create the chooser Intent
|
||||
final Intent target = new Intent(Intent.ACTION_GET_CONTENT)
|
||||
.setType("*/*")
|
||||
.setType("file/*")
|
||||
.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
final IITC_Mobile iitc = (IITC_Mobile) mActivity;
|
||||
|
||||
|
@ -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,40 @@ public class IITC_Mobile extends Activity
|
||||
mPermalink = href;
|
||||
}
|
||||
|
||||
private void sendScreenshot() {
|
||||
Bitmap bitmap = mIitcWebView.getDrawingCache();
|
||||
if (bitmap == null) {
|
||||
mIitcWebView.buildDrawingCache();
|
||||
bitmap = mIitcWebView.getDrawingCache();
|
||||
if (bitmap == null) {
|
||||
Log.e("could not get bitmap!");
|
||||
return;
|
||||
}
|
||||
bitmap = Bitmap.createBitmap(bitmap);
|
||||
if (!mIitcWebView.isDrawingCacheEnabled()) mIitcWebView.destroyDrawingCache();
|
||||
}
|
||||
else {
|
||||
bitmap = Bitmap.createBitmap(bitmap);
|
||||
}
|
||||
|
||||
try {
|
||||
final File cache = getExternalCacheDir();
|
||||
final File file = File.createTempFile("IITC screenshot", ".png", cache);
|
||||
if (!bitmap.compress(CompressFormat.PNG, 100, new FileOutputStream(file))) {
|
||||
// quality is ignored by PNG
|
||||
throw new IOException("Could not compress bitmap!");
|
||||
}
|
||||
startActivityForResult(ShareActivity.forFile(this, file, "image/png"), new ResponseHandler() {
|
||||
@Override
|
||||
public void onActivityResult(final int resultCode, final Intent data) {
|
||||
file.delete();
|
||||
}
|
||||
});
|
||||
} catch (final IOException e) {
|
||||
Log.e("Could not generate screenshot", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NdefMessage createNdefMessage(final NfcEvent event) {
|
||||
NdefRecord[] records;
|
||||
|
@ -7,6 +7,7 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import com.cradle.iitc_mobile.Log;
|
||||
import com.cradle.iitc_mobile.R;
|
||||
@ -136,12 +137,20 @@ public class IntentGenerator {
|
||||
return targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of intents capable of sharing a plain text string
|
||||
*
|
||||
* @param title
|
||||
* description of the shared string
|
||||
* @param text
|
||||
* the string to be shared
|
||||
*/
|
||||
public ArrayList<Intent> getShareIntents(final String title, final String text) {
|
||||
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 +163,30 @@ public class IntentGenerator {
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of intents capable of sharing the given content
|
||||
*
|
||||
* @param uri
|
||||
* URI of a file to share
|
||||
* @param type
|
||||
* MIME type of the file
|
||||
*/
|
||||
public ArrayList<Intent> getShareIntents(final Uri uri, final String type) {
|
||||
final Intent intent = new Intent(Intent.ACTION_SEND)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
|
||||
.setType(type)
|
||||
.putExtra(Intent.EXTRA_SUBJECT, uri.getLastPathSegment())
|
||||
.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
|
||||
final ArrayList<Intent> targets = resolveTargets(intent);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
targets.add(new Intent(intent)
|
||||
.setComponent(new ComponentName(mContext, SaveToFile.class))
|
||||
.putExtra(EXTRA_FLAG_TITLE, mContext.getString(R.string.activity_save_to_file)));
|
||||
}
|
||||
|
||||
return targets;
|
||||
}
|
||||
}
|
||||
|
97
mobile/src/com/cradle/iitc_mobile/share/SaveToFile.java
Normal file
97
mobile/src/com/cradle/iitc_mobile/share/SaveToFile.java
Normal file
@ -0,0 +1,97 @@
|
||||
package com.cradle.iitc_mobile.share;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.view.Window;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_FileManager;
|
||||
import com.cradle.iitc_mobile.Log;
|
||||
import com.cradle.iitc_mobile.R;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@TargetApi(19)
|
||||
public class SaveToFile extends Activity implements Runnable {
|
||||
private static final int REQUEST_SAVE_FILE = 1;
|
||||
private Uri mData;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||
if (requestCode == REQUEST_SAVE_FILE) {
|
||||
mData = data.getData();
|
||||
if (resultCode != Activity.RESULT_OK || mData == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
(new Thread(this)).start();
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
setProgressBarIndeterminate(true);
|
||||
setProgressBarIndeterminateVisibility(true);
|
||||
|
||||
setContentView(R.layout.dialog_progressbar);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (!(intent.hasExtra(Intent.EXTRA_STREAM) || intent.hasExtra(Intent.EXTRA_TEXT))) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
String filename = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
||||
final Uri src = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (src.getLastPathSegment() != null) filename = src.getLastPathSegment();
|
||||
}
|
||||
|
||||
final Intent request = new Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||
.setType(intent.getType())
|
||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
.putExtra(Intent.EXTRA_TITLE, filename);
|
||||
startActivityForResult(request, REQUEST_SAVE_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Intent intent = getIntent();
|
||||
if (mData == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final ParcelFileDescriptor fdOut = getContentResolver().openFileDescriptor(mData, "w");
|
||||
final FileOutputStream os = new FileOutputStream(fdOut.getFileDescriptor());
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
||||
final Uri src = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
final ParcelFileDescriptor fdIn = getContentResolver().openFileDescriptor(src, "r");
|
||||
final FileInputStream is = new FileInputStream(fdIn.getFileDescriptor());
|
||||
IITC_FileManager.copyStream(is, os, true);
|
||||
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||
os.write(intent.getStringExtra(Intent.EXTRA_TEXT).getBytes());
|
||||
os.close();
|
||||
}
|
||||
fdOut.close();
|
||||
} catch (final IOException e) {
|
||||
Log.w("Could not save file!", e);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
@ -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 int REQUEST_START_INTENT = 1;
|
||||
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;
|
||||
}
|
||||
@ -54,6 +85,18 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
|
||||
.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||
if (REQUEST_START_INTENT == requestCode) {
|
||||
setResult(resultCode, data);
|
||||
// parent activity can now clean up
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -68,29 +111,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)) {
|
||||
mTitle = intent.getStringExtra("title");
|
||||
mLl = intent.getDoubleExtra("lat", 0) + "," + intent.getDoubleExtra("lng", 0);
|
||||
mZoom = intent.getIntExtra("zoom", 0);
|
||||
mIsPortal = intent.getBooleanExtra("isPortal", false);
|
||||
if (TYPE_PERMALINK.equals(type) || TYPE_PORTAL_LINK.equals(type)) {
|
||||
final String title = intent.getStringExtra("title");
|
||||
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);
|
||||
actionBar.setTitle(title);
|
||||
|
||||
addTab(mGenerator.getShareIntents(mTitle, getIntelUrl()),
|
||||
addTab(mGenerator.getShareIntents(title, url),
|
||||
R.string.tab_share,
|
||||
R.drawable.ic_action_share);
|
||||
addTab(mGenerator.getGeoIntents(mTitle, mLl, mZoom),
|
||||
addTab(mGenerator.getGeoIntents(title, ll, zoom),
|
||||
R.string.tab_map,
|
||||
R.drawable.ic_action_place);
|
||||
addTab(mGenerator.getBrowserIntents(mTitle, getIntelUrl()),
|
||||
addTab(mGenerator.getBrowserIntents(title, url),
|
||||
R.string.tab_browser,
|
||||
R.drawable.ic_action_web_site);
|
||||
} else {
|
||||
mTitle = getString(R.string.app_name);
|
||||
} else if (TYPE_STRING.equals(type)) {
|
||||
final String title = 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);
|
||||
addTab(mGenerator.getShareIntents(title, shareString), R.string.tab_share, R.drawable.ic_action_share);
|
||||
} else if (TYPE_FILE.equals(type)) {
|
||||
|
||||
final Uri uri = intent.getParcelableExtra("uri");
|
||||
final String mime = intent.getStringExtra("type");
|
||||
|
||||
addTab(mGenerator.getShareIntents(uri, mime), R.string.tab_share, R.drawable.ic_action_share);
|
||||
} else {
|
||||
Log.w("Unknown sharing type: " + type);
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
@ -143,8 +198,9 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
|
||||
public void launch(final Intent intent) {
|
||||
mComparator.trackIntentSelection(intent);
|
||||
mGenerator.cleanup(intent);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
|
||||
// we should wait for the new intent to be finished so the calling activity (IITC_Mobile) can clean up
|
||||
startActivityForResult(intent, REQUEST_START_INTENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user