Home » Android » android – setBottomSheetCallback is deprecated

android – setBottomSheetCallback is deprecated

Posted by: admin June 15, 2020 Leave a comment

Questions:

while developing an app for object detection using ml kit firebise, i’ve implemented my bottom sheet but it’s not working,so the camera still focused on the object without any result.
code:

private void setUpBottomSheet() {
    bottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
    bottomSheetBehavior.setBottomSheetCallback(
            new BottomSheetBehavior.BottomSheetCallback() {
                @Override
                public void onStateChanged(@NonNull View bottomSheet, int newState) {
                    Log.d(TAG, "Bottom sheet new state: " + newState);
                    bottomSheetScrimView.setVisibility(
                            newState == BottomSheetBehavior.STATE_HIDDEN ? View.GONE : View.VISIBLE);
                    graphicOverlay.clear();

                    switch (newState) {
                        case BottomSheetBehavior.STATE_HIDDEN:
                            workflowModel.setWorkflowState(WorkflowState.DETECTING);
                            break;
                        case BottomSheetBehavior.STATE_COLLAPSED:
                        case BottomSheetBehavior.STATE_EXPANDED:
                        case BottomSheetBehavior.STATE_HALF_EXPANDED:
                            slidingSheetUpFromHiddenState = false;
                            break;
                        case BottomSheetBehavior.STATE_DRAGGING:
                        case BottomSheetBehavior.STATE_SETTLING:
                        default:
                            break;
                    }
                }

                @Override
                public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                    SearchedObject searchedObject = workflowModel.searchedObject.getValue();
                    if (searchedObject == null || Float.isNaN(slideOffset)) {
                        return;
                    }

                    int collapsedStateHeight =
                            Math.min(bottomSheetBehavior.getPeekHeight(), bottomSheet.getHeight());
                    if (slidingSheetUpFromHiddenState) {
                        RectF thumbnailSrcRect =
                                graphicOverlay.translateRect(searchedObject.getBoundingBox());
                        bottomSheetScrimView.updateWithThumbnailTranslateAndScale(
                                objectThumbnailForBottomSheet,
                                collapsedStateHeight,
                                slideOffset,
                                thumbnailSrcRect);

                    } else {
                        bottomSheetScrimView.updateWithThumbnailTranslate(
                                objectThumbnailForBottomSheet, collapsedStateHeight, slideOffset, bottomSheet);
                    }
                }
            });

Error: setBottomSheetCallback is deprecated

any help would be appreciated

How to&Answers:

Use addBottomSheetCallback and removeBottomSheetCallback instead.

Check out the Android docs.

From the docs:

setBottomSheetCallback

This method is deprecated. use
addBottomSheetCallback(BottomSheetCallback) and
removeBottomSheetCallback(BottomSheetCallback) instead