3 import java.io.BufferedWriter;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 import java.io.OutputStream;
9 import java.io.OutputStreamWriter;
10 import java.io.PrintWriter;
11 import java.io.StringWriter;
13 import javax.xml.transform.TransformerException;
14 import javax.xml.transform.stream.StreamResult;
16 import mhr.app.fragments.layers.LayersPaneFragment;
17 import mhr.app.fragments.toolbox.ToolBoxPaneFragment;
18 import mhr.appandroid.adapters.APDBitmap;
19 import mhr.appandroid.displayer.BitmapDisplayer;
20 import mhr.appcore.AppCore;
21 import mhr.appcore.commands.AppCommand;
22 import mhr.appcore.interfaces.PDExceptionFeedback;
24 import android.net.Uri;
25 import android.os.Bundle;
26 import android.provider.MediaStore;
27 import android.app.Activity;
28 import android.app.AlertDialog;
29 import android.app.Fragment;
30 import android.app.FragmentTransaction;
31 import android.content.DialogInterface;
32 import android.content.Intent;
33 import android.database.Cursor;
34 import android.graphics.Bitmap;
35 import android.graphics.BitmapFactory;
36 import android.graphics.Canvas;
37 import android.util.Log;
38 import android.view.SurfaceView;
39 import android.view.View;
40 import android.view.View.OnTouchListener;
41 import android.widget.FrameLayout;
42 import android.widget.TextView;
43 import android.widget.Toast;
52 System.loadLibrary(
"gnustl_shared");
53 System.loadLibrary(
"app_android");
54 System.loadLibrary(
"app_core");
97 protected class WorkerEH implements Thread.UncaughtExceptionHandler {
101 final Throwable threx = ex;
102 runOnUiThread(
new Runnable() {
106 final Throwable thr = threx;
107 b.setTitle(
"Worker unhandled exception!");
114 b.setMessage(threx.getMessage());
115 b.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
117 public void onClick(DialogInterface
dialog,
int which) {
118 thr.printStackTrace();
132 protected class RendererEH implements Thread.UncaughtExceptionHandler {
136 final Throwable threx = ex;
137 runOnUiThread(
new Runnable() {
141 final Throwable thr = threx;
142 b.setTitle(
"Renderer unhandled exception!");
148 b.setMessage(threx.getMessage());
149 b.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
151 public void onClick(DialogInterface
dialog,
int which) {
152 thr.printStackTrace();
166 protected class UIEH implements Thread.UncaughtExceptionHandler {
170 File root = getExternalFilesDir(null);
171 File err =
new File(root,
"err.txt");
172 OutputStream output = null;
173 StringWriter sw =
new StringWriter();
174 PrintWriter pw =
new PrintWriter(sw);
175 ex.printStackTrace(pw);
176 BufferedWriter writer = null;
178 output =
new FileOutputStream(err);
179 writer =
new BufferedWriter(
new OutputStreamWriter(output));
180 writer.append(sw.toString());
182 }
catch (Exception e) {
184 throw new RuntimeException(
"Unhandled exception " + e.toString());
186 if (writer != null) {
189 }
catch (IOException e) {
190 throw new RuntimeException(
"Unhandled exception " + e.toString());
193 if (output != null) {
196 }
catch (IOException e) {
197 throw new RuntimeException(
"Unhandled exception " + e.toString());
201 ex.printStackTrace();
271 canvas.setOnTouchListener(listener);
282 getFragmentManager().beginTransaction().replace(
R.id.DialogPlaceholder, dialog).commit();
290 getFragmentManager().beginTransaction().remove(
dialog).commit();
323 AlertDialog.Builder builder =
new AlertDialog.Builder(
this);
324 builder.setTitle(
"Non-fatal exception occured")
325 .setIconAttribute(android.R.attr.alertDialogIcon)
326 .setMessage(e.getMessage())
327 .setCancelable(
false)
329 AlertDialog alert = builder.create();
339 String[] projection = { MediaStore.Images.Media.DATA };
340 Cursor cursor = managedQuery(uri, projection, null, null, null);
341 int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
342 cursor.moveToFirst();
343 return cursor.getString(column_index);
349 String filePath = null;
350 String realPath = null;
352 switch (requestCode) {
354 if (resultCode == RESULT_OK && data != null && data.getData() != null) {
355 filePath = data.getData().getPath();
356 imgFile =
new File(filePath);
357 if (!imgFile.exists()) {
358 realPath = this.
getPath(data.getData());
359 imgFile =
new File(realPath);
361 if (imgFile.exists()) {
362 Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
372 AlertDialog.Builder b =
new AlertDialog.Builder(
this);
373 b.setTitle(
"Exit").setMessage(
"Dou you really want to exit?");
374 b.setNegativeButton(
"No", null);
375 b.setPositiveButton(
"Yes",
new DialogInterface.OnClickListener() {
378 public void onClick(DialogInterface
dialog,
int which) {
389 protected void onCreate(Bundle savedInstanceState) {
390 super.onCreate(savedInstanceState);
397 setContentView(
R.layout.activity_app_main);
399 if (findViewById(
R.id.ErrorMessage) != null) {
400 AlertDialog.Builder b =
new AlertDialog.Builder(
this);
401 b.setTitle(
"ERROR").setMessage(
"Only 10'' screens are currently supported.");
402 b.setCancelable(
false);
403 b.setNeutralButton(
"Ok",
new DialogInterface.OnClickListener() {
406 public void onClick(DialogInterface
dialog,
int which) {
416 Thread.setDefaultUncaughtExceptionHandler(
new UIEH());
420 guiOverCanvas = (FrameLayout) findViewById(
R.id.GuiOverCanvasPlaceholder);
422 canvas = (SurfaceView) findViewById(
R.id.DrawingCanvas);
427 FragmentTransaction ft = getFragmentManager().beginTransaction();
435 Bitmap initBitmap = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);
436 Canvas canv =
new Canvas(initBitmap);
437 canv.drawColor(0xFFFFFFFF);