pull/589/head
FongMi 1 year ago
parent 7d55374b48
commit 6d4547ad69
  1. 48
      app/src/main/java/com/fongmi/android/tv/utils/ColorGenerator.java
  2. 8
      app/src/main/java/com/fongmi/android/tv/utils/ImgUtil.java
  3. 31
      app/src/main/java/com/fongmi/android/tv/utils/QRCode.java

@ -7,30 +7,30 @@ import java.util.List;
public class ColorGenerator {
private static final List<Integer> PALETTE_500;
private static final List<Integer> PALETTE_400;
private static final List<Integer> PALETTE_700;
static {
PALETTE_500 = new ArrayList<>();
PALETTE_500.add(MDColor.RED_500);
PALETTE_500.add(MDColor.PINK_500);
PALETTE_500.add(MDColor.PURPLE_500);
PALETTE_500.add(MDColor.DEEP_PURPLE_500);
PALETTE_500.add(MDColor.INDIGO_500);
PALETTE_500.add(MDColor.BLUE_500);
PALETTE_500.add(MDColor.LIGHT_BLUE_500);
PALETTE_500.add(MDColor.CYAN_500);
PALETTE_500.add(MDColor.TEAL_500);
PALETTE_500.add(MDColor.GREEN_500);
PALETTE_500.add(MDColor.LIGHT_GREEN_500);
PALETTE_500.add(MDColor.LIME_500);
PALETTE_500.add(MDColor.YELLOW_500);
PALETTE_500.add(MDColor.AMBER_500);
PALETTE_500.add(MDColor.ORANGE_500);
PALETTE_500.add(MDColor.DEEP_ORANGE_500);
PALETTE_500.add(MDColor.BROWN_500);
PALETTE_500.add(MDColor.GREY_500);
PALETTE_500.add(MDColor.BLUE_GREY_500);
PALETTE_400 = new ArrayList<>();
PALETTE_400.add(MDColor.RED_400);
PALETTE_400.add(MDColor.PINK_400);
PALETTE_400.add(MDColor.PURPLE_400);
PALETTE_400.add(MDColor.DEEP_PURPLE_400);
PALETTE_400.add(MDColor.INDIGO_400);
PALETTE_400.add(MDColor.BLUE_400);
PALETTE_400.add(MDColor.LIGHT_BLUE_400);
PALETTE_400.add(MDColor.CYAN_400);
PALETTE_400.add(MDColor.TEAL_400);
PALETTE_400.add(MDColor.GREEN_400);
PALETTE_400.add(MDColor.LIGHT_GREEN_400);
PALETTE_400.add(MDColor.LIME_400);
PALETTE_400.add(MDColor.YELLOW_400);
PALETTE_400.add(MDColor.AMBER_400);
PALETTE_400.add(MDColor.ORANGE_400);
PALETTE_400.add(MDColor.DEEP_ORANGE_400);
PALETTE_400.add(MDColor.BROWN_400);
PALETTE_400.add(MDColor.GREY_400);
PALETTE_400.add(MDColor.BLUE_GREY_400);
PALETTE_700 = new ArrayList<>();
PALETTE_700.add(MDColor.RED_700);
@ -54,11 +54,11 @@ public class ColorGenerator {
PALETTE_700.add(MDColor.BLUE_GREY_700);
}
public static int get500(String key) {
return PALETTE_500.get(Math.abs(key.hashCode()) % PALETTE_500.size());
public static int get400(String key) {
return PALETTE_400.get((key.hashCode() & Integer.MAX_VALUE) % PALETTE_400.size());
}
public static int get700(String key) {
return PALETTE_700.get(Math.abs(key.hashCode()) % PALETTE_700.size());
return PALETTE_700.get((key.hashCode() & Integer.MAX_VALUE) % PALETTE_700.size());
}
}

@ -50,14 +50,14 @@ public class ImgUtil {
public static void load(String text, String url, ImageView view, ImageView.ScaleType scaleType, boolean rect) {
view.setScaleType(scaleType);
if (!TextUtils.isEmpty(url)) Glide.with(App.get()).asBitmap().load(getUrl(url)).placeholder(R.drawable.ic_img_loading).skipMemoryCache(true).dontAnimate().sizeMultiplier(Setting.getThumbnail()).signature(getSignature(url)).listener(getListener(view, scaleType)).into(view);
else if (text.length() > 0) view.setImageDrawable(getTextDrawable(text.substring(0, 1), rect));
else if (!text.isEmpty()) view.setImageDrawable(getTextDrawable(text.substring(0, 1), rect));
else view.setImageResource(R.drawable.ic_img_error);
}
public static void loadVod(String text, String url, ImageView view) {
view.setScaleType(ImageView.ScaleType.CENTER);
if (!TextUtils.isEmpty(url)) Glide.with(App.get()).asBitmap().load(getUrl(url)).placeholder(R.drawable.ic_img_loading).listener(getListener(view)).into(view);
else if (text.length() > 0) view.setImageDrawable(getTextDrawable(text.substring(0, 1), true));
else if (!text.isEmpty()) view.setImageDrawable(getTextDrawable(text.substring(0, 1), true));
else view.setImageResource(R.drawable.ic_img_error);
}
@ -69,8 +69,8 @@ public class ImgUtil {
private static Drawable getTextDrawable(String text, boolean rect) {
TextDrawable.Builder builder = new TextDrawable.Builder().withBorder(ResUtil.dp2px(2), ColorGenerator.get700(text));
if (rect) return builder.buildRoundRect(text, ColorGenerator.get500(text), ResUtil.dp2px(8));
return builder.buildRound(text, ColorGenerator.get500(text));
if (rect) return builder.buildRoundRect(text, ColorGenerator.get400(text), ResUtil.dp2px(8));
return builder.buildRound(text, ColorGenerator.get400(text));
}
public static Object getUrl(String url) {

@ -13,27 +13,24 @@ import java.util.Map;
public class QRCode {
private static Bitmap createBitmap(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = matrix.get(x, y) ? Color.BLACK : Color.WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
public static Bitmap getBitmap(String contents, int size, int margin) {
public static Bitmap getBitmap(String content, int size, int margin) {
try {
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.MARGIN, margin);
return createBitmap(new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, ResUtil.dp2px(size), ResUtil.dp2px(size), hints));
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, ResUtil.dp2px(size), ResUtil.dp2px(size), hints);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = matrix.get(x, y) ? Color.BLACK : Color.WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
} catch (Exception e) {
return null;
}

Loading…
Cancel
Save