Methods Summary |
---|
public static void | main(java.lang.String[] args)
new Ime().run(args);
|
private java.lang.String | nextArg()
if (mNextArg >= mArgs.length) {
return null;
}
String arg = mArgs[mNextArg];
mNextArg++;
return arg;
|
private java.lang.String | nextOption()
if (mNextArg >= mArgs.length) {
return null;
}
String arg = mArgs[mNextArg];
if (!arg.startsWith("-")) {
return null;
}
mNextArg++;
if (arg.equals("--")) {
return null;
}
if (arg.length() > 1 && arg.charAt(1) != '-") {
if (arg.length() > 2) {
mCurArgData = arg.substring(2);
return arg.substring(0, 2);
} else {
mCurArgData = null;
return arg;
}
}
mCurArgData = null;
return arg;
|
private java.lang.String | nextOptionData()
if (mCurArgData != null) {
return mCurArgData;
}
if (mNextArg >= mArgs.length) {
return null;
}
String data = mArgs[mNextArg];
mNextArg++;
return data;
|
public void | run(java.lang.String[] args)
if (args.length < 1) {
showUsage();
return;
}
mImm = IInputMethodManager.Stub.asInterface(ServiceManager.getService("input_method"));
if (mImm == null) {
System.err.println(IMM_NOT_RUNNING_ERR);
return;
}
mArgs = args;
String op = args[0];
mNextArg = 1;
if ("list".equals(op)) {
runList();
return;
}
if ("enable".equals(op)) {
runSetEnabled(true);
return;
}
if ("disable".equals(op)) {
runSetEnabled(false);
return;
}
if ("set".equals(op)) {
runSet();
return;
}
if (op != null) {
System.err.println("Error: unknown command '" + op + "'");
}
showUsage();
|
private void | runList()Execute the list sub-command.
String opt;
boolean all = false;
boolean brief = false;
while ((opt=nextOption()) != null) {
if (opt.equals("-a")) {
all = true;
} else if (opt.equals("-s")) {
brief = true;
} else {
System.err.println("Error: Unknown option: " + opt);
showUsage();
return;
}
}
List<InputMethodInfo> methods;
if (!all) {
try {
methods = mImm.getEnabledInputMethodList();
} catch (RemoteException e) {
System.err.println(e.toString());
System.err.println(IMM_NOT_RUNNING_ERR);
return;
}
} else {
try {
methods = mImm.getInputMethodList();
} catch (RemoteException e) {
System.err.println(e.toString());
System.err.println(IMM_NOT_RUNNING_ERR);
return;
}
}
if (methods != null) {
Printer pr = new PrintStreamPrinter(System.out);
for (int i=0; i<methods.size(); i++) {
InputMethodInfo imi = methods.get(i);
if (brief) {
System.out.println(imi.getId());
} else {
System.out.println(imi.getId() + ":");
imi.dump(pr, " ");
}
}
}
|
private void | runSet()
String id = nextArg();
if (id == null) {
System.err.println("Error: no input method ID specified");
showUsage();
return;
}
try {
mImm.setInputMethod(null, id);
System.out.println("Input method " + id + " selected");
} catch (IllegalArgumentException e) {
System.err.println("Error: " + e.getMessage());
return;
} catch (RemoteException e) {
System.err.println(e.toString());
System.err.println(IMM_NOT_RUNNING_ERR);
return;
}
|
private void | runSetEnabled(boolean state)
String id = nextArg();
if (id == null) {
System.err.println("Error: no input method ID specified");
showUsage();
return;
}
try {
boolean res = mImm.setInputMethodEnabled(id, state);
if (state) {
System.out.println("Input method " + id + ": "
+ (res ? "already enabled" : "now enabled"));
} else {
System.out.println("Input method " + id + ": "
+ (res ? "now disabled" : "already disabled"));
}
} catch (IllegalArgumentException e) {
System.err.println("Error: " + e.getMessage());
return;
} catch (RemoteException e) {
System.err.println(e.toString());
System.err.println(IMM_NOT_RUNNING_ERR);
return;
}
|
private static void | showUsage()
System.err.println("usage: ime list [-a] [-s]");
System.err.println(" ime enable ID");
System.err.println(" ime disable ID");
System.err.println(" ime set ID");
System.err.println("");
System.err.println("The list command prints all enabled input methods. Use");
System.err.println("the -a option to see all input methods. Use");
System.err.println("the -s option to see only a single summary line of each.");
System.err.println("");
System.err.println("The enable command allows the given input method ID to be used.");
System.err.println("");
System.err.println("The disable command disallows the given input method ID from use.");
System.err.println("");
System.err.println("The set command switches to the given input method ID.");
|