Experiment with basic dev mode context.

This commit is contained in:
kenkeiras 2017-07-09 22:29:15 -04:00
parent 5e583bed05
commit fe0794632d
6 changed files with 93 additions and 13 deletions

View File

@ -52,6 +52,7 @@ class CanvasView extends View {
private boolean _isDragging = false; private boolean _isDragging = false;
private MainActivity parentActivity = null; private MainActivity parentActivity = null;
private Tuple<Integer, Integer, Integer, Integer> _dropZone = new Tuple<>(0, 0, 0, 0); private Tuple<Integer, Integer, Integer, Integer> _dropZone = new Tuple<>(0, 0, 0, 0);
private boolean _devMode = false;
public CanvasView(Context context) { public CanvasView(Context context) {
super(context); super(context);
@ -122,13 +123,17 @@ class CanvasView extends View {
drawBackground(canvas); drawBackground(canvas);
for (Part part : parts){ for (Part part : parts){
part.draw(canvas); part.draw(canvas, _devMode);
} }
Log.d("Render time", System.currentTimeMillis() - renderStartTime + "ms"); Log.d("Render time", System.currentTimeMillis() - renderStartTime + "ms");
} }
private void drawBackground(Canvas canvas) { private void drawBackground(Canvas canvas) {
if (!_devMode){
return;
}
// Blueprint background // Blueprint background
final int width = getWidth() + getLeft(); final int width = getWidth() + getLeft();
final int height = getHeight() + getTop(); final int height = getHeight() + getTop();
@ -200,6 +205,10 @@ class CanvasView extends View {
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
{ {
if (!_devMode) {
break;
}
Log.i("Canvas", "X: " + x + " Y: " + y Log.i("Canvas", "X: " + x + " Y: " + y
+ " in drop zone " + _dropZone + " : " + inDropZone(x, y)); + " in drop zone " + _dropZone + " : " + inDropZone(x, y));
if (motionMode == null){ if (motionMode == null){
@ -308,6 +317,11 @@ class CanvasView extends View {
_dropZone = new Tuple<>((int) x1, (int) x2, (int) y1, (int) y2); _dropZone = new Tuple<>((int) x1, (int) x2, (int) y1, (int) y2);
} }
public void setDevMode(boolean devMode) {
_devMode = devMode;
this.invalidate();
}
private class Tuple<T, T1, T2, T3> { private class Tuple<T, T1, T2, T3> {
final T _x1; final T _x1;

View File

@ -16,9 +16,15 @@ public class MainActivity extends AppCompatActivity {
CanvasView canvasView; CanvasView canvasView;
com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton; com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton;
com.getbase.floatingactionbutton.FloatingActionButton SetDevModeButton; 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; FloatingActionButton removePartFab;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -41,8 +47,10 @@ public class MainActivity extends AppCompatActivity {
removePartFab.getY(), removePartFab.getY() + removePartFab.getHeight()); removePartFab.getY(), removePartFab.getY() + removePartFab.getHeight());
// Set callbacks to fab buttons // Set callbacks to fab buttons
fabMenu = (com.getbase.floatingactionbutton.FloatingActionsMenu) devFabMenu = (com.getbase.floatingactionbutton.FloatingActionsMenu)
findViewById(R.id.fab); findViewById(R.id.dev_mode_fab);
userFabMenu = (com.getbase.floatingactionbutton.FloatingActionsMenu)
findViewById(R.id.user_mode_fab);
AddPartButton = (com.getbase.floatingactionbutton.AddFloatingActionButton) AddPartButton = (com.getbase.floatingactionbutton.AddFloatingActionButton)
findViewById(R.id.add_part_button); findViewById(R.id.add_part_button);
@ -52,7 +60,6 @@ public class MainActivity extends AppCompatActivity {
if (canvasView != null) { if (canvasView != null) {
canvasView.addPart(new RoundButton(500, 500, 50, 100)); 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() { SetDevModeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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 @Override
@ -80,12 +118,13 @@ public class MainActivity extends AppCompatActivity {
public void invalidate() { public void invalidate() {
if (canvasView != null){ if (canvasView != null){
if (canvasView.isDragging()){ if (canvasView.isDragging()){
fabMenu.setVisibility(View.GONE); devFabMenu.setVisibility(View.GONE);
userFabMenu.setVisibility(View.GONE);
removePartFab.setVisibility(View.VISIBLE); removePartFab.setVisibility(View.VISIBLE);
Log.d("Main", "Changing visibility!"); Log.d("Main", "Changing visibility!");
} }
else { else {
fabMenu.setVisibility(View.VISIBLE); this.setDevMode(devMode);
removePartFab.setVisibility(View.GONE); removePartFab.setVisibility(View.GONE);
Log.d("Main", "Now changing visibility!"); Log.d("Main", "Now changing visibility!");
} }

View File

@ -11,7 +11,7 @@ public interface Part {
int getTop(); int getTop();
int getBottom(); int getBottom();
void draw(Canvas canvas); void draw(Canvas canvas, boolean devMode);
void move(int x, int y); void move(int x, int y);

View File

@ -42,7 +42,7 @@ public class Placeholder implements Part {
} }
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas, boolean devMode) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE); paint.setColor(Color.WHITE);

View File

@ -47,7 +47,7 @@ public class RoundButton implements Part {
} }
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas, boolean devMode) {
Paint foregroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint foregroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
foregroundPaint.setColor(Color.WHITE); foregroundPaint.setColor(Color.WHITE);

View File

@ -40,7 +40,7 @@
app:srcCompat="@android:drawable/ic_delete" /> app:srcCompat="@android:drawable/ic_delete" />
<com.getbase.floatingactionbutton.FloatingActionsMenu <com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/fab" android:id="@+id/user_mode_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
@ -62,7 +62,34 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white" fab:fab_colorNormal="@color/white"
fab:fab_title="TBI: change to develop mode" fab:fab_title="Go to develop mode"
fab:fab_colorPressed="@color/white_pressed"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/dev_mode_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|end"
fab:fab_addButtonColorNormal="@color/white"
fab:fab_addButtonColorPressed="@color/white_pressed"
fab:fab_addButtonPlusIconColor="@color/half_black"
fab:fab_addButtonSize="mini"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="left">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/set_user_mode_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Go to user mode"
fab:fab_colorPressed="@color/white_pressed"/> fab:fab_colorPressed="@color/white_pressed"/>
<com.getbase.floatingactionbutton.AddFloatingActionButton <com.getbase.floatingactionbutton.AddFloatingActionButton