Improve image handling

as there is a new type coming soon
This commit is contained in:
ligi 2015-06-15 22:07:30 +02:00
parent c41b4af545
commit 9a6181699b
6 changed files with 31 additions and 50 deletions

View file

@ -3,12 +3,25 @@ package org.ligi.passandroid.model;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import java.io.Serializable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import org.joda.time.DateTime;
public interface Pass extends Serializable {
String BITMAP_ICON = "icon";
String BITMAP_THUMBNAIL = "thumbnail";
String BITMAP_STRIP = "strip";
String BITMAP_LOGO = "logo";
@StringDef({BITMAP_ICON, BITMAP_THUMBNAIL, BITMAP_STRIP, BITMAP_LOGO})
@Retention(RetentionPolicy.SOURCE)
@interface PassBitmap {
}
String[] TYPES = new String[]{"generic", "coupon", "eventTicket", "boardingPass", "storeCard"};
String getDescription();
@ -73,16 +86,6 @@ public interface Pass extends Serializable {
String getApp();
@Nullable
Bitmap getIconBitmap();
@Nullable
Bitmap getThumbnailImage();
@Nullable
Bitmap getStripBitmap();
@Nullable
Bitmap getLogoBitmap();
Bitmap getBitmap(@PassBitmap String passBitmap);
}

View file

@ -4,11 +4,14 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@ -18,10 +21,7 @@ import org.ligi.tracedroid.logging.Log;
@Data
public class PassImpl implements FiledPass, Serializable {
public static final String FNAME_ICON = "icon";
public static final String FNAME_THUMBNAIL = "thumbnail";
public static final String FNAME_STRIP = "strip";
public static final String FNAME_LOGO = "logo";
public static final String FILETYPE_IMAGES = ".png";
private String organisation = null;
@ -83,8 +83,9 @@ public class PassImpl implements FiledPass, Serializable {
}
@Nullable
private Bitmap getBitmapFromFileNameString(final String in) {
final String fileWithPathString = getPath() + "/" + in + PassImpl.FILETYPE_IMAGES;
@Override
public Bitmap getBitmap(@PassBitmap final String passBitmap) {
final String fileWithPathString = getPath() + "/" + passBitmap + PassImpl.FILETYPE_IMAGES;
try {
final File file = new File(fileWithPathString);
@ -94,30 +95,6 @@ public class PassImpl implements FiledPass, Serializable {
}
}
@Override
@Nullable
public Bitmap getIconBitmap() {
return getBitmapFromFileNameString(FNAME_ICON);
}
@Override
@Nullable
public Bitmap getThumbnailImage() {
return getBitmapFromFileNameString(FNAME_THUMBNAIL);
}
@Override
@Nullable
public Bitmap getStripBitmap() {
return getBitmapFromFileNameString(FNAME_STRIP);
}
@Override
@Nullable
public Bitmap getLogoBitmap() {
return getBitmapFromFileNameString(FNAME_LOGO);
}
@NonNull
public String getTypeNotNull() {
return (type == null) ? "none" : type;

View file

@ -50,10 +50,10 @@ public class AppleStylePassReader {
translation.loadFromFile(file);
}
copyBitmapFile(path, localized_path, PassImpl.FNAME_ICON);
copyBitmapFile(path, localized_path, PassImpl.FNAME_LOGO);
copyBitmapFile(path, localized_path, PassImpl.FNAME_STRIP);
copyBitmapFile(path, localized_path, PassImpl.FNAME_THUMBNAIL);
copyBitmapFile(path, localized_path, PassImpl.BITMAP_ICON);
copyBitmapFile(path, localized_path, PassImpl.BITMAP_LOGO);
copyBitmapFile(path, localized_path, PassImpl.BITMAP_STRIP);
copyBitmapFile(path, localized_path, PassImpl.BITMAP_THUMBNAIL);
final File file = new File(path + "/pass.json");

View file

@ -113,12 +113,12 @@ public class PassViewActivity extends PassViewActivityBase {
setBitmapSafe(barcode_img, null);
}
setBitmapSafe(logo_img, pass.getLogoBitmap());
setBitmapSafe(logo_img, pass.getBitmap(Pass.BITMAP_LOGO));
logo_img.setBackgroundColor(pass.getBackgroundColor());
setBitmapSafe(thumbnail_img, pass.getThumbnailImage());
setBitmapSafe(strip_img, pass.getStripBitmap());
setBitmapSafe(thumbnail_img, pass.getBitmap(Pass.BITMAP_THUMBNAIL));
setBitmapSafe(strip_img, pass.getBitmap(Pass.BITMAP_STRIP));
if (findViewById(R.id.map_container) != null) {
if (!(pass.getLocations().size() > 0 && PassbookMapsFacade.init(this))) {

View file

@ -97,7 +97,7 @@ public class PassViewHolder extends RecyclerView.ViewHolder {
addCalendar.setVisibility(View.INVISIBLE);
}
final Bitmap iconBitmap = pass.getIconBitmap();
final Bitmap iconBitmap = pass.getBitmap(Pass.BITMAP_ICON);
if (iconBitmap != null) {
final int size = (int) root.getResources().getDimension(R.dimen.pass_icon_size);

View file

@ -17,6 +17,7 @@ import org.ligi.passandroid.R;
import org.ligi.passandroid.events.SortOrderChangeEvent;
import org.ligi.passandroid.model.FiledPass;
import org.ligi.passandroid.model.InputStreamWithSource;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PastLocationsStore;
import org.ligi.passandroid.reader.AppleStylePassReader;
import org.ligi.tracedroid.logging.Log;
@ -129,7 +130,7 @@ public class SearchPassesIntentService extends IntentService {
final String language = getBaseContext().getResources().getConfiguration().locale.getLanguage();
final FiledPass pass = AppleStylePassReader.read(App.getPassStore().getPathForID(uuid), language);
App.getBus().post(new SortOrderChangeEvent());
final Bitmap iconBitmap = pass.getIconBitmap();
final Bitmap iconBitmap = pass.getBitmap(Pass.BITMAP_ICON);
if (iconBitmap != null) {
final Bitmap bitmap = scale2maxSize(iconBitmap, getResources().getDimensionPixelSize(R.dimen.finger));
findNotificationBuilder.setLargeIcon(bitmap);