From 23eb5acafa1cafb56db4445977ad55433c21c041 Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Sat, 16 Jul 2016 00:35:59 +0000
Subject: [PATCH] Use AppCompatDelegate to add AppCompat support to
 BaseCrashReportDialog subclass

This enables the toolbar to be used as an action bar, and tinting of UI elements
like checkboxes.
---
 briar-android/AndroidManifest.xml             |  3 +-
 .../res/layout/activity_dev_report.xml        | 14 ++---
 .../android/report/DevReportActivity.java     | 61 +++++++++++++++++--
 3 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/briar-android/AndroidManifest.xml b/briar-android/AndroidManifest.xml
index 702e7e6976..7c7be67ccf 100644
--- a/briar-android/AndroidManifest.xml
+++ b/briar-android/AndroidManifest.xml
@@ -51,7 +51,8 @@
 			android:finishOnTaskLaunch="true"
 			android:label="@string/crash_report_title"
 			android:launchMode="singleInstance"
-			android:process=":briar_error_handler">
+			android:process=":briar_error_handler"
+			android:theme="@style/BriarThemeNoActionBar.Default">
 		</activity>
 
 		<activity
diff --git a/briar-android/res/layout/activity_dev_report.xml b/briar-android/res/layout/activity_dev_report.xml
index b8bb74b12c..37fac97b85 100644
--- a/briar-android/res/layout/activity_dev_report.xml
+++ b/briar-android/res/layout/activity_dev_report.xml
@@ -4,20 +4,14 @@
 	xmlns:tools="http://schemas.android.com/tools"
 	android:layout_width="match_parent"
 	android:layout_height="match_parent"
-	android:orientation="vertical">
+	android:orientation="vertical"
+	tools:context=".android.report.DevReportActivity">
 
 	<android.support.v7.widget.Toolbar
+		android:id="@+id/toolbar"
 		style="@style/BriarToolbar"
 		android:layout_width="match_parent"
-		android:layout_height="wrap_content">
-
-		<TextView
-			android:id="@+id/title"
-			style="@style/TextAppearance.AppCompat.Large.Inverse"
-			android:layout_width="match_parent"
-			android:layout_height="wrap_content"
-			tools:text="@string/crash_report_title"/>
-	</android.support.v7.widget.Toolbar>
+		android:layout_height="wrap_content"/>
 
 	<RelativeLayout
 		android:layout_width="match_parent"
diff --git a/briar-android/src/org/briarproject/android/report/DevReportActivity.java b/briar-android/src/org/briarproject/android/report/DevReportActivity.java
index 3419920a82..26dcaafae0 100644
--- a/briar-android/src/org/briarproject/android/report/DevReportActivity.java
+++ b/briar-android/src/org/briarproject/android/report/DevReportActivity.java
@@ -2,10 +2,13 @@ package org.briarproject.android.report;
 
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
+import android.content.res.Configuration;
 import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatDelegate;
+import android.support.v7.widget.Toolbar;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -66,6 +69,7 @@ public class DevReportActivity extends BaseCrashReportDialog
 		requiredFields.add(STACK_TRACE);
 	}
 
+	private AppCompatDelegate delegate;
 	private SharedPreferencesFactory sharedPreferencesFactory;
 	private Set<ReportField> excludedFields;
 	private EditText userCommentView = null;
@@ -77,11 +81,20 @@ public class DevReportActivity extends BaseCrashReportDialog
 	private View share = null;
 	private boolean reviewing = false;
 
+	private AppCompatDelegate getDelegate() {
+		if (delegate == null) {
+			delegate = AppCompatDelegate.create(this, null);
+		}
+		return delegate;
+	}
+
 	@Override
 	public void onCreate(Bundle state) {
+		getDelegate().installViewFactory();
+		getDelegate().onCreate(state);
 		super.onCreate(state);
 
-		setContentView(R.layout.activity_dev_report);
+		getDelegate().setContentView(R.layout.activity_dev_report);
 
 		sharedPreferencesFactory = new SharedPreferencesFactory(
 				getApplicationContext(), getConfig());
@@ -95,7 +108,9 @@ public class DevReportActivity extends BaseCrashReportDialog
 			}
 		}
 
-		TextView title = (TextView) findViewById(R.id.title);
+		Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
+		getDelegate().setSupportActionBar(tb);
+
 		userCommentView = (EditText) findViewById(R.id.user_comment);
 		userEmailView = (EditText) findViewById(R.id.user_email);
 		TextView debugReport = (TextView) findViewById(R.id.debug_report);
@@ -105,8 +120,10 @@ public class DevReportActivity extends BaseCrashReportDialog
 		progress = findViewById(R.id.progress_wheel);
 		share = findViewById(R.id.share_dev_report);
 
-		title.setText(isFeedback() ? R.string.feedback_title :
-				R.string.crash_report_title);
+		//noinspection ConstantConditions
+		getDelegate().getSupportActionBar().setTitle(
+				isFeedback() ? R.string.feedback_title :
+						R.string.crash_report_title);
 		userCommentView.setHint(isFeedback() ? R.string.enter_feedback :
 				R.string.describe_crash);
 
@@ -137,6 +154,12 @@ public class DevReportActivity extends BaseCrashReportDialog
 			reviewing = state.getBoolean(STATE_REVIEWING, false);
 	}
 
+	@Override
+	public void onPostCreate(Bundle state) {
+		super.onPostCreate(state);
+		getDelegate().onPostCreate(state);
+	}
+
 	@Override
 	public void onResume() {
 		super.onResume();
@@ -144,12 +167,42 @@ public class DevReportActivity extends BaseCrashReportDialog
 		if (chevron.isSelected()) refresh();
 	}
 
+	@Override
+	protected void onPostResume() {
+		super.onPostResume();
+		getDelegate().onPostResume();
+	}
+
+	@Override
+	public void onTitleChanged(CharSequence title, int color) {
+		super.onTitleChanged(title, color);
+		getDelegate().setTitle(title);
+	}
+
+	@Override
+	public void onConfigurationChanged(Configuration newConfig) {
+		super.onConfigurationChanged(newConfig);
+		getDelegate().onConfigurationChanged(newConfig);
+	}
+
 	@Override
 	public void onSaveInstanceState(Bundle state) {
 		super.onSaveInstanceState(state);
 		state.putBoolean(STATE_REVIEWING, reviewing);
 	}
 
+	@Override
+	public void onStop() {
+		super.onStop();
+		getDelegate().onStop();
+	}
+
+	@Override
+	public void onDestroy() {
+		super.onDestroy();
+		getDelegate().onDestroy();
+	}
+
 	@Override
 	public void onBackPressed() {
 		closeReport();
-- 
GitLab