Java Code Examples for android.support.design.widget.BottomSheetBehavior#setState()

The following examples show how to use android.support.design.widget.BottomSheetBehavior#setState() . 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: MainActivity.java    From CircularReveal with MIT License 6 votes vote down vote up
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ButterKnife.bind(this);

  final ViewRevealManager revealManager = new ViewRevealManager();
  final SpringViewAnimatorManager springManager = new SpringViewAnimatorManager();
  springManager.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
  springManager.setStiffness(SpringForce.STIFFNESS_LOW);

  parent.setViewRevealManager(revealManager);

  settingsView.addSwitch("Enable Spring", false, new CompoundButton.OnCheckedChangeListener() {
    @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      parent.setViewRevealManager(isChecked ? springManager : revealManager);
    }
  });
  settingsView.setAnimatorManager(springManager);

  final BottomSheetBehavior behavior = BottomSheetBehavior.from(settingsView);
  behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_peek_height));
  behavior.setSkipCollapsed(false);
  behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
 
Example 2
Source File: TimeDateDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 3
Source File: LocationConfigDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 4
Source File: BottomSheetMediaActions.java    From Gallery-example with GNU General Public License v3.0 6 votes vote down vote up
private static void toggleBottomSheet(View bottomSheet) {

        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);

        int state = bottomSheetBehavior.getState();

        switch (state) {
            case BottomSheetBehavior.STATE_COLLAPSED:
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                break;
            case BottomSheetBehavior.STATE_HIDDEN:
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                break;
            case BottomSheetBehavior.STATE_EXPANDED:
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
                break;

        }
    }
 
Example 5
Source File: TimeZoneDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(true);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 6
Source File: MoonDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 7
Source File: AlarmDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(true);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 8
Source File: LightMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog != null) {
        BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
        FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
        if (layout != null) {
            BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
            behavior.setHideable(false);
            behavior.setSkipCollapsed(true);
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    }
}
 
Example 9
Source File: WorldMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(Dialog dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(true);
        behavior.setPeekHeight((int)(dialogHeader.getHeight() + getResources().getDimension(R.dimen.dialog_margin) * 2));
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 10
Source File: WorldMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void collapseSheet(Dialog dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(false);
        behavior.setPeekHeight((int)(dialogHeader.getHeight() + getResources().getDimension(R.dimen.dialog_margin) * 2));
        behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    }
}
 
Example 11
Source File: AboutDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 12
Source File: MainActivity.java    From ViewPrinter with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    BottomSheetBehavior b = BottomSheetBehavior.from(mPanel);
    if (b.getState() != BottomSheetBehavior.STATE_HIDDEN) {
        b.setState(BottomSheetBehavior.STATE_HIDDEN);
        return;
    }
    super.onBackPressed();
}
 
Example 13
Source File: EquinoxDialog.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog != null)
    {
        BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
        FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
        if (layout != null)
        {
            BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
            behavior.setHideable(true);
            behavior.setSkipCollapsed(true);
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    }
}
 
Example 14
Source File: HelpDialog.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog != null) {
        BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
        FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
        if (layout != null) {
            BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
            behavior.setHideable(false);
            behavior.setSkipCollapsed(false);
            behavior.setPeekHeight(200);
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    }
}
 
Example 15
Source File: SecondActivity.java    From boxing with Apache License 2.0 5 votes vote down vote up
private void showFragment() {
    if (mInsideBottomSheet != null) {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(mInsideBottomSheet);
        if (behavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        } else {
            behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        }
    }
}
 
Example 16
Source File: MainActivity.java    From ViewPrinter with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.print_jpeg: print(PRINT_JPEG); break;
        case R.id.print_pdf: print(PRINT_PDF); break;
        case R.id.print_png: print(PRINT_PNG); break;
        case R.id.edit:
            BottomSheetBehavior b = BottomSheetBehavior.from(mPanel);
            b.setState(BottomSheetBehavior.STATE_COLLAPSED);
            break;
        case R.id.logo_prompt:
            startActivity(new Intent(this, LogoActivity.class));
            break;
    }
}
 
Example 17
Source File: AppListViewModel.java    From island with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("MethodMayBeStatic") public final void onBottomSheetClick(final View view) {
	final BottomSheetBehavior bottom_sheet = BottomSheetBehavior.from(view);
	bottom_sheet.setState(BottomSheetBehavior.STATE_EXPANDED);
}
 
Example 18
Source File: ReqMenuDialog.java    From NanoIconPack with Apache License 2.0 4 votes vote down vote up
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);

    Bundle bundle = getArguments();
    pos = bundle.getInt("pos");
    bean = (AppBean) bundle.getSerializable("bean");

    contentView = View.inflate(getContext(), R.layout.fragment_req_menu, null);
    dialog.setContentView(contentView);

    ((TextView) contentView.findViewById(R.id.tv_title)).setText(bean.getLabel());
    if (bean.isMark()) {
        contentView.findViewById(R.id.view_menu_mark).setVisibility(View.GONE);
        contentView.findViewById(R.id.view_menu_undo_mark).setOnClickListener(this);
        contentView.findViewById(R.id.view_hint_undo_mark)
                .setVisibility(bean.isHintUndoMark() ? View.VISIBLE : View.GONE);
    } else {
        contentView.findViewById(R.id.view_menu_undo_mark).setVisibility(View.GONE);
        contentView.findViewById(R.id.view_menu_mark).setOnClickListener(this);
        contentView.findViewById(R.id.view_hint_mark)
                .setVisibility(bean.isHintMark() ? View.VISIBLE : View.GONE);
    }
    contentView.findViewById(R.id.view_hint_lost)
            .setVisibility(bean.isHintLost() ? View.VISIBLE : View.GONE);
    contentView.findViewById(R.id.view_menu_goto_market).setOnClickListener(this);
    contentView.findViewById(R.id.view_menu_copy_code).setOnClickListener(this);

    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior
            .from((View) contentView.getParent());
    if (bean.isHintLost()) {
        // In landscape, STATE_EXPANDED doesn't make sheet expanded.
        // Maybe it's a bug. So do this to fix it.
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            contentView.measure(0, 0);
            bottomSheetBehavior.setPeekHeight(contentView.getMeasuredHeight());
        }
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    } else {
        bottomSheetBehavior.setPeekHeight(getResources()
                .getDimensionPixelSize(R.dimen.req_bottom_menu_height));
    }
}
 
Example 19
Source File: RadialTransformationActivity.java    From CircularReveal with MIT License 4 votes vote down vote up
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_sample_2);
  ButterKnife.bind(this);

  Picasso.with(this)
      .load("http://camp-campbell.com/wp-content/uploads/2014/09/847187872-san-francisco.jpg")
      .resizeDimen(R.dimen.radial_card_width, R.dimen.radial_card_height)
      .centerCrop()
      .into(sanFranciscoView);

  videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override public void onPrepared(MediaPlayer mp) {
      mp.setLooping(true);
    }
  });
  videoView.setVideoURI(Uri.parse(VIDEO_URL));
  videoView.start();

  final GestureDetector detector = new GestureDetector(this, tapDetector);

  for (int i = 0; i < stack.getChildCount(); i++) {
    View view = stack.getChildAt(i);
    view.setOnTouchListener(new View.OnTouchListener() {
      @Override public boolean onTouch(View v, MotionEvent event) {
        return detector.onTouchEvent(event);
      }
    });
  }

  final ViewRevealManager revealManager = new ViewRevealManager();
  final SpringViewAnimatorManager springManager = new SpringViewAnimatorManager();
  springManager.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
  springManager.setStiffness(SpringForce.STIFFNESS_LOW);

  stack.setViewRevealManager(revealManager);

  settingsView.addSwitch("Enable Spring", false, new CompoundButton.OnCheckedChangeListener() {
    @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      stack.setViewRevealManager(isChecked ? springManager : revealManager);
    }
  });
  settingsView.setAnimatorManager(springManager);

  final BottomSheetBehavior behavior = BottomSheetBehavior.from(settingsView);
  behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_peek_height));
  behavior.setSkipCollapsed(false);
  behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}