I want to turn screen off and disable UI when it close to user's face.I've done first part. but I have problem on second part. I must to know how to get current view and use my_view.setClickable(false); , However I developing this application with Qt and some java file attached to Qt
I've tried this but it's not working and I had an error:
non-static method getCurrentFocus() cannot be referenced from a static context
@Override
public void onSensorChanged(SensorEvent event)
{
WindowManager.LayoutParams params = this.getWindow().getAttributes();
if(event.sensor.getType()==Sensor.TYPE_PROXIMITY)
{
if(event.values[0]==0)
{
CustomMainActivity.getCurrentFocus().setClickable(false);
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);
}
else
{
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = -1f;
getWindow().setAttributes(params);
}
}
}