Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4956)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java

Issue 1244443005: Patch 5: Implemented android message filter and platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@4_remove_mac_redundancies
Patch Set: Implemented Android spellchecker red underlining Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..18802c8c6a7941e74836e20b95db89e963d97ad8
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java
@@ -0,0 +1,112 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.spellchecker;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.view.textservice.SentenceSuggestionsInfo;
+import android.view.textservice.SpellCheckerSession;
+import android.view.textservice.SuggestionsInfo;
+import android.view.textservice.TextInfo;
+import android.view.textservice.TextServicesManager;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+/**
+* JNI interface for spellcheck_platform_android to use Android's spellchecker.
+*/
+@JNINamespace("spellcheck_platform")
+public class SpellCheckerSessionBridge implements SpellCheckerSession.SpellCheckerSessionListener {
+
+ private SpellCheckerSession mSpellCheckerSession;
+
+ private String mText;
+ public SpellCheckerSessionBridge() {
+
+ Context context = ApplicationStatus.getApplicationContext();
+ final TextServicesManager textServicesManager =
+ (TextServicesManager) context.getSystemService(
+ Context.TEXT_SERVICES_MANAGER_SERVICE);
+
+ Handler handler = new Handler(Looper.getMainLooper());
+ System.out.println("DYLANKING In Ctor1");
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ mSpellCheckerSession = textServicesManager.newSpellCheckerSession(null,
+ Locale.ENGLISH, SpellCheckerSessionBridge.this, true);
+ System.out.println("DYLANKING In Run" + (mSpellCheckerSession == null));
+ }
+ });
+ }
+
+ @CalledByNative
+ private static SpellCheckerSessionBridge create() {
+ return new SpellCheckerSessionBridge();
+ }
+
+ @CalledByNative
+ private void checkSpelling(String text) {
+ mSpellCheckerSession.getSentenceSuggestions(new TextInfo[]{ new TextInfo(text)}, 5);
+ System.out.println("DYLANKING checkSpelling on word: " + text);
+ mText = text;
+ }
+
+ @Override
+ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
+ System.out.println("DYLANKING top of onGetSentenceSuggestions");
+ ArrayList<String> suggestions = new ArrayList<String>();
+ ArrayList<Integer> offsets = new ArrayList<Integer>();
+ ArrayList<Integer> lengths = new ArrayList<Integer>();
+
+ for (SentenceSuggestionsInfo result: results) {
+ System.out.println("DYLANKING OnGetSuggestions Text: " + text + " length: "
+ + text.length());
+ for (int i = 0; i < result.getSuggestionsCount(); i++) {
+ SuggestionsInfo currentSuggestion = result.getSuggestionsInfoAt(i);
+ boolean isWordCorrect = (currentSuggestion.getSuggestionsAttributes()
+ & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) == 0;
+ int currOffset = result.getOffsetAt(i);
+ int currLength = result.getLengthAt(i);
+ if (!isWordCorrect) {
+ offsets.add(result.getOffsetAt(i));
+ lengths.add(result.getLengthAt(i));
+ System.out.println("DYLANKING offset: " + result.getOffsetAt(i)
+ + " length: " + result.getLengthAt(i));
+
+ for (int j = 0; j < currentSuggestion.getSuggestionsCount(); j++) {
+ suggestions.add(currentSuggestion.getSuggestionAt(j));
+ }
+ }
+ }
+ }
+
+ nativeGetSpellcheckInfo(suggestions.toArray(new String[suggestions.size()]),
+ convertListToArray(offsets), convertListToArray(lengths));
+ System.out.println("DYLANKING bottom of onGetSentenceSuggestions");
+ }
+
+ private int[] convertListToArray(ArrayList<Integer> toConvert) {
+ int[] toReturn = new int[toConvert.size()];
+ int index = 0;
+ for (Integer number : toConvert) {
+ toReturn[index++] = number.intValue();
+ }
+ return toReturn;
+ }
+
+ @Override
+ public void onGetSuggestions(SuggestionsInfo[] results) {
+ }
+
+ private native void nativeGetSpellcheckInfo(String[] nativeSuggestions, int[] offsets,
+ int[] lengths);
+}

Powered by Google App Engine
This is Rietveld 408576698