init redesign

This commit is contained in:
ligi 2013-12-04 00:07:17 +01:00
parent a4c0f22339
commit 12e9ea5cbb
11 changed files with 159 additions and 83 deletions

BIN
promo/icon512x512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View file

@ -21,4 +21,8 @@ public class App extends Application {
Log.setTAG("TicketViewer");
}
public static boolean isDeveloperMode() {
return true;
}
}

View file

@ -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) {
}

View file

@ -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

View file

@ -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<Field> primaryFields, secondaryFields, backFields, auxiliaryFields, headerFields;
private List<PassLocation> locations = new ArrayList<PassLocation>();
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() {

View file

@ -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;
}

View file

@ -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 += "<b>" + f.label + "</b>: " + f.value + "<br/>";
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() + "<br/>";
}
return result;
}
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

View file

@ -1,38 +1,55 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/pass_list_item" />
<ImageView
android:id="@+id/thumbnail_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
android:paddingBottom="10dp"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/main_fields"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/colorable_top"
android:orientation="vertical">
/>
<include layout="@layout/pass_list_item"/>
<ImageView
android:id="@+id/barcode_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
android:paddingBottom="10dp"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
<ImageView
android:id="@+id/barcode_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
android:paddingBottom="10dp"
android:layout_gravity="center_horizontal" />
<TextView android:id="@+id/back_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
<TextView
android:id="@+id/back_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
/>
/>
<ImageView
android:id="@+id/logo_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
android:paddingBottom="10dp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</ScrollView>