Search in sources :

Example 1 with SpeedDialActionItem

use of com.leinardi.android.speeddial.SpeedDialActionItem in project FloatingActionButtonSpeedDial by leinardi.

the class MainActivity method initSpeedDial.

private void initSpeedDial(boolean addActionItems) {
    mSpeedDialView = findViewById(R.id.speedDial);
    if (addActionItems) {
        mSpeedDialView.addFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_no_label, R.drawable.ic_link_white_24dp).create());
        mSpeedDialView.addFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_long_label, R.drawable.ic_lorem_ipsum).setLabel("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " + "incididunt ut labore et dolore magna aliqua.").create());
        mSpeedDialView.addFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_custom_color, R.drawable.ic_custom_color).setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.material_white_1000, getTheme())).setFabImageTintColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme())).setLabel(getString(R.string.label_custom_color)).setLabelColor(Color.WHITE).setLabelBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme())).create());
        mSpeedDialView.addFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_add_action, R.drawable.ic_add_white_24dp).setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.material_green_500, getTheme())).setLabel(getString(R.string.label_add_action)).create());
        mSpeedDialView.addFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_custom_theme, R.drawable.ic_theme_white_24dp).setLabel(getString(R.string.label_custom_theme)).setTheme(R.style.AppTheme_Purple).create());
    }
    SpeedDialOverlayLayout speedDialOverlayLayout = findViewById(R.id.overlay);
    mSpeedDialView.setSpeedDialOverlayLayout(speedDialOverlayLayout);
    // Set main fab clicklistener.
    mSpeedDialView.setMainFabOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            showToast("Main fab clicked!");
            if (mSpeedDialView.isFabMenuOpen()) {
                mSpeedDialView.closeOptionsMenu();
            }
        }
    });
    // Set option fabs clicklisteners.
    mSpeedDialView.setOptionFabSelectedListener(new SpeedDialView.OnOptionFabSelectedListener() {

        @Override
        public void onOptionFabSelected(SpeedDialActionItem speedDialActionItem) {
            switch(speedDialActionItem.getId()) {
                case R.id.fab_no_label:
                    showToast("No label action clicked!");
                    break;
                case R.id.fab_long_label:
                    showSnackbar(speedDialActionItem.getLabel() + " clicked!");
                    break;
                case R.id.fab_custom_color:
                    showToast(speedDialActionItem.getLabel() + " clicked!");
                    break;
                case R.id.fab_custom_theme:
                    showToast(speedDialActionItem.getLabel() + " clicked!");
                    break;
                case R.id.fab_add_action:
                    mSpeedDialView.addFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_replace_action, R.drawable.ic_replace_white_24dp).setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.material_orange_500, getTheme())).setLabel(getString(R.string.label_replace_action)).create(), ADD_ACTION_POSITION);
                    break;
                case R.id.fab_replace_action:
                    mSpeedDialView.replaceFabOptionItem(new SpeedDialActionItem.Builder(R.id.fab_remove_action, R.drawable.ic_delete_white_24dp).setLabel(getString(R.string.label_remove_action)).setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.inbox_accent, getTheme())).create(), ADD_ACTION_POSITION);
                    break;
                case R.id.fab_remove_action:
                    mSpeedDialView.removeFabOptionItemById(R.id.fab_remove_action);
                    break;
                default:
                    break;
            }
        }
    });
}
Also used : SpeedDialActionItem(com.leinardi.android.speeddial.SpeedDialActionItem) SpeedDialOverlayLayout(com.leinardi.android.speeddial.SpeedDialOverlayLayout) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView)

Example 2 with SpeedDialActionItem

use of com.leinardi.android.speeddial.SpeedDialActionItem in project Conversations by siacs.

the class StartConversationActivity method inflateFab.

private void inflateFab(final SpeedDialView speedDialView, @MenuRes final int menuRes) {
    speedDialView.clearActionItems();
    final PopupMenu popupMenu = new PopupMenu(this, new View(this));
    popupMenu.inflate(menuRes);
    final Menu menu = popupMenu.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        final MenuItem menuItem = menu.getItem(i);
        final SpeedDialActionItem actionItem = new SpeedDialActionItem.Builder(menuItem.getItemId(), menuItem.getIcon()).setLabel(menuItem.getTitle() != null ? menuItem.getTitle().toString() : null).setFabImageTintColor(ContextCompat.getColor(this, R.color.white)).create();
        speedDialView.addActionItem(actionItem);
    }
}
Also used : SpeedDialActionItem(com.leinardi.android.speeddial.SpeedDialActionItem) MenuItem(android.view.MenuItem) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint) PopupMenu(androidx.appcompat.widget.PopupMenu)

Aggregations

View (android.view.View)2 SpeedDialActionItem (com.leinardi.android.speeddial.SpeedDialActionItem)2 SpeedDialView (com.leinardi.android.speeddial.SpeedDialView)2 SuppressLint (android.annotation.SuppressLint)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ContextMenu (android.view.ContextMenu)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 PopupMenu (androidx.appcompat.widget.PopupMenu)1 SpeedDialOverlayLayout (com.leinardi.android.speeddial.SpeedDialOverlayLayout)1