Improved fab speed dial
This commit is contained in:
parent
faa6752b10
commit
e064012551
@ -36,11 +36,12 @@ import com.google.zxing.integration.android.IntentIntegrator;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
|
||||||
import ch.dissem.apps.abit.repository.AndroidAddressRepository;
|
import ch.dissem.apps.abit.repository.AndroidAddressRepository;
|
||||||
import ch.dissem.apps.abit.service.Singleton;
|
import ch.dissem.apps.abit.service.Singleton;
|
||||||
|
import ch.dissem.apps.abit.util.FabUtils;
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||||
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that shows a list of all contacts, the ones we subscribed to first.
|
* Fragment that shows a list of all contacts, the ones we subscribed to first.
|
||||||
@ -119,28 +120,23 @@ public class AddressListFragment extends AbstractItemListFragment<Void, Bitmessa
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context ctx) {
|
public void onAttach(Context ctx) {
|
||||||
super.onAttach(ctx);
|
super.onAttach(ctx);
|
||||||
if (ctx instanceof ActionBarListener) {
|
if (ctx instanceof MainActivity) {
|
||||||
((ActionBarListener) ctx).updateTitle(getString(R.string.contacts_and_subscriptions));
|
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);
|
||||||
@Nullable
|
menu.add(R.string.create_contact).setIcon(R.drawable.ic_action_create_contact);
|
||||||
@Override
|
FabUtils.initFab(activity, R.drawable.ic_action_add_contact, menu)
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
|
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||||
savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.fragment_address_list, container, false);
|
|
||||||
|
|
||||||
FabSpeedDial fabSpeedDial = (FabSpeedDial) view.findViewById(R.id.fab_add_contact);
|
|
||||||
fabSpeedDial.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case R.id.action_read_qr_code:
|
case 1:
|
||||||
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
||||||
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
||||||
.initiateScan();
|
.initiateScan();
|
||||||
break;
|
break;
|
||||||
case R.id.action_create_contact:
|
case 2:
|
||||||
Intent intent = new Intent(getActivity(), CreateAddressActivity.class);
|
Intent intent = new Intent(getActivity(), CreateAddressActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
break;
|
break;
|
||||||
@ -149,8 +145,14 @@ public class AddressListFragment extends AbstractItemListFragment<Void, Bitmessa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return view;
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
|
||||||
|
savedInstanceState) {
|
||||||
|
return inflater.inflate(R.layout.fragment_address_list, container, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,7 +56,6 @@ import java.util.List;
|
|||||||
import ch.dissem.apps.abit.dialog.FullNodeDialogActivity;
|
import ch.dissem.apps.abit.dialog.FullNodeDialogActivity;
|
||||||
import ch.dissem.apps.abit.drawer.ProfileImageListener;
|
import ch.dissem.apps.abit.drawer.ProfileImageListener;
|
||||||
import ch.dissem.apps.abit.drawer.ProfileSelectionListener;
|
import ch.dissem.apps.abit.drawer.ProfileSelectionListener;
|
||||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
|
||||||
import ch.dissem.apps.abit.listener.ListSelectionListener;
|
import ch.dissem.apps.abit.listener.ListSelectionListener;
|
||||||
import ch.dissem.apps.abit.service.BitmessageService;
|
import ch.dissem.apps.abit.service.BitmessageService;
|
||||||
import ch.dissem.apps.abit.service.Singleton;
|
import ch.dissem.apps.abit.service.Singleton;
|
||||||
@ -67,6 +66,7 @@ import ch.dissem.bitmessage.BitmessageContext;
|
|||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||||
|
|
||||||
import static ch.dissem.apps.abit.ComposeMessageActivity.launchReplyTo;
|
import static ch.dissem.apps.abit.ComposeMessageActivity.launchReplyTo;
|
||||||
import static ch.dissem.apps.abit.repository.AndroidMessageRepository.LABEL_ARCHIVE;
|
import static ch.dissem.apps.abit.repository.AndroidMessageRepository.LABEL_ARCHIVE;
|
||||||
@ -91,7 +91,7 @@ import static ch.dissem.apps.abit.service.BitmessageService.isRunning;
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AppCompatActivity
|
public class MainActivity extends AppCompatActivity
|
||||||
implements ListSelectionListener<Serializable>, ActionBarListener {
|
implements ListSelectionListener<Serializable> {
|
||||||
public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
|
public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
|
||||||
public static final String EXTRA_SHOW_LABEL = "ch.dissem.abit.ShowLabel";
|
public static final String EXTRA_SHOW_LABEL = "ch.dissem.abit.ShowLabel";
|
||||||
public static final String EXTRA_REPLY_TO_MESSAGE = "ch.dissem.abit.ReplyToMessage";
|
public static final String EXTRA_REPLY_TO_MESSAGE = "ch.dissem.abit.ReplyToMessage";
|
||||||
@ -120,13 +120,17 @@ public class MainActivity extends AppCompatActivity
|
|||||||
private Drawer drawer;
|
private Drawer drawer;
|
||||||
private SwitchDrawerItem nodeSwitch;
|
private SwitchDrawerItem nodeSwitch;
|
||||||
|
|
||||||
|
private FabSpeedDial fab;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
instance = new WeakReference<>(this);
|
instance = new WeakReference<>(this);
|
||||||
bmc = Singleton.getBitmessageContext(this);
|
bmc = Singleton.getBitmessageContext(this);
|
||||||
|
|
||||||
setContentView(R.layout.activity_message_list);
|
setContentView(R.layout.activity_main);
|
||||||
|
fab = (FabSpeedDial) findViewById(R.id.fab);
|
||||||
|
fab.hide();
|
||||||
|
|
||||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@ -487,7 +491,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateUnread() {
|
public void updateUnread() {
|
||||||
for (IDrawerItem item : drawer.getDrawerItems()) {
|
for (IDrawerItem item : drawer.getDrawerItems()) {
|
||||||
if (item.getTag() instanceof Label) {
|
if (item.getTag() instanceof Label) {
|
||||||
@ -573,7 +576,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateTitle(CharSequence title) {
|
public void updateTitle(CharSequence title) {
|
||||||
if (getSupportActionBar() != null) {
|
if (getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setTitle(title);
|
getSupportActionBar().setTitle(title);
|
||||||
@ -584,6 +586,10 @@ public class MainActivity extends AppCompatActivity
|
|||||||
return selectedLabel;
|
return selectedLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FabSpeedDial getFloatingActionButton() {
|
||||||
|
return fab;
|
||||||
|
}
|
||||||
|
|
||||||
public static MainActivity getInstance() {
|
public static MainActivity getInstance() {
|
||||||
if (instance == null) return null;
|
if (instance == null) return null;
|
||||||
return instance.get();
|
return instance.get();
|
||||||
|
@ -43,7 +43,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
|
||||||
import ch.dissem.apps.abit.service.Singleton;
|
import ch.dissem.apps.abit.service.Singleton;
|
||||||
import ch.dissem.apps.abit.util.Assets;
|
import ch.dissem.apps.abit.util.Assets;
|
||||||
import ch.dissem.apps.abit.util.Drawables;
|
import ch.dissem.apps.abit.util.Drawables;
|
||||||
@ -142,8 +141,8 @@ public class MessageDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
MessageRepository messageRepo = Singleton.getMessageRepository(inflater.getContext());
|
MessageRepository messageRepo = Singleton.getMessageRepository(inflater.getContext());
|
||||||
if (removed) {
|
if (removed) {
|
||||||
if (getActivity() instanceof ActionBarListener) {
|
if (getActivity() instanceof MainActivity) {
|
||||||
((ActionBarListener) getActivity()).updateUnread();
|
((MainActivity) getActivity()).updateUnread();
|
||||||
}
|
}
|
||||||
messageRepo.save(item);
|
messageRepo.save(item);
|
||||||
}
|
}
|
||||||
@ -200,13 +199,13 @@ public class MessageDetailFragment extends Fragment {
|
|||||||
case R.id.mark_unread:
|
case R.id.mark_unread:
|
||||||
item.addLabels(messageRepo.getLabels(Label.Type.UNREAD));
|
item.addLabels(messageRepo.getLabels(Label.Type.UNREAD));
|
||||||
messageRepo.save(item);
|
messageRepo.save(item);
|
||||||
if (getActivity() instanceof ActionBarListener) {
|
if (getActivity() instanceof MainActivity) {
|
||||||
((ActionBarListener) getActivity()).updateUnread();
|
((MainActivity) getActivity()).updateUnread();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.archive:
|
case R.id.archive:
|
||||||
if (item.isUnread() && getActivity() instanceof ActionBarListener) {
|
if (item.isUnread() && getActivity() instanceof MainActivity) {
|
||||||
((ActionBarListener) getActivity()).updateUnread();
|
((MainActivity) getActivity()).updateUnread();
|
||||||
}
|
}
|
||||||
item.getLabels().clear();
|
item.getLabels().clear();
|
||||||
messageRepo.save(item);
|
messageRepo.save(item);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package ch.dissem.apps.abit;
|
package ch.dissem.apps.abit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -45,14 +46,15 @@ import java.util.List;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import ch.dissem.apps.abit.adapter.SwipeableMessageAdapter;
|
import ch.dissem.apps.abit.adapter.SwipeableMessageAdapter;
|
||||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
|
||||||
import ch.dissem.apps.abit.listener.ListSelectionListener;
|
import ch.dissem.apps.abit.listener.ListSelectionListener;
|
||||||
import ch.dissem.apps.abit.repository.AndroidMessageRepository;
|
import ch.dissem.apps.abit.repository.AndroidMessageRepository;
|
||||||
import ch.dissem.apps.abit.service.Singleton;
|
import ch.dissem.apps.abit.service.Singleton;
|
||||||
|
import ch.dissem.apps.abit.util.FabUtils;
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||||
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu;
|
||||||
|
|
||||||
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_BROADCAST;
|
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_BROADCAST;
|
||||||
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_IDENTITY;
|
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_IDENTITY;
|
||||||
@ -119,8 +121,8 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
|||||||
private void doUpdateList(final Label label) {
|
private void doUpdateList(final Label label) {
|
||||||
adapter.clear(label);
|
adapter.clear(label);
|
||||||
if (label == null) {
|
if (label == null) {
|
||||||
if (getActivity() instanceof ActionBarListener) {
|
if (getActivity() instanceof MainActivity) {
|
||||||
((ActionBarListener) getActivity()).updateTitle(getString(R.string.app_name));
|
((MainActivity) getActivity()).updateTitle(getString(R.string.app_name));
|
||||||
}
|
}
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
return;
|
return;
|
||||||
@ -129,8 +131,8 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
|||||||
if (emptyTrashMenuItem != null) {
|
if (emptyTrashMenuItem != null) {
|
||||||
emptyTrashMenuItem.setVisible(label.getType() == Label.Type.TRASH);
|
emptyTrashMenuItem.setVisible(label.getType() == Label.Type.TRASH);
|
||||||
}
|
}
|
||||||
if (getActivity() instanceof ActionBarListener) {
|
if (getActivity() instanceof MainActivity) {
|
||||||
ActionBarListener actionBarListener = (ActionBarListener) getActivity();
|
MainActivity actionBarListener = (MainActivity) getActivity();
|
||||||
if ("archive".equals(label.toString())) {
|
if ("archive".equals(label.toString())) {
|
||||||
actionBarListener.updateTitle(getString(R.string.archive));
|
actionBarListener.updateTitle(getString(R.string.archive));
|
||||||
} else {
|
} else {
|
||||||
@ -167,38 +169,6 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
|||||||
recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
|
recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
|
||||||
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
||||||
|
|
||||||
// Show the dummy content as text in a TextView.
|
|
||||||
FabSpeedDial fab = (FabSpeedDial) rootView.findViewById(R.id
|
|
||||||
.fab_compose_message);
|
|
||||||
fab.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 R.id.action_compose_message: {
|
|
||||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
|
||||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
|
||||||
startActivity(intent);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case R.id.action_compose_broadcast: {
|
|
||||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
|
||||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
|
||||||
intent.putExtra(EXTRA_BROADCAST, true);
|
|
||||||
startActivity(intent);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// touch guard manager (this class is required to suppress scrolling while swipe-dismiss
|
// touch guard manager (this class is required to suppress scrolling while swipe-dismiss
|
||||||
// animation is running)
|
// animation is running)
|
||||||
recyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
|
recyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
|
||||||
@ -269,6 +239,45 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
|||||||
return rootView;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
super.onAttach(context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
if (recyclerViewSwipeManager != null) {
|
if (recyclerViewSwipeManager != null) {
|
||||||
|
@ -24,12 +24,12 @@ import android.os.Bundle;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.mikepenz.aboutlibraries.Libs;
|
import com.mikepenz.aboutlibraries.Libs;
|
||||||
import com.mikepenz.aboutlibraries.LibsBuilder;
|
import com.mikepenz.aboutlibraries.LibsBuilder;
|
||||||
|
|
||||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
|
||||||
import ch.dissem.apps.abit.service.Singleton;
|
import ch.dissem.apps.abit.service.Singleton;
|
||||||
import ch.dissem.apps.abit.synchronization.SyncAdapter;
|
import ch.dissem.apps.abit.synchronization.SyncAdapter;
|
||||||
import ch.dissem.bitmessage.BitmessageContext;
|
import ch.dissem.bitmessage.BitmessageContext;
|
||||||
@ -121,11 +121,14 @@ public class SettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context ctx) {
|
public void onAttach(Context ctx) {
|
||||||
super.onAttach(ctx);
|
super.onAttach(ctx);
|
||||||
|
if (ctx instanceof MainActivity){
|
||||||
|
((MainActivity) ctx).getFloatingActionButton().hide();
|
||||||
|
}
|
||||||
PreferenceManager.getDefaultSharedPreferences(ctx)
|
PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||||
.registerOnSharedPreferenceChangeListener(this);
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
if (ctx instanceof ActionBarListener) {
|
if (ctx instanceof MainActivity) {
|
||||||
((ActionBarListener) ctx).updateTitle(getString(R.string.settings));
|
((MainActivity) ctx).updateTitle(getString(R.string.settings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.apps.abit.listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Christian Basler
|
|
||||||
*/
|
|
||||||
public interface ActionBarListener {
|
|
||||||
void updateTitle(CharSequence title);
|
|
||||||
|
|
||||||
void updateUnread();
|
|
||||||
}
|
|
35
app/src/main/java/ch/dissem/apps/abit/util/FabUtils.java
Normal file
35
app/src/main/java/ch/dissem/apps/abit/util/FabUtils.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
9
app/src/main/res/drawable/ic_action_add.xml
Normal file
9
app/src/main/res/drawable/ic_action_add.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#DEFFFFFF"
|
||||||
|
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||||
|
</vector>
|
@ -58,4 +58,15 @@
|
|||||||
tools:ignore="InconsistentLayout"
|
tools:ignore="InconsistentLayout"
|
||||||
tools:layout="@layout/fragment_message_detail" />
|
tools:layout="@layout/fragment_message_detail" />
|
||||||
|
|
||||||
|
<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.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
35
app/src/main/res/layout/activity_main.xml
Normal file
35
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:elevation="4dp"
|
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||||
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||||
|
tools:ignore="UnusedAttribute" />
|
||||||
|
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/item_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@id/toolbar"
|
||||||
|
tools:context=".MessageListActivity"
|
||||||
|
tools:layout="@android:layout/list_content" />
|
||||||
|
|
||||||
|
<io.github.kobakei.materialfabspeeddial.FabSpeedDial
|
||||||
|
android:id="@+id/fab"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:fab_useTouchGuard="true"
|
||||||
|
app:fab_miniFabTextBackground="@color/colorAccent"
|
||||||
|
app:fab_miniFabTextColor="@color/colorPrimaryDarkText" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -1,26 +0,0 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
android:background="?attr/colorPrimary"
|
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
|
||||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
|
||||||
android:elevation="4dp"
|
|
||||||
tools:ignore="UnusedAttribute"/>
|
|
||||||
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_below="@id/toolbar"
|
|
||||||
android:id="@+id/item_list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".MessageListActivity"
|
|
||||||
tools:layout="@android:layout/list_content"/>
|
|
||||||
</RelativeLayout>
|
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="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">
|
||||||
|
|
||||||
@ -17,17 +16,4 @@
|
|||||||
android:paddingBottom="88dp"
|
android:paddingBottom="88dp"
|
||||||
android:scrollbarStyle="outsideOverlay" />
|
android:scrollbarStyle="outsideOverlay" />
|
||||||
|
|
||||||
<io.github.kobakei.materialfabspeeddial.FabSpeedDial
|
|
||||||
android:id="@+id/fab_add_contact"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="16dp"
|
|
||||||
app:elevation="8dp"
|
|
||||||
app:fab_useTouchGuard="true"
|
|
||||||
app:fab_miniFabTextBackground="@color/colorPrimaryLight"
|
|
||||||
app:fab_fabDrawable="@drawable/ic_action_add_contact"
|
|
||||||
app:fab_menu="@menu/fab_address" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
@ -19,17 +18,4 @@
|
|||||||
android:scrollbars="vertical"
|
android:scrollbars="vertical"
|
||||||
tools:listitem="@layout/message_row"/>
|
tools:listitem="@layout/message_row"/>
|
||||||
|
|
||||||
<io.github.kobakei.materialfabspeeddial.FabSpeedDial
|
|
||||||
android:id="@+id/fab_compose_message"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="16dp"
|
|
||||||
app:elevation="8dp"
|
|
||||||
app:fab_useTouchGuard="true"
|
|
||||||
app:fab_miniFabTextBackground="@color/colorPrimaryLight"
|
|
||||||
app:fab_fabDrawable="@drawable/ic_action_compose_message"
|
|
||||||
app:fab_menu="@menu/fab_message"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ Copyright 2016 Christian Basler
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_read_qr_code"
|
|
||||||
android:icon="@drawable/ic_action_qr_code"
|
|
||||||
android:title="@string/scan_qr_code"/>
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_create_contact"
|
|
||||||
android:icon="@drawable/ic_action_create_contact"
|
|
||||||
android:title="@string/create_contact"/>
|
|
||||||
</menu>
|
|
@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ Copyright 2016 Christian Basler
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_compose_broadcast"
|
|
||||||
android:icon="@drawable/ic_action_broadcast"
|
|
||||||
android:title="@string/broadcast"/>
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_compose_message"
|
|
||||||
android:icon="@drawable/ic_action_personal"
|
|
||||||
android:title="@string/personal_message"/>
|
|
||||||
</menu>
|
|
Loading…
Reference in New Issue
Block a user