How to change Brigthness from Window manager View?

200 Views Asked by At

I have added a view in Window manager inside onCrate(). In this view i am using a seekbar and when seek bar is changed i want to change the brightness low or high accordingly.But if i put the seek bar in any other view except window manager i am able to change the brightness but requirement is to chanage the brightness from window manager view.Please help me out.

Problem could be using two times window manager. One is for adding window manager and second is for changing the brightness attribute of window manager. When i use same window manager object and try to move the seeek bar.i get the execption as window is already added we can not chagne its property once window manager is added.

manager = ((WindowManager) getApplicationContext().getSystemService(
                Context.WINDOW_SERVICE));

        localLayoutParams = new WindowManager.LayoutParams();
        localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        localLayoutParams.gravity = Gravity.TOP;
        localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        localLayoutParams.flags = 0x80000000 | localLayoutParams.flags;
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = (int) (80 * getResources()
                .getDisplayMetrics().scaledDensity);
        localLayoutParams.format = PixelFormat.TRANSPARENT;
        LayoutInflater inflater = getLayoutInflater();
        Constant.lp = localLayoutParams;
        overlay = inflater.inflate(R.layout.systembar_overlay, null);
        linearLayout = new LinearLayout(getApplicationContext());
        linearLayout.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        linearLayout.addView(overlay);
        Animation animation = AnimationUtils.loadAnimation(
                getApplicationContext(), R.anim.fade_in);
        overlay.startAnimation(animation);
        mSeekBarRedLine = (ImageView) overlay.findViewById(R.id.seekbarredline);
        initLayout(overlay);
        manager.addView(linearLayout, localLayoutParams);



@Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub
            localLayoutParams.screenBrightness = progress / 750.0f;
            getWindow().setAttributes(localLayoutParams);
        }
1

There are 1 best solutions below

0
On

If you define the WindowManager, linearLayout and localLayoutParams as fields, you can use the follwing method:

 @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        localLayoutParams.screenBrightness = progress / 750.0f;
        manager.updateViewLayout(linearLayout, localLayoutParams);
    }