Java Code Examples for com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton#setOnClickListener()

The following examples show how to use com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton#setOnClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedFabBehaviorDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View root =
      layoutInflater.inflate(getExtendedFabContent(), viewGroup, false /* attachToRoot */);

  Toolbar toolbar = root.findViewById(R.id.toolbar);
  AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);

  List<ExtendedFloatingActionButton> extendedFabs =
      DemoUtils.findViewsWithType(root, ExtendedFloatingActionButton.class);
  for (ExtendedFloatingActionButton extendedFab : extendedFabs) {
    extendedFab.setOnClickListener(
        v ->
            Snackbar.make(
                    v, R.string.cat_extended_fab_clicked, Snackbar.LENGTH_SHORT)
                .show());
  }

  return root;
}
 
Example 2
Source File: RangesActivity.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranges);
    ButterKnife.bind(this);
    mViewModel = new ViewModelProvider(this, mViewModelFactory).get(RangesViewModel.class);
    mType = getIntent().getExtras().getInt(Utils.RANGE_TYPE);

    //Bind ui
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final RecyclerView recyclerView = findViewById(R.id.recycler_view);
    final View rangesContainer = findViewById(R.id.info_ranges);
    rangesContainer.findViewById(R.id.container).setVisibility(View.VISIBLE);
    mRangeView = rangesContainer.findViewById(R.id.range);
    final TextView startAddress = rangesContainer.findViewById(R.id.start_address);
    final TextView endAddress = rangesContainer.findViewById(R.id.end_address);
    final ExtendedFloatingActionButton fab_add = findViewById(R.id.fab_add);

    mProvisioner = mViewModel.getSelectedProvisioner().getValue();

    switch (mType) {
        case Utils.GROUP_RANGE:
            startAddress.setText(MeshAddress.formatAddress(MeshAddress.START_GROUP_ADDRESS, true));
            endAddress.setText(MeshAddress.formatAddress(MeshAddress.END_GROUP_ADDRESS, true));
            getSupportActionBar().setTitle(R.string.title_edit_group_ranges);
            mRangeAdapter = new RangeAdapter(this,
                    mProvisioner.getProvisionerUuid(),
                    mProvisioner.getAllocatedGroupRanges(),
                    mViewModel.getNetworkLiveData().getProvisioners());
            break;
        case Utils.SCENE_RANGE:
            startAddress.setText(MeshAddress.formatAddress(0x0000, true));
            endAddress.setText(MeshAddress.formatAddress(0xFFFF, true));
            getSupportActionBar().setTitle(R.string.title_edit_scene_ranges);
            mRangeAdapter = new RangeAdapter(this,
                    mProvisioner.getProvisionerUuid(),
                    mProvisioner.getAllocatedSceneRanges(),
                    mViewModel.getNetworkLiveData().getProvisioners());
            break;
        default:
        case Utils.UNICAST_RANGE:
            startAddress.setText(MeshAddress.formatAddress(MeshAddress.START_UNICAST_ADDRESS, true));
            endAddress.setText(MeshAddress.formatAddress(MeshAddress.END_UNICAST_ADDRESS, true));
            getSupportActionBar().setTitle(R.string.title_edit_unicast_ranges);
            mRangeAdapter = new RangeAdapter(this,
                    mProvisioner.getProvisionerUuid(),
                    mProvisioner.getAllocatedUnicastRanges(),
                    mViewModel.getNetworkLiveData().getProvisioners());
            break;
    }

    mRangeAdapter.setOnItemClickListener(this);

    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final DividerItemDecoration dividerItemDecoration =
            new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
    recyclerView.addItemDecoration(dividerItemDecoration);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mRangeAdapter);
    final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this);
    final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);

    fab_add.setOnClickListener(v -> {
        switch (mType) {
            case Utils.GROUP_RANGE:
                final DialogFragmentGroupRange groupRange = DialogFragmentGroupRange.newInstance(null);
                groupRange.show(getSupportFragmentManager(), null);
                break;
            case Utils.SCENE_RANGE:
                final DialogFragmentSceneRange sceneRange = DialogFragmentSceneRange.newInstance(null);
                sceneRange.show(getSupportFragmentManager(), null);
                break;
            default:
            case Utils.UNICAST_RANGE:
                final DialogFragmentUnicastRange unicastRange = DialogFragmentUnicastRange.newInstance(null);
                unicastRange.show(getSupportFragmentManager(), null);
                break;
        }
    });

    mFabResolve.setOnClickListener(v -> resolveRanges());

    updateRanges();
    updateOtherRanges();
    updateEmptyView();
    updateResolveFab();
}
 
Example 3
Source File: NetworkFragment.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
    @SuppressLint("InflateParams") final View rootView = inflater.inflate(R.layout.fragment_network, null);
    mViewModel = new ViewModelProvider(requireActivity(), mViewModelFactory).get(SharedViewModel.class);
    ButterKnife.bind(this, rootView);

    final ExtendedFloatingActionButton fab = rootView.findViewById(R.id.fab_add_node);
    final View noNetworksConfiguredView = rootView.findViewById(R.id.no_networks_configured);

    // Configure the recycler view
    mNodeAdapter = new NodeAdapter(this, mViewModel.getNodes());
    mNodeAdapter.setOnItemClickListener(this);
    mRecyclerViewNodes.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerViewNodes.addItemDecoration(new DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL));
    final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this);
    final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerViewNodes);
    mRecyclerViewNodes.setAdapter(mNodeAdapter);

    // Create view model containing utility methods for scanning
    mViewModel.getNodes().observe(getViewLifecycleOwner(), nodes -> {
        if (nodes != null && !nodes.isEmpty()) {
            noNetworksConfiguredView.setVisibility(View.GONE);
        } else {
            noNetworksConfiguredView.setVisibility(View.VISIBLE);
        }
        requireActivity().invalidateOptionsMenu();
    });

    mViewModel.isConnectedToProxy().observe(getViewLifecycleOwner(), isConnected -> {
        if (isConnected != null) {
            requireActivity().invalidateOptionsMenu();
        }
    });

    mRecyclerViewNodes.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {
            super.onScrolled(recyclerView, dx, dy);
            final LinearLayoutManager m = (LinearLayoutManager) recyclerView.getLayoutManager();
            if (m != null) {
                if (m.findFirstCompletelyVisibleItemPosition() == 0) {
                    fab.extend();
                } else {
                    fab.shrink();
                }
            }
        }
    });

    fab.setOnClickListener(v -> {
        final Intent intent = new Intent(requireContext(), ScannerActivity.class);
        intent.putExtra(Utils.EXTRA_DATA_PROVISIONING_SERVICE, true);
        startActivityForResult(intent, Utils.PROVISIONING_SUCCESS);
    });

    return rootView;
}
 
Example 4
Source File: GroupsFragment.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
    @SuppressLint("InflateParams") final View rootView = inflater.inflate(R.layout.fragment_groups, null);
    mViewModel = new ViewModelProvider(requireActivity(), mViewModelFactory).get(SharedViewModel.class);
    ButterKnife.bind(this, rootView);

    final ExtendedFloatingActionButton fab = rootView.findViewById(R.id.fab_add_group);

    // Configure the recycler view
    final RecyclerView recyclerViewGroups = rootView.findViewById(R.id.recycler_view_groups);
    recyclerViewGroups.setLayoutManager(new LinearLayoutManager(requireContext()));
    final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerViewGroups.getContext(), DividerItemDecoration.VERTICAL);
    recyclerViewGroups.addItemDecoration(dividerItemDecoration);
    final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this);
    final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
    itemTouchHelper.attachToRecyclerView(recyclerViewGroups);
    final GroupAdapter adapter = new GroupAdapter(requireContext());
    adapter.setOnItemClickListener(this);
    recyclerViewGroups.setAdapter(adapter);

    mViewModel.getNetworkLiveData().observe(getViewLifecycleOwner(), meshNetworkLiveData -> {
        if (meshNetworkLiveData != null) {
            if (meshNetworkLiveData.getMeshNetwork().getGroups().isEmpty()) {
                mEmptyView.setVisibility(View.VISIBLE);
            } else {
                mEmptyView.setVisibility(View.INVISIBLE);
            }
        }
    });

    mViewModel.getGroups().observe(getViewLifecycleOwner(), groups -> {
        final MeshNetwork network = mViewModel.getNetworkLiveData().getMeshNetwork();
        adapter.updateAdapter(network, groups);
    });

    fab.setOnClickListener(v -> {
        DialogFragmentCreateGroup fragmentCreateGroup = DialogFragmentCreateGroup.newInstance();
        fragmentCreateGroup.show(getChildFragmentManager(), null);
    });

    recyclerViewGroups.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {
            super.onScrolled(recyclerView, dx, dy);
            final LinearLayoutManager m = (LinearLayoutManager) recyclerView.getLayoutManager();
            if (m != null) {
                if (m.findFirstCompletelyVisibleItemPosition() == 0) {
                    fab.extend();
                } else {
                    fab.shrink();
                }
            }
        }
    });

    return rootView;

}
 
Example 5
Source File: AppKeysActivity.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_keys);
    mViewModel = new ViewModelProvider(this, mViewModelFactory).get(AppKeysViewModel.class);

    //Bind ui
    ButterKnife.bind(this);

    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final ExtendedFloatingActionButton fab = findViewById(R.id.fab_add);
    final RecyclerView appKeysRecyclerView = findViewById(R.id.recycler_view_keys);
    appKeysRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    final DividerItemDecoration dividerItemDecoration =
            new DividerItemDecoration(appKeysRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
    appKeysRecyclerView.addItemDecoration(dividerItemDecoration);
    appKeysRecyclerView.setItemAnimator(new DefaultItemAnimator());

    final Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        switch (bundle.getInt(EXTRA_DATA)) {
            case MANAGE_APP_KEY:
                break;
            case ADD_APP_KEY:
                getSupportActionBar().setTitle(R.string.title_select_app_key);
                fab.hide();
                mAdapter = new ManageAppKeyAdapter(this, mViewModel.getNetworkLiveData());
                mAdapter.setOnItemClickListener(this);
                appKeysRecyclerView.setAdapter(mAdapter);
                setUpObserver();
                break;
            case BIND_APP_KEY:
            case PUBLICATION_APP_KEY:
                getSupportActionBar().setTitle(R.string.title_select_app_key);
                fab.hide();
                //Get selected mesh node
                final ProvisionedMeshNode node = mViewModel.getSelectedMeshNode().getValue();
                if (node != null) {
                    final List<NodeKey> applicationKeys = node.getAddedAppKeys();
                    if (!applicationKeys.isEmpty()) {
                        mAdapter = new ManageAppKeyAdapter(mViewModel.getNetworkLiveData().getAppKeys(), applicationKeys);
                        mAdapter.setOnItemClickListener(this);
                        appKeysRecyclerView.setAdapter(mAdapter);
                    } else {
                        final TextView textView = mEmptyView.findViewById(R.id.rationale);
                        textView.setText(R.string.no_added_app_keys_rationale);
                        mEmptyView.setVisibility(View.VISIBLE);
                    }
                }
                break;
        }
    } else {
        getSupportActionBar().setTitle(R.string.title_manage_app_keys);
        final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this);
        final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
        itemTouchHelper.attachToRecyclerView(appKeysRecyclerView);
        mAdapter = new ManageAppKeyAdapter(this, mViewModel.getNetworkLiveData());
        mAdapter.setOnItemClickListener(this);
        appKeysRecyclerView.setAdapter(mAdapter);
        setUpObserver();
    }


    fab.setOnClickListener(v -> {
        final Intent intent = new Intent(this, AddAppKeyActivity.class);
        startActivity(intent);
    });

    appKeysRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {
            super.onScrolled(recyclerView, dx, dy);
            final LinearLayoutManager m = (LinearLayoutManager) recyclerView.getLayoutManager();
            if (m != null) {
                if (m.findFirstCompletelyVisibleItemPosition() == 0) {
                    fab.extend();
                } else {
                    fab.shrink();
                }
            }
        }
    });
}