Search in sources :

Example 1 with SpeedDialOverlayLayout

use of com.leinardi.android.speeddial.SpeedDialOverlayLayout 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)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 SpeedDialActionItem (com.leinardi.android.speeddial.SpeedDialActionItem)1 SpeedDialOverlayLayout (com.leinardi.android.speeddial.SpeedDialOverlayLayout)1 SpeedDialView (com.leinardi.android.speeddial.SpeedDialView)1