status icon cache now works, even with minified code
This commit is contained in:
parent
6e0c32b17d
commit
608e07a761
5 changed files with 128 additions and 40 deletions
|
|
@ -7,6 +7,7 @@ apply from: 'build-definitions.gradle'
|
||||||
apply from: 'build-dictionaries.gradle'
|
apply from: 'build-dictionaries.gradle'
|
||||||
apply from: 'validate-languages.gradle'
|
apply from: 'validate-languages.gradle'
|
||||||
apply from: 'help-tools.gradle'
|
apply from: 'help-tools.gradle'
|
||||||
|
apply from: 'status-icon-tools.gradle'
|
||||||
apply from: 'version-tools.gradle'
|
apply from: 'version-tools.gradle'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,6 +64,12 @@ tasks.register('generateDocs') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register('updateStatusIcons') {
|
||||||
|
doLast {
|
||||||
|
updateStatusIconCache(DEFINITIONS_INPUT_DIR, ICONS_DIR, ICONS_JAVA_FILE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tasks.register('updateManifest') {
|
tasks.register('updateManifest') {
|
||||||
doLast {
|
doLast {
|
||||||
updateManifestVersion(getVersionCode(), getVersionName())
|
updateManifestVersion(getVersionCode(), getVersionName())
|
||||||
|
|
@ -141,6 +148,8 @@ android {
|
||||||
|
|
||||||
applicationVariants.configureEach { variant ->
|
applicationVariants.configureEach { variant ->
|
||||||
def variantName = variant.name.capitalize()
|
def variantName = variant.name.capitalize()
|
||||||
|
tasks.named("javaPreCompile${variantName}")?.configure {dependsOn(updateStatusIcons) }
|
||||||
|
|
||||||
[
|
[
|
||||||
"merge${variantName}Assets",
|
"merge${variantName}Assets",
|
||||||
"lintAnalyze${variantName}",
|
"lintAnalyze${variantName}",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ ext.DICTIONARY_SIZES_DIR_NAME = 'dictionary-sizes'
|
||||||
|
|
||||||
def APP_ROOT_DIR = "${project.rootDir}/app"
|
def APP_ROOT_DIR = "${project.rootDir}/app"
|
||||||
ext.ICONS_DIR = "${APP_ROOT_DIR}/src/main/res/drawable"
|
ext.ICONS_DIR = "${APP_ROOT_DIR}/src/main/res/drawable"
|
||||||
|
ext.ICONS_JAVA_FILE = "${APP_ROOT_DIR}/src/main/java/${PACKAGE_NAME.replaceAll("\\.", "/")}/ui/StatusIcon.java"
|
||||||
def MAIN_ASSETS_DIR = "${APP_ROOT_DIR}/src/main/assets"
|
def MAIN_ASSETS_DIR = "${APP_ROOT_DIR}/src/main/assets"
|
||||||
def FULL_VERSION_ASSETS_DIR = "${APP_ROOT_DIR}/src/full/assets"
|
def FULL_VERSION_ASSETS_DIR = "${APP_ROOT_DIR}/src/full/assets"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ abstract class UiHandler extends AbstractHandler {
|
||||||
|
|
||||||
|
|
||||||
protected void setStatusIcon(InputMode mode, Language language) {
|
protected void setStatusIcon(InputMode mode, Language language) {
|
||||||
int resId = StatusIcon.getResource(this, settings, mode, language);
|
int resId = new StatusIcon(this, settings, mode, language).resourceId;
|
||||||
if (resId == 0) {
|
if (resId == 0) {
|
||||||
hideStatusIcon();
|
hideStatusIcon();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
78
app/status-icon-tools.gradle
Normal file
78
app/status-icon-tools.gradle
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
ext.updateStatusIconCache = { String definitionsDir, String drawablesDir, String javaFile ->
|
||||||
|
def java = new File(javaFile)
|
||||||
|
if (!java.exists()) {
|
||||||
|
throw new GradleException("Cannot update the status icons. Java file not found: ${javaFile}")
|
||||||
|
}
|
||||||
|
|
||||||
|
final METHOD_NAME = "generateIconsCache()"
|
||||||
|
|
||||||
|
def javaText = java.getText()
|
||||||
|
if (!javaText.contains(METHOD_NAME)) {
|
||||||
|
throw new GradleException("Cannot update the status icons. Method not found: ${METHOD_NAME}")
|
||||||
|
}
|
||||||
|
|
||||||
|
def hashMap = generateMap(definitionsDir, drawablesDir)
|
||||||
|
|
||||||
|
def newJava = java.getText().replaceFirst(/$METHOD_NAME.+?}/, "$METHOD_NAME { $hashMap }")
|
||||||
|
java.write(newJava)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static def generateMap(String definitionsDirPath, String drawablesDirPath) {
|
||||||
|
def drawablesDir = new File(drawablesDirPath)
|
||||||
|
if (!drawablesDir.exists()) {
|
||||||
|
throw new GradleException("Cannot update the status icons. Icons directory not found: ${drawablesDir}")
|
||||||
|
}
|
||||||
|
|
||||||
|
def definitionsDir = new File(definitionsDirPath)
|
||||||
|
if (!definitionsDir.exists()) {
|
||||||
|
throw new GradleException("Cannot update the status icons. Definitions directory not found: ${definitionsDir}")
|
||||||
|
}
|
||||||
|
|
||||||
|
def icons = []
|
||||||
|
|
||||||
|
definitionsDir.listFiles().each{ file ->
|
||||||
|
file.readLines().each { line ->
|
||||||
|
if (!line.contains("icon")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
def parts = line.split(":")
|
||||||
|
if (parts.length != 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
def iconName = parts[1].trim()
|
||||||
|
def iconFile = new File(drawablesDir, "${iconName}.xml")
|
||||||
|
if (iconFile.exists()) {
|
||||||
|
icons << iconName
|
||||||
|
}
|
||||||
|
|
||||||
|
def iconUppercase = new File(drawablesDir, "${iconName}_up.xml")
|
||||||
|
if (iconUppercase.exists()) {
|
||||||
|
icons << iconName + "_up"
|
||||||
|
}
|
||||||
|
|
||||||
|
def iconLowercase = new File(drawablesDir, "${iconName}_lo.xml")
|
||||||
|
if (iconLowercase.exists()) {
|
||||||
|
icons << iconName + "_lo"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def iconCapitalized = new File(drawablesDir, "${iconName}_cp.xml")
|
||||||
|
if (iconCapitalized.exists()) {
|
||||||
|
icons << iconName + "_cp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def javaHashMap = ""
|
||||||
|
icons = icons.sort()
|
||||||
|
|
||||||
|
for (int i = 0; i < icons.size(); i++) {
|
||||||
|
def iconName = icons[i]
|
||||||
|
javaHashMap += "ICONS.put(\"${iconName}\", R.drawable.${iconName});"
|
||||||
|
}
|
||||||
|
|
||||||
|
return javaHashMap
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue