我正在开发一个 xposed 模块来在EditTexts
. 用户应该能够使用音量增大/减小键单击不同的字符串。到目前为止,我的模块正在运行。我钩住了 的onFocusChanged
方法View
,然后检查View
对象是否是 的实例EditText
。然后我将一个设置OnKeyListener
为EditText
.
因此,当我专注于EditText
字段并继续单击volumeDown 键时,我希望字段中出现不同的字符串。但我无法存储计数器值。我在我的 xposed 类中将其设为静态(我认为静态变量保存在应用程序中),但这也不起作用。
有没有存储(计数器)值的方法?我将能够检查文本字段中的文本,在我的文本数组中搜索相同的文本,确定当前索引并从那里开始工作,但我希望有一种“更好”的方式:)
这是我的文本的代码,index
变量是问题所在:
public class Xposed implements IXposedHookZygoteInit, IXposedHookLoadPackage {
private static int index, indexMax;
private static boolean first = true;
private static String[] valuesX = {"bla1", "bla2", "bla3", "bla4"};
private Context mCon;
private EditText et;
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
findAndHookMethod(TextView.class, "onFocusChanged", boolean.class, int.class, Rect.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (param.thisObject instanceof EditText) {
et = (EditText) param.thisObject;
if ((boolean) param.args[0]) {
et.setText("I have focus!!! (1)");
XposedBridge.log("starting quickinsert after focus");
mCon = et.getContext().getApplicationContext();
View.OnKeyListener okl = new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
keyPressed(keyCode);
return true;
}
}
return false;
}
};;
et.setOnKeyListener(okl);
}
}
}
});
}
private void keyPressed(int keyCode) {
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
if (first) {
first = false;
} else {
if (index < indexMax) {
index++;
} else {
index = 0;
}
}
et.setText(valuesX[index]);
XposedBridge.log("keycode down consumed (index " + index + ")");
} else if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
if (first) {
first = false;
} else {
if (index > 0) {
index--;
} else {
index = indexMax;
}
}
et.setText(valuesX[index]);
XposedBridge.log("keycode up consumed (index " + index + ")");
}
}
}