833: Padding improvements r=TheLastProject a=TheLastProject

Fixes #823 

Sadly, it also caused a new regression, cutting off part of the card ID if you use AZTEC and a photo...

| Before | After |
| - | - |
| ![image](https://user-images.githubusercontent.com/1885159/157125003-e336fef8-4dbe-4f75-8d00-908bced3e533.png) | ![image](https://user-images.githubusercontent.com/1885159/157125032-41f3e8ac-9fca-4f21-9a0e-df955670814a.png) |

Co-authored-by: Sylvia van Os <sylvia@hackerchick.me>
This commit is contained in:
bors[bot]
2022-03-08 20:13:56 +00:00
committed by GitHub
12 changed files with 54 additions and 25 deletions

View File

@@ -3,6 +3,7 @@
## Unreleased - 104
- Save card detail expansion state
- Minor UI fixes
## v2.15.2 - 103 (2022-02-11)

View File

@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@@ -46,7 +47,7 @@ public class BarcodeImageWriterTask implements CompatCallable<Bitmap> {
BarcodeImageWriterTask(
Context context, ImageView imageView, String cardIdString,
CatimaBarcode barcodeFormat, TextView textView,
boolean showFallback, Runnable callback
boolean showFallback, Runnable callback, boolean roundCornerPadding
) {
mContext = context;
@@ -60,18 +61,27 @@ public class BarcodeImageWriterTask implements CompatCallable<Bitmap> {
cardId = cardIdString;
format = barcodeFormat;
int padding = roundCornerPadding ? Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics())) : 0;
final int MAX_WIDTH = getMaxWidth(format);
int tempImageHeight;
int tempImageWidth;
if (imageView.getWidth() < MAX_WIDTH) {
imageHeight = imageView.getHeight();
imageWidth = imageView.getWidth();
tempImageHeight = imageView.getHeight();
tempImageWidth = imageView.getWidth();
} else {
// Scale down the image to reduce the memory needed to produce it
imageWidth = MAX_WIDTH;
tempImageWidth = MAX_WIDTH;
double ratio = (double) MAX_WIDTH / (double) imageView.getWidth();
imageHeight = (int) (imageView.getHeight() * ratio);
tempImageHeight = (int) (imageView.getHeight() * ratio);
}
// Ensure space for padding if wanted
imageWidth = tempImageWidth;
imageHeight = tempImageHeight - padding;
this.showFallback = showFallback;
}

View File

@@ -76,6 +76,7 @@ public class BarcodeSelectorAdapter extends ArrayAdapter<CatimaBarcodeWithValue>
final CatimaBarcode format = CatimaBarcode.fromName(formatType);
image.setImageBitmap(null);
image.setClipToOutline(true);
if (image.getHeight() == 0) {
// The size of the ImageView is not yet available as it has not
@@ -89,13 +90,13 @@ public class BarcodeSelectorAdapter extends ArrayAdapter<CatimaBarcodeWithValue>
Log.d(TAG, "Generating barcode for type " + formatType);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getContext(), image, cardId, format, text, true, null);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getContext(), image, cardId, format, text, true, null, true);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
});
} else {
Log.d(TAG, "Generating barcode for type " + formatType);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getContext(), image, cardId, format, text, true, null);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getContext(), image, cardId, format, text, true, null, true);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
}

View File

@@ -323,6 +323,7 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
barcodeIdField = findViewById(R.id.barcodeIdField);
barcodeTypeField = findViewById(R.id.barcodeTypeField);
barcodeImage = findViewById(R.id.barcode);
barcodeImage.setClipToOutline(true);
barcodeImageLayout = findViewById(R.id.barcodeLayout);
barcodeCaptureLayout = findViewById(R.id.barcodeCaptureLayout);
cardImageFrontHolder = findViewById(R.id.frontImageHolder);
@@ -1449,13 +1450,13 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
barcodeImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Log.d(TAG, "ImageView size now known");
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, barcodeImageGenerationFinishedCallback);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, barcodeImageGenerationFinishedCallback, true);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
});
} else {
Log.d(TAG, "ImageView size known known, creating barcode");
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, barcodeImageGenerationFinishedCallback);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, barcodeImageGenerationFinishedCallback, true);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
}

View File

@@ -278,6 +278,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
storeName = findViewById(R.id.storeName);
maximizeButton = findViewById(R.id.maximizeButton);
mainImage = findViewById(R.id.mainImage);
mainImage.setClipToOutline(true);
dotIndicator = findViewById(R.id.dotIndicator);
minimizeButton = findViewById(R.id.minimizeButton);
collapsingToolbarLayout = findViewById(R.id.collapsingToolbarLayout);
@@ -304,7 +305,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
setCenterGuideline(loyaltyCard.zoomLevel);
drawMainImage(mainImageIndex, true);
drawMainImage(mainImageIndex, true, isFullscreen);
}
@Override
@@ -807,7 +808,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
}
}
private void drawBarcode() {
private void drawBarcode(boolean addPadding) {
mTasks.flushTaskList(TaskHandler.TYPE.BARCODE, true, false, false);
if (format != null) {
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(
@@ -817,12 +818,13 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
format,
null,
false,
null);
null,
addPadding);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
}
private void redrawBarcodeAfterResize() {
private void redrawBarcodeAfterResize(boolean addPadding) {
if (format != null) {
mainImage.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@@ -831,13 +833,13 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
mainImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Log.d(TAG, "ImageView size now known");
drawBarcode();
drawBarcode(addPadding);
}
});
}
}
private void drawMainImage(int index, boolean waitForResize) {
private void drawMainImage(int index, boolean waitForResize, boolean isFullscreen) {
if (imageTypes.isEmpty()) {
mainImage.setVisibility(View.GONE);
return;
@@ -853,12 +855,19 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
ImageType wantedImageType = imageTypes.get(index);
if (wantedImageType == ImageType.BARCODE) {
if (waitForResize) {
redrawBarcodeAfterResize();
// Use border in non-fullscreen mode
if (!isFullscreen) {
mainImage.setBackground(AppCompatResources.getDrawable(this, R.drawable.round_outline));
} else {
drawBarcode();
mainImage.setBackgroundColor(Color.WHITE);
}
mainImage.setBackgroundColor(Color.WHITE);
if (waitForResize) {
redrawBarcodeAfterResize(!isFullscreen);
} else {
drawBarcode(!isFullscreen);
}
mainImage.setContentDescription(getString(R.string.barcodeImageDescriptionWithType, format.prettyName()));
} else if (wantedImageType == ImageType.IMAGE_FRONT) {
mainImage.setImageBitmap(frontImageBitmap);
@@ -888,7 +897,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
mainImageIndex = newIndex;
drawMainImage(newIndex, false);
drawMainImage(newIndex, false, isFullscreen);
}
/**
@@ -904,7 +913,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
if (enabled && !imageTypes.isEmpty()) {
Log.d(TAG, "Move into fullscreen");
drawMainImage(mainImageIndex, true);
drawMainImage(mainImageIndex, true, isFullscreen);
barcodeScaler.setProgress(loyaltyCard.zoomLevel);
setCenterGuideline(loyaltyCard.zoomLevel);
@@ -950,7 +959,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
// Reset center guideline
setCenterGuideline(100);
drawMainImage(mainImageIndex, true);
drawMainImage(mainImageIndex, true, isFullscreen);
// Show maximize and hide minimize button and scaler
maximizeButton.setVisibility(imageTypes.isEmpty() ? View.GONE : View.VISIBLE);

View File

@@ -0,0 +1,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="10dp" />
</shape>

View File

@@ -5,6 +5,7 @@
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:background="@drawable/round_outline"
android:importantForAccessibility="no"
android:layout_width="match_parent"
android:layout_height="@dimen/barcode_disp_height"

View File

@@ -179,17 +179,18 @@
<!-- Barcode -->
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:layout_marginTop="10.0dp"
android:layout_marginStart="10.0dp"
android:layout_marginEnd="10.0dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/barcodeLayout">
<ImageView
android:background="@drawable/round_outline"
android:importantForAccessibility="no"
android:layout_width="0dp"
android:layout_height="@dimen/barcode_disp_height"
android:layout_gravity="center_horizontal"
android:padding="10.0dp"
android:background="#ffffff"
android:id="@+id/barcode"
android:layout_weight="1.0"/>
</LinearLayout>

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 74 KiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 59 KiB