diff --git a/promo/icon512x512.png b/promo/icon512x512.png new file mode 100644 index 00000000..ae85559a Binary files /dev/null and b/promo/icon512x512.png differ diff --git a/src/main/java/org/ligi/ticketviewer/App.java b/src/main/java/org/ligi/ticketviewer/App.java index 035c9794..330e3d10 100644 --- a/src/main/java/org/ligi/ticketviewer/App.java +++ b/src/main/java/org/ligi/ticketviewer/App.java @@ -21,4 +21,8 @@ public class App extends Application { Log.setTAG("TicketViewer"); } + public static boolean isDeveloperMode() { + return true; + } + } diff --git a/src/main/java/org/ligi/ticketviewer/helper/PassbookVisualisationHelper.java b/src/main/java/org/ligi/ticketviewer/helper/PassbookVisualisationHelper.java index ba456628..243acf42 100644 --- a/src/main/java/org/ligi/ticketviewer/helper/PassbookVisualisationHelper.java +++ b/src/main/java/org/ligi/ticketviewer/helper/PassbookVisualisationHelper.java @@ -1,7 +1,6 @@ package org.ligi.ticketviewer.helper; import android.graphics.Bitmap; -import android.text.Html; import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -12,7 +11,7 @@ import org.ligi.ticketviewer.model.PassbookParser; import java.util.List; public class PassbookVisualisationHelper { - public static void visualizePassbookData(PassbookParser passbookParser, View res, boolean verbose) { + public static void visualizePassbookData(PassbookParser passbookParser, View res) { TextView tv = (TextView) res.findViewById(R.id.label); TextView more_tv = (TextView) res.findViewById(R.id.descr); View colorIndicator = res.findViewById(R.id.colorIndicator); @@ -29,7 +28,7 @@ public class PassbookVisualisationHelper { if (ico != null) { icon_img.setImageBitmap(Bitmap.createScaledBitmap(ico, size, size, false)); } else { - icon_img.setImageBitmap(Bitmap.createScaledBitmap(ico, size, size, false)); + icon_img.setImageResource(R.drawable.ic_launcher); } } @@ -40,21 +39,16 @@ public class PassbookVisualisationHelper { //more_tv.setTextColor(passbookParser.getForegroundColor()); colorIndicator.setBackgroundColor(passbookParser.getBackGroundColor()); - tv.setText(passbookParser.getDescription()); + tv.setText(passbookParser.getType()); String more_str = ""; - if (passbookParser.getType() != null) { - more_str += getFieldListAsString(passbookParser.getPrimaryFields()); - more_str += getFieldListAsString(passbookParser.getSecondaryFields()); - more_str += getFieldListAsString(passbookParser.getHeaderFields()); + /* - if (verbose) { - more_str += getFieldListAsString(passbookParser.getAuxiliaryFields()); - } - } +*/ + + more_tv.setText(passbookParser.getDescription()); - more_tv.setText(Html.fromHtml(more_str)); } catch (Exception e) { } diff --git a/src/main/java/org/ligi/ticketviewer/helper/SafeJSONReader.java b/src/main/java/org/ligi/ticketviewer/helper/SafeJSONReader.java index fba48f03..276d850a 100644 --- a/src/main/java/org/ligi/ticketviewer/helper/SafeJSONReader.java +++ b/src/main/java/org/ligi/ticketviewer/helper/SafeJSONReader.java @@ -68,6 +68,9 @@ public class SafeJSONReader { }}; public static JSONObject readJSONSafely(String str) throws JSONException { + if (str == null) { + return null; + } String allReplaced = str; // first try with single fixes diff --git a/src/main/java/org/ligi/ticketviewer/model/PassbookParser.java b/src/main/java/org/ligi/ticketviewer/model/PassbookParser.java index ed9025c8..a0471d0d 100644 --- a/src/main/java/org/ligi/ticketviewer/model/PassbookParser.java +++ b/src/main/java/org/ligi/ticketviewer/model/PassbookParser.java @@ -28,17 +28,15 @@ public class PassbookParser { private String path; private boolean passbook_valid = true; // be positive private String barcodeMessage; - private Bitmap barcodeBitmap = null; private com.google.zxing.BarcodeFormat barcodeFormat; - private Bitmap icon_bitmap; private int backGroundColor; private int foregroundColor; private String description; private String type; private List primaryFields, secondaryFields, backFields, auxiliaryFields, headerFields; private List locations = new ArrayList(); - private JSONObject eventTicket = null; + public String plainJsonString; public PassbookParser(String path) { @@ -47,31 +45,33 @@ public class PassbookParser { JSONObject pass_json = null; final File file = new File(path + "/pass.json"); - try { - pass_json = SafeJSONReader.readJSONSafely(AXT.at(file).loadToString()); - } catch (Exception e) { - Log.i("PassParse Exception " + e); - } + if (file.exists()) { + try { + plainJsonString = AXT.at(file).loadToString(); + pass_json = SafeJSONReader.readJSONSafely(plainJsonString); + } catch (Exception e) { + Log.i("PassParse Exception " + e); + } - if (pass_json == null) { - // I had got a strange passbook with UCS-2 which could not be parsed before - // was searching for a auto-detection, but could not find one with support for this encoding - // and the right license + if (pass_json == null) { + // I had got a strange passbook with UCS-2 which could not be parsed before + // was searching for a auto-detection, but could not find one with support for this encoding + // and the right license - for (Charset charset : Charset.availableCharsets().values()) { - try { + for (Charset charset : Charset.availableCharsets().values()) { + try { - String json_str = AXT.at(file).loadToString(charset); - pass_json = SafeJSONReader.readJSONSafely(json_str); - } catch (Exception e) { - } + String json_str = AXT.at(file).loadToString(charset); + pass_json = SafeJSONReader.readJSONSafely(json_str); + } catch (Exception e) { + } - if (pass_json != null) { - break; + if (pass_json != null) { + break; + } } } } - if (pass_json == null) { Log.w("could not load pass.json from passcode "); Tracker.get().trackEvent("problem_event", "pass", "without_pass_json", null); @@ -321,23 +321,53 @@ public class PassbookParser { } public Bitmap getIconBitmap() { - if (icon_bitmap == null && path != null) { - /* - icon_bitmap = BitmapFactory.decodeFile(path + "/logo@2x.png"); + Bitmap result = null; - if (icon_bitmap == null) - icon_bitmap = BitmapFactory.decodeFile(path + "/logo.png"); - */ - if (icon_bitmap == null) { - icon_bitmap = BitmapFactory.decodeFile(path + "/icon@2x.png"); + if (path != null) { + + // first we try to fetch the small icon + result = BitmapFactory.decodeFile(path + "/icon@2x.png"); + + // if that failed we use the small one + if (result == null) { + result = BitmapFactory.decodeFile(path + "/icon.png"); } - if (icon_bitmap == null) { - icon_bitmap = BitmapFactory.decodeFile(path + "/icon.png"); + + } + return result; + } + + public Bitmap getThumbnailImage() { + Bitmap result = null; + + if (path != null) { + + // first we try to fetch the small icon + result = BitmapFactory.decodeFile(path + "/thumbnail@2x.png"); + + // if that failed we use the small one + if (result == null) { + result = BitmapFactory.decodeFile(path + "/thumbnail.png"); + } + + + } + return result; + } + + public Bitmap getLogoBitmap() { + Bitmap result = null; + + if (path != null) { + result = BitmapFactory.decodeFile(path + "/logo@2x.png"); + + if (result == null) { + result = BitmapFactory.decodeFile(path + "/logo.png"); } } - return icon_bitmap; + return result; } public int getBackGroundColor() { diff --git a/src/main/java/org/ligi/ticketviewer/ui/TicketListActivity.java b/src/main/java/org/ligi/ticketviewer/ui/TicketListActivity.java index f1ad0a1c..7d0c392e 100644 --- a/src/main/java/org/ligi/ticketviewer/ui/TicketListActivity.java +++ b/src/main/java/org/ligi/ticketviewer/ui/TicketListActivity.java @@ -288,7 +288,7 @@ public class TicketListActivity extends ActionBarActivity { View res = inflater.inflate(R.layout.pass_list_item, null); - PassbookVisualisationHelper.visualizePassbookData(passbookParser, res, false); + PassbookVisualisationHelper.visualizePassbookData(passbookParser, res); return res; } diff --git a/src/main/java/org/ligi/ticketviewer/ui/TicketViewActivity.java b/src/main/java/org/ligi/ticketviewer/ui/TicketViewActivity.java index 5796bdf1..c89f9403 100644 --- a/src/main/java/org/ligi/ticketviewer/ui/TicketViewActivity.java +++ b/src/main/java/org/ligi/ticketviewer/ui/TicketViewActivity.java @@ -13,12 +13,16 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import org.ligi.axt.AXT; +import org.ligi.ticketviewer.App; import org.ligi.ticketviewer.R; import org.ligi.ticketviewer.TicketDefinitions; import org.ligi.ticketviewer.helper.PassbookVisualisationHelper; import org.ligi.ticketviewer.maps.PassbookMapsFacade; import org.ligi.ticketviewer.model.PassbookParser; +import java.io.File; + public class TicketViewActivity extends TicketViewActivityBase { @@ -26,7 +30,6 @@ public class TicketViewActivity extends TicketViewActivityBase { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (!passbookParser.isValid()) { // don't deal with invalid passes new AlertDialog.Builder(this) .setMessage("Sorry, but there was a problem processing this Passbook. If you want you can send me this passbook so I can check what the problem is and improve the software.") @@ -47,14 +50,16 @@ public class TicketViewActivity extends TicketViewActivityBase { return; } - View v = getLayoutInflater().inflate(R.layout.activity_ticket_view, null); - setContentView(v); + View contentView = getLayoutInflater().inflate(R.layout.activity_ticket_view, null); + setContentView(contentView); ImageView barcode_img = (ImageView) findViewById(R.id.barcode_img); + ImageView logo_img = (ImageView) findViewById(R.id.logo_img); + ImageView thumbnail_img = (ImageView) findViewById(R.id.thumbnail_img); - int smallestSize = Math.min(getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getWidth()); - - barcode_img.setImageBitmap(passbookParser.getBarcodeBitmap(smallestSize / 3)); + barcode_img.setImageBitmap(passbookParser.getBarcodeBitmap(AXT.at(getWindowManager()).getSmallestSide() / 3)); + logo_img.setImageBitmap(passbookParser.getLogoBitmap()); + thumbnail_img.setImageBitmap(passbookParser.getThumbnailImage()); // when clicking on the barcode we want to go to the activity showing the barcode fullscreen barcode_img.setOnClickListener(new View.OnClickListener() { @@ -74,17 +79,40 @@ public class TicketViewActivity extends TicketViewActivityBase { } } - String back_str = ""; - for (PassbookParser.Field f : passbookParser.getBackFields()) { - back_str += "" + f.label + ": " + f.value + "
"; + if (passbookParser.getType() != null) { + TextView front_tv = getAQ().find(R.id.main_fields).getTextView(); + String front_str = ""; + front_str += PassbookVisualisationHelper.getFieldListAsString(passbookParser.getPrimaryFields()); + front_str += PassbookVisualisationHelper.getFieldListAsString(passbookParser.getSecondaryFields()); + front_str += PassbookVisualisationHelper.getFieldListAsString(passbookParser.getHeaderFields()); + front_str += PassbookVisualisationHelper.getFieldListAsString(passbookParser.getAuxiliaryFields()); + + front_tv.setText(Html.fromHtml(front_str)); } + String back_str = ""; + + if (App.isDeveloperMode()) { + back_str += getPassDebugInfo(passbookParser); + } + + back_str += PassbookVisualisationHelper.getFieldListAsString(passbookParser.getBackFields()); TextView back_tv = getAQ().find(R.id.back_fields).getTextView(); back_tv.setText(Html.fromHtml(back_str)); Linkify.addLinks(back_tv, Linkify.ALL); - PassbookVisualisationHelper.visualizePassbookData(passbookParser, v, true); + PassbookVisualisationHelper.visualizePassbookData(passbookParser, contentView); + } + public String getPassDebugInfo(PassbookParser passbook) { + + String result = passbook.plainJsonString; + + for (File f : new File(passbookParser.getPath()).listFiles()) { + result += f.getName() + "
"; + } + + return result; } @Override diff --git a/src/main/res/drawable-xxhdpi/ic_launcher.png b/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..a46fd192 Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_launcher.png b/src/main/res/drawable-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..f0e9fb51 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_launcher.png differ diff --git a/src/main/res/drawable/pkbox.9.png b/src/main/res/drawable/pkbox.9.png new file mode 100644 index 00000000..ac7f3d91 Binary files /dev/null and b/src/main/res/drawable/pkbox.9.png differ diff --git a/src/main/res/layout/activity_ticket_view_base.xml b/src/main/res/layout/activity_ticket_view_base.xml index adbd4150..f4227265 100644 --- a/src/main/res/layout/activity_ticket_view_base.xml +++ b/src/main/res/layout/activity_ticket_view_base.xml @@ -1,38 +1,55 @@ + android:layout_width="match_parent" + android:layout_height="match_parent"> + + + + + + + - + /> - - - - + - + /> + + \ No newline at end of file