From b2d25a3ee819541dfa3e6c00b3aa2843a0590186 Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Thu, 22 Mar 2018 10:05:36 +0100 Subject: [PATCH] Replace custom FAM with FABsMenu --- README.md | 6 +- app/build.gradle | 30 ++-- .../andotp/Activities/MainActivity.java | 26 ++- .../andotp/View/FloatingActionMenu.java | 154 ------------------ app/src/main/res/anim/fab_close.xml | 18 -- app/src/main/res/anim/fab_open.xml | 18 -- app/src/main/res/drawable/shape_fab_label.xml | 7 - app/src/main/res/layout/component_fam.xml | 95 ----------- app/src/main/res/layout/content_main.xml | 47 +++++- app/src/main/res/raw/licenses.xml | 6 + app/src/main/res/values/dimens.xml | 11 -- 11 files changed, 89 insertions(+), 329 deletions(-) delete mode 100644 app/src/main/java/org/shadowice/flocke/andotp/View/FloatingActionMenu.java delete mode 100644 app/src/main/res/anim/fab_close.xml delete mode 100644 app/src/main/res/anim/fab_open.xml delete mode 100644 app/src/main/res/drawable/shape_fab_label.xml delete mode 100644 app/src/main/res/layout/component_fam.xml diff --git a/README.md b/README.md index c42d52c8..f40f2bc0 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,7 @@ So make sure you have a **current backup** before switching! * [Apache Commons Codec](https://commons.apache.org/proper/commons-codec/) * [Expandable Layout](https://github.com/AAkira/ExpandableLayout) + * [FABsMenu](https://github.com/jahirfiquitiva/FABsMenu) * [LicensesDialog](https://github.com/PSDev/LicensesDialog) * [material-intro](https://github.com/heinrichreimer/material-intro) * [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar) @@ -159,10 +160,13 @@ So make sure you have a **current backup** before switching! * [Android-ItemTouchHelper-Demo](https://github.com/iPaulPro/Android-ItemTouchHelper-Demo/tree/master/app/src/main/java/co/paulburke/android/itemtouchhelperdemo/helper) * [Code Parts from Google's Android Samples](https://android.googlesource.com/platform/development/+/master/samples/Vault/src/com/example/android/vault) - * [FloatingActionMenuAndroid](https://github.com/pmahsky/FloatingActionMenuAndroid) * [LetterBitmap](http://stackoverflow.com/questions/23122088/colored-boxed-with-letters-a-la-gmail) * [DimensionConverter](https://stackoverflow.com/questions/8343971/how-to-parse-a-dimension-string-and-convert-it-to-a-dimension-value) +#### Previously used code examples: + + * [FloatingActionMenuAndroid](https://github.com/pmahsky/FloatingActionMenuAndroid) + ## License: ``` Copyright (C) 2017-2018 Jakob Nixdorf diff --git a/app/build.gradle b/app/build.gradle index 55083b6e..e48e34cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,6 +10,7 @@ android { targetSdkVersion 27 versionCode 16 versionName "0.5.0.1" + vectorDrawables.useSupportLibrary = true } buildTypes { release { @@ -35,19 +36,18 @@ ext { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - - compile "commons-codec:commons-codec:1.11" - compile "com.android.support:appcompat-v7:$supportLibVersion" - compile "com.android.support:cardview-v7:$supportLibVersion" - compile "com.android.support:design:$supportLibVersion" - compile "com.android.support:recyclerview-v7:$supportLibVersion" - compile "com.android.support.constraint:constraint-layout:1.0.2" - compile "com.github.aakira:expandable-layout:1.6.0" - compile "com.heinrichreimersoftware:material-intro:1.6.2" - compile "com.journeyapps:zxing-android-embedded:3.6.0" - compile "com.vanniktech:vntnumberpickerpreference:1.0.0" - compile "de.psdev.licensesdialog:licensesdialog:1.8.3" - compile "me.zhanghai.android.materialprogressbar:library:1.4.2" - compile "org.sufficientlysecure:openpgp-api:12.0" + implementation "commons-codec:commons-codec:1.11" + implementation "com.android.support:appcompat-v7:$supportLibVersion" + implementation "com.android.support:cardview-v7:$supportLibVersion" + implementation "com.android.support:design:$supportLibVersion" + implementation "com.android.support:recyclerview-v7:$supportLibVersion" + implementation "com.android.support.constraint:constraint-layout:1.0.2" + implementation "com.github.aakira:expandable-layout:1.6.0" + implementation "com.heinrichreimersoftware:material-intro:1.6.2" + implementation "com.journeyapps:zxing-android-embedded:3.6.0" + implementation "com.vanniktech:vntnumberpickerpreference:1.0.0" + implementation "de.psdev.licensesdialog:licensesdialog:1.8.3" + implementation "me.zhanghai.android.materialprogressbar:library:1.4.2" + implementation "org.sufficientlysecure:openpgp-api:12.0" + implementation "me.jahirfiquitiva:FABsMenu:1.1.2" } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index f1d33923..94f3f6e0 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -33,7 +33,6 @@ import android.content.res.Configuration; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; -import android.support.constraint.ConstraintLayout; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; @@ -63,7 +62,6 @@ import org.shadowice.flocke.andotp.Utilities.KeyStoreHelper; import org.shadowice.flocke.andotp.Utilities.NotificationHelper; import org.shadowice.flocke.andotp.Utilities.TokenCalculator; import org.shadowice.flocke.andotp.View.EntriesCardAdapter; -import org.shadowice.flocke.andotp.View.FloatingActionMenu; import org.shadowice.flocke.andotp.View.ItemTouchHelper.SimpleItemTouchHelperCallback; import org.shadowice.flocke.andotp.View.ManualEntryDialog; import org.shadowice.flocke.andotp.View.TagsAdapter; @@ -73,6 +71,9 @@ import java.util.HashMap; import javax.crypto.SecretKey; +import jahirfiquitiva.libs.fabsmenu.FABsMenu; +import jahirfiquitiva.libs.fabsmenu.TitleFAB; + import static org.shadowice.flocke.andotp.Utilities.Constants.AuthMethod; import static org.shadowice.flocke.andotp.Utilities.Constants.EncryptionType; import static org.shadowice.flocke.andotp.Utilities.Constants.SortMode; @@ -81,7 +82,7 @@ public class MainActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener { private EntriesCardAdapter adapter; - private FloatingActionMenu floatingActionMenu; + private FABsMenu fabsMenu; private MenuItem sortMenu; private SimpleItemTouchHelperCallback touchHelperCallback; @@ -193,15 +194,22 @@ public class MainActivity extends BaseActivity showFirstTimeWarning(); } - floatingActionMenu = new FloatingActionMenu(this, (ConstraintLayout) findViewById(R.id.fab_main_layout)); - floatingActionMenu.setFABHandler(new FloatingActionMenu.FABHandler() { + fabsMenu = findViewById(R.id.fabs_menu); + + TitleFAB qrFAB = findViewById(R.id.fab_qr_scan); + qrFAB.setOnClickListener(new View.OnClickListener() { @Override - public void onQRFabClick() { + public void onClick(View view) { + fabsMenu.collapse(); scanQRCode(); } + }); + TitleFAB manualFAB = findViewById(R.id.fab_manual_entry); + manualFAB.setOnClickListener(new View.OnClickListener() { @Override - public void onManualFabClick() { + public void onClick(View view) { + fabsMenu.collapse(); ManualEntryDialog.show(MainActivity.this, settings, adapter); } }); @@ -446,7 +454,7 @@ public class MainActivity extends BaseActivity searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { - floatingActionMenu.hide(); + fabsMenu.setVisibility(View.GONE); touchHelperCallback.setDragEnabled(false); if (sortMenu != null) sortMenu.setVisible(false); @@ -455,7 +463,7 @@ public class MainActivity extends BaseActivity @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { - floatingActionMenu.show(); + fabsMenu.setVisibility(View.VISIBLE); if (adapter == null || adapter.getSortMode() == SortMode.UNSORTED) touchHelperCallback.setDragEnabled(true); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/FloatingActionMenu.java b/app/src/main/java/org/shadowice/flocke/andotp/View/FloatingActionMenu.java deleted file mode 100644 index b8b0dec0..00000000 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/FloatingActionMenu.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2017-2018 Jakob Nixdorf - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.shadowice.flocke.andotp.View; - -import android.content.Context; -import android.support.constraint.ConstraintLayout; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.view.ViewCompat; -import android.view.View; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.view.animation.LinearInterpolator; -import android.widget.LinearLayout; - -import org.shadowice.flocke.andotp.R; - -public class FloatingActionMenu { - private boolean isFabMenuOpen = false; - - private ConstraintLayout mainLayout; - - private Animation fabOpenAnimation; - private Animation fabCloseAnimation; - - private FloatingActionButton baseFloatingActionButton; - private FloatingActionButton qrFAB; - private FloatingActionButton manualFAB; - - private LinearLayout qrLayout; - private LinearLayout manualLayout; - - private FABHandler fabHandler; - - public FloatingActionMenu(Context context, ConstraintLayout mainLayout) { - this.mainLayout = mainLayout; - - fabOpenAnimation = AnimationUtils.loadAnimation(context, R.anim.fab_open); - fabCloseAnimation = AnimationUtils.loadAnimation(context, R.anim.fab_close); - - baseFloatingActionButton = mainLayout.findViewById(R.id.baseFloatingActionButton); - - qrFAB = mainLayout.findViewById(R.id.qrFAB); - manualFAB = mainLayout.findViewById(R.id.manualFAB); - - qrLayout = mainLayout.findViewById(R.id.qrLayout); - manualLayout = mainLayout.findViewById(R.id.manualLayout); - - baseFloatingActionButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (isFabMenuOpen) - collapse(); - else - expand(); - } - }); - - qrFAB.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (fabHandler != null) - fabHandler.onQRFabClick(); - collapse(); - } - }); - - manualFAB.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (fabHandler != null) - fabHandler.onManualFabClick(); - collapse(); - } - }); - } - - public void setFABHandler(FABHandler fabHandler) { - this.fabHandler = fabHandler; - } - - public void show() { - mainLayout.setVisibility(View.VISIBLE); - } - - public void hide() { - mainLayout.setVisibility(View.GONE); - } - - public void expand() { - ViewCompat.animate(baseFloatingActionButton) - .rotation(45F) - .withLayer() - .setDuration(150) - .setInterpolator(new LinearInterpolator()) - .start(); - - qrLayout.setVisibility(View.VISIBLE); - manualLayout.setVisibility(View.VISIBLE); - - qrLayout.startAnimation(fabOpenAnimation); - manualLayout.startAnimation(fabOpenAnimation); - - qrFAB.setClickable(true); - manualFAB.setClickable(true); - - isFabMenuOpen = true; - } - - public void collapse() { - ViewCompat.animate(baseFloatingActionButton) - .rotation(0F) - .withLayer() - .setDuration(150) - .setInterpolator(new LinearInterpolator()) - .start(); - - qrLayout.startAnimation(fabCloseAnimation); - manualLayout.startAnimation(fabCloseAnimation); - - qrLayout.setVisibility(View.GONE); - manualLayout.setVisibility(View.GONE); - - qrFAB.setClickable(false); - manualFAB.setClickable(false); - - isFabMenuOpen = false; - - } - - public interface FABHandler { - void onQRFabClick(); - void onManualFabClick(); - } -} diff --git a/app/src/main/res/anim/fab_close.xml b/app/src/main/res/anim/fab_close.xml deleted file mode 100644 index 2b0c1e8f..00000000 --- a/app/src/main/res/anim/fab_close.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/fab_open.xml b/app/src/main/res/anim/fab_open.xml deleted file mode 100644 index 63348099..00000000 --- a/app/src/main/res/anim/fab_open.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_fab_label.xml b/app/src/main/res/drawable/shape_fab_label.xml deleted file mode 100644 index 90f59ff7..00000000 --- a/app/src/main/res/drawable/shape_fab_label.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/component_fam.xml b/app/src/main/res/layout/component_fam.xml deleted file mode 100644 index cc9b9f46..00000000 --- a/app/src/main/res/layout/component_fam.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index d027e7b9..201f3f0e 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -22,7 +22,52 @@ android:paddingBottom="@dimen/fab_recyclerview_padding" android:clipToPadding="false" /> - + + + + + + + + + + + diff --git a/app/src/main/res/raw/licenses.xml b/app/src/main/res/raw/licenses.xml index b31a3b12..9f365e8c 100644 --- a/app/src/main/res/raw/licenses.xml +++ b/app/src/main/res/raw/licenses.xml @@ -12,6 +12,12 @@ Copyright (C) 2015 A.Akira Apache Software License 2.0 + + FABsMenu + https://github.com/jahirfiquitiva/FABsMenu + Copyright (c) 2018 Jahir Fiquitiva + Apache Software License 2.0 + material-intro https://github.com/heinrichreimer/material-intro diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 945247ae..4d90d39b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -19,16 +19,5 @@ 1dp - 2dp - 8dp - 16dp - 8dp - 16dp - 4dp - 4dp - 8dp - 16dp - 16dp - 84dp