按钮的长短按事件交换的最佳实践

View imageMenu = (View) XposedHelpers.getObjectField(param.thisObject, "目标view");
Object mListenerInfo = XposedHelpers.getObjectField(imageMenu, "mListenerInfo");
Object onClick = XposedHelpers.getObjectField(mListenerInfo, "mOnClickListener");
Object onLongClick = XposedHelpers.getObjectField(mListenerInfo, "mOnLongClickListener");
imageMenu.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        XposedHelpers.callMethod(onLongClick, "onLongClick", imageMenu);
    }
});
imageMenu.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        XposedHelpers.callMethod(onClick, "onClick", imageMenu);
        return true;
    }
});

你可能感兴趣的:(Java,android)