From 4592bb33828b971add62c63efb6c83e80db7e2e3 Mon Sep 17 00:00:00 2001 From: Daniele Date: Fri, 17 Sep 2021 08:58:27 +0200 Subject: [PATCH] WIP Porting category color code from Nextcloud Maps js code --- .idea/compiler.xml | 2 +- .idea/misc.xml | 2 +- app/release/output-metadata.json | 4 ++-- .../nextcloudmaps/utils/Color.java | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/it/danieleverducci/nextcloudmaps/utils/Color.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..61a9130 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 561b289..dd95f50 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -18,5 +18,5 @@ - + \ No newline at end of file diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index fb95255..948c000 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -10,8 +10,8 @@ { "type": "SINGLE", "filters": [], - "versionCode": 2, - "versionName": "0.2", + "versionCode": 3, + "versionName": "0.3.1", "outputFile": "app-release.apk" } ] diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/Color.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/Color.java new file mode 100644 index 0000000..f92fc48 --- /dev/null +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/Color.java @@ -0,0 +1,22 @@ +package it.danieleverducci.nextcloudmaps.utils; + +public class Color { + + /** + * Based on Nextcloud Maps's getLetterColor util + * @see "https://github.com/nextcloud/maps/blob/master/src/utils.js" + * @param catName category name + */ + public static generareCategoryColor(String catName) { + // If category is default, return default color + + // Else + int letter1Index = letter1.toLowerCase().charCodeAt(0); + int letter2Index = letter2.toLowerCase().charCodeAt(0); + var letterCoef = ((letter1Index * letter2Index) % 100) / 100; + var h = letterCoef * 360; + var s = 75 + letterCoef * 10; + var l = 50 + letterCoef * 10; + return {h: Math.round(h), s: Math.round(s), l: Math.round(l)}; + } +}