首页 > 系统 > Android > 正文

android滑动解锁震动效果的开启和取消

2020-04-11 12:15:43
字体:
来源:转载
供稿:网友

如果我们需要根据设置中的触摸震动开关来开启和取消滑动解锁的震动效果,就需要做以下修改了。


      在LockScreen.java类中的LockScreen方法中的

复制代码 代码如下:

else if (mUnlockWidget instanceof MultiWaveView) {
            MultiWaveView multiWaveView = (MultiWaveView) mUnlockWidget;

            multiWaveView.setVibrateEnabled(Settings.System.getInt(mContext.getContentResolver(),//通过判断是否设置了触摸震动效果来设置解锁的震动。
                            Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) != 0);

            MultiWaveViewMethods multiWaveViewMethods = new MultiWaveViewMethods(multiWaveView);
            multiWaveView.setOnTriggerListener(multiWaveViewMethods);
            mUnlockWidgetMethods = multiWaveViewMethods;


还要在这里加入
复制代码 代码如下:

 class MultiWaveViewMethods implements MultiWaveView.OnTriggerListener,
            UnlockWidgetCommonMethods {

        private final MultiWaveView mMultiWaveView;
        private boolean mCameraDisabled;

        MultiWaveViewMethods(MultiWaveView multiWaveView) {
            mMultiWaveView = multiWaveView;

            multiWaveView.setVibrateEnabled(Settings.System.getInt(mContext.getContentResolver(),
                            Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) != 0);

            final boolean cameraDisabled = mLockPatternUtils.getDevicePolicyManager()
                    .getCameraDisabled(null);

因为滑动解锁主要使用的就是MultiWaveView这个控件,而这个控件是有设置是否振动的属性。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表