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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
<bytecodeTargetLevel target="1.8" />
</component>
</project>

View File

@ -18,5 +18,5 @@
</option>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>

View File

@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 2,
"versionName": "0.2",
"versionCode": 3,
"versionName": "0.3.1",
"outputFile": "app-release.apk"
}
]

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