diff --git a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java index f986694..d9a6a1b 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java @@ -52,6 +52,7 @@ class CanvasView extends View { private boolean _isDragging = false; private MainActivity parentActivity = null; private Tuple _dropZone = new Tuple<>(0, 0, 0, 0); + private boolean _devMode = false; public CanvasView(Context context) { super(context); @@ -122,13 +123,17 @@ class CanvasView extends View { drawBackground(canvas); for (Part part : parts){ - part.draw(canvas); + part.draw(canvas, _devMode); } Log.d("Render time", System.currentTimeMillis() - renderStartTime + "ms"); } private void drawBackground(Canvas canvas) { + if (!_devMode){ + return; + } + // Blueprint background final int width = getWidth() + getLeft(); final int height = getHeight() + getTop(); @@ -200,6 +205,10 @@ class CanvasView extends View { case MotionEvent.ACTION_MOVE: { + if (!_devMode) { + break; + } + Log.i("Canvas", "X: " + x + " Y: " + y + " in drop zone " + _dropZone + " : " + inDropZone(x, y)); if (motionMode == null){ @@ -308,6 +317,11 @@ class CanvasView extends View { _dropZone = new Tuple<>((int) x1, (int) x2, (int) y1, (int) y2); } + public void setDevMode(boolean devMode) { + _devMode = devMode; + this.invalidate(); + } + private class Tuple { final T _x1; diff --git a/app/src/main/java/com/codigoparallevar/minicards/MainActivity.java b/app/src/main/java/com/codigoparallevar/minicards/MainActivity.java index 7d7dae8..eed0677 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/MainActivity.java +++ b/app/src/main/java/com/codigoparallevar/minicards/MainActivity.java @@ -16,9 +16,15 @@ public class MainActivity extends AppCompatActivity { CanvasView canvasView; com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton; com.getbase.floatingactionbutton.FloatingActionButton SetDevModeButton; - com.getbase.floatingactionbutton.FloatingActionsMenu fabMenu; + com.getbase.floatingactionbutton.FloatingActionButton SetUserModeButton; + + com.getbase.floatingactionbutton.FloatingActionsMenu devFabMenu; + com.getbase.floatingactionbutton.FloatingActionsMenu userFabMenu; + + boolean devMode = false; FloatingActionButton removePartFab; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -41,8 +47,10 @@ public class MainActivity extends AppCompatActivity { removePartFab.getY(), removePartFab.getY() + removePartFab.getHeight()); // Set callbacks to fab buttons - fabMenu = (com.getbase.floatingactionbutton.FloatingActionsMenu) - findViewById(R.id.fab); + devFabMenu = (com.getbase.floatingactionbutton.FloatingActionsMenu) + findViewById(R.id.dev_mode_fab); + userFabMenu = (com.getbase.floatingactionbutton.FloatingActionsMenu) + findViewById(R.id.user_mode_fab); AddPartButton = (com.getbase.floatingactionbutton.AddFloatingActionButton) findViewById(R.id.add_part_button); @@ -52,7 +60,6 @@ public class MainActivity extends AppCompatActivity { if (canvasView != null) { canvasView.addPart(new RoundButton(500, 500, 50, 100)); } - Snackbar.make(v, "Add part", Snackbar.LENGTH_SHORT).show(); } }); @@ -61,9 +68,40 @@ public class MainActivity extends AppCompatActivity { SetDevModeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Snackbar.make(v, "Set dev mode", Snackbar.LENGTH_SHORT).show(); + MainActivity.this.setDevMode(true); } }); + + SetUserModeButton = (com.getbase.floatingactionbutton.FloatingActionButton) + findViewById(R.id.set_user_mode_button); + SetUserModeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MainActivity.this.setDevMode(false); + } + }); + + setDevMode(devMode); + } + + private void setDevMode(boolean goToDevMode) { + boolean willInvalidate = devMode != goToDevMode; + + devMode = goToDevMode; + if (goToDevMode){ + devFabMenu.setVisibility(View.VISIBLE); + userFabMenu.setVisibility(View.GONE); + } + else { + devFabMenu.setVisibility(View.GONE); + userFabMenu.setVisibility(View.VISIBLE); + } + + this.canvasView.setDevMode(devMode); + + if (willInvalidate){ + invalidate(); + } } @Override @@ -80,12 +118,13 @@ public class MainActivity extends AppCompatActivity { public void invalidate() { if (canvasView != null){ if (canvasView.isDragging()){ - fabMenu.setVisibility(View.GONE); + devFabMenu.setVisibility(View.GONE); + userFabMenu.setVisibility(View.GONE); removePartFab.setVisibility(View.VISIBLE); Log.d("Main", "Changing visibility!"); } else { - fabMenu.setVisibility(View.VISIBLE); + this.setDevMode(devMode); removePartFab.setVisibility(View.GONE); Log.d("Main", "Now changing visibility!"); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java b/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java index ee6c46d..cd3d79f 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java @@ -11,7 +11,7 @@ public interface Part { int getTop(); int getBottom(); - void draw(Canvas canvas); + void draw(Canvas canvas, boolean devMode); void move(int x, int y); diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java b/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java index 1cae278..faa4134 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java @@ -42,7 +42,7 @@ public class Placeholder implements Part { } @Override - public void draw(Canvas canvas) { + public void draw(Canvas canvas, boolean devMode) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.WHITE); diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java b/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java index 621fe46..6c110f2 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java @@ -47,7 +47,7 @@ public class RoundButton implements Part { } @Override - public void draw(Canvas canvas) { + public void draw(Canvas canvas, boolean devMode) { Paint foregroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); foregroundPaint.setColor(Color.WHITE); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 64ebf47..1c1a8bc 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -40,7 +40,7 @@ app:srcCompat="@android:drawable/ic_delete" /> + + + + +