add some color

This commit is contained in:
ligi 2013-02-09 23:53:26 +01:00
parent 49b36cbae5
commit c6c8df083b
2 changed files with 30 additions and 11 deletions

View file

@ -9,6 +9,8 @@ import org.ligi.ticketviewer.helper.FileHelper;
import org.ligi.tracedroid.logging.Log;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* User: ligi
@ -18,15 +20,13 @@ import java.io.File;
public class PassbookParser {
private String path;
private String problem_str = "";
private boolean passbook_valid = true; // be positive
private String barcode_msg;
private Bitmap barcodeBitmap = null;
private com.google.zxing.BarcodeFormat barcodeFormat;
private Bitmap icon_bitmap;
private int bgcolor;
public PassbookParser(String path) {
@ -56,20 +56,36 @@ public class PassbookParser {
if (pass_json != null)
try {
String color_str = pass_json.getString("backgroundColor");
bgcolor = parseColor(pass_json.getString("backgroundColor"));
Log.i("parsed color:" + color_str);
} catch (JSONException e) {
}
}
private Integer parseColor(String color_str) {
Pattern pattern = Pattern.compile("rgb *\\( *([0-9]+), *([0-9]+), *([0-9]+) *\\)");
Matcher matcher = pattern.matcher(color_str);
if (matcher.matches()) {
return (255 << 24 |
Integer.valueOf(matcher.group(1)) << 16 | // r
Integer.valueOf(matcher.group(2)) << 24 | // g
Integer.valueOf(matcher.group(3))); // b
}
return null;
}
public boolean isValid() {
return passbook_valid;
}
public Bitmap getBarcodeBitmap() {
if (barcodeBitmap == null) {
barcodeBitmap = BarcodeHelper.generateBarCode(barcode_msg, barcodeFormat);
if (barcode_msg != null && barcodeFormat != null)
barcodeBitmap = BarcodeHelper.generateBarCode(barcode_msg, barcodeFormat);
else
Log.w("Barcode msg or format is null");
}
return barcodeBitmap;
}
@ -92,4 +108,8 @@ public class PassbookParser {
return icon_bitmap;
}
public int getBgcolor() {
return bgcolor;
}
}

View file

@ -5,7 +5,6 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@ -280,6 +279,8 @@ public class TicketListActivity extends SherlockListActivity {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String mPath = path + "/" + passes[position];
PassbookParser passbookParser = new PassbookParser(mPath);
View res = inflater.inflate(R.layout.pass_list_item, null);
TextView tv = (TextView) res.findViewById(R.id.label);
TextView more_tv = (TextView) res.findViewById(R.id.descr);
@ -315,16 +316,14 @@ public class TicketListActivity extends SherlockListActivity {
int size = (int) getResources().getDimension(R.dimen.pass_icon_size);
ImageView icon_img = (ImageView) res.findViewById(R.id.icon);
if (path != null) {
Bitmap ico = BitmapFactory.decodeFile(mPath + "/logo@2x.png");
if (ico == null)
ico = BitmapFactory.decodeFile(mPath + "/logo.png");
Bitmap ico = passbookParser.getIconBitmap();
if (ico != null)
icon_img.setImageBitmap(Bitmap.createScaledBitmap(ico, size, size, false));
}
icon_img.setBackgroundColor(passbookParser.getBgcolor());
return res;
}