Try menu-deploying fab.

This commit is contained in:
kenkeiras 2017-07-09 15:49:52 -04:00
parent 1f5f9cb8de
commit cd6b7c87d6
7 changed files with 90 additions and 12 deletions

View File

@ -28,4 +28,5 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.4.0' implementation 'com.android.support:design:25.4.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
} }

View File

@ -265,4 +265,9 @@ class CanvasView extends View {
} }
return null; return null;
} }
public void addPart(Part part) {
parts.add(part);
invalidate();
}
} }

View File

@ -1,5 +1,6 @@
package com.codigoparallevar.minicards; package com.codigoparallevar.minicards;
import android.graphics.Canvas;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
@ -8,10 +9,16 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button;
import com.codigoparallevar.minicards.parts.buttons.RoundButton;
import com.getbase.floatingactionbutton.AddFloatingActionButton;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
CanvasView canvasView; CanvasView canvasView;
com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton;
com.getbase.floatingactionbutton.FloatingActionButton SetDevModeButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -23,19 +30,29 @@ public class MainActivity extends AppCompatActivity {
actionBar.hide(); actionBar.hide();
} }
// Use controled canvas
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// Use manually controlled canvas
canvasView = (CanvasView) findViewById(R.id.canvasView); canvasView = (CanvasView) findViewById(R.id.canvasView);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { // Set callbacks to fab buttons
AddPartButton = (com.getbase.floatingactionbutton.AddFloatingActionButton)
findViewById(R.id.add_part_button);
AddPartButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View v) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) Snackbar.make(v, "Add part", Snackbar.LENGTH_SHORT).show();
.setAction("Action", null).show();
} }
}); });
SetDevModeButton = (com.getbase.floatingactionbutton.FloatingActionButton)
findViewById(R.id.set_developer_mode_button);
SetDevModeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Snackbar.make(v, "Set dev mode", Snackbar.LENGTH_SHORT).show();
}
});
} }
@Override @Override

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/black_semi_transparent"/>
<padding
android:left="16dp"
android:top="4dp"
android:right="16dp"
android:bottom="4dp"/>
<corners
android:radius="2dp"/>
</shape>

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.codigoparallevar.minicards.MainActivity"> tools:context="com.codigoparallevar.minicards.MainActivity">
@ -27,14 +29,41 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<!-- include layout="@layout/content_main" / --> <com.getbase.floatingactionbutton.FloatingActionsMenu
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/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_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin" fab:fab_addButtonColorNormal="@color/white"
app:srcCompat="@android:drawable/ic_dialog_email" /> 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_developer_mode_button"
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_colorPressed="@color/white_pressed"/>
<com.getbase.floatingactionbutton.AddFloatingActionButton
android:id="@+id/add_part_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_plusIconColor="@color/half_black"
fab:fab_colorNormal="@color/white"
fab:fab_title="Add new part"
fab:fab_colorPressed="@color/white_pressed"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

View File

@ -3,4 +3,14 @@
<color name="colorPrimary">#066996</color> <color name="colorPrimary">#066996</color>
<color name="colorPrimaryDark">#044563</color> <color name="colorPrimaryDark">#044563</color>
<color name="colorAccent">#b2ff59</color> <color name="colorAccent">#b2ff59</color>
<color name="black_semi_transparent">#B2000000</color>
<color name="background">#e5e5e5</color>
<color name="half_black">#808080</color>
<color name="white">#fafafa</color>
<color name="white_pressed">#f1f1f1</color>
<color name="pink">#e91e63</color>
<color name="pink_pressed">#ec407a</color>
<color name="blue_semi_transparent">#805677fc</color>
<color name="blue_semi_transparent_pressed">#80738ffe</color>
</resources> </resources>

View File

@ -8,4 +8,9 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="menu_labels_style">
<item name="android:background">@drawable/fab_label_background</item>
<item name="android:textColor">@color/white</item>
</style>
</resources> </resources>