Merge pull request #71 from longjunyu2/fix-screen-dimming-when-using-gamepad

Fix screen dimming when using game controller
This commit is contained in:
BrunoSX 2024-07-20 15:12:18 -03:00 committed by GitHub
commit 8e2058e30a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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;
}
}