Java Code Examples for com.google.android.material.bottomsheet.BottomSheetBehavior#from()

The following examples show how to use com.google.android.material.bottomsheet.BottomSheetBehavior#from() . 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: ChatFragment.java    From Twire with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onMessageClicked(SpannableStringBuilder formattedMessage, final String userName, final String message) {
    View v = LayoutInflater.from(getContext()).inflate(R.layout.chat_message_options, null);
    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 2
Source File: LoginSignUpFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override public void bindViews(View view) {
  super.bindViews(view);

  try {
    bottomSheetBehavior = BottomSheetBehavior.from(view.findViewById(R.id.login_signup_layout));
  } catch (IllegalArgumentException ex) {
    // this happens because in landscape the R.id.login_signup_layout is not
    // a child of CoordinatorLayout
  }

  if (bottomSheetBehavior != null) {
    mainContent = view.findViewById(R.id.main_content);
    originalBottomPadding = withBottomBar ? mainContent.getPaddingBottom() : 0;
    toolbarTitle = getString(R.string.my_account_title_my_account);
    mainContent.setPadding(0, 0, 0, originalBottomPadding);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
  }
}
 
Example 3
Source File: ThreadListFragment.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
private void showThreadListSettingsDialog() {
    final LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View view = inflater.inflate(R.layout.dialog_thread_list_settings, null);

    final ValueChagerView valueChagerView = view.findViewById(R.id.value_changer);

    valueChagerView.setCurrentValue(HiSettingsHelper.getInstance().getTitleTextSizeAdj());

    final BottomSheetDialog dialog = new BottomDialog(getActivity());

    valueChagerView.setOnChangeListener(new ValueChagerView.OnChangeListener() {
        @Override
        public void onChange(int currentValue) {
            HiSettingsHelper.getInstance().setTitleTextSizeAdj(currentValue);
            if (mThreadListAdapter != null)
                mThreadListAdapter.notifyDataSetChanged();
        }
    });

    dialog.setContentView(view);
    BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) view.getParent());
    mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    dialog.show();
}
 
Example 4
Source File: ChatFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
@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 5
Source File: BaseLibraryActivityViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Bindable
public View.OnClickListener getMiniplayerClickListener() {
    return v -> {
        View bottomSheet = (View) v.getParent();
        BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(bottomSheet);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    };
}
 
Example 6
Source File: SettingActivity.java    From Bop with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setting);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(ExtraUtils.getThemedIcon(this, getDrawable(R.drawable.ic_backarrow)));
    Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });

    mode = findViewById(R.id.settingsMode);
    theme = findViewById(R.id.settingsTheme);
    pauseHeadphoneUnplugged = findViewById(R.id.pauseHeadphoneUnplugged);
    resumeHeadphonePlugged = findViewById(R.id.resumeHeadphonePlugged);
    headphoneControl = findViewById(R.id.headphoneControl);
    saveRecent = findViewById(R.id.saveRecent);
    saveCount = findViewById(R.id.saveCount);
    savePlaylist = findViewById(R.id.savePlaylist);
    blockfolder = findViewById(R.id.blockFolder);
    llBottomSheet = findViewById(R.id.bottom_sheet);
    mBottomSheetBehavior = BottomSheetBehavior.from(llBottomSheet);
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    TextView slds = findViewById(R.id.curVersion);
    slds.setText(Main.versionName);
    setupCheckBoxes();
    setListeners();

}
 
Example 7
Source File: BaseModalBottomSheet.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void attachCustomCallback(@NonNull View bottomSheet) {
    bottomSheet.setBackgroundColor(Color.TRANSPARENT);

    behavior = BottomSheetBehavior.from(bottomSheet);
    behavior.addBottomSheetCallback(prepareCallback());
    attachedBehavior(bottomSheet.getContext(), behavior);
}
 
Example 8
Source File: BottomSheetMetrics.java    From ground-android with Apache License 2.0 5 votes vote down vote up
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 9
Source File: BottomSheetBindingAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: RoundedBottomSheetDialogFragment.java    From zephyr with MIT License 5 votes vote down vote up
public void onShow(DialogInterface dialog) {
    BottomSheetDialog d = (BottomSheetDialog) dialog;
    FrameLayout bottomSheet = d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
    if (bottomSheet != null) {
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        bottomSheetBehavior.setSkipCollapsed(shouldSkipCollapsedState());
        bottomSheetBehavior.setState(getInitialBottomSheetState());
    }
}
 
Example 11
Source File: OpenWithFragment.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@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 12
Source File: BindingAdapters.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@BindingAdapter("behavior_peekHeight")
public static void bindPeekHeight(View view, int peekHeight) {
    BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(view);
    behavior.setPeekHeight(peekHeight);
}
 
Example 13
Source File: BottomSheetBindingAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@BindingAdapter("behavior_bottomSheetCallback")
public static void bindBottomSheetCallback(final View view, final BottomSheetCallback callback) {
	final BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(view);
	if (behavior == null) throw new IllegalArgumentException(view + " has no BottomSheetBehavior");
	behavior.setBottomSheetCallback(callback);
}
 
Example 14
Source File: BottomSheetMenuDialog.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    final FrameLayout sheet = findViewById(R.id.design_bottom_sheet);

    if (sheet != null) {
        mBehavior = BottomSheetBehavior.from(sheet);
        mBehavior.setBottomSheetCallback(mBottomSheetCallback);

        if (getContext().getResources().getBoolean(R.bool.tablet_landscape)) {
            CoordinatorLayout.LayoutParams layoutParams
                    = (CoordinatorLayout.LayoutParams) sheet.getLayoutParams();
            layoutParams.width = getContext().getResources()
                    .getDimensionPixelSize(R.dimen.bottomsheet_width);
            sheet.setLayoutParams(layoutParams);
        }

        // Make sure the sheet doesn't overlap the appbar
        if (mAppBarLayout != null) {
            if (mAppBarLayout.getHeight() == 0) {
                mAppBarLayout.getViewTreeObserver()
                        .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                            @Override
                            public void onGlobalLayout() {
                                applyAppbarMargin(sheet);
                            }
                        });
            } else {
                applyAppbarMargin(sheet);
            }
        }


        if (mExpandOnStart) {
            sheet.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                    if (mBehavior.getState() == BottomSheetBehavior.STATE_SETTLING
                            && mRequestedExpand) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            sheet.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        } else {
                            //noinspection deprecation
                            sheet.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        }
                    }
                    mRequestedExpand = true;
                }
            });
        } else if (getContext().getResources().getBoolean(R.bool.landscape)) {
            fixLandscapePeekHeight(sheet);
        }
    }
}
 
Example 15
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater  inflater, ViewGroup container, Bundle savedInstanceState) {
	View view = inflater.inflate(R.layout.fragment_map, container, false);

	setHasOptionsMenu(true);

	staticGeometryCollection = new StaticGeometryCollection();

	availableLayerDownloadsIcon = view.findViewById(R.id.available_layer_downloads);
	zoomToLocationButton = view.findViewById(R.id.zoom_button);

	compassButton = view.findViewById(R.id.compass_button);
	compassButton.setOnClickListener(v -> resetMapBearing());

	searchButton = view.findViewById(R.id.map_search_button);
	if (Geocoder.isPresent()) {
		searchButton.setOnClickListener(v -> search());
	} else {
		searchButton.hide();
	}

	view.findViewById(R.id.new_observation_button).setOnClickListener(v -> onNewObservation());

	searchLayout = view.findViewById(R.id.search_layout);
	searchView = view.findViewById(R.id.search_view);
	searchView.setIconifiedByDefault(false);
	searchView.setIconified(false);
	searchView.clearFocus();

	MapsInitializer.initialize(context);

	ImageButton mapSettings = view.findViewById(R.id.map_settings);
	mapSettings.setOnClickListener(this);

	mapView = view.findViewById(R.id.mapView);
	Bundle mapState = (savedInstanceState != null) ? savedInstanceState.getBundle(MAP_VIEW_STATE): null;
	mapView.onCreate(mapState);

	mgrsBottomSheet = view.findViewById(R.id.mgrs_bottom_sheet);
	mgrsBottomSheetBehavior = BottomSheetBehavior.from(mgrsBottomSheet);
	mgrsCursor = view.findViewById(R.id.mgrs_grid_cursor);
	mgrsTextView = mgrsBottomSheet.findViewById(R.id.mgrs_code);
	mgrsGzdTextView = mgrsBottomSheet.findViewById(R.id.mgrs_gzd_zone);
	mgrs100dKmTextView = mgrsBottomSheet.findViewById(R.id.mgrs_grid_zone);
	mgrsEastingTextView = mgrsBottomSheet.findViewById(R.id.mgrs_easting);
	mgrsNorthingTextView = mgrsBottomSheet.findViewById(R.id.mgrs_northing);

	// Initialize the GeoPackage cache with a GeoPackage manager
	GeoPackageManager geoPackageManager = GeoPackageFactory.getManager(getActivity().getApplicationContext());
	geoPackageCache = new GeoPackageCache(geoPackageManager);

	locationProvider = locationPolicy.getBestLocationProvider();

	return view;
}
 
Example 16
Source File: StreamFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
private BottomSheetBehavior getDefaultBottomSheetBehaviour(View bottomSheetView) {
    BottomSheetBehavior behavior = BottomSheetBehavior.from((View) bottomSheetView.getParent());
    behavior.setPeekHeight(getContext().getResources().getDisplayMetrics().heightPixels / 3);
    return behavior;
}
 
Example 17
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 4 votes vote down vote up
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  mSceneView = findViewById(R.id.sceneView);
  mLayersRecyclerView = findViewById(R.id.layersRecyclerView);

  View bottomSheet = findViewById(R.id.bottomSheet);
  mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
  mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

  mSceneView.setOnTouchListener(new DefaultSceneViewOnTouchListener(mSceneView) {
    @Override public boolean onTouch(View view, MotionEvent motionEvent) {
      if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        return true;
      }
      return super.onTouch(view, motionEvent);
    }
  });

  // create a scene with a basemap and add it to the scene view
  ArcGISScene scene = new ArcGISScene();
  scene.setBasemap(Basemap.createImagery());
  mSceneView.setScene(scene);

  // set the base surface with world elevation
  Surface surface = new Surface();
  surface.getElevationSources().add(new ArcGISTiledElevationSource(getString(R.string.elevation_source_url)));
  scene.setBaseSurface(surface);

  // create different types of layers
  ArcGISSceneLayer trees = new ArcGISSceneLayer(getString(R.string.tree_scene_service));
  FeatureLayer pathways = new FeatureLayer(new ServiceFeatureTable(getString(R.string.pathway_feature_service)));
  ArcGISSceneLayer buildingsA = new ArcGISSceneLayer(getString(R.string.building_scene_service_a));
  ArcGISSceneLayer buildingsB = new ArcGISSceneLayer(getString(R.string.building_scene_service_b));
  FeatureLayer projectArea = new FeatureLayer(
      new ServiceFeatureTable(getString(R.string.project_area_feature_service)));

  // create a group layer from scratch by adding the layers as children
  GroupLayer buildingsGroupLayer = new GroupLayer();
  buildingsGroupLayer.setName("Buildings group");
  buildingsGroupLayer.getLayers().addAll(Arrays.asList(buildingsA, buildingsB));

  // add the group layer and other layers to the scene as operational layers
  scene.getOperationalLayers().addAll(Arrays.asList(projectArea, buildingsGroupLayer, trees, pathways));

  // zoom to the extent of the group layer when the child layers are loaded
  ListenableList<Layer> layers = buildingsGroupLayer.getLayers();
  for (Layer childLayer : layers) {
    childLayer.addDoneLoadingListener(() -> {
      if (childLayer.getLoadStatus() == LoadStatus.LOADED) {
        mSceneView.setViewpointCamera(new Camera(buildingsGroupLayer.getFullExtent().getCenter(), 700, 0, 60, 0));
      }
    });
  }

  setupRecyclerView(scene.getOperationalLayers());
}
 
Example 18
Source File: HomeScreenFragment.java    From ground-android with Apache License 2.0 4 votes vote down vote up
private void setUpBottomSheetBehavior() {
  bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout);
  bottomSheetBehavior.setHideable(true);
  bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
  bottomSheetBehavior.setBottomSheetCallback(new BottomSheetCallback());
}
 
Example 19
Source File: BaseBottomSheetDialogFragment.java    From SAI with GNU General Public License v3.0 4 votes vote down vote up
protected void revealBottomSheet() {
    FrameLayout bottomSheet = mDialog.findViewById(R.id.design_bottom_sheet);
    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
 
Example 20
Source File: DynamicActivity.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the current bottom sheet behavior.
 *
 * @return The bottom sheet behavior.
 */
public BottomSheetBehavior getBottomSheetBehavior() {
    return BottomSheetBehavior.from(mBottomSheet);
}