简体   繁体   English

Android如何在物理按钮上执行反馈触觉?

[英]How does android perform a feedback haptic on physical button?

After checking android source code, I knew the when a button perform click it will call the view's performHapticFeedback methor so that the phone will perform a BZZZTT effect. 在检查了android源代码之后,我知道按钮执行单击时它将调用视图的performHapticFeedback方法,以便手机执行BZZZTT效果。 the performHapticFeedback code is like: performHapticFeedback代码类似于:

public boolean performHapticFeedback(int feedbackConstant, int flags) {
    if (mAttachInfo == null) {
        return false;
    }
    //noinspection SimplifiableIfStatement
    if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0
            && !isHapticFeedbackEnabled()) {
        return false;
    }
    return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant,
            (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0);
}

But, I wonder how android performs a feedback haptic on physical button (such as key_home,key_Back,key_menu). 但是,我不知道android如何在物理按钮(例如key_home,key_Back,key_menu)上执行反馈触觉。 cause the physical button doesn't base on View. 导致物理按钮不基于View。 I have searched the source code for a whole afternoon but I got nothing valuable code lines about how physical button performs Haptic Feedback~~~~ Can anyone give me some tips? 我已经搜索了整个下午的源代码,但是关于物理按钮如何执行触觉反馈,我没有任何有价值的代码行~~~~有人可以给我一些提示吗?

Thanks 谢谢

The relative code lines are found in PhoneWindowManager.java -> public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) .(which is called before the other uplever apps can handle); 相对的代码行位于PhoneWindowManager.java > public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) PhoneWindowManager.java public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) (在其他高级应用程序可以处理之前调用); After judging on KeyEvent code, then it will call the mVibrator.vibrate(pattern[0]); 判断KeyEvent代码后,它将调用mVibrator.vibrate(pattern[0]); in which the mVibrator is got by calling mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); 其中,通过调用mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);获得mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM