mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
control flow for moving the fab up with snackbar
This commit is contained in:
parent
0669193e75
commit
9c62c3fd39
@ -46,14 +46,19 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.ViewGroup.MarginLayoutParams;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@ -71,6 +76,7 @@ import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.util.ExportHelper;
|
||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
@ -87,7 +93,7 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||
*/
|
||||
public class KeyListFragment extends LoaderFragment
|
||||
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
LoaderManager.LoaderCallbacks<Cursor>, FabContainer {
|
||||
|
||||
ExportHelper mExportHelper;
|
||||
|
||||
@ -102,6 +108,8 @@ public class KeyListFragment extends LoaderFragment
|
||||
private String mQuery;
|
||||
private SearchView mSearchView;
|
||||
|
||||
private FloatingActionsMenu mFab;
|
||||
|
||||
private FloatingActionButton mFabQrCode;
|
||||
private FloatingActionButton mFabCloud;
|
||||
private FloatingActionButton mFabFile;
|
||||
@ -124,6 +132,8 @@ public class KeyListFragment extends LoaderFragment
|
||||
mStickyList = (StickyListHeadersListView) view.findViewById(R.id.key_list_list);
|
||||
mStickyList.setOnItemClickListener(this);
|
||||
|
||||
mFab = (FloatingActionsMenu) view.findViewById(R.id.fab_main);
|
||||
|
||||
mFabQrCode = (FloatingActionButton) view.findViewById(R.id.fab_add_qr_code);
|
||||
mFabCloud = (FloatingActionButton) view.findViewById(R.id.fab_add_cloud);
|
||||
mFabFile = (FloatingActionButton) view.findViewById(R.id.fab_add_file);
|
||||
@ -609,6 +619,25 @@ public class KeyListFragment extends LoaderFragment
|
||||
}
|
||||
}
|
||||
|
||||
LayoutParams mFabOrigin = null;
|
||||
@Override
|
||||
public void fabMoveUp(int height) {
|
||||
if (mFabOrigin == null) {
|
||||
mFabOrigin = mFab.getLayoutParams();
|
||||
}
|
||||
|
||||
// TODO reposition properly!
|
||||
MarginLayoutParams marginParams = new MarginLayoutParams(mFabOrigin);
|
||||
marginParams.setMargins(0, 0, 16, 16+height);
|
||||
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
|
||||
mFab.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabRestorePosition() {
|
||||
mFab.setLayoutParams(mFabOrigin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements StickyListHeadersAdapter from library
|
||||
*/
|
||||
|
@ -25,10 +25,11 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
|
||||
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
|
||||
|
||||
public class MainActivity extends MaterialNavigationDrawer {
|
||||
public class MainActivity extends MaterialNavigationDrawer implements FabContainer {
|
||||
|
||||
@Override
|
||||
public void init(Bundle savedInstanceState) {
|
||||
@ -51,7 +52,6 @@ public class MainActivity extends MaterialNavigationDrawer {
|
||||
addBottomSection(newSection(getString(R.string.menu_help), R.drawable.ic_help_black_24dp, new Intent(this, HelpActivity.class)));
|
||||
|
||||
|
||||
|
||||
// if this is the first time show first time activity
|
||||
Preferences prefs = Preferences.getPreferences(this);
|
||||
if (prefs.isFirstTime()) {
|
||||
@ -68,4 +68,20 @@ public class MainActivity extends MaterialNavigationDrawer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabMoveUp(int height) {
|
||||
Object fragment = getCurrentSection().getTargetFragment();
|
||||
if (fragment instanceof FabContainer) {
|
||||
((FabContainer) fragment).fabMoveUp(height);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabRestorePosition() {
|
||||
Object fragment = getCurrentSection().getTargetFragment();
|
||||
if (fragment instanceof FabContainer) {
|
||||
((FabContainer) fragment).fabRestorePosition();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,15 +19,16 @@ package org.sufficientlysecure.keychain.ui.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.nispok.snackbar.Snackbar;
|
||||
import com.nispok.snackbar.Snackbar.SnackbarDuration;
|
||||
import com.nispok.snackbar.SnackbarManager;
|
||||
import com.nispok.snackbar.enums.SnackbarType;
|
||||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
import com.nispok.snackbar.listeners.EventListener;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
|
||||
/**
|
||||
* Notify wrapper which allows a more easy use of different notification libraries
|
||||
@ -45,13 +46,47 @@ public class Notify {
|
||||
* @param text Text to show
|
||||
* @param style Notification styling
|
||||
*/
|
||||
public static void showNotify(Activity activity, CharSequence text, Style style) {
|
||||
public static void showNotify(final Activity activity, CharSequence text, Style style) {
|
||||
|
||||
Snackbar bar = Snackbar.with(activity)
|
||||
.text(text)
|
||||
.type(SnackbarType.MULTI_LINE)
|
||||
.duration(SnackbarDuration.LENGTH_LONG);
|
||||
|
||||
if (activity instanceof FabContainer) {
|
||||
bar.eventListener(new EventListener() {
|
||||
@Override
|
||||
public void onShow(Snackbar snackbar) {
|
||||
((FabContainer) activity).fabMoveUp(snackbar.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowByReplace(Snackbar snackbar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShown(Snackbar snackbar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(Snackbar snackbar) {
|
||||
((FabContainer) activity).fabRestorePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissByReplace(Snackbar snackbar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissed(Snackbar snackbar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
switch (style) {
|
||||
case OK:
|
||||
break;
|
||||
|
@ -2,7 +2,8 @@
|
||||
<RelativeLayout xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent">
|
||||
android:layout_width="match_parent"
|
||||
>
|
||||
|
||||
<!--rebuild functionality of ListFragment -->
|
||||
<FrameLayout
|
||||
@ -52,7 +53,8 @@
|
||||
fab:fab_labelStyle="@style/FabMenuStyle"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
android:layout_marginEnd="16dp"
|
||||
>
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_add_qr_code"
|
||||
|
Loading…
Reference in New Issue
Block a user