com.google.android.material.bottomsheet.BottomSheetBehavior Java Examples
The following examples show how to use
com.google.android.material.bottomsheet.BottomSheetBehavior.
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: UserActivity.java From materialistic with Apache License 2.0 | 6 votes |
private void bind() { SpannableString karma = new SpannableString(String.format(Locale.US, KARMA, NumberFormat.getInstance(Locale.getDefault()).format(mUser.getKarma()))); karma.setSpan(new RelativeSizeSpan(0.8f), 0, karma.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); mTitle.append(karma); mInfo.setText(getString(R.string.user_info, mUser.getCreated(this))); if (TextUtils.isEmpty(mUser.getAbout())) { mAbout.setVisibility(View.GONE); } else { AppUtils.setTextWithLinks(mAbout, AppUtils.fromHtml(mUser.getAbout(), true)); } int count = mUser.getItems().length; mTabLayout.addTab(mTabLayout.newTab() .setText(getResources().getQuantityString(R.plurals.submissions_count, count, count))); mRecyclerView.setAdapter(new SubmissionRecyclerViewAdapter(mItemManger, mUser.getItems())); mRecyclerView.setLayoutFrozen(mBottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED); }
Example #2
Source File: TestRecyclerViewInNestedScrollViewInSrlActivity.java From SmoothRefreshLayout with MIT License | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; case Menu.FIRST: LinearLayout linearLayout = findViewById(R.id.linearLayout_test_recyclerView_in_nestedScrollView); BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(linearLayout); if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } else { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); } return true; default: return super.onOptionsItemSelected(item); } }
Example #3
Source File: TestRecyclerViewInNestedScrollViewActivity.java From SmoothRefreshLayout with MIT License | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; case Menu.FIRST: LinearLayout linearLayout = findViewById(R.id.linearLayout_test_recyclerView_in_nestedScrollView); BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(linearLayout); if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } else { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); } return true; default: return super.onOptionsItemSelected(item); } }
Example #4
Source File: MainActivity.java From call_manage with MIT License | 6 votes |
/** * Handle a VIEW intent (For example when you click a number in whatsapp) * * @param intent */ private void handleViewIntent(Intent intent) { String sharedText = ""; // Try decoding incoming intent data try { sharedText = URLDecoder.decode(intent.getDataString(), "utf-8"); } catch (UnsupportedEncodingException e) { Toast.makeText(this, "An error occured when trying to get phone number :(", Toast.LENGTH_LONG).show(); return; } if (sharedText.contains("tel:") && sharedText != "tel:") { mSharedIntentViewModel.setData(sharedText.replace("tel:", "")); mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); } else { Toast.makeText(this, "No phone number detected", Toast.LENGTH_SHORT).show(); } }
Example #5
Source File: AmenityInformation.java From trekarta with GNU General Public License v3.0 | 6 votes |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mViews = FragmentAmenityInformationBinding.inflate(inflater, container, false); final ViewGroup rootView = (ViewGroup) mViews.getRoot(); rootView.post(() -> { updatePeekHeight(rootView, false); int panelState = BottomSheetBehavior.STATE_COLLAPSED; if (savedInstanceState != null) { panelState = savedInstanceState.getInt("panelState", panelState); View dragHandle = rootView.findViewById(R.id.dragHandle); dragHandle.setAlpha(panelState == BottomSheetBehavior.STATE_EXPANDED ? 0f : 1f); } mBottomSheetBehavior.setState(panelState); // Workaround for panel partially drawn on first slide // TODO Try to put transparent view above map if (Configuration.getHideSystemUI()) rootView.requestLayout(); }); mMapHolder.updateMapViewArea(); return rootView; }
Example #6
Source File: AbstractWidgetConfigActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onBackPressed() { if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) { setBottomSheetState(true); return; } long time = System.currentTimeMillis(); if (time - lastBackPressedTime < 2000) { super.onBackPressed(); return; } lastBackPressedTime = time; SnackbarUtils.showSnackbar(this, getString(R.string.feedback_click_again_to_exit)); }
Example #7
Source File: BottomSheetUserDialogFragment.java From intra42 with Apache License 2.0 | 6 votes |
@Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sheet_user, null); dialog.setContentView(contentView); imageViewProfile = contentView.findViewById(R.id.imageViewProfile); textViewName = contentView.findViewById(R.id.textViewName); textViewName.setText(mUser.login); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams(); CoordinatorLayout.Behavior behavior = params.getBehavior(); if (behavior != null && behavior instanceof BottomSheetBehavior) { ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback); } }
Example #8
Source File: MapFragment.java From nearby-android with Apache License 2.0 | 6 votes |
/** * Set the menu options based on * the bottom sheet state * */ @Override public final void onPrepareOptionsMenu(final Menu menu){ final MenuItem listItem = menu.findItem(R.id.list_action); final MenuItem routeItem = menu.findItem(R.id.route_action); final MenuItem filterItem = menu.findItem(R.id.filter_in_map); if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { listItem.setVisible(true); filterItem.setVisible(true); routeItem.setVisible(false); }else if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED){ listItem.setVisible(false); filterItem.setVisible(true); routeItem.setVisible(true); } }
Example #9
Source File: MapFragment.java From nearby-android with Apache License 2.0 | 6 votes |
/** * Show snackbar prompting user about * scanning for new locations */ private void showSearchSnackbar(){ final Snackbar snackbar = Snackbar .make(mMapLayout, "Search for places?", Snackbar.LENGTH_LONG) .setAction("SEARCH", new View.OnClickListener() { @Override public void onClick(final View view) { if (mRouteOverlay != null){ mRouteOverlay.getGraphics().clear(); } mCenteredPlace = null; mCenteredPlaceName = null; mPresenter.findPlacesNearby(); mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } }); snackbar.show(); }
Example #10
Source File: DynamicBottomSheet.java From dynamic-support with Apache License 2.0 | 6 votes |
@Override public void applyWindowInsets() { if (getParent() == null || !(getParent() instanceof CoordinatorLayout)) { return; } final int paddingBottom = getPaddingBottom(); final int peekHeight = BottomSheetBehavior.from(this).getPeekHeight(); ViewCompat.setOnApplyWindowInsetsListener(this, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), paddingBottom + insets.getSystemWindowInsetBottom()); BottomSheetBehavior.from(v).setPeekHeight( peekHeight + insets.getSystemWindowInsetBottom()); insets.consumeSystemWindowInsets(); return insets; } }); }
Example #11
Source File: DynamicThemeFragment.java From dynamic-support with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { int i = item.getItemId(); if (i == R.id.ads_menu_default) { mSettingsChanged = false; mDynamicAppTheme = new DynamicAppTheme(mDynamicAppThemeDefault); loadTheme(mDynamicAppTheme); mFontScalePreference.setValue(mFontScalePreference.getDefaultValue()); mCornerSizePreference.setValue(mCornerSizePreference.getDefaultValue()); getDynamicActivity().getSnackBar(R.string.ads_theme_reset_desc).show(); getDynamicActivity().setBottomSheetState(BottomSheetBehavior.STATE_EXPANDED); return true; } return super.onOptionsItemSelected(item); }
Example #12
Source File: ThemeFragment.java From dynamic-support with Apache License 2.0 | 6 votes |
/** * Try to import the supplied theme string. * * @param theme The theme string to be imported. * @param file {@code true} if importing from the file. **/ protected void importTheme(@Nullable String theme, boolean file) { if (theme == null || !DynamicThemeUtils.isValidTheme(theme)) { invalidTheme(file); } else { try { mSettingsChanged = false; loadTheme(onImportTheme(theme)); getDynamicActivity().getSnackBar( R.string.ads_theme_import_done).show(); getDynamicActivity().setBottomSheetState( BottomSheetBehavior.STATE_EXPANDED); } catch (Exception ignored) { invalidTheme(file); } } }
Example #13
Source File: ChatFragment.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 6 votes |
@Override public void onMessageClicked(SpannableStringBuilder formattedMessage, final String userName, final String message) { View v = LayoutInflater.from(getContext()).inflate(R.layout.chat_message_options, null); final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getContext()); bottomSheetDialog.setContentView(v); final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) v.getParent()); behavior.setPeekHeight(getContext().getResources().getDisplayMetrics().heightPixels/3); bottomSheetDialog.setOnDismissListener(dialogInterface -> behavior.setState(BottomSheetBehavior.STATE_COLLAPSED)); TextView mMessage = v.findViewById(R.id.text_chat_message); TextView mMention = v.findViewById(R.id.text_mention); TextView mDuplicateMessage = v.findViewById(R.id.text_duplicate_message); mMessage.setText(formattedMessage); mMention.setOnClickListener(view -> { insertSendText("@" + userName); bottomSheetDialog.dismiss(); }); mDuplicateMessage.setOnClickListener(view -> { insertSendText(message); bottomSheetDialog.dismiss(); }); bottomSheetDialog.show(); }
Example #14
Source File: BottomSheetBuilderUtils.java From SimplicityBrowser with MIT License | 5 votes |
public static void delayDismiss(final BottomSheetBehavior behavior) { new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { behavior.setState(BottomSheetBehavior.STATE_HIDDEN); } }, 100); }
Example #15
Source File: DynamicBottomSheet.java From dynamic-support with Apache License 2.0 | 5 votes |
@Override public void initialize() { setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { BottomSheetBehavior.from(v).setState(BottomSheetBehavior.STATE_EXPANDED); } }); }
Example #16
Source File: AppChooserDialog.java From Status with Apache License 2.0 | 5 votes |
@Override public void onGottenPackages(AppPreferenceData[] packages) { this.packages = new ArrayList<>(Arrays.asList(packages)); if (recycler != null) { recycler.setAdapter(new AppAdapter(getContext(), this.packages)); if (progress != null) progress.setVisibility(View.GONE); if (behavior != null) behavior.setState(BottomSheetBehavior.STATE_EXPANDED); } }
Example #17
Source File: MainActivity.java From Status with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent != null && intent.getAction() != null && intent.getAction().equals(ACTION_TOO_MANY_ICONS)) { if (intent.getBooleanExtra(EXTRA_MANY_ICONS, true)) activity.setTutorial(R.string.tutorial_too_many_icons, R.string.tutorial_too_many_icons_desc, null, true); else if (!activity.behavior.isHideable()) { activity.behavior.setHideable(true); activity.behavior.setState(BottomSheetBehavior.STATE_HIDDEN); } } }
Example #18
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 5 votes |
private void updateMap(WfsLayerInfo wfsLayerInfo) { mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); mLoadingView.setVisibility(View.VISIBLE); // clear existing layer infos mMapView.getMap().getOperationalLayers().clear(); // create feature table WfsFeatureTable featureTable = new WfsFeatureTable(wfsLayerInfo); // set the axis order dependant on whether the checkbox is ticked or not featureTable.setAxisOrder(mAxisCheckbox.isChecked() ? OgcAxisOrder.SWAP : OgcAxisOrder.NO_SWAP); // set the table's feature request mode featureTable.setFeatureRequestMode(ServiceFeatureTable.FeatureRequestMode.MANUAL_CACHE); // create a feature layer from the table FeatureLayer featureLayer = new FeatureLayer(featureTable); // set a renderer to the table once is loaded, since the renderer is chosen based on the table's geometry type featureTable.addDoneLoadingListener(() -> featureLayer.setRenderer(getRandomRendererForTable(featureTable))); // add the layer to the map mMapView.getMap().getOperationalLayers().add(featureLayer); // populate the table ListenableFuture<FeatureQueryResult> featureQueryResultFuture = featureTable .populateFromServiceAsync(new QueryParameters(), false, null); // run when the table has been populated featureQueryResultFuture.addDoneListener(() -> { // zoom to the extent of the layer mMapView.setViewpointGeometryAsync(featureLayer.getFullExtent(), 50); mLoadingView.setVisibility(View.GONE); }); }
Example #19
Source File: OpenWithFragment.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Override public void show() { if (getContext().getResources().getBoolean(R.bool.is_tablet)) { final int peekHeight = getContext().getResources().getDimensionPixelSize(R.dimen.tablet_bottom_sheet_peekheight); BottomSheetBehavior<View> bsBehaviour = BottomSheetBehavior.from((View) contentView.getParent()); bsBehaviour.setPeekHeight(peekHeight); } super.show(); }
Example #20
Source File: LauncherActivity.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
public void showStartDialog() { DialogStartHintBinding binding = DialogStartHintBinding.inflate(getLayoutInflater()); final BottomSheetDialog startDialog = new BottomSheetDialog(this); startDialog.setContentView(binding.getRoot()); startDialog.setCancelable(false); startDialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED); Button startDismiss = binding.dismiss; startDismiss.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startDialog.dismiss(); PreferenceHelper.update("is_new_user", false); } }); startDialog.show(); }
Example #21
Source File: ChatFragmentSendMessageHelper.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
@Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { mServerMessagesContainer.setVisibility(View.GONE); mServerMessagesListAdapter.clear(); } }
Example #22
Source File: BaseLibraryActivityViewModel.java From Jockey with Apache License 2.0 | 5 votes |
@Bindable public View.OnClickListener getMiniplayerClickListener() { return v -> { View bottomSheet = (View) v.getParent(); BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(bottomSheet); behavior.setState(BottomSheetBehavior.STATE_EXPANDED); }; }
Example #23
Source File: BottomSheetBindingAdapter.java From deagle with Apache License 2.0 | 5 votes |
@BindingAdapter("behavior_state") public static void setBottomSheetState(final View view, final @BottomSheetBehavior.State int state) { final BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(view); if (behavior == null) return; try { behavior.setState(state); } catch (final RuntimeException e) { new Handler().post(new Runnable() { @Override public void run() { try { behavior.setState(state); } catch (final RuntimeException ignored) {} }}); } }
Example #24
Source File: BottomSheetScrollableContentDemoFragment.java From material-components-android with Apache License 2.0 | 5 votes |
@Override public View onCreateDemoView( LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { View view = layoutInflater.inflate(getDemoContent(), viewGroup, false /* attachToRoot */); // Set up BottomSheetDialog BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getContext()); bottomSheetDialog.setContentView(R.layout.cat_bottomsheet_scrollable_content); View bottomSheetInternal = bottomSheetDialog.findViewById(R.id.design_bottom_sheet); BottomSheetBehavior.from(bottomSheetInternal).setPeekHeight(400); View button = view.findViewById(R.id.bottomsheet_button); button.setOnClickListener(v -> bottomSheetDialog.show()); return view; }
Example #25
Source File: BottomSheetMenuDialog.java From SimplicityBrowser with MIT License | 5 votes |
@Override public void onBottomSheetItemClick(MenuItem item) { if (!mClicked) { if (mBehavior != null) { mBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); } if (mClickListener != null) { mClickListener.onBottomSheetItemClick(item); } mClicked = true; } }
Example #26
Source File: BottomSheetBehaviorActivity.java From material-components-android with Apache License 2.0 | 5 votes |
@Override protected void onContentViewSet() { mCoordinatorLayout = findViewById(R.id.coordinator); mBottomSheet = findViewById(R.id.bottom_sheet); mBehavior = BottomSheetBehavior.from(mBottomSheet); mFab = findViewById(R.id.fab); Intent intent = getIntent(); if (intent != null) { int initialState = intent.getIntExtra(EXTRA_INITIAL_STATE, -1); if (initialState != -1) { //noinspection ResourceType mBehavior.setState(initialState); } } }
Example #27
Source File: EmojiBSFragment.java From PhotoEditor with MIT License | 5 votes |
@Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { dismiss(); } }
Example #28
Source File: BottomSheetMetrics.java From ground-android with Apache License 2.0 | 5 votes |
BottomSheetMetrics(View bottomSheet) { this.parent = (CoordinatorLayout) bottomSheet.getParent(); this.bottomSheet = bottomSheet; this.addObservationButton = parent.findViewById(R.id.add_observation_btn); this.bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); this.header = parent.findViewById(R.id.bottom_sheet_header); this.toolbarWrapper = parent.findViewById(R.id.toolbar_wrapper); this.marginTop = (int) parent.getResources().getDimension(R.dimen.bottom_sheet_margin_top); }
Example #29
Source File: MapFragment.java From nearby-android with Apache License 2.0 | 5 votes |
/** * Dismiss the bottom sheet * when map is scrolled and notify * presenter */ @Override public final void onMapViewChange() { mShowSnackbar = true; if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED){ if (!mShowingRouteDetail){ // show snackbar prompting for re-doing search showSearchSnackbar(); } }else{ mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } mPresenter.setCurrentExtent(mMapView.getVisibleArea().getExtent()); }
Example #30
Source File: StickerBSFragment.java From PhotoEditor with MIT License | 5 votes |
@Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { dismiss(); } }