Add footer image support
This is not really optional as one could think in the beginning USAirways hides TSA Precheck image there ..
This commit is contained in:
parent
2391fa8046
commit
be6899723a
4 changed files with 103 additions and 65 deletions
|
@ -16,12 +16,14 @@ public interface Pass extends Serializable {
|
|||
String BITMAP_THUMBNAIL = "thumbnail";
|
||||
String BITMAP_STRIP = "strip";
|
||||
String BITMAP_LOGO = "logo";
|
||||
String BITMAP_FOOTER = "footer";
|
||||
|
||||
@StringDef({BITMAP_ICON, BITMAP_THUMBNAIL, BITMAP_STRIP, BITMAP_LOGO})
|
||||
@StringDef({BITMAP_ICON, BITMAP_THUMBNAIL, BITMAP_STRIP, BITMAP_LOGO, BITMAP_FOOTER})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface PassBitmap {
|
||||
}
|
||||
|
||||
|
||||
String[] TYPES = new String[]{"generic", "coupon", "eventTicket", "boardingPass", "storeCard"};
|
||||
|
||||
String getDescription();
|
||||
|
|
|
@ -54,6 +54,7 @@ public class AppleStylePassReader {
|
|||
copyBitmapFile(path, localized_path, PassImpl.BITMAP_LOGO);
|
||||
copyBitmapFile(path, localized_path, PassImpl.BITMAP_STRIP);
|
||||
copyBitmapFile(path, localized_path, PassImpl.BITMAP_THUMBNAIL);
|
||||
copyBitmapFile(path, localized_path, PassImpl.BITMAP_FOOTER);
|
||||
|
||||
final File file = new File(path + "/pass.json");
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.ligi.passandroid.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.text.Html;
|
||||
|
@ -13,6 +15,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
@ -51,6 +54,9 @@ public class PassViewActivity extends PassViewActivityBase {
|
|||
@InjectView(R.id.logo_img)
|
||||
ImageView logo_img;
|
||||
|
||||
@InjectView(R.id.footer_img)
|
||||
ImageView footer_img;
|
||||
|
||||
@InjectView(R.id.thumbnail_img)
|
||||
ImageView thumbnail_img;
|
||||
|
||||
|
@ -114,8 +120,7 @@ public class PassViewActivity extends PassViewActivityBase {
|
|||
}
|
||||
|
||||
setBitmapSafe(logo_img, pass.getBitmap(Pass.BITMAP_LOGO));
|
||||
|
||||
logo_img.setBackgroundColor(pass.getBackgroundColor());
|
||||
setBitmapSafe(footer_img, pass.getBitmap(Pass.BITMAP_FOOTER));
|
||||
|
||||
setBitmapSafe(thumbnail_img, pass.getBitmap(Pass.BITMAP_THUMBNAIL));
|
||||
setBitmapSafe(strip_img, pass.getBitmap(Pass.BITMAP_STRIP));
|
||||
|
@ -179,14 +184,31 @@ public class PassViewActivity extends PassViewActivityBase {
|
|||
private static void setBitmapSafe(ImageView imageView, Bitmap bitmap) {
|
||||
|
||||
if (bitmap != null) {
|
||||
imageView.setLayoutParams(getLayoutParamsSoThatWeHaveAtLeasHalfAFinger(imageView, bitmap));
|
||||
|
||||
imageView.setImageBitmap(bitmap);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
imageView.requestLayout();
|
||||
} else {
|
||||
imageView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static ViewGroup.LayoutParams getLayoutParamsSoThatWeHaveAtLeasHalfAFinger(final ImageView imageView, final Bitmap bitmap) {
|
||||
final Context context = imageView.getContext();
|
||||
final int halfAFingerInPixels = context.getResources().getDimensionPixelSize(R.dimen.finger)/2 ;
|
||||
final ViewGroup.LayoutParams params=imageView.getLayoutParams();
|
||||
if (bitmap.getHeight()< halfAFingerInPixels) {
|
||||
params.height= halfAFingerInPixels;
|
||||
|
||||
} else {
|
||||
params.height= LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
|
|
|
@ -1,78 +1,91 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumbnail_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/logo"
|
||||
android:paddingBottom="10dp" />
|
||||
android:id="@+id/thumbnail_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/logo"
|
||||
android:paddingBottom="10dp"/>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/strip_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingBottom="10dp" />
|
||||
android:id="@+id/strip_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingBottom="10dp"
|
||||
tools:ignore="ContentDescription"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/front_field_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/barcode_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/barcode" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/barcode_alt_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingBottom="10dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/moreTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:fontFamily="sans-serif"
|
||||
android:padding="10dp"
|
||||
android:text="@string/more"
|
||||
android:textSize="21sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/back_fields"
|
||||
android:id="@+id/front_field_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif"
|
||||
android:padding="20dp"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
android:visibility="gone" />
|
||||
<ImageView
|
||||
android:id="@+id/barcode_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/barcode"/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/barcode_alt_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingBottom="10dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/moreTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:fontFamily="sans-serif"
|
||||
android:padding="10dp"
|
||||
android:text="@string/more"
|
||||
android:textSize="21sp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/back_fields"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif"
|
||||
android:padding="24dp"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logo_img"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/logo"
|
||||
android:padding="3dp"
|
||||
android:paddingBottom="3dp" />
|
||||
android:id="@+id/logo_img"
|
||||
android:scaleType="fitXY"
|
||||
tools:src="@drawable/ic_launcher"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/logo"
|
||||
android:padding="8dp"/>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/footer_img"
|
||||
android:scaleType="fitXY"
|
||||
tools:src="@drawable/ic_launcher"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="148dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/logo"
|
||||
android:padding="8dp"/>
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue