Experiment with basic dev mode context.
This commit is contained in:
parent
5e583bed05
commit
fe0794632d
@ -52,6 +52,7 @@ class CanvasView extends View {
|
||||
private boolean _isDragging = false;
|
||||
private MainActivity parentActivity = null;
|
||||
private Tuple<Integer, Integer, Integer, Integer> _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<T, T1, T2, T3> {
|
||||
|
||||
final T _x1;
|
||||
|
@ -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!");
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
app:srcCompat="@android:drawable/ic_delete" />
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionsMenu
|
||||
android:id="@+id/fab"
|
||||
android:id="@+id/user_mode_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
@ -62,7 +62,34 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
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"/>
|
||||
|
||||
<com.getbase.floatingactionbutton.AddFloatingActionButton
|
||||
|
Loading…
Reference in New Issue
Block a user