Fixed screen dimming when using game controller

This commit is contained in:
Junyu Long 2024-07-14 01:26:35 +08:00
parent 14bbdad598
commit a2d72a36a6

View File

@ -1,6 +1,9 @@
package com.winlator.widget;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
@ -40,8 +43,9 @@ public class TouchpadView extends View {
super(context);
this.xServer = xServer;
setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
setBackground(createTransparentBg());
setClickable(true);
setFocusable(false);
setFocusable(true);
setFocusableInTouchMode(false);
updateXform(AppUtils.getScreenWidth(), AppUtils.getScreenHeight(), xServer.screenInfo.width, xServer.screenInfo.height);
}
@ -353,4 +357,16 @@ public class TouchpadView extends View {
result[1] = y - lastY;
return result;
}
private StateListDrawable createTransparentBg() {
StateListDrawable stateListDrawable = new StateListDrawable();
ColorDrawable focusedDrawable = new ColorDrawable(Color.TRANSPARENT);
ColorDrawable defaultDrawable = new ColorDrawable(Color.TRANSPARENT);
stateListDrawable.addState(new int[]{android.R.attr.state_focused}, focusedDrawable);
stateListDrawable.addState(new int[]{}, defaultDrawable);
return stateListDrawable;
}
}