我正在为视障人士构建固件。当连接外部键盘时,我必须禁用触摸屏。并用 切换它Alt + T
。为此,我static volatile
在 View 类中有一个名为 misTouchScreenEnabled 的标志。插入外部键盘后,我false
从dispatchTouchEvent()
.
在视图类中:
/*
* A register to hold the status of touch screen
*
*{@hide}
*/
public static volatile boolean misTouchScreenEnabled = false;
public boolean dispatchTouchEvent(MotionEvent event) {
if(event == null)
{
return false;
}
Log.d ("CnxsTA","View :: Into dispatchTouchEvent");
// Added by Harsh Vardhan 05102013
Configuration config = getResources().getConfiguration();
if (config.keyboard != Configuration.KEYBOARD_NOKEYS)
{
// And if the device has a hard keyboard, even if it is
// currently hidden, don't pass the touch events to the view
if(!mIsTouchScreenEnabled)
{
Log.d ("CnxsTA","View :: Into dispatchTouchEvent :: Returning False");
return false;
}
}
// Added By Harsh Vardhan
// Some Other Code...
}
ALT + T
在 Launcher中,我dispatchTouchEvent()
使用反射捕获并切换标志:
case KeyEvent.KEYCODE_T:
{
//Added By Harsh Vardhan 31052013
Log.d ("CnxsTA","Launcher :: onKeyDown :: T pressed");
if ((event.getMetaState() & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON)
{
Object s;
try
{
Log.d ("CnxsTA","Launcher :: In onKeyDown :: In isAltPressed");
s = ToogleTouchScreen(Class.forName("android.view.View"), "mIsTouchScreenEnabled");
if (s instanceof Boolean)
{
boolean v = ((Boolean) s).booleanValue();
//do something
Log.d ("CnxsTA","Launcher :: onKeyDown :: In isAltPressed :: Toggling touchscreen enable flag :: " + v);
if (accessibilityEnabled)
{
if (mTts != null)
{
if (v)
mTts.speak("Touch Screen enabled", TextToSpeech.QUEUE_FLUSH, null);
else
mTts.speak("Touch Screen disabled", TextToSpeech.QUEUE_FLUSH, null);
}
}
}
else if (s == null)
{
//do something
Log.d ("CnxsTA","Launcher :: onKeyDown :: S is Null");
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
//return super.dispatchKeyEvent(event);
return true;
//break;
//Added By Harsh Vardhan 31052013
}
这适用于启动器及其工作区,即。按下时触摸会启用和禁用ALT + T
。但是底部的面板(包含背面、主页、最近的应用程序和通知)在触摸时仍然没有响应,应用程序中的 UI 也是如此;虽然在探索模式下,图标名称是在触摸时说出的,但没有实现触摸。一旦移除外接键盘,这一切都会保持正常状态。
我认为这背后的原因可能是 StatusBar 类和扩展View
它们的其他类将其flag
设为 false 仅缓存了整个类或变量和方法,而不是指已切换标志的主内存。我知道我已经制作了旗帜volatile
。我知道我的标志会切换,因为我可以从logcat
.
请建议我可以解决这个问题的方向。提前致谢。