mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-01-16 19:08:00 -05:00
Start implementing color parsing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -12,6 +13,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@@ -93,6 +96,32 @@ public class PkpassImporter {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, null, null);
|
||||
// Prepare to parse colors
|
||||
Pattern rgbPattern = Pattern.compile("^rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)$");
|
||||
|
||||
// Optional. Background color of the pass, specified as an CSS-style RGB triple. For example, rgb(23, 187, 82).
|
||||
Integer headerColor = null;
|
||||
Matcher headerColorMatcher = rgbPattern.matcher(json.getString("backgroundColor"));
|
||||
if(headerColorMatcher.find())
|
||||
{
|
||||
headerColor = Color.rgb(
|
||||
Integer.parseInt(headerColorMatcher.group(0)),
|
||||
Integer.parseInt(headerColorMatcher.group(1)),
|
||||
Integer.parseInt(headerColorMatcher.group(2)));
|
||||
}
|
||||
|
||||
|
||||
// Optional. Color of the label text, specified as a CSS-style RGB triple. For example, rgb(255, 255, 255).
|
||||
Integer headerTextColor = null;
|
||||
Matcher headerTextColorMatcher = rgbPattern.matcher(json.getString("labelColor"));
|
||||
if(headerTextColorMatcher.find())
|
||||
{
|
||||
headerTextColor = Color.rgb(
|
||||
Integer.parseInt(headerTextColorMatcher.group(0)),
|
||||
Integer.parseInt(headerTextColorMatcher.group(1)),
|
||||
Integer.parseInt(headerTextColorMatcher.group(2)));
|
||||
}
|
||||
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -110,5 +111,7 @@ public class PkpassTest {
|
||||
assertEquals(card.cardId, "0000001");
|
||||
assertEquals(card.note, "Staff Pass for Employee Number 001");
|
||||
assertEquals(card.store, "Passbook Example Company");
|
||||
assertEquals(card.headerColor, String.valueOf(Color.rgb(90, 90, 90)));
|
||||
assertEquals(card.headerTextColor, String.valueOf(Color.rgb(255, 255, 255)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user