In my app, I need to create a circle camera preview from Service. I create a CameraPreview class, which extends SurfaceView. In my service, I added CameraPreview object to WindowManager.
For getting circle, I override methods draw and dispatchDraw of SurfaceView:
Path circ = new Path();
circ.addCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, canvas.getWidth() / 2, Path.Direction.CW);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawPath(circ, paint);
this.setZOrderOnTop(true);
Here are my results for 3 different tests:
If I create CameraPreview object in
Service, I get rectangle.If I create CameraPreview object in an
Activitywith no-transparent theme, I get circle.If I create CameraPreview object in an
ActivitywithTheme.Translucent, I get rectangle.
Please tell me why I got these results. How does the theme of Activity affect to Canvas?