From 65da823bd87a23bdd1dca427688d2f711109e59a Mon Sep 17 00:00:00 2001 From: Clam Date: Mon, 17 Feb 2014 19:05:58 +1100 Subject: [PATCH] Fix a little slowness and update build scripts --- .gitignore | 1 + build.gradle | 72 +++++++++++++++++-- .../nyanya/android/traditionalt9/T9DB.java | 7 +- .../android/traditionalt9/TraditionalT9.java | 4 +- 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 079b33e8..9a24713f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ proguard/ #Other .gradle/ assets/dict.properties +t9build.properties \ No newline at end of file diff --git a/build.gradle b/build.gradle index 043ce667..d0e9b2e7 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,65 @@ dependencies { compile fileTree(dir: 'libs', include: '*.jar') } +def execThing ( String cmdStr ) { + def stdout = new ByteArrayOutputStream() + String prefix = System.getenv("GITCMDPREFIX") + if (prefix != null) { + String cmd = prefix + cmdStr + exec { + commandLine cmd.tokenize() + standardOutput = stdout + } + } else { + exec { + commandLine cmdStr.tokenize() + standardOutput = stdout + } + } + return stdout +} + +def computeVersionName = { -> + + String ver = "git-source" + try { + if (execThing(" git status -z").toString().trim().equals("")) { + return execThing(' git log -1 --format="%h"').toString().trim() + } else { + return ver + } + } catch (all) { + ant.echo("Cannot run git (not in path?), using default versioning") + } + + return ver +} + +def getProps() { + Properties props = new Properties() + File f = new File("t9build.properties") + if (!f.exists()) { + f.createNewFile() + } + props.load(new FileInputStream(f)) + return props +} + +def saveProps(Properties props) { + props.store(new FileOutputStream(new File("t9build.properties"))) +} + +def computeVersionNumber = { -> + Properties props = getProps() + int verNum = Integer.valueOf(props.getProperty("verNum", "0")) + if (hasProperty('incrementBuildNumber')) { + verNum++ + props.setProperty("verNum", String.valueOf(verNum)) + saveProps(props) + } + return verNum +} + android { compileSdkVersion 10 buildToolsVersion "19.0.0" @@ -45,6 +104,12 @@ android { release.setRoot('build-types/release') } + + defaultConfig { + versionCode computeVersionNumber() + versionName computeVersionName() + } + // http://stackoverflow.com/a/19130098 signingConfigs { release { @@ -62,15 +127,10 @@ android { } } - task getDictSizes { inputs.files 'assets/en-utf8.txt', 'assets/ru-utf8.txt' - outputs.file "assets/dict.properties" + outputs.file "t9build.properties" doLast { - ant.echo("Deleting old file...") - - delete 'assets/dict.properties' - ant.echo("Calculating dict size...") FileCollection dicts = files("assets/en-utf8.txt", "assets/ru-utf8.txt") diff --git a/src/org/nyanya/android/traditionalt9/T9DB.java b/src/org/nyanya/android/traditionalt9/T9DB.java index 59e9bb46..f8bec301 100644 --- a/src/org/nyanya/android/traditionalt9/T9DB.java +++ b/src/org/nyanya/android/traditionalt9/T9DB.java @@ -32,6 +32,8 @@ public class T9DB { // 50k, 10k private static final int FREQ_MAX = 50000; private static final int FREQ_DIV = 10000; + // This seems to be pretty fast on my phone. 10 is pretty slow (Might be because > MAX_RESULTS (8).) + private static final int MINHITS = 4; protected static final String COLUMN_ID = BaseColumns._ID; protected static final String COLUMN_LANG = "lang"; @@ -257,8 +259,7 @@ public class T9DB { } cur.close(); - // TODO: profile this and if it takes too long to only do it when hits is super low... - if (hits < 10) { + if (hits < MINHITS) { char c = is.charAt(islen - 1); c++; String q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + @@ -363,7 +364,7 @@ public class T9DB { hits++; } cur.close(); - if (hits < 4) { + if (hits < MINHITS) { char c = is.charAt(islen - 1); c++; q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + ", " + COLUMN_FREQUENCY + diff --git a/src/org/nyanya/android/traditionalt9/TraditionalT9.java b/src/org/nyanya/android/traditionalt9/TraditionalT9.java index cfbe377a..52405e8b 100644 --- a/src/org/nyanya/android/traditionalt9/TraditionalT9.java +++ b/src/org/nyanya/android/traditionalt9/TraditionalT9.java @@ -270,9 +270,7 @@ public class TraditionalT9 extends InputMethodService implements updateCandidates(); - if (!restarting) { - // Clear shift states. - } + //TODO: Check if "restarting" variable will make things faster/more effecient mKeyMode = MODE_TEXT;