aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-08-26 15:02:40 +0200
committerChristian Schneppe <christian@pix-art.de>2018-08-26 15:02:40 +0200
commit3e5c026f31b2403ea8e2387c1360bedb1ca4c27a (patch)
treef2297eaffd9d0e37f5157702a7476f9a804ccf39
parent251d6591df502c466a9d54a80dc4b3b939a61cdf (diff)
disabled by default variant of XEP-0392
-rw-r--r--build.gradle1
-rw-r--r--src/main/java/de/pixart/messenger/Config.java2
-rw-r--r--src/main/java/de/pixart/messenger/utils/UIHelper.java3
-rw-r--r--src/main/java/de/pixart/messenger/utils/XEP0392Helper.java30
4 files changed, 36 insertions, 0 deletions
diff --git a/build.gradle b/build.gradle
index b96a299ef..b18c3d864 100644
--- a/build.gradle
+++ b/build.gradle
@@ -64,6 +64,7 @@ dependencies {
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.3'
implementation 'in.championswimmer:SimpleFingerGestures_Android_Library:1.2'
implementation 'rocks.xmpp:xmpp-addr:0.8.0'
+ implementation 'org.hsluv:hsluv:0.2'
}
ext {
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java
index ac99b1709..644b0af82 100644
--- a/src/main/java/de/pixart/messenger/Config.java
+++ b/src/main/java/de/pixart/messenger/Config.java
@@ -77,6 +77,8 @@ public final class Config {
public static final int CONNECT_DISCO_TIMEOUT = 30;
public static final int MINI_GRACE_PERIOD = 750;
+ public static final boolean XEP_0392 = false; //enables a variant of XEP-0392 that is based on HSLUV
+
public static final int FILE_SIZE = 1048576; // 1 MiB
public static final int AVATAR_SIZE = 480;
diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java
index f5730e981..b603f68ee 100644
--- a/src/main/java/de/pixart/messenger/utils/UIHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java
@@ -222,6 +222,9 @@ public class UIHelper {
}
public static int getColorForName(String name, boolean safe) {
+ if (Config.XEP_0392) {
+ return XEP0392Helper.rgbFromNick(name);
+ }
if (name == null || name.isEmpty()) {
return 0xFF202020;
}
diff --git a/src/main/java/de/pixart/messenger/utils/XEP0392Helper.java b/src/main/java/de/pixart/messenger/utils/XEP0392Helper.java
new file mode 100644
index 000000000..bbfe50898
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/utils/XEP0392Helper.java
@@ -0,0 +1,30 @@
+package de.pixart.messenger.utils;
+
+import android.graphics.Color;
+
+import org.hsluv.HUSLColorConverter;
+
+import java.security.MessageDigest;
+
+public class XEP0392Helper {
+
+ private static double angle(String nickname) {
+ try {
+ MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
+ byte[] digest = sha1.digest(nickname.getBytes("UTF-8"));
+ int angle = ((int) (digest[0]) & 0xff) + ((int) (digest[1]) & 0xff) * 256;
+ return angle / 65536.;
+ } catch (Exception e) {
+ return 0.0;
+ }
+ }
+
+ public static int rgbFromNick(String name) {
+ double[] hsluv = new double[3];
+ hsluv[0] = angle(name) * 360;
+ hsluv[1] = 100;
+ hsluv[2] = 50;
+ double[] rgb = HUSLColorConverter.hsluvToRgb(hsluv);
+ return Color.rgb((int) Math.round(rgb[0] * 255), (int) Math.round(rgb[1] * 255), (int) Math.round(rgb[2] * 255));
+ }
+} \ No newline at end of file