Merge "Add functions to set / get SpellCheckerSubtype"
This commit is contained in:
@@ -3768,12 +3768,21 @@ public final class Settings {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link ComponentName} string of the service to be used as the spell checker
|
* The {@link ComponentName} string of the selected spell checker service which is
|
||||||
|
* one of the services managed by the text service manager.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String SELECTED_SPELL_CHECKER = "selected_spell_checker";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link ComponentName} string of the selected subtype of the selected spell checker
|
||||||
* service which is one of the services managed by the text service manager.
|
* service which is one of the services managed by the text service manager.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String SPELL_CHECKER_SERVICE = "spell_checker_service";
|
public static final String SELECTED_SPELL_CHECKER_SUBTYPE =
|
||||||
|
"selected_spell_checker_subtype";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What happens when the user presses the Power button while in-call
|
* What happens when the user presses the Power button while in-call
|
||||||
|
|||||||
@@ -135,11 +135,40 @@ public final class TextServicesManager {
|
|||||||
public void setCurrentSpellChecker(SpellCheckerInfo sci) {
|
public void setCurrentSpellChecker(SpellCheckerInfo sci) {
|
||||||
try {
|
try {
|
||||||
if (sci == null) {
|
if (sci == null) {
|
||||||
throw new NullPointerException("SpellCheckerInfo is null");
|
throw new NullPointerException("SpellCheckerInfo is null.");
|
||||||
}
|
}
|
||||||
sService.setCurrentSpellChecker(sci.getId());
|
sService.setCurrentSpellChecker(null, sci.getId());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Error in setCurrentSpellChecker: " + e);
|
Log.e(TAG, "Error in setCurrentSpellChecker: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public SpellCheckerSubtype getCurrentSpellCheckerSubtype() {
|
||||||
|
try {
|
||||||
|
// Passing null as a locale for ICS
|
||||||
|
return sService.getCurrentSpellCheckerSubtype(null);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Error in getCurrentSpellCheckerSubtype: " + e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setSpellCheckerSubtype(SpellCheckerSubtype subtype) {
|
||||||
|
try {
|
||||||
|
if (subtype == null) {
|
||||||
|
throw new NullPointerException("SpellCheckerSubtype is null.");
|
||||||
|
}
|
||||||
|
sService.setCurrentSpellCheckerSubtype(null, subtype.hashCode());
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Error in setSpellCheckerSubtype:" + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.android.internal.textservice.ITextServicesSessionListener;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.textservice.SpellCheckerInfo;
|
import android.view.textservice.SpellCheckerInfo;
|
||||||
|
import android.view.textservice.SpellCheckerSubtype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to the text service manager.
|
* Interface to the text service manager.
|
||||||
@@ -29,10 +30,12 @@ import android.view.textservice.SpellCheckerInfo;
|
|||||||
*/
|
*/
|
||||||
interface ITextServicesManager {
|
interface ITextServicesManager {
|
||||||
SpellCheckerInfo getCurrentSpellChecker(String locale);
|
SpellCheckerInfo getCurrentSpellChecker(String locale);
|
||||||
|
SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale);
|
||||||
oneway void getSpellCheckerService(String sciId, in String locale,
|
oneway void getSpellCheckerService(String sciId, in String locale,
|
||||||
in ITextServicesSessionListener tsListener,
|
in ITextServicesSessionListener tsListener,
|
||||||
in ISpellCheckerSessionListener scListener, in Bundle bundle);
|
in ISpellCheckerSessionListener scListener, in Bundle bundle);
|
||||||
oneway void finishSpellCheckerService(in ISpellCheckerSessionListener listener);
|
oneway void finishSpellCheckerService(in ISpellCheckerSessionListener listener);
|
||||||
oneway void setCurrentSpellChecker(String sciId);
|
oneway void setCurrentSpellChecker(String locale, String sciId);
|
||||||
|
oneway void setCurrentSpellCheckerSubtype(String locale, int hashCode);
|
||||||
SpellCheckerInfo[] getEnabledSpellCheckers();
|
SpellCheckerInfo[] getEnabledSpellCheckers();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import android.service.textservice.SpellCheckerService;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.view.textservice.SpellCheckerInfo;
|
import android.view.textservice.SpellCheckerInfo;
|
||||||
|
import android.view.textservice.SpellCheckerSubtype;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -174,7 +175,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
synchronized (mSpellCheckerMap) {
|
synchronized (mSpellCheckerMap) {
|
||||||
String curSpellCheckerId =
|
String curSpellCheckerId =
|
||||||
Settings.Secure.getString(mContext.getContentResolver(),
|
Settings.Secure.getString(mContext.getContentResolver(),
|
||||||
Settings.Secure.SPELL_CHECKER_SERVICE);
|
Settings.Secure.SELECTED_SPELL_CHECKER);
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.w(TAG, "getCurrentSpellChecker: " + curSpellCheckerId);
|
Slog.w(TAG, "getCurrentSpellChecker: " + curSpellCheckerId);
|
||||||
}
|
}
|
||||||
@@ -185,6 +186,35 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Save SpellCheckerSubtype by supported languages.
|
||||||
|
@Override
|
||||||
|
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale) {
|
||||||
|
synchronized (mSpellCheckerMap) {
|
||||||
|
final String subtypeHashCodeStr =
|
||||||
|
Settings.Secure.getString(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE);
|
||||||
|
if (DBG) {
|
||||||
|
Slog.w(TAG, "getCurrentSpellChecker: " + subtypeHashCodeStr);
|
||||||
|
}
|
||||||
|
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
|
||||||
|
if (sci.getSubtypeCount() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(subtypeHashCodeStr)) {
|
||||||
|
// Return the first Subtype if there is no settings for the current subtype.
|
||||||
|
return sci.getSubtypeAt(0);
|
||||||
|
}
|
||||||
|
final int hashCode = Integer.valueOf(subtypeHashCodeStr);
|
||||||
|
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
|
||||||
|
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
|
||||||
|
if (scs.hashCode() == hashCode) {
|
||||||
|
return scs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sci.getSubtypeAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getSpellCheckerService(String sciId, String locale,
|
public void getSpellCheckerService(String sciId, String locale,
|
||||||
ITextServicesSessionListener tsListener, ISpellCheckerSessionListener scListener,
|
ITextServicesSessionListener tsListener, ISpellCheckerSessionListener scListener,
|
||||||
@@ -301,7 +331,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCurrentSpellChecker(String sciId) {
|
public void setCurrentSpellChecker(String locale, String sciId) {
|
||||||
synchronized(mSpellCheckerMap) {
|
synchronized(mSpellCheckerMap) {
|
||||||
if (mContext.checkCallingOrSelfPermission(
|
if (mContext.checkCallingOrSelfPermission(
|
||||||
android.Manifest.permission.WRITE_SECURE_SETTINGS)
|
android.Manifest.permission.WRITE_SECURE_SETTINGS)
|
||||||
@@ -314,6 +344,20 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCurrentSpellCheckerSubtype(String locale, int hashCode) {
|
||||||
|
synchronized(mSpellCheckerMap) {
|
||||||
|
if (mContext.checkCallingOrSelfPermission(
|
||||||
|
android.Manifest.permission.WRITE_SECURE_SETTINGS)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
throw new SecurityException(
|
||||||
|
"Requires permission "
|
||||||
|
+ android.Manifest.permission.WRITE_SECURE_SETTINGS);
|
||||||
|
}
|
||||||
|
setCurrentSpellCheckerLocked(hashCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setCurrentSpellCheckerLocked(String sciId) {
|
private void setCurrentSpellCheckerLocked(String sciId) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
|
Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
|
||||||
@@ -322,7 +366,32 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
Settings.Secure.putString(mContext.getContentResolver(),
|
Settings.Secure.putString(mContext.getContentResolver(),
|
||||||
Settings.Secure.SPELL_CHECKER_SERVICE, sciId);
|
Settings.Secure.SELECTED_SPELL_CHECKER, sciId);
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCurrentSpellCheckerLocked(int hashCode) {
|
||||||
|
if (DBG) {
|
||||||
|
Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
|
||||||
|
}
|
||||||
|
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
|
||||||
|
if (sci == null) return;
|
||||||
|
boolean found = false;
|
||||||
|
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
|
||||||
|
if(sci.getSubtypeAt(i).hashCode() == hashCode) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final long ident = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
|
Settings.Secure.putString(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(hashCode));
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(ident);
|
Binder.restoreCallingIdentity(ident);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user