Fixed FAB
This commit is contained in:
parent
ec3009a257
commit
e2aa0e8b1d
@ -75,7 +75,7 @@ dependencies {
|
||||
compile 'com.journeyapps:zxing-android-embedded:3.5.0@aar'
|
||||
compile 'com.google.zxing:core:3.3.0'
|
||||
|
||||
compile 'com.github.kobakei:MaterialFabSpeedDial:1.1.4'
|
||||
compile 'com.github.kobakei:MaterialFabSpeedDial:1.1.5'
|
||||
compile 'com.github.amlcurran.showcaseview:library:5.4.3'
|
||||
compile('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.10.4@aar') {
|
||||
transitive = true
|
||||
|
@ -91,6 +91,7 @@ public class AddressListFragment extends AbstractItemListFragment<Void, Bitmessa
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
initFab((MainActivity) getActivity());
|
||||
updateList();
|
||||
}
|
||||
|
||||
@ -117,35 +118,30 @@ public class AddressListFragment extends AbstractItemListFragment<Void, Bitmessa
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context ctx) {
|
||||
super.onAttach(ctx);
|
||||
if (ctx instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) ctx;
|
||||
activity.updateTitle(getString(R.string.contacts_and_subscriptions));
|
||||
FabSpeedDialMenu menu = new FabSpeedDialMenu(ctx);
|
||||
menu.add(R.string.scan_qr_code).setIcon(R.drawable.ic_action_qr_code);
|
||||
menu.add(R.string.create_contact).setIcon(R.drawable.ic_action_create_contact);
|
||||
FabUtils.initFab(activity, R.drawable.ic_action_add_contact, menu)
|
||||
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
switch (itemId) {
|
||||
case 1:
|
||||
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
||||
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
||||
.initiateScan();
|
||||
break;
|
||||
case 2:
|
||||
Intent intent = new Intent(getActivity(), CreateAddressActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
private void initFab(MainActivity activity){
|
||||
activity.updateTitle(getString(R.string.contacts_and_subscriptions));
|
||||
FabSpeedDialMenu menu = new FabSpeedDialMenu(activity);
|
||||
menu.add(R.string.scan_qr_code).setIcon(R.drawable.ic_action_qr_code);
|
||||
menu.add(R.string.create_contact).setIcon(R.drawable.ic_action_create_contact);
|
||||
FabUtils.initFab(activity, R.drawable.ic_action_add_contact, menu)
|
||||
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
switch (itemId) {
|
||||
case 1:
|
||||
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
||||
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
||||
.initiateScan();
|
||||
break;
|
||||
case 2:
|
||||
Intent intent = new Intent(getActivity(), CreateAddressActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -96,6 +96,7 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
initFab(activity);
|
||||
messageRepo = Singleton.getMessageRepository(activity);
|
||||
|
||||
if (backStack.isEmpty()) {
|
||||
@ -239,43 +240,39 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
if (context instanceof MainActivity) {
|
||||
FabSpeedDialMenu menu = new FabSpeedDialMenu(context);
|
||||
menu.add(R.string.broadcast).setIcon(R.drawable.ic_action_broadcast);
|
||||
menu.add(R.string.personal_message).setIcon(R.drawable.ic_action_personal);
|
||||
FabUtils.initFab((MainActivity) context, R.drawable.ic_action_compose_message, menu)
|
||||
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
BitmessageAddress identity = Singleton.getIdentity(getActivity());
|
||||
if (identity == null) {
|
||||
Toast.makeText(getActivity(), R.string.no_identity_warning,
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
switch (itemId) {
|
||||
case 1: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
intent.putExtra(EXTRA_BROADCAST, true);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
private void initFab(MainActivity context){
|
||||
FabSpeedDialMenu menu = new FabSpeedDialMenu(context);
|
||||
menu.add(R.string.broadcast).setIcon(R.drawable.ic_action_broadcast);
|
||||
menu.add(R.string.personal_message).setIcon(R.drawable.ic_action_personal);
|
||||
FabUtils.initFab(context, R.drawable.ic_action_compose_message, menu)
|
||||
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
BitmessageAddress identity = Singleton.getIdentity(getActivity());
|
||||
if (identity == null) {
|
||||
Toast.makeText(getActivity(), R.string.no_identity_warning,
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
switch (itemId) {
|
||||
case 1: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
intent.putExtra(EXTRA_BROADCAST, true);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
super.onAttach(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,35 +0,0 @@
|
||||
package ch.dissem.apps.abit.util;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
||||
import ch.dissem.apps.abit.MainActivity;
|
||||
import ch.dissem.apps.abit.R;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu;
|
||||
|
||||
/**
|
||||
* Utilities to work with the common floating action button in the main activity
|
||||
*/
|
||||
public class FabUtils {
|
||||
public static FabSpeedDial initFab(MainActivity activity, final @DrawableRes int drawableRes, FabSpeedDialMenu menu) {
|
||||
FabSpeedDial fab = activity.getFloatingActionButton();
|
||||
fab.show();
|
||||
fab.closeMenu();
|
||||
final FloatingActionButton mainFab = fab.getMainFab();
|
||||
mainFab.setImageResource(drawableRes);
|
||||
fab.setMenu(menu);
|
||||
fab.addOnStateChangeListener(new FabSpeedDial.OnStateChangeListener() {
|
||||
@Override
|
||||
public void onStateChange(boolean isOpened) {
|
||||
if (isOpened) {
|
||||
// It will be turned 45 degrees, which makes an x out of the +
|
||||
mainFab.setImageResource(R.drawable.ic_action_add);
|
||||
} else {
|
||||
mainFab.setImageResource(drawableRes);
|
||||
}
|
||||
}
|
||||
});
|
||||
return fab;
|
||||
}
|
||||
}
|
34
app/src/main/java/ch/dissem/apps/abit/util/FabUtils.kt
Normal file
34
app/src/main/java/ch/dissem/apps/abit/util/FabUtils.kt
Normal file
@ -0,0 +1,34 @@
|
||||
package ch.dissem.apps.abit.util
|
||||
|
||||
import android.support.annotation.DrawableRes
|
||||
import android.support.design.widget.FloatingActionButton
|
||||
|
||||
import ch.dissem.apps.abit.MainActivity
|
||||
import ch.dissem.apps.abit.R
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu
|
||||
|
||||
/**
|
||||
* Utilities to work with the common floating action button in the main activity
|
||||
*/
|
||||
object FabUtils {
|
||||
@JvmStatic
|
||||
fun initFab(activity: MainActivity, @DrawableRes drawableRes: Int, menu: FabSpeedDialMenu): FabSpeedDial {
|
||||
val fab = activity.floatingActionButton
|
||||
fab.removeAllOnMenuItemClickListeners()
|
||||
fab.show()
|
||||
fab.closeMenu()
|
||||
val mainFab = fab.mainFab
|
||||
mainFab.setImageResource(drawableRes)
|
||||
fab.setMenu(menu)
|
||||
fab.addOnStateChangeListener { isOpened ->
|
||||
if (isOpened) {
|
||||
// It will be turned 45 degrees, which makes an x out of the +
|
||||
mainFab.setImageResource(R.drawable.ic_action_add)
|
||||
} else {
|
||||
mainFab.setImageResource(drawableRes)
|
||||
}
|
||||
}
|
||||
return fab
|
||||
}
|
||||
}
|
@ -60,13 +60,10 @@
|
||||
|
||||
<io.github.kobakei.materialfabspeeddial.FabSpeedDial
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:elevation="8dp"
|
||||
app:fab_useTouchGuard="true"/>
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:fab_useTouchGuard="true"
|
||||
app:fab_miniFabTextBackground="@color/colorAccent"
|
||||
app:fab_miniFabTextColor="@color/colorPrimaryDarkText" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user