WIP Porting category color code from Nextcloud Maps js code

This commit is contained in:
Daniele
2021-09-17 08:58:27 +02:00
parent 88cf7711b0
commit 4592bb3382
4 changed files with 26 additions and 4 deletions

View File

@ -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)};
}
}