Add "save to file" option for screenshots (+ lots of XML formatting)

This commit is contained in:
fkloft
2014-03-01 22:43:26 +01:00
parent 83ead3a358
commit f43cfeb5aa
20 changed files with 113 additions and 67 deletions

View File

@ -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 {

View File

@ -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,6 +137,14 @@ 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)
@ -155,11 +164,29 @@ 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)
/**
* 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, title)
.putExtra(Intent.EXTRA_STREAM, uri));
.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;
}
}

View File

@ -55,7 +55,6 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
private FragmentAdapter mFragmentAdapter;
private IntentGenerator mGenerator;
private SharedPreferences mSharedPrefs = null;
private String mTitle;
private ViewPager mViewPager;
private void addTab(final ArrayList<Intent> intents, final int label, final int icon) {
@ -115,34 +114,33 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
final String type = intent.getStringExtra(EXTRA_TYPE);
// from portallinks/permalinks we build 3 intents (share / geo / vanilla-intel-link)
if (TYPE_PERMALINK.equals(type) || TYPE_PORTAL_LINK.equals(type)) {
mTitle = intent.getStringExtra("title");
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, url),
addTab(mGenerator.getShareIntents(title, url),
R.string.tab_share,
R.drawable.ic_action_share);
addTab(mGenerator.getGeoIntents(mTitle, ll, zoom),
addTab(mGenerator.getGeoIntents(title, ll, zoom),
R.string.tab_map,
R.drawable.ic_action_place);
addTab(mGenerator.getBrowserIntents(mTitle, url),
addTab(mGenerator.getBrowserIntents(title, url),
R.string.tab_browser,
R.drawable.ic_action_web_site);
} else if (TYPE_STRING.equals(type)) {
mTitle = getString(R.string.app_name);
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)) {
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);
addTab(mGenerator.getShareIntents(uri, mime), R.string.tab_share, R.drawable.ic_action_share);
} else {
Log.w("Unknown sharing type: " + type);
setResult(RESULT_CANCELED);