Permalink
Browse files

Enable suggestions from Varnam

  • Loading branch information...
malayaleecoder committed Aug 27, 2016
1 parent 8921660 commit 3d6c2b190a67092219d388381e00c81afeaf4d4c
@@ -7,12 +7,15 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;


public class Varnam{

private String engineName;
private ArrayList<String> suggestions = new ArrayList<>();

public String transliterate(String input) {
String starting = "https://api.varnamproject.com/tl/";
starting = starting + getLanguage() + "/";
@@ -27,7 +30,11 @@ public String transliterate(String input) {
scan.close();
JSONObject json = new JSONObject(finalresult);
JSONArray dummy = json.getJSONArray("result");
return dummy.getString(0);
suggestions.clear();
for(int i = 0; i < dummy.length(); i++) {
suggestions.add(dummy.getString(i));
}
return suggestions.get(0);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
@@ -37,6 +44,14 @@ public String transliterate(String input) {
}
}

public ArrayList<SuggestedWords.SuggestedWordInfo> getSuggestions() {
final ArrayList<SuggestedWords.SuggestedWordInfo> suggestionsList = new ArrayList<>();
int n = suggestions.size();
for(int i = 0; i < suggestions.size(); i++) {
suggestionsList.add(new SuggestedWords.SuggestedWordInfo(suggestions.get(i), i, 0, null, -1, -1));
}
return suggestionsList;
}
public void setEngineName(String engineName1) {
engineName = engineName1;
}
@@ -65,7 +65,7 @@
// as an ad-hockery here.
private String mRejectedBatchModeSuggestion;
private InputMethod mTransliterationMethod;
private Varnam mTransliterationEngine;
public Varnam mTransliterationEngine;
// Cache these values for performance
private CharSequence mTypedWordCache;
private int mCapsCount;
@@ -83,6 +83,10 @@
*/
private boolean mIsOnlyFirstCharCapitalized;

public String finalword = "";
public String previousreplacement = "";
public int startPosition;

public WordComposer() {
mCombinerChain = new CombinerChain("");
mEvents = new ArrayList<>();
@@ -243,9 +247,7 @@ public void applyTransliteration(final Event event) {
}
}
}
String finalword = "";
String previousreplacement = "";
int startPosition;

public void applyTransliterationByEngine (final Event event) {
context = "";
final int primaryCode = event.mCodePoint;
@@ -121,6 +121,7 @@ public void onClickComposingTextToAddToDictionary(final String word) {

private boolean isIndic;
private boolean isTransliteration;
public boolean isTransliterationByEngine;
/**
* Create a new instance of the input logic.
* @param latinIME the instance of the parent LatinIME. We should remove this when we can.
@@ -1398,7 +1399,15 @@ public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
final SuggestedWords suggestedWords = holder.get(null,
Constants.GET_SUGGESTED_WORDS_TIMEOUT);
if (suggestedWords != null) {
mSuggestionStripViewAccessor.showSuggestionStrip(suggestedWords);
if(isTransliterationByEngine) {
SuggestedWords suggestedWords1 = new SuggestedWords(mWordComposer.mTransliterationEngine.getSuggestions(),
null, false, false, false, SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED);
mSuggestionStripViewAccessor.showSuggestionStrip(suggestedWords1);

}
else {
mSuggestionStripViewAccessor.showSuggestionStrip(suggestedWords);
}
}
}

@@ -2298,6 +2307,7 @@ public void setIndic(boolean flag) {

public void enableTransliteration(String transliterationMethod, Context context) {
InputMethod im;
isTransliterationByEngine = false;
try {
im = InputMethod.fromName(transliterationMethod, context);
mWordComposer.setTransliterationMethod(im);
@@ -2311,6 +2321,7 @@ public void enableTransliteration(String transliterationMethod, Context context)

public void enableTransliterationByEngine(String transliterationEngine, Context context) {
try {
isTransliterationByEngine = true;
Varnam vm = new Varnam();
mWordComposer.setTransliterationEngine(vm, transliterationEngine);
isTransliteration = true;
@@ -2321,6 +2332,7 @@ public void enableTransliterationByEngine(String transliterationEngine, Context
}

public void disableTransliteration() {
isTransliterationByEngine = false;
mWordComposer.setTransliterationMethod(null);
mConnection.setTransliterationMethod(null);
isTransliteration = false;

0 comments on commit 3d6c2b1

Please sign in to comment.