77import android .graphics .Paint ;
88import android .graphics .Rect ;
99import android .support .v4 .content .res .ResourcesCompat ;
10+ import android .util .TypedValue ;
1011import android .view .MotionEvent ;
1112import android .view .SurfaceHolder ;
1213import android .view .SurfaceView ;
1314import android .view .View ;
1415
1516public class Field implements View .OnTouchListener {
1617
18+ FieldUIPage fieldUIPage ;
1719
1820 SurfaceView surface ;
1921 Bitmap fieldRed , fieldBlue ;
@@ -37,14 +39,11 @@ public class Field implements View.OnTouchListener {
3739 makeRect (664 , 206 ),
3840 makeRect (744 , 206 ),
3941 makeRect (824 , 206 ),
40- makeRect (584 , 225 ),
41- makeRect (584 , 305 ),
42+ makeRect (584 , 267 ),
4243 makeRect (664 , 328 ),
4344 makeRect (744 , 328 ),
4445 makeRect (824 , 328 )
4546 };
46-
47-
4847
4948 //the normal paint for the boxes
5049 Paint normal = new Paint ();
@@ -62,7 +61,11 @@ public class Field implements View.OnTouchListener {
6261 //code in surfacecreated can only be called once
6362 boolean alreadyCreated = false ;
6463
65- public Field (SurfaceView s , Bitmap fieldRed , Bitmap fieldBlue ) {
64+ Rect backgroundRect ;
65+ Paint backgroundPaint ;
66+
67+ public Field (final FieldUIPage fieldUIPage , SurfaceView s , Bitmap fieldRed , Bitmap fieldBlue ) {
68+ this .fieldUIPage = fieldUIPage ;
6669 surface = s ;
6770 this .fieldRed = fieldRed ;
6871 this .fieldBlue = fieldBlue ;
@@ -77,13 +80,26 @@ public Field(SurfaceView s, Bitmap fieldRed, Bitmap fieldBlue) {
7780 surface .getHolder ().addCallback (new SurfaceHolder .Callback () {
7881 @ Override
7982 public void surfaceCreated (SurfaceHolder holder ) {
80-
8183 if (alreadyCreated ){
8284 redraw ();
8385 return ;
8486 }
8587 alreadyCreated = true ;
8688
89+ backgroundRect = new Rect (0 , 0 , surface .getWidth (), surface .getHeight ());
90+
91+ //get theme background color
92+ backgroundPaint = new Paint ();
93+ if (fieldUIPage .autoPage ) {
94+ TypedValue typedValue = new TypedValue ();
95+ Field .this .fieldUIPage .getContext ().getTheme ().resolveAttribute (R .attr .colorAuto , typedValue , true );
96+ backgroundPaint .setColor (typedValue .data );
97+ } else {
98+ TypedValue typedValue = new TypedValue ();
99+ Field .this .fieldUIPage .getContext ().getTheme ().resolveAttribute (android .R .attr .colorBackground , typedValue , true );
100+ backgroundPaint .setColor (typedValue .data );
101+ }
102+
87103 boolean scaleByHeight = false ;
88104
89105 //scaled with height
@@ -144,6 +160,7 @@ public void surfaceDestroyed(SurfaceHolder holder) {
144160
145161 }
146162 });
163+
147164 }
148165
149166 // called by the FieldUIPage class when the deselect button is hit
@@ -256,19 +273,19 @@ public void drawImage(Canvas c, int selected) {
256273 field = fieldBlue ;
257274 }
258275
276+ //clear screen
277+ c .drawRect (backgroundRect , backgroundPaint );
278+
259279 c .drawBitmap (field , 0 , 0 , null );
260280
261281 for (Rect rect : fieldPlacements ) {
262-
263282 Rect scaledRect = scaleRect (rect , c );
264283
265284 if (java .util .Arrays .asList (fieldPlacements ).indexOf (rect ) == selected ){
266285 c .drawRect (scaledRect .left , scaledRect .top , scaledRect .right , scaledRect .bottom , highlited );
267286 }else {
268287 c .drawRect (scaledRect .left , scaledRect .top , scaledRect .right , scaledRect .bottom , normal );
269288 }
270-
271-
272289 }
273290 }
274291
0 commit comments