mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merge branch '2148-shrink-hotspot-qr-codes' into 'master'
Shrink QR code to avoid scrolling Closes #2148 See merge request briar/briar!1528
This commit is contained in:
@@ -52,6 +52,7 @@ import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.briar.android.util.QrCodeUtils.HOTSPOT_QRCODE_FACTOR;
|
||||
import static org.briarproject.briar.android.util.UiUtils.handleException;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -334,7 +335,8 @@ class HotspotManager {
|
||||
ioExecutor.execute(() -> {
|
||||
String content = createWifiLoginString(group.getNetworkName(),
|
||||
group.getPassphrase());
|
||||
Bitmap qrCode = QrCodeUtils.createQrCode(dm, content);
|
||||
Bitmap qrCode = QrCodeUtils.createQrCode(
|
||||
(int) (dm.heightPixels * HOTSPOT_QRCODE_FACTOR), content);
|
||||
NetworkConfig config = new NetworkConfig(group.getNetworkName(),
|
||||
group.getPassphrase(), qrCode);
|
||||
listener.onHotspotStarted(config);
|
||||
|
||||
@@ -27,6 +27,7 @@ import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.NetworkUtils.getNetworkInterfaces;
|
||||
import static org.briarproject.briar.android.hotspot.WebServer.PORT;
|
||||
import static org.briarproject.briar.android.util.QrCodeUtils.HOTSPOT_QRCODE_FACTOR;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -83,7 +84,8 @@ class WebServerManager {
|
||||
}
|
||||
url = "http://" + address.getHostAddress() + ":" + PORT;
|
||||
}
|
||||
Bitmap qrCode = QrCodeUtils.createQrCode(dm, url);
|
||||
Bitmap qrCode = QrCodeUtils.createQrCode(
|
||||
(int) (dm.heightPixels * HOTSPOT_QRCODE_FACTOR), url);
|
||||
listener.onWebServerStarted(new WebsiteConfig(url, qrCode));
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,19 @@ public class QrCodeUtils {
|
||||
|
||||
private static final Logger LOG = getLogger(QrCodeUtils.class.getName());
|
||||
|
||||
public static final double HOTSPOT_QRCODE_FACTOR = 0.35;
|
||||
|
||||
@Nullable
|
||||
public static Bitmap createQrCode(DisplayMetrics dm, String input) {
|
||||
int smallestDimen = Math.min(dm.widthPixels, dm.heightPixels);
|
||||
return createQrCode(Math.min(dm.widthPixels, dm.heightPixels), input);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Bitmap createQrCode(int edgeLen, String input) {
|
||||
try {
|
||||
// Generate QR code
|
||||
BitMatrix encoded = new QRCodeWriter().encode(input, QR_CODE,
|
||||
smallestDimen, smallestDimen);
|
||||
edgeLen, edgeLen);
|
||||
return renderQrCode(encoded);
|
||||
} catch (WriterException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
Reference in New Issue
Block a user