From 75c2a4c654ff3752713bbeda8e3c4a39197bbd2e Mon Sep 17 00:00:00 2001 From: Mark Ormesher Date: Wed, 6 Apr 2016 22:53:16 +0100 Subject: [PATCH 1/8] Hide/show methods --- .../android_fab/app/DemoActivity.java | 19 +++++- app/src/main/res/layout/fab_activity.xml | 6 ++ app/src/main/res/values/values.xml | 4 ++ .../android_fab/FloatingActionButton.java | 66 +++++++++++++++++-- 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/uk/co/markormesher/android_fab/app/DemoActivity.java b/app/src/main/java/uk/co/markormesher/android_fab/app/DemoActivity.java index e72e314..f2abc14 100644 --- a/app/src/main/java/uk/co/markormesher/android_fab/app/DemoActivity.java +++ b/app/src/main/java/uk/co/markormesher/android_fab/app/DemoActivity.java @@ -33,11 +33,23 @@ public void onCreate(Bundle savedInstanceState) { fab = (FloatingActionButton) findViewById(R.id.fab); // get references to buttons + final Button hideShowButton = (Button) findViewById(R.id.hide_show); final Button switchModeButton = (Button) findViewById(R.id.switch_mode); final Button toggleSpeedDialColoursSwitch = (Button) findViewById(R.id.toggle_colours); final Button toggleSpeedDialOptionalCloseButton = (Button) findViewById(R.id.toggle_optional_close); final Button openSpeedDialButton = (Button) findViewById(R.id.open_speed_dial); + hideShowButton.setText(R.string.hide_fab); + hideShowButton.setOnClickListener(v -> { + if (fab.isShown()) { + fab.hide(); + hideShowButton.setText(R.string.show_fab); + } else { + fab.show(); + hideShowButton.setText(R.string.hide_fab); + } + }); + switchModeButton.setOnClickListener(v -> { inClickMode = !inClickMode; if (inClickMode) { @@ -95,7 +107,10 @@ public void onCreate(Bundle savedInstanceState) { fab.rebuildSpeedDialMenu(); }); - openSpeedDialButton.setOnClickListener(v -> fab.openSpeedDialMenu()); + openSpeedDialButton.setOnClickListener(v -> { + fab.openSpeedDialMenu(); + if (!fab.isShown()) Toast.makeText(this, R.string.disabled_when_hidden, Toast.LENGTH_SHORT).show(); + }); // set stuff going findViewById(R.id.switch_mode).performClick(); @@ -141,7 +156,7 @@ protected MenuItem getViews(Context context, int position) { // example: Drawable ID and String ID return new MenuItem() {{ iconDrawableId = R.mipmap.ic_cloud; - labelStringId = R.string.label_optional_close; + labelStringId = R.string.label_optional_close; }}; default: diff --git a/app/src/main/res/layout/fab_activity.xml b/app/src/main/res/layout/fab_activity.xml index b3c30f4..96b9796 100644 --- a/app/src/main/res/layout/fab_activity.xml +++ b/app/src/main/res/layout/fab_activity.xml @@ -15,6 +15,12 @@ android:orientation="vertical" android:gravity="center_horizontal"> +