android触摸屏校准中间层实现方法

来源:互联网 发布:python与java 编辑:程序博客网 时间:2024/04/29 06:03

android第一次开机启动,进行了校准屏幕,但如果没有设置正确或用户需要重新校准时,进行按键校准的需求就来了。

根据公司情况采取的方法是长按两次back键删除校准程序产生的文件,然后重新启动系统。系统检测到没有校准产生的文件时,将启动重新校准。


修改/myandroid/frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java

根据长按电源键启动的mPowerLongPress方式创建自己的线程mBackLongPress。


    private  AlertDialog dialog = null;
    Runnable mBackLongPress = new Runnable(){
        public void run() {
            Log.d("debug", "execute back key long press");
            if(dialog != null && dialog.isShowing()){
                File file = new File("/data/system/calibration");
                if(file.exists())
                    if(!file.delete())
                        Log.e("debug", "failded to delete /data/system/calibration.");
                Intent intent = new Intent(Intent.ACTION_REBOOT);
                intent.putExtra("nowait", 1);
                intent.putExtra("interval", 1);
                intent.putExtra("window", 0);
                mContext.sendBroadcast(intent);
            }else{
                dialog = new AlertDialog.Builder(mContext)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle("Warning")
                .setMessage("Long press back key again will restart your mid to calibrate.")
                .create();
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
                dialog.show();
            }
        }       
    };

添加按键监控

            else if(code ==  KeyEvent.KEYCODE_BACK){
                if (down) {
                    mHandler.postDelayed(mBackLongPress,
                            ViewConfiguration.getGlobalActionKeyTimeout());
                }else{
                    mHandler.removeCallbacks(mBackLongPress);
                }
                    
            }




原创粉丝点击