2

I'm developing an Android app that have a overlay view that the user can access from anywhere. I have taken the code from the following question:

Overlay

Put it simple, a class "HUD" that call a subclass ViewGroup"HUDView", containing all the necessary elements.

Now I want to add in this ViewGroup also a SeekBar that, on progress change, draw a Canvas every time: for example seekBar progress =1, draw a circle with 10° angle, progress=2, redraw the circle with 20° angle, and so on... The circle and the seekbar must overlay the actual screen from everywhere.

I've managed to put the Canvas (created in the onDraw method of the ViewGroup) and the seekBar (created in the onCreate method of the HUD class, also with his listener). In the method "onProgressChanged" I would like to redraw the circle, but this doesnt seems to work.

Here the listener code:

// SeekBar Change Listener
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
            mView = new HUDView(getApplicationContext());
            progress = progresValue;


            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.CENTER | Gravity.TOP;
            params.setTitle("Load Average");
            WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
            wm.addView(mView, params);




        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            //Toast.makeText(getApplicationContext(), "Started tracking seekbar", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //textView.setText("Covered: " + progress + "/" + seekBar.getMax());
            //Toast.makeText(getApplicationContext(), "Stopped tracking seekbar", Toast.LENGTH_SHORT).show();
        }
    });

Here the onDraw method of the HUDView:

}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    final RectF oval = new RectF();
    oval.set(30, 30, 450, 450);
    Bitmap bg = Bitmap.createBitmap(480, 480, Bitmap.Config.ARGB_8888);
    canvas.drawArc(oval, 90, progress*10 , true, paint);
}
Community
  • 1
  • 1
Ryukai
  • 41
  • 4

0 Answers0