Well, thanks to fadden, I found the easiest solution (at least for me).
First I created another Surface view, and my XML file looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:opencv="http://schemas.android.com/apk/res-auto" android:layout_gravity="left|top"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <SurfaceView android:layout_alignParentTop="true" android:id="@+id/CameraView" android:layout_width="match_parent" android:layout_height="match_parent" /> <SurfaceView android:layout_alignParentTop="true" android:id="@+id/TransparentView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> </RelativeLayout>
And than I create another holder for a new surface, this is part of my java code:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_capture);
Finally, I implement a method called 'DrawFocusRect'
private void DrawFocusRect(float RectLeft, float RectTop, float RectRight, float RectBottom, int color) { canvas = holderTransparent.lockCanvas(); canvas.drawColor(0,Mode.CLEAR);
As you can see, I clean the canvas every time, if I do not, the surface will display additionally more rectangles on top of each other.
This is how I call this method from the OnTouchListener event:
OnTouchListener onTouchListner = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { RectLeft = event.getX() - 100; RectTop = event.getY() - 100 ; RectRight = event.getX() + 100; RectBottom = event.getY() + 100; DrawFocusRect(RectLeft , RectTop , RectRight , RectBottom , Color.BLUE); } };
Hope this will be helpful to someone else.