Skip to content

Commit

Permalink
Merge pull request brunodev85#71 from longjunyu2/fix-screen-dimming-w…
Browse files Browse the repository at this point in the history
…hen-using-gamepad

Fix screen dimming when using game controller
  • Loading branch information
brunodev85 authored Jul 20, 2024
2 parents 14bbdad + a2d72a3 commit 8e2058e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/src/main/java/com/winlator/widget/TouchpadView.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,8 +43,9 @@ public TouchpadView(Context context, XServer xServer) {
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);
}
Expand Down Expand Up @@ -353,4 +357,16 @@ public float[] computeDeltaPoint(float lastX, float lastY, float x, float y) {
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;
}
}

0 comments on commit 8e2058e

Please sign in to comment.