0

So im trying to make something like this https://play.google.com/store/apps/details?id=pt.bbarao.nightmode . I added transparrent background at first before layout and when the imagebutton is clicked, then the blackish screen filter is applied, but for some reason, the button is not working and i cant even move the seekbar around. Help is much appriciated, thank you! Heres the code:

public class Nightmode extends AppCompatActivity {
    private boolean nightmodeOnOff;
    public ImageButton modeOnOffButton;
    private int brightness;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

        setContentView(R.layout.activity_nightmode);
        modeOnOffButton = (ImageButton) findViewById(R.id.nightmodeOnOffButton);
        nightmodeOnOff = false;


        int prog;
        //Seekbar
        SeekBar skbar = (SeekBar) findViewById(R.id.nightModeBar);
        skbar.setMax(255);
        skbar.setKeyProgressIncrement(127);

        try {
            brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        skbar.setProgress(brightness);

        skbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
                if (progress <= 25) {
                    brightness = 25;
                } else {
                    brightness = progress;
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                android.provider.Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
                WindowManager.LayoutParams lpp = getWindow().getAttributes();
                lpp.screenBrightness = brightness/(float)255;
                getWindow().setAttributes(lpp);
            }
        });

    }


    public void nightmodeButtonClicked(View view) {
        try {
            if (nightmodeOnOff) {
                nightmodeOnOff = false;

                turnNightOff();
            } else {
                nightmodeOnOff = true;
                turnNightOn();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void turnNightOn() {

        try {
            modeOnOffButton.setImageResource(R.drawable.nightmodeonbutton);

            findViewById(R.id.activity_nightmode).setBackgroundColor(0x66000000);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void turnNightOff() {

        try {
            modeOnOffButton.setImageResource(R.drawable.nightmodeonoffbutton);
            findViewById(R.id.activity_nightmode).setBackgroundColor(33000000);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        turnNightOff();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
        turnNightOff();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        turnNightOff();
    }

    @Override
    protected void onPause() {
        super.onPause();
        turnNightOn();
    }
}
Kenertj
  • 57
  • 7
  • Without reading the code, are you sure the event can go below your transparent layer ? – AxelH Nov 21 '16 at 15:15
  • Possible duplicate of [Transparent Activity with background activity click through behaviour in android](http://stackoverflow.com/questions/19835672/transparent-activity-with-background-activity-click-through-behaviour-in-android) – AxelH Nov 21 '16 at 15:16

0 Answers0