Permalink
Browse files

initial varnam keyboard commit

  • Loading branch information...
malayaleecoder committed Aug 21, 2016
1 parent 10fbed0 commit eb128110e2b763ff2e59f3b5a16770baa520f0a3
@@ -21,7 +21,7 @@
android:versionName="2.0.4">

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
@@ -12,7 +12,7 @@

public class Varnam{

public String readfromurl(String input) {
public String transliterate(String input) {
String starting = "https://api.varnamproject.com/tl/ml/";
String urlstring = starting + input;

@@ -27,12 +27,19 @@ public String readfromurl(String input) {
JSONArray dummy = json.getJSONArray("result");
return dummy.getString(0);
} catch (MalformedURLException e) {
throw new RuntimeExceptio(e);
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeExceptio(e);
throw new RuntimeException(e);
} catch (JSONException e) {
throw new RuntimeExceptio(e);
throw new RuntimeException(e);
}
return "";
}

public int getMaxKeyLength() {
return 4;
}

public int getContextLength() {
return 2;
}
}
@@ -241,6 +241,27 @@ public void applyTransliteration(final Event event) {
}
}

public void applyTransliterationByEngine(final Event event) {
context = "";
final int primaryCode = event.mCodePoint;

refreshTypedWordCache();

String mTypedWord = mTypedWordCache.toString();

if(mTransliterationEngine != null && Constants.CODE_DELETE != event.mKeyCode) {
String current = new String(Character.toChars(primaryCode));
int startPos = mTypedWord.length() - 1 > mTransliterationEngine.getMaxKeyLength() ? mTypedWord.length() - mTransliterationEngine.getMaxKeyLength() - 1: 0;
String replacement = mTransliterationEngine.transliterate(mTypedWord);
mCombinerChain.replace(startPos + replacement.length() - 1, mTypedWord.length(), replacement);

context += current;
if(context.length() > mTransliterationEngine.getContextLength()) {
context = context.substring(context.length() - mTransliterationEngine.getContextLength());
}
}
}

/**
* Apply a processed input event.
*
@@ -257,6 +278,7 @@ public void applyProcessedEvent(final Event event) {
final int newIndex = size();

applyTransliteration(event);
applyTransliterationByEngine(event);

refreshTypedWordCache();
mCursorPositionWithinWord = mCodePointSize;

0 comments on commit eb12811

Please sign in to comment.