Java Code Examples for com.google.android.material.button.MaterialButtonToggleGroup#addOnButtonCheckedListener()

The following examples show how to use com.google.android.material.button.MaterialButtonToggleGroup#addOnButtonCheckedListener() . 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: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void initializeChooseThemeButtons(View view) {
  Context context = view.getContext();
  ThemePreferencesManager themePreferencesManager =
      new ThemePreferencesManager(context, resourceProvider);

  MaterialButtonToggleGroup themeToggleGroup = view.findViewById(R.id.theme_toggle_group);
  themeToggleGroup.check(themePreferencesManager.getCurrentThemeId());

  themeToggleGroup.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
    if (isChecked) {
      themePreferencesManager.saveAndApplyTheme(checkedId);
    }
  });
}
 
Example 2
Source File: ContainerTransformConfigurationHelper.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Update whether to use arc motion based on the selected radio button */
private void setUpBottomSheetPathMotionButtonGroup(View view) {
  MaterialButtonToggleGroup toggleGroup = view.findViewById(R.id.path_motion_button_group);
  if (toggleGroup != null) {
    // Set initial value.
    toggleGroup.check(arcMotionEnabled ? R.id.arc_motion_button : R.id.linear_motion_button);
    toggleGroup.addOnButtonCheckedListener(
        (group, checkedId, isChecked) -> {
          if (checkedId == R.id.arc_motion_button) {
            arcMotionEnabled = isChecked;
          }
        });
  }
}
 
Example 3
Source File: ContainerTransformConfigurationHelper.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Update the fade mode based on the selected radio button */
private void setUpBottomSheetFadeModeButtonGroup(View view) {
  MaterialButtonToggleGroup toggleGroup = view.findViewById(R.id.fade_mode_button_group);
  if (toggleGroup != null) {
    // Set initial value.
    toggleGroup.check(fadeModeButtonId);
    toggleGroup.addOnButtonCheckedListener(
        (group, checkedId, isChecked) -> {
          if (isChecked) {
            fadeModeButtonId = checkedId;
          }
        });
  }
}
 
Example 4
Source File: ShapeableImageViewMainDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a demo fragment with an image that can change shape and randomely makes the dog image
 * wink.
 */
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view =
      layoutInflater.inflate(R.layout.catalog_imageview, viewGroup, false /* attachToRoot */);
  MaterialButtonToggleGroup toggleGroup = view.findViewById(R.id.togglegroup);
  ShapeableImageView imageView = view.findViewById(R.id.image_view);

  SparseArray<ShapeAppearanceModel> shapes = new SparseArray<>();
  shapes.put(
      R.id.button_diamond,
      ShapeAppearanceModel.builder()
          .setAllCorners(CornerFamily.CUT, /*cornerSize=*/0f)
          .setAllCornerSizes(ShapeAppearanceModel.PILL)
          .build());
  shapes.put(
      R.id.button_circle,
      ShapeAppearanceModel.builder().setAllCornerSizes(ShapeAppearanceModel.PILL).build());
  shapes.put(R.id.button_square, ShapeAppearanceModel.builder().build());

  Random random = new Random();

  toggleGroup.addOnButtonCheckedListener(
      (group, checkedId, isChecked) -> {
        if (!isChecked) {
          return;
        }

        // Randomly makes dog wink.
        imageView.setImageResource(
            random.nextBoolean() ? R.drawable.dog_image : R.drawable.dog_image_wink);
        imageView.setShapeAppearanceModel(shapes.get(checkedId));
      });

  return view;
}
 
Example 5
Source File: TimePickerMainDemoFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation") // requireFragmentManager()
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  ViewGroup view =
      (ViewGroup) layoutInflater.inflate(R.layout.time_picker_main_demo, viewGroup, false);

  Button button = view.findViewById(R.id.timepicker_button);
  textView = view.findViewById(R.id.timepicker_time);
  MaterialButtonToggleGroup timeFormatToggle = view.findViewById(R.id.time_format_toggle);
  clockFormat = TimeFormat.CLOCK_12H;
  timeFormatToggle.check(R.id.time_format_12h);

  timeFormatToggle.addOnButtonCheckedListener(
      (group, checkedId, isChecked) -> {
        boolean isSystem24Hour = DateFormat.is24HourFormat(getContext());
        boolean is24Hour =
            checkedId == R.id.time_format_24h
                || (checkedId == R.id.time_format_system && isSystem24Hour);

        clockFormat = is24Hour ? TimeFormat.CLOCK_24H : TimeFormat.CLOCK_12H;
      });

  SwitchCompat frameworkSwitch = view.findViewById(R.id.framework_switch);
  button.setOnClickListener(v -> {
    if (frameworkSwitch.isChecked()) {
      showFrameworkTimepicker();
      return;
    }
    TimePickerDialog timePickerDialog = TimePickerDialog.newInstance();
    timePickerDialog.show(requireFragmentManager(), "fragment_tag");
    timePickerDialog.setTimeFormat(clockFormat);
    timePickerDialog.setHour(hour);
    timePickerDialog.setMinute(minute);

    timePickerDialog.setListener(dialog -> {
      int newHour = dialog.getHour();
      int newMinute = dialog.getMinute();
      TimePickerMainDemoFragment.this.onTimeSet(newHour, newMinute);
    });
  });

  return view;
}