Crash Screen angepasst
authorpk910 <philipp@pk910.de>
Fri, 11 Mar 2016 13:41:55 +0000 (14:41 +0100)
committerpk910 <philipp@pk910.de>
Fri, 11 Mar 2016 13:43:12 +0000 (14:43 +0100)
app/src/main/AndroidManifest.xml
app/src/main/java/de/dhbwloe/campusapp/CampusApp.java
app/src/main/java/de/dhbwloe/campusapp/CampusAppCrashHandler.java
app/src/main/java/de/dhbwloe/campusapp/CampusAppExceptionHandler.java
app/src/main/res/drawable/android_crash.png [new file with mode: 0644]
app/src/main/res/layout/crash_log.xml

index d8fce1d6f387453453fbf8389c7b42905bf55685..035e1a30053924a1af253d8e15baf0904a563927 100644 (file)
@@ -31,8 +31,7 @@
         </activity>
         <activity
             android:name=".CampusAppCrashHandler"
-            android:theme="@android:style/Theme.Dialog"
-            android:textAppearance="@android:style/TextAppearance.Large"
+            android:theme="@style/AppTheme"
             android:windowSoftInputMode="stateHidden">
             <intent-filter>
                 <action android:name="de.dhbw.campusapp.CRASH_LOG" />
index 403c7401b748e12feeb2d2ca8f935f60b7eb6596..ba3d60445d45b3c232ec51d48e33336b2f2fea3b 100644 (file)
@@ -308,7 +308,7 @@ public class CampusApp extends FragmentActivity {
             AppContext = new CampusAppContext(this, R.id.fragment_container, R.id.nav_view);
         else
             AppContext.setMainActivity(this);
-        
+
         super.onResume();
         Log.i("CampusApp", "onResume event");
         AppContext.getNfcCardListener().resumeForefrontDispatcher();
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);
+                    }
+                });
+            }
+        });
     }
 }
index 9d5a974713f2792dc15a14efa4e6369de8ccd29f..00cca75c189d143147142af97c8e6c88b6fa9e19 100644 (file)
@@ -22,12 +22,6 @@ import java.util.Date;
 import java.util.List;
 
 import cz.msebera.android.httpclient.Header;
-import cz.msebera.android.httpclient.NameValuePair;
-import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
-import cz.msebera.android.httpclient.client.methods.HttpPost;
-import cz.msebera.android.httpclient.impl.client.DefaultHttpClient;
-import cz.msebera.android.httpclient.message.BasicNameValuePair;
-import cz.msebera.android.httpclient.protocol.HTTP;
 
 /**
  * Created by pk910 on 11.03.2016.
@@ -37,11 +31,18 @@ public class CampusAppExceptionHandler {
     private String localPath;
 
     private static boolean crashLogWindowOpened = false;
+    private static final Object crashWindowLock = new Object();
 
     public void handleUncaughtException(Thread thread, Throwable e) {
         // automatically send crash log to my server for debuggging.
         // disable this for productive use! (CampusAppContext.DEBUG)
 
+        synchronized (crashWindowLock) {
+            if(crashLogWindowOpened)
+                return;
+            crashLogWindowOpened = true;
+        }
+
         final Writer result = new StringWriter();
         final PrintWriter printWriter = new PrintWriter(result);
         e.printStackTrace(printWriter);
@@ -73,16 +74,13 @@ public class CampusAppExceptionHandler {
             writeToFile(stacktrace, filename);
 
         // start crash screen
-        if(!crashLogWindowOpened) {
-            try {
-                Intent intent = new Intent();
-                intent.setAction("de.dhbw.campusapp.CRASH_LOG");
-                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
-                intent.putExtra("crashdate", crashdate);
-                mainActivity.startActivity(intent);
-                crashLogWindowOpened = true;
-            } catch (Exception ex) {
-            }
+        try {
+            Intent intent = new Intent();
+            intent.setAction("de.dhbw.campusapp.CRASH_LOG");
+            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
+            intent.putExtra("crashdate", crashdate);
+            mainActivity.startActivity(intent);
+        } catch (Exception ex) {
         }
     }
 
@@ -98,7 +96,12 @@ public class CampusAppExceptionHandler {
         }
     }
 
-    public void postprocessException(Activity crashLogScreen, String crashdate) {
+
+    public interface PostProcessingCallback {
+        public void onPostProcessFinished(String response);
+    }
+
+    public String getCrashStacktrace(Activity crashLogScreen, String crashdate) {
         localPath = crashLogScreen.getApplicationContext().getFilesDir().getAbsolutePath();
         String fileName = localPath + "/" + crashdate + ".stacktrace";
         StringBuilder stackTrace = new StringBuilder();
@@ -116,11 +119,14 @@ public class CampusAppExceptionHandler {
         catch (IOException e) {
             //You'll need to add proper error handling here
         }
+        return stackTrace.toString();
+    }
 
-        sendToServer(CRASHLOG_UPLOAD, stackTrace.toString(), crashdate);
+    public void postprocessException(String crashdate, String stacktrace, PostProcessingCallback callback) {
+        sendToServer(CRASHLOG_UPLOAD, stacktrace, crashdate, callback);
     }
 
-    private void sendToServer(String url, String stacktrace, String crashdate) {
+    private void sendToServer(String url, String stacktrace, String crashdate, final PostProcessingCallback callback) {
         AsyncHttpClient client = new AsyncHttpClient();
         RequestParams params = new RequestParams();
         params.add("stacktrace", stacktrace);
@@ -130,12 +136,12 @@ public class CampusAppExceptionHandler {
 
             @Override
             public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
-                Log.i("CrashLog", "OK: "+(responseBody != null ? new String(responseBody) : null));
+                callback.onPostProcessFinished((responseBody != null ? new String(responseBody) : null));
             }
 
             @Override
             public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
-                Log.i("CrashLog", "Failed: "+(responseBody != null ? new String(responseBody) : null));
+                callback.onPostProcessFinished("Failed: "+(responseBody != null ? new String(responseBody) : null));
             }
         });
     }
diff --git a/app/src/main/res/drawable/android_crash.png b/app/src/main/res/drawable/android_crash.png
new file mode 100644 (file)
index 0000000..044a786
Binary files /dev/null and b/app/src/main/res/drawable/android_crash.png differ
index 176d49daa0114f2e230a4ba2df51b9a1f3c8566b..8f6e4ac189e5914ed6e8e579e1320c0f041e9d0b 100644 (file)
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:orientation="vertical" android:layout_width="match_parent"
     android:layout_height="match_parent">
 
-    <RelativeLayout
-        android:layout_width="250dp"
+    <android.support.design.widget.AppBarLayout
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_gravity="center_horizontal">
-
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:text="Irgendwas Doofes ist passiert. :/"
-            android:id="@+id/textView38"
-            android:layout_gravity="center_horizontal" />
-
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:text="Crash Stacktrace wird an Entwickler gesendet..."
-            android:id="@+id/textView39"
+        android:theme="@style/AppTheme.AppBarOverlay">
+        <android.support.v7.widget.Toolbar
+            android:id="@+id/toolbar"
+            android:layout_width="match_parent"
+            android:layout_height="?attr/actionBarSize"
+            android:background="?attr/colorPrimary"
+            app:popupTheme="@style/AppTheme.PopupOverlay">
+
+            <LinearLayout
+                android:id="@+id/title_container"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center_vertical"
+                android:orientation="horizontal"
+                android:visibility="visible">
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textAppearance="?android:attr/textAppearanceLarge"
+                    android:text="@string/app_name"
+                    android:layout_weight="1"
+                    android:id="@+id/title" />
+
+            </LinearLayout>
+
+        </android.support.v7.widget.Toolbar>
+    </android.support.design.widget.AppBarLayout>
+
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <ImageView
+            android:layout_width="match_parent"
+            android:layout_height="100dp"
+            android:id="@+id/imageView4"
             android:layout_gravity="center_horizontal"
-            android:layout_below="@+id/textView38" />
-    </RelativeLayout>
+            android:src="@drawable/android_crash"
+            android:background="#ffffff"
+            android:paddingTop="8dp"
+            android:paddingBottom="8dp" />
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="8dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="Sorry, Irgendwas Doofes ist passiert."
+                android:id="@+id/textView38" />
+
+            <RelativeLayout
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal"
+                android:layout_marginTop="8dp">
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="Crash Log:"
+                    android:id="@+id/textView39" />
+
+                <ScrollView
+                    android:layout_width="fill_parent"
+                    android:layout_height="200dp"
+                    android:id="@+id/scrollView6"
+                    android:layout_below="@+id/textView39"
+                    android:background="#ffffff">
+
+                    <EditText
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:padding="2dp"
+                        android:background="#FFF"
+                        android:textSize="10dp"
+                        android:layout_below="@+id/textView39"
+                        android:typeface="monospace"
+                        android:id="@+id/crashLog" />
+                </ScrollView>
+
+                <ProgressBar
+                    style="?android:attr/progressBarStyleLarge"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:id="@+id/sendProgressBar"
+                    android:layout_centerVertical="true"
+                    android:layout_centerHorizontal="true"
+                    android:visibility="gone" />
+
+            </RelativeLayout>
+
+            <Button
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Crash Log an Entwickler senden"
+                android:id="@+id/sendCrashLog"
+                android:layout_gravity="center_horizontal"
+                android:layout_marginTop="4dp" />
+
+            <WebView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:id="@+id/crashReportResponse"
+                android:layout_gravity="center_horizontal"
+                android:visibility="gone" />
+
+        </LinearLayout>
+
+    </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file