2011-12-13 08:37:41 +01:00
|
|
|
package org.webodf;
|
|
|
|
|
|
2012-06-11 19:26:54 +02:00
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.BufferedOutputStream;
|
2012-06-11 18:32:21 +02:00
|
|
|
import java.io.File;
|
2012-06-11 19:26:54 +02:00
|
|
|
import java.io.FileInputStream;
|
2012-06-11 18:32:21 +02:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
2012-06-11 19:26:54 +02:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
2012-06-11 18:32:21 +02:00
|
|
|
|
2012-06-11 21:00:18 +02:00
|
|
|
import org.apache.cordova.DroidGap;
|
|
|
|
|
|
2012-06-11 18:32:21 +02:00
|
|
|
import android.content.Context;
|
2012-06-11 16:57:21 +02:00
|
|
|
import android.content.Intent;
|
2012-06-11 18:32:21 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.Picture;
|
2012-06-11 16:57:21 +02:00
|
|
|
import android.net.Uri;
|
2011-12-13 08:37:41 +01:00
|
|
|
import android.os.Bundle;
|
2012-06-11 16:57:21 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
|
import android.view.MenuItem;
|
2011-12-13 08:37:41 +01:00
|
|
|
|
|
|
|
|
public class WebODFActivity extends DroidGap {
|
|
|
|
|
|
|
|
|
|
private String path;
|
2012-06-12 17:08:43 +02:00
|
|
|
private ZipReader zipreader;
|
|
|
|
|
|
2011-12-13 08:37:41 +01:00
|
|
|
/** Called when the activity is first created. */
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
path = null;
|
|
|
|
|
if (getIntent() != null && getIntent().getData() != null) {
|
|
|
|
|
path = getIntent().getData().getPath();
|
|
|
|
|
}
|
|
|
|
|
setContentView(R.layout.main);
|
|
|
|
|
super.loadUrl("file:///android_asset/www/index.html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
2012-06-12 17:08:43 +02:00
|
|
|
zipreader = new ZipReader(appView);
|
|
|
|
|
appView.addJavascriptInterface(zipreader, "zipreader");
|
2011-12-13 08:37:41 +01:00
|
|
|
if (path == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String escapedPath = "file://" + path.replace("'", "\\'");
|
|
|
|
|
sendJavascript("invokeString = '" + escapedPath + "';");
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 16:57:21 +02:00
|
|
|
@Override
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
|
inflater.inflate(R.menu.main, menu);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
// Handle item selection
|
|
|
|
|
switch (item.getItemId()) {
|
2012-06-11 18:32:21 +02:00
|
|
|
case R.id.report_issue:
|
2012-06-11 16:57:21 +02:00
|
|
|
reportIssue();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.about:
|
|
|
|
|
about();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.visit_website:
|
|
|
|
|
visitWebODFWebsite();
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void visitWebODFWebsite() {
|
|
|
|
|
String url = "http://webodf.org/";
|
|
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
i.setData(Uri.parse(url));
|
|
|
|
|
startActivity(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void about() {
|
|
|
|
|
String url = "http://webodf.org/about/";
|
|
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
i.setData(Uri.parse(url));
|
|
|
|
|
startActivity(i);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 19:26:54 +02:00
|
|
|
private File takeScreenShot() {
|
2012-06-11 18:32:21 +02:00
|
|
|
Picture screenshot = appView.capturePicture();
|
|
|
|
|
Bitmap bitmap = Bitmap.createBitmap(screenshot.getWidth(),
|
|
|
|
|
screenshot.getHeight(), Bitmap.Config.ARGB_8888);
|
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
|
screenshot.draw(canvas);
|
|
|
|
|
screenshot = null;
|
|
|
|
|
String filename = "screenshot.png";
|
|
|
|
|
try {
|
|
|
|
|
FileOutputStream out = openFileOutput(filename,
|
|
|
|
|
Context.MODE_WORLD_READABLE);
|
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
} catch (IOException e) {
|
2012-06-11 19:26:54 +02:00
|
|
|
return null;
|
2012-06-11 18:32:21 +02:00
|
|
|
}
|
2012-06-11 19:26:54 +02:00
|
|
|
return new File(getFilesDir(), filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Uri getApplicationFileUri(String filename) {
|
|
|
|
|
// start path from /mnt/sdcard to make gmail mail client work
|
|
|
|
|
return Uri.fromFile(new File("/mnt/sdcard/../.." + getFilesDir() + "/"
|
|
|
|
|
+ filename));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File createZip(File files[]) {
|
|
|
|
|
final int buffersize = 2048;
|
|
|
|
|
String zipfile = "issuereport.zip";
|
|
|
|
|
try {
|
|
|
|
|
BufferedInputStream origin = null;
|
|
|
|
|
FileOutputStream dest = openFileOutput(zipfile,
|
|
|
|
|
Context.MODE_WORLD_READABLE);
|
|
|
|
|
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
|
|
|
|
|
dest));
|
|
|
|
|
byte data[] = new byte[buffersize];
|
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
|
FileInputStream fi = new FileInputStream(files[i]);
|
|
|
|
|
origin = new BufferedInputStream(fi, buffersize);
|
|
|
|
|
ZipEntry entry = new ZipEntry(files[i].getName());
|
|
|
|
|
out.putNextEntry(entry);
|
|
|
|
|
int count;
|
|
|
|
|
while ((count = origin.read(data, 0, buffersize)) != -1) {
|
|
|
|
|
out.write(data, 0, count);
|
|
|
|
|
}
|
|
|
|
|
origin.close();
|
|
|
|
|
}
|
|
|
|
|
out.close();
|
|
|
|
|
dest.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new File(getFilesDir(), zipfile);
|
2012-06-11 16:57:21 +02:00
|
|
|
}
|
2012-06-11 18:32:21 +02:00
|
|
|
|
|
|
|
|
private void reportIssue() {
|
2012-06-11 19:26:54 +02:00
|
|
|
File screenshotfile = takeScreenShot();
|
2012-06-12 22:50:03 +02:00
|
|
|
File odffile = (path == null) ?null :new File(path);
|
2012-06-11 19:26:54 +02:00
|
|
|
File attachmentfile = null;
|
|
|
|
|
String type = "text/plain";
|
|
|
|
|
if (screenshotfile != null) {
|
|
|
|
|
if (odffile != null) {
|
|
|
|
|
type = "application/zip";
|
|
|
|
|
attachmentfile = createZip(new File[] { screenshotfile });
|
|
|
|
|
} else {
|
|
|
|
|
type = "image/png";
|
|
|
|
|
attachmentfile = screenshotfile;
|
|
|
|
|
}
|
|
|
|
|
} else if (odffile != null) {
|
|
|
|
|
attachmentfile = odffile;
|
|
|
|
|
type = "application/vnd.oasis.opendocument.text";
|
|
|
|
|
}
|
2012-06-11 18:32:21 +02:00
|
|
|
|
|
|
|
|
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
|
|
|
|
|
String aEmailList[] = { "WebODF <kogmbh-android@kogmbh.com>",
|
|
|
|
|
"jos@vandenoever.info" };
|
|
|
|
|
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
|
|
|
|
|
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
|
|
|
|
|
"Issue report");
|
2012-06-11 19:26:54 +02:00
|
|
|
|
|
|
|
|
if (attachmentfile != null) {
|
|
|
|
|
// start path from /mnt/sdcard to make gmail mail client work
|
|
|
|
|
Uri uri = Uri.fromFile(new File("/mnt/sdcard/../.."
|
|
|
|
|
+ attachmentfile.getAbsolutePath()));
|
|
|
|
|
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
|
|
|
|
}
|
|
|
|
|
emailIntent.setType(type);
|
2012-06-11 18:32:21 +02:00
|
|
|
emailIntent.putExtra(Intent.EXTRA_TEXT, "My message body.");
|
|
|
|
|
startActivity(emailIntent);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 19:26:54 +02:00
|
|
|
}
|