Crash Screen angepasst
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / CampusAppCrashHandler.java
index 7f66e1c28e8ddf7b9a5707ad8d0ac4f5b1626b43..3d1b8c53e63a0cfe3157b4af049cc169f3344f83 100644 (file)
@@ -2,24 +2,73 @@ package de.dhbwloe.campusapp;
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.view.View;
 import android.view.Window;
+import android.webkit.WebView;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ProgressBar;
 
 /**
  * Created by pk910 on 11.03.2016.
  */
 public class CampusAppCrashHandler extends Activity {
+    private static boolean crashLogWindowOpened = false;
+    private static final Object crashWindowLock = new Object();
+
+    private String crashdate, stacktrace;
+    private CampusAppExceptionHandler exceptionHandler;
 
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
-        requestWindowFeature(Window.FEATURE_NO_TITLE); // make a dialog without a titlebar
+
+        synchronized (crashWindowLock) {
+            if(crashLogWindowOpened) {
+                int p = android.os.Process.myPid();
+                android.os.Process.killProcess(p);
+                return;
+            }
+            crashLogWindowOpened = true;
+        }
+
+        requestWindowFeature(Window.FEATURE_NO_TITLE); // make a window without a titlebar
         setContentView(R.layout.crash_log);
+        final Activity that = this;
+
+        Bundle extras = getIntent().getExtras();
+        crashdate = (extras != null ? extras.getString("crashdate") : null);
+
+        EditText crashLog = (EditText) findViewById(R.id.crashLog);
+        exceptionHandler = new CampusAppExceptionHandler();
+        stacktrace = exceptionHandler.getCrashStacktrace(that, crashdate);
+        crashLog.setText(stacktrace);
+
+        Button sendButton = (Button) findViewById(R.id.sendCrashLog);
+        sendButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Button sendButton = (Button) v;
+                ProgressBar sendProgress = (ProgressBar) findViewById(R.id.sendProgressBar);
+
+
+                sendButton.setEnabled(false);
+                sendProgress.setVisibility(View.VISIBLE);
+
 
-        Bundle extras = this.getIntent().getExtras();
-        String crashdate = (extras != null ? extras.getString("crashdate") : null);
+                exceptionHandler.postprocessException(crashdate, stacktrace, new CampusAppExceptionHandler.PostProcessingCallback() {
+                    @Override
+                    public void onPostProcessFinished(String response) {
+                        ProgressBar sendProgress = (ProgressBar) findViewById(R.id.sendProgressBar);
+                        WebView reportResponse = (WebView) findViewById(R.id.crashReportResponse);
 
-        CampusAppExceptionHandler exceptionHandler = new CampusAppExceptionHandler();
-        exceptionHandler.postprocessException(this, crashdate);
+                        sendProgress.setVisibility(View.GONE);
+                        reportResponse.setVisibility(View.VISIBLE);
+                        reportResponse.loadData(response, "text/html", null);
+                    }
+                });
+            }
+        });
     }
 }