Skip to content

Commit

Permalink
Minor improvements to the entry sharing activity
Browse files Browse the repository at this point in the history
This patch makes a couple of minor improvements to the entry sharing
activity:
- Remove the double "Transfer entries" heading.
- Make the QR codes larger. Especially helpful with Google Authenticator
  exports.
- Increase screen brightness to 100%.

Before and after:

<img width="200" src="https://alexbakker.me/u/d91cl1x495.png"/>
<img width="200" src="https://alexbakker.me/u/ckzhrs5nf5.png"/>

<img width="200" src="https://alexbakker.me/u/6bo0womot0.png"/>
<img width="200" src="https://alexbakker.me/u/mw7yskjn7z.png"/>
  • Loading branch information
alexbakker committed Oct 4, 2024
1 parent 0573dbb commit a4f372e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.ColorInt;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Theme;
Expand All @@ -27,14 +28,16 @@
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
import com.beemdevelopment.aegis.otp.Transferable;
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.zxing.WriterException;

import java.util.ArrayList;
import java.util.List;

public class TransferEntriesActivity extends AegisActivity {
private List<Transferable> _authInfos;
private ImageView _qrImage;
private ShapeableImageView _qrImage;
private TextView _description;
private TextView _issuer;
private TextView _accountName;
Expand Down Expand Up @@ -62,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
_previousButton = findViewById(R.id.btnPrevious);
_copyButton = findViewById(R.id.btnCopyClipboard);

if (getSupportActionBar() != null){
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
Expand All @@ -88,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
});

_previousButton.setOnClickListener(v -> {
if (_currentEntryCount > 1 ) {
if (_currentEntryCount > 1) {
_nextButton.setText(R.string.next);
_currentEntryCount--;
generateQR();
Expand Down Expand Up @@ -116,14 +119,39 @@ protected void onCreate(Bundle savedInstanceState) {
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
}
Toast.makeText(this,R.string.uri_copied_to_clipboard, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.uri_copied_to_clipboard, Toast.LENGTH_SHORT).show();

} catch (GoogleAuthInfoException e) {
Dialogs.showErrorDialog(this, R.string.unable_to_copy_uri_to_clipboard, e);
}
});

generateQR();
// Calculate sensible dimensions for the QR code depending on whether we're in landscape
_qrImage.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ConstraintLayout layout = findViewById(R.id.layoutShareEntry);
if (layout.getWidth() > layout.getHeight()) {
int squareSize = (int) (0.5 * layout.getHeight());
ViewGroup.LayoutParams params = _qrImage.getLayoutParams();
params.width = squareSize;
params.height = squareSize;
_qrImage.setLayoutParams(params);
}

generateQR();

_qrImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

@Override
public void onAttachedToWindow() {
// Max brightness to make the QR codes easier to scan
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = 1.0f;
getWindow().setAttributes(attrs);
}

@Override
Expand Down Expand Up @@ -151,16 +179,13 @@ private void generateQR() {

_entriesCount.setText(getResources().getQuantityString(R.plurals.qr_count, _authInfos.size(), _currentEntryCount, _authInfos.size()));

@ColorInt int backgroundColor = Color.WHITE;
if (_themeHelper.getConfiguredTheme() == Theme.LIGHT) {
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(androidx.appcompat.R.attr.background, typedValue, true);
backgroundColor = typedValue.data;
}
int backgroundColor = _themeHelper.getConfiguredTheme() == Theme.LIGHT
? MaterialColors.getColor(_qrImage, com.google.android.material.R.attr.colorSurfaceContainer)
: Color.WHITE;

Bitmap bitmap;
try {
bitmap = QrCodeHelper.encodeToBitmap(selectedEntry.getUri().toString(), 512, 512, backgroundColor);
bitmap = QrCodeHelper.encodeToBitmap(selectedEntry.getUri().toString(), _qrImage.getWidth(), _qrImage.getWidth(), backgroundColor);
} catch (WriterException | GoogleAuthInfoException e) {
Dialogs.showErrorDialog(this, R.string.unable_to_generate_qrcode, e);
return;
Expand Down
44 changes: 18 additions & 26 deletions app/src/main/res/layout/activity_share_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,40 @@
</com.google.android.material.appbar.AppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutShareEntry"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/ivQrCode"
android:layout_width="250dp"
android:layout_height="250dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tvTransfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/transfer_entry"
android:textSize="22sp"
android:textStyle="bold"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toTopOf="@+id/tvDescription"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
android:layout_height="match_parent"
android:paddingHorizontal="30dp"
android:layout_marginTop="?attr/actionBarSize">

<TextView
android:id="@+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="@string/transfer_entry_description"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/ivQrCode"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/ivQrCode"
android:layout_width="0dp"
android:layout_height="0dp"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Aegis.ImageView.Rounded"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintVertical_bias="0.3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<TextView
android:id="@+id/tvIssuer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginTop="20dp"
tools:text="Issuer"
android:textSize="18sp"
android:textStyle="bold"
Expand Down Expand Up @@ -95,7 +89,6 @@
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
style="@style/Widget.Material3.Button.TextButton"
android:text="@string/next"
Expand Down Expand Up @@ -123,7 +116,6 @@
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/btnNext"
app:layout_constraintHorizontal_bias="0.506"
app:layout_constraintStart_toStartOf="@+id/btnPrevious" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down

0 comments on commit a4f372e

Please sign in to comment.