From 2c4d5680a63da407dbd73a4ecb29fcf8466e6fba Mon Sep 17 00:00:00 2001
From: akwizgran <michael@briarproject.org>
Date: Tue, 20 Mar 2018 11:14:27 +0000
Subject: [PATCH] Add fullscreen button to QR code view.

---
 .../keyagreement/ShowQrCodeFragment.java      | 23 ++++++
 .../res/drawable/ic_fullscreen_black_48dp.xml |  4 +
 .../ic_fullscreen_exit_black_48dp.xml         |  4 +
 .../layout-land/fragment_keyagreement_qr.xml  | 76 +++++++++++--------
 .../res/layout/fragment_keyagreement_qr.xml   | 76 +++++++++++--------
 briar-android/src/main/res/values/strings.xml |  2 +
 6 files changed, 123 insertions(+), 62 deletions(-)
 create mode 100644 briar-android/src/main/res/drawable/ic_fullscreen_black_48dp.xml
 create mode 100644 briar-android/src/main/res/drawable/ic_fullscreen_exit_black_48dp.xml

diff --git a/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java
index b89f630d10..c648a0b739 100644
--- a/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java
+++ b/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java
@@ -14,6 +14,7 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.animation.AlphaAnimation;
 import android.widget.ImageView;
+import android.widget.LinearLayout.LayoutParams;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -52,6 +53,7 @@ import javax.inject.Provider;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
 import static android.view.View.INVISIBLE;
 import static android.view.View.VISIBLE;
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
 import static android.widget.Toast.LENGTH_LONG;
 import static java.util.logging.Level.INFO;
 import static java.util.logging.Level.WARNING;
@@ -83,6 +85,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
 	private ImageView qrCode;
 	private TextView mainProgressTitle;
 	private ViewGroup mainProgressContainer;
+	private boolean fullscreen = false;
 
 	private boolean gotRemotePayload;
 	private volatile boolean gotLocalPayload;
@@ -127,6 +130,25 @@ public class ShowQrCodeFragment extends BaseEventFragment
 		qrCode = view.findViewById(R.id.qr_code);
 		mainProgressTitle = view.findViewById(R.id.title_progress_bar);
 		mainProgressContainer = view.findViewById(R.id.container_progress);
+		ImageView fullscreenButton = view.findViewById(R.id.fullscreen_button);
+		fullscreenButton.setOnClickListener(v -> {
+			View qrCodeContainer = view.findViewById(R.id.qr_code_container);
+			if (fullscreen) {
+				// Shrink the QR code container
+				qrCodeContainer.setLayoutParams(
+						new LayoutParams(MATCH_PARENT, 0, 1f));
+				fullscreenButton.setBackgroundResource(
+						R.drawable.ic_fullscreen_black_48dp);
+			} else {
+				// Grow the QR code container
+				qrCodeContainer.setLayoutParams(
+						new LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f));
+				fullscreenButton.setBackgroundResource(
+						R.drawable.ic_fullscreen_exit_black_48dp);
+			}
+			view.findViewById(R.id.camera_overlay).invalidate();
+			fullscreen = !fullscreen;
+		});
 	}
 
 	@Override
@@ -274,6 +296,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
 		new AsyncTask<Void, Void, Bitmap>() {
 
 			@Override
+			@Nullable
 			protected Bitmap doInBackground(Void... params) {
 				byte[] payloadBytes = payloadEncoder.encode(payload);
 				if (LOG.isLoggable(INFO)) {
diff --git a/briar-android/src/main/res/drawable/ic_fullscreen_black_48dp.xml b/briar-android/src/main/res/drawable/ic_fullscreen_black_48dp.xml
new file mode 100644
index 0000000000..affab0d465
--- /dev/null
+++ b/briar-android/src/main/res/drawable/ic_fullscreen_black_48dp.xml
@@ -0,0 +1,4 @@
+<vector android:height="48dp" android:viewportHeight="24.0"
+    android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/>
+</vector>
diff --git a/briar-android/src/main/res/drawable/ic_fullscreen_exit_black_48dp.xml b/briar-android/src/main/res/drawable/ic_fullscreen_exit_black_48dp.xml
new file mode 100644
index 0000000000..5b62d104c1
--- /dev/null
+++ b/briar-android/src/main/res/drawable/ic_fullscreen_exit_black_48dp.xml
@@ -0,0 +1,4 @@
+<vector android:height="48dp" android:viewportHeight="24.0"
+    android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M5,16h3v3h2v-5L5,14v2zM8,8L5,8v2h5L10,5L8,5v3zM14,19h2v-3h3v-2h-5v5zM16,8L16,5h-2v5h5L19,8h-3z"/>
+</vector>
diff --git a/briar-android/src/main/res/layout-land/fragment_keyagreement_qr.xml b/briar-android/src/main/res/layout-land/fragment_keyagreement_qr.xml
index e9a174c778..c811b58c8b 100644
--- a/briar-android/src/main/res/layout-land/fragment_keyagreement_qr.xml
+++ b/briar-android/src/main/res/layout-land/fragment_keyagreement_qr.xml
@@ -15,39 +15,36 @@
 		android:layout_width="match_parent"
 		android:layout_height="match_parent"
 		android:orientation="horizontal"
-		android:weightSum="2">
+		android:weightSum="2"
+		android:baselineAligned="false">
 
-		<FrameLayout
+		<LinearLayout
+			android:id="@+id/status_container"
 			android:layout_width="0dp"
 			android:layout_height="match_parent"
-			android:layout_weight="1">
+			android:layout_weight="1"
+			android:background="@android:color/background_light"
+			android:gravity="center"
+			android:orientation="vertical"
+			android:padding="@dimen/margin_medium"
+			android:visibility="invisible">
 
-			<LinearLayout
-				android:id="@+id/status_container"
+			<ProgressBar
+				style="?android:attr/progressBarStyleLarge"
+				android:layout_width="wrap_content"
+				android:layout_height="wrap_content"/>
+
+			<TextView
+				android:id="@+id/connect_status"
 				android:layout_width="match_parent"
-				android:layout_height="match_parent"
-				android:background="@android:color/background_light"
+				android:layout_height="wrap_content"
 				android:gravity="center"
-				android:orientation="vertical"
-				android:padding="@dimen/margin_medium"
-				android:visibility="invisible">
-
-				<ProgressBar
-					style="?android:attr/progressBarStyleLarge"
-					android:layout_width="wrap_content"
-					android:layout_height="wrap_content"/>
-
-				<TextView
-					android:id="@+id/connect_status"
-					android:layout_width="match_parent"
-					android:layout_height="wrap_content"
-					android:gravity="center"
-					android:paddingTop="@dimen/margin_large"
-					tools:text="Connection failed"/>
-			</LinearLayout>
-		</FrameLayout>
+				android:paddingTop="@dimen/margin_large"
+				tools:text="Connection failed"/>
+		</LinearLayout>
 
 		<FrameLayout
+			android:id="@+id/qr_code_container"
 			android:layout_width="0dp"
 			android:layout_height="match_parent"
 			android:layout_weight="1"
@@ -59,12 +56,30 @@
 				android:layout_height="wrap_content"
 				android:layout_gravity="center"/>
 
-			<ImageView
-				android:id="@+id/qr_code"
+			<RelativeLayout
 				android:layout_width="match_parent"
-				android:layout_height="match_parent"
-				android:scaleType="fitCenter"
-				android:layout_gravity="center"/>
+				android:layout_height="match_parent">
+
+				<ImageView
+					android:id="@+id/qr_code"
+					android:layout_width="match_parent"
+					android:layout_height="match_parent"
+					android:layout_centerInParent="true"
+					android:contentDescription="@string/qr_code"
+					android:scaleType="fitCenter"/>
+
+				<ImageView
+					android:id="@+id/fullscreen_button"
+					android:background="@drawable/ic_fullscreen_black_48dp"
+					android:alpha="0.54"
+					android:layout_width="wrap_content"
+					android:layout_height="wrap_content"
+					android:layout_margin="@dimen/margin_small"
+					android:layout_alignParentBottom="true"
+					android:layout_alignParentRight="true"
+					android:layout_alignParentEnd="true"
+					android:contentDescription="@string/show_qr_code_fullscreen"/>
+			</RelativeLayout>
 		</FrameLayout>
 	</LinearLayout>
 
@@ -92,5 +107,4 @@
 			android:paddingTop="@dimen/margin_large"
 			tools:text="@string/waiting_for_contact_to_scan"/>
 	</RelativeLayout>
-
 </FrameLayout>
diff --git a/briar-android/src/main/res/layout/fragment_keyagreement_qr.xml b/briar-android/src/main/res/layout/fragment_keyagreement_qr.xml
index 1aaf28183f..456ffbca12 100644
--- a/briar-android/src/main/res/layout/fragment_keyagreement_qr.xml
+++ b/briar-android/src/main/res/layout/fragment_keyagreement_qr.xml
@@ -15,39 +15,36 @@
 		android:layout_width="match_parent"
 		android:layout_height="match_parent"
 		android:orientation="vertical"
-		android:weightSum="2">
+		android:weightSum="2"
+		android:baselineAligned="false">
 
-		<FrameLayout
+		<LinearLayout
+			android:id="@+id/status_container"
 			android:layout_width="match_parent"
 			android:layout_height="0dp"
-			android:layout_weight="1">
+			android:layout_weight="1"
+			android:background="@android:color/background_light"
+			android:gravity="center"
+			android:orientation="vertical"
+			android:padding="@dimen/margin_medium"
+			android:visibility="invisible">
 
-			<LinearLayout
-				android:id="@+id/status_container"
+			<ProgressBar
+				style="?android:attr/progressBarStyleLarge"
+				android:layout_width="wrap_content"
+				android:layout_height="wrap_content"/>
+
+			<TextView
+				android:id="@+id/connect_status"
 				android:layout_width="match_parent"
-				android:layout_height="match_parent"
-				android:background="@android:color/background_light"
+				android:layout_height="wrap_content"
 				android:gravity="center"
-				android:orientation="vertical"
-				android:padding="@dimen/margin_medium"
-				android:visibility="invisible">
-
-				<ProgressBar
-					style="?android:attr/progressBarStyleLarge"
-					android:layout_width="wrap_content"
-					android:layout_height="wrap_content"/>
-
-				<TextView
-					android:id="@+id/connect_status"
-					android:layout_width="match_parent"
-					android:layout_height="wrap_content"
-					android:gravity="center"
-					android:paddingTop="@dimen/margin_large"
-					tools:text="Connection failed"/>
-			</LinearLayout>
-		</FrameLayout>
+				android:paddingTop="@dimen/margin_large"
+				tools:text="Connection failed"/>
+		</LinearLayout>
 
 		<FrameLayout
+			android:id="@+id/qr_code_container"
 			android:layout_width="match_parent"
 			android:layout_height="0dp"
 			android:layout_weight="1"
@@ -59,12 +56,30 @@
 				android:layout_height="wrap_content"
 				android:layout_gravity="center"/>
 
-			<ImageView
-				android:id="@+id/qr_code"
+			<RelativeLayout
 				android:layout_width="match_parent"
-				android:layout_height="match_parent"
-				android:scaleType="fitCenter"
-				android:layout_gravity="center"/>
+				android:layout_height="match_parent">
+
+				<ImageView
+					android:id="@+id/qr_code"
+					android:layout_width="match_parent"
+					android:layout_height="match_parent"
+					android:layout_centerInParent="true"
+					android:contentDescription="@string/qr_code"
+					android:scaleType="fitCenter"/>
+
+				<ImageView
+					android:id="@+id/fullscreen_button"
+					android:background="@drawable/ic_fullscreen_black_48dp"
+					android:alpha="0.54"
+					android:layout_width="wrap_content"
+					android:layout_height="wrap_content"
+					android:layout_margin="@dimen/margin_small"
+					android:layout_alignParentBottom="true"
+					android:layout_alignParentRight="true"
+					android:layout_alignParentEnd="true"
+					android:contentDescription="@string/show_qr_code_fullscreen"/>
+			</RelativeLayout>
 		</FrameLayout>
 	</LinearLayout>
 
@@ -92,5 +107,4 @@
 			android:paddingTop="@dimen/margin_large"
 			tools:text="@string/waiting_for_contact_to_scan"/>
 	</RelativeLayout>
-
 </FrameLayout>
diff --git a/briar-android/src/main/res/values/strings.xml b/briar-android/src/main/res/values/strings.xml
index 14de9071b5..4df1ed1981 100644
--- a/briar-android/src/main/res/values/strings.xml
+++ b/briar-android/src/main/res/values/strings.xml
@@ -410,5 +410,7 @@
 	<string name="permission_camera_request_body">To scan the QR code, Briar needs access to the camera.</string>
 	<string name="permission_camera_denied_body">You have denied access to the camera, but adding contacts requires using the camera.\n\nPlease consider granting access.</string>
 	<string name="permission_camera_denied_toast">Camera permission was not granted</string>
+	<string name="qr_code">QR code</string>
+	<string name="show_qr_code_fullscreen">Show QR code fullscreen</string>
 
 </resources>
-- 
GitLab