alternative text for barcodes

This commit is contained in:
ligi 2014-09-15 20:32:33 +02:00
parent 61af0e8781
commit 608d334947
4 changed files with 33 additions and 8 deletions

View file

@ -92,7 +92,12 @@ public class AppleStylePassReader {
final String barcodeFormatString = barcode_json.getString("format");
final BarcodeFormat barcodeFormat = BarCode.getFormatFromString(barcodeFormatString);
pass.setBarCode(new BarCode(barcodeFormat, barcode_json.getString("message")));
final BarCode barCode = new BarCode(barcodeFormat, barcode_json.getString("message"));
pass.setBarCode(barCode);
if (barcode_json.has("altText")) {
pass.getBarCode().get().setAlternativeText(barcode_json.getString("altText"));
}
// TODO should check a bit more with barcode here - this can be dangerous

View file

@ -2,6 +2,7 @@ package org.ligi.passandroid.model;
import android.graphics.Bitmap;
import com.google.common.base.Optional;
import com.google.zxing.BarcodeFormat;
import org.ligi.passandroid.Tracker;
@ -14,10 +15,12 @@ import java.util.Locale;
public class BarCode implements Serializable {
private final BarcodeFormat barcodeFormat;
private final String barcodeMessage;
private Optional<String> alternativeText;
public BarCode(BarcodeFormat barcodeFormat, String barcodeMessage) {
this.barcodeFormat = barcodeFormat;
this.barcodeMessage = barcodeMessage;
alternativeText = Optional.absent();
}
public Bitmap getBitmap(final int size) {
@ -54,5 +57,12 @@ public class BarCode implements Serializable {
}
public void setAlternativeText(final String alternativeText) {
this.alternativeText = Optional.fromNullable(alternativeText);
}
public Optional<String> getAlternativeText() {
return alternativeText;
}
}

View file

@ -53,6 +53,10 @@ public class PassViewActivity extends PassViewActivityBase {
@InjectView(R.id.main_fields)
TextView front_tv;
@InjectView(R.id.barcode_alt_text)
TextView barcodeAlternatvieText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -90,20 +94,20 @@ public class PassViewActivity extends PassViewActivityBase {
ButterKnife.inject(this);
if (pass.getBarCode().isPresent()) {
barcode_img.setVisibility(View.VISIBLE);
} else {
barcode_img.setVisibility(View.GONE);
}
if (pass.getBarCode().isPresent()) {
final int smallestSide = AXT.at(getWindowManager()).getSmallestSide();
final Bitmap bitmap = pass.getBarCode().get().getBitmap(smallestSide / 3);
setBitmapSafe(barcode_img, Optional.fromNullable(bitmap));
if (pass.getBarCode().get().getAlternativeText().isPresent()) {
barcodeAlternatvieText.setText(pass.getBarCode().get().getAlternativeText().get());
barcodeAlternatvieText.setVisibility(View.VISIBLE);
} else {
barcodeAlternatvieText.setVisibility(View.GONE);
}
} else {
setBitmapSafe(barcode_img, Optional.<Bitmap>absent());
}
setBitmapSafe(logo_img, pass.getLogoBitmap());
logo_img.setBackgroundColor(pass.getBackGroundColor());

View file

@ -34,6 +34,12 @@
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/barcode_alt_text"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/back_fields"
android:layout_width="match_parent"