com.google.android.material.button.MaterialButton Java Examples

The following examples show how to use com.google.android.material.button.MaterialButton. 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: WelcomeActivity.java    From SimplicityBrowser with MIT License 7 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
    prefManager = new PrefManager(this);
    MaterialButton appCompatButton = findViewById(R.id.wel_button);
    AppCompatTextView termsTextView = findViewById(R.id.wel_term);
    AppCompatTextView policyTextView = findViewById(R.id.wel_pri);
    appCompatButton.setOnClickListener(this);
    termsTextView.setOnClickListener(this);
    policyTextView.setOnClickListener(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.white));
    }else{
        getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.black));
    }
    getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.black));
}
 
Example #2
Source File: ShapeThemingDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view =
      layoutInflater.inflate(
          R.layout.cat_shape_theming_container, viewGroup, false /* attachToRoot */);
  ViewGroup container = view.findViewById(R.id.container);
  layoutInflater.inflate(R.layout.cat_shape_theming_content, container, true  /* attachToRoot */);

  MaterialButton materialButton = container.findViewById(R.id.material_button);
  MaterialAlertDialogBuilder materialAlertDialogBuilder =
      new MaterialAlertDialogBuilder(getContext(), getShapeTheme())
          .setTitle(R.string.cat_shape_theming_dialog_title)
          .setMessage(R.string.cat_shape_theming_dialog_message)
          .setPositiveButton(R.string.cat_shape_theming_dialog_ok, null);
  materialButton.setOnClickListener(v -> materialAlertDialogBuilder.show());
  BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(wrappedContext);
  bottomSheetDialog.setContentView(R.layout.cat_shape_theming_bottomsheet_content);
  View bottomSheetInternal = bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
  BottomSheetBehavior.from(bottomSheetInternal).setPeekHeight(300);
  MaterialButton button = container.findViewById(R.id.material_button_2);
  button.setOnClickListener(v -> bottomSheetDialog.show());

  return view;
}
 
Example #3
Source File: ButtonsContainer.java    From MaterialBanner with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    mButtonMarginEnd = getDimen(R.dimen.mb_button_margin_end);
    mButtonMarginBottom = getDimen(R.dimen.mb_button_margin_bottom);

    MarginLayoutParams layoutParams = new MarginLayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        layoutParams.setMarginEnd(mButtonMarginEnd);
    } else {
        layoutParams.rightMargin = mButtonMarginEnd;
    }
    layoutParams.bottomMargin = mButtonMarginBottom;

    mLeftButton = new MaterialButton(context, null, R.attr.borderlessButtonStyle);
    mLeftButton.setId(R.id.mb_button_left);
    mLeftButton.setSingleLine(true);
    mLeftButton.setMaxLines(1);
    mLeftButton.setMinWidth(0);
    mLeftButton.setMinimumWidth(0);
    mLeftButton.setLayoutParams(layoutParams);
    mLeftButton.setVisibility(GONE);

    mRightButton = new MaterialButton(context, null, R.attr.borderlessButtonStyle);
    mRightButton.setId(R.id.mb_button_right);
    mRightButton.setSingleLine(true);
    mRightButton.setMaxLines(1);
    mRightButton.setMinWidth(0);
    mRightButton.setMinimumWidth(0);
    mRightButton.setLayoutParams(layoutParams);
    mRightButton.setVisibility(GONE);

    addView(mLeftButton);
    addView(mRightButton);
}
 
Example #4
Source File: MainActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Update app DPI for debug purpose.
    NaviBeeApplication.getInstance().init();
    updateDpi(this);
    setContentView(R.layout.activity_main);

    mAuth = FirebaseAuth.getInstance();
    mUser = mAuth.getCurrentUser();

    if (!NaviBeeApplication.getInstance().getInited()) {
        NaviBeeApplication.getInstance().init();
    }

    findViewById(R.id.landing_sos_btn).setOnClickListener(this);
    findViewById(R.id.landing_social_btn).setOnClickListener(this);

    setupWelcomeBanner();

    setupOverflowMenu();

    MaterialButton naviBtn = findViewById(R.id.landing_navigation_btn);
    naviBtn.setBackgroundTintList(null);
    naviBtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_landing_major_background));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        naviBtn.setClipToOutline(true);
    }

    String convID = getIntent().getStringExtra("convID");
    if (convID != null) {
        // notification clicked
        ConversationManager.getInstance().waitForOpenChatAvtivity(convID);
    }

}
 
Example #5
Source File: EventsFragment.java    From Deadline with GNU General Public License v3.0 5 votes vote down vote up
private void setupQuickView() {
//        mViewModel.isShowQuickView.setValue(AppPreferences.isEnableQuickView(getContext()));
        if (mViewModel.isShowQuickView.getValue()) {
            MaterialButton button = getView().findViewById(R.id.check_today_event);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mViewModel.updateCurrentCategory(FilterType.TODAY_EVENTS);
                    updateShowedEventList();
                }
            });
        }

    }
 
Example #6
Source File: RewardsFragment.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
public void onCustomClaimButtonClicked(String code, EditText inputCustomCode, MaterialButton buttonClaim, View loadingView) {
    if (rewardClaimInProgress) {
        return;
    }
    claimReward(Reward.TYPE_REWARD_CODE, code, inputCustomCode, buttonClaim, loadingView);
}
 
Example #7
Source File: DialogMainDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void addDialogLauncher(
    ViewGroup viewGroup, @StringRes int stringResId, AlertDialog.Builder alertDialogBuilder) {
  MaterialButton dialogLauncherButton = new MaterialButton(viewGroup.getContext());
  dialogLauncherButton.setOnClickListener(v -> alertDialogBuilder.show());
  dialogLauncherButton.setText(stringResId);
  viewGroup.addView(dialogLauncherButton);
}
 
Example #8
Source File: TimePickerDialog.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void updateInputMode(MaterialButton modeButton) {
  modeButton.setChecked(false);
  if (activePresenter != null) {
    activePresenter.hide();
  }

  activePresenter = initializeOrRetrieveActivePresenterForMode(mode);
  activePresenter.show();
  activePresenter.invalidate();
  modeButton.setIconResource(iconForMode(mode));
}
 
Example #9
Source File: ButtonsContainer.java    From MaterialBanner with Apache License 2.0 4 votes vote down vote up
public MaterialButton getLeftButton() {
    return mLeftButton;
}
 
Example #10
Source File: ButtonsContainer.java    From MaterialBanner with Apache License 2.0 4 votes vote down vote up
public MaterialButton getRightButton() {
    return mRightButton;
}
 
Example #11
Source File: DynamicTintUtils.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
/**
 * Set a view background tint according to the supplied color.
 *
 * @param view The view to set the background tint.
 * @param background The background color to calculate the default color.
 * @param color The tint color to be used.
 * @param borderless {@code true} if the view is borderless.
 * @param checkable {@code true} if the view is checkable.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setViewBackgroundTint(@NonNull View view, @ColorInt int background,
        @ColorInt int color, boolean borderless, boolean checkable) {
    @ColorInt int pressedColor = DynamicColorUtils.shiftColor(color,
            WidgetDefaults.ADS_SHIFT_LIGHT, WidgetDefaults.ADS_SHIFT_DARK);

    if (view instanceof MaterialButton) {
        if (borderless) {
            if (!DynamicSdkUtils.is21()) {
                pressedColor = DynamicColorUtils.getStateColor(
                        DynamicColorUtils.adjustAlpha(
                                pressedColor, WidgetDefaults.ADS_STATE_PRESSED),
                        WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK);

                ViewCompat.setBackgroundTintList(view,
                        DynamicResourceUtils.getColorStateList(
                                Color.TRANSPARENT, pressedColor, checkable));
            } else {
                ((MaterialButton) view).setRippleColor(
                        DynamicResourceUtils.getColorStateList(
                                Color.TRANSPARENT, pressedColor, checkable));
            }
        } else {
            ViewCompat.setBackgroundTintList(view,
                    DynamicResourceUtils.getColorStateList(
                            DynamicColorUtils.getTintColor(background),
                            color, pressedColor, checkable));
        }
    } else if (view instanceof TintableBackgroundView) {
        if (borderless) {
            ViewCompat.setBackgroundTintList(view,
                    DynamicResourceUtils.getColorStateList(
                            Color.TRANSPARENT, pressedColor, checkable));
        } else {
            ViewCompat.setBackgroundTintList(view,
                    DynamicResourceUtils.getColorStateList(
                            DynamicColorUtils.getTintColor(background),
                            color, pressedColor, checkable));
        }
    } else {
        if (!DynamicSdkUtils.is21()) {
            background = DynamicColorUtils.getStateColor(
                    DynamicColorUtils.adjustAlpha(DynamicColorUtils.getTintColor(background),
                            WidgetDefaults.ADS_STATE_PRESSED),
                    WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK);
            pressedColor = DynamicColorUtils.getStateColor(
                    DynamicColorUtils.adjustAlpha(color, WidgetDefaults.ADS_STATE_PRESSED),
                    WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK);

            if (borderless) {
                DynamicDrawableUtils.setBackground(view,
                        DynamicResourceUtils.getStateListDrawable(Color.TRANSPARENT,
                                background, pressedColor, checkable));
            } else {
                // TODO:
            }
        }
    }

    if (DynamicSdkUtils.is21() && view.getBackground() instanceof RippleDrawable) {
        if (borderless) {
            pressedColor = DynamicColorUtils.adjustAlpha(
                    color, WidgetDefaults.ADS_STATE_PRESSED);
        }

        pressedColor = DynamicColorUtils.getStateColor(pressedColor,
                WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK);

        RippleDrawable rippleDrawable = (RippleDrawable) view.getBackground();
        if (checkable && !(view instanceof DynamicCheckedTextView)) {
            background = DynamicColorUtils.getStateColor(
                    DynamicColorUtils.adjustAlpha(
                            DynamicColorUtils.getTintColor(background),
                            WidgetDefaults.ADS_STATE_PRESSED),
                    WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK);

            rippleDrawable.setColor(DynamicResourceUtils.getColorStateList(
                    Color.TRANSPARENT, background, pressedColor, true));
        } else {
            rippleDrawable.setColor(ColorStateList.valueOf(pressedColor));
        }
    }
}
 
Example #12
Source File: DatePickerMainDemoFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view = layoutInflater.inflate(R.layout.picker_main_demo, viewGroup, false);
  LinearLayout root = view.findViewById(R.id.picker_launcher_buttons_layout);
  MaterialButton launcher = root.findViewById(R.id.cat_picker_launch_button);

  snackbar = Snackbar.make(viewGroup, R.string.cat_picker_no_action, Snackbar.LENGTH_LONG);
  int dialogTheme = resolveOrThrow(getContext(), R.attr.materialCalendarTheme);
  int fullscreenTheme = resolveOrThrow(getContext(), R.attr.materialCalendarFullscreenTheme);

  final RadioGroup selectionMode = root.findViewById(R.id.cat_picker_date_selector_group);
  final RadioGroup theme = root.findViewById(R.id.cat_picker_theme_group);
  final RadioGroup bounds = root.findViewById(R.id.cat_picker_bounds_group);
  final RadioGroup validation = root.findViewById(R.id.cat_picker_validation_group);
  final RadioGroup title = root.findViewById(R.id.cat_picker_title_group);
  final RadioGroup opening = root.findViewById(R.id.cat_picker_opening_month_group);
  final RadioGroup selection = root.findViewById(R.id.cat_picker_selection_group);
  final RadioGroup inputMode = root.findViewById(R.id.cat_picker_input_mode_group);

  launcher.setOnClickListener(
      v -> {
        initSettings();
        int selectionModeChoice = selectionMode.getCheckedRadioButtonId();
        int themeChoice = theme.getCheckedRadioButtonId();
        int boundsChoice = bounds.getCheckedRadioButtonId();
        int validationChoice = validation.getCheckedRadioButtonId();
        int titleChoice = title.getCheckedRadioButtonId();
        int openingChoice = opening.getCheckedRadioButtonId();
        int selectionChoice = selection.getCheckedRadioButtonId();
        int inputModeChoices = inputMode.getCheckedRadioButtonId();

        MaterialDatePicker.Builder<?> builder =
            setupDateSelectorBuilder(selectionModeChoice, selectionChoice, inputModeChoices);
        CalendarConstraints.Builder constraintsBuilder =
            setupConstraintsBuilder(boundsChoice, openingChoice, validationChoice);

        if (themeChoice == R.id.cat_picker_theme_dialog) {
          builder.setTheme(dialogTheme);
        } else if (themeChoice == R.id.cat_picker_theme_fullscreen) {
          builder.setTheme(fullscreenTheme);
        }

        if (titleChoice == R.id.cat_picker_title_custom) {
          builder.setTitleText(R.string.cat_picker_title_custom);
        }

        try {
          builder.setCalendarConstraints(constraintsBuilder.build());
          MaterialDatePicker<?> picker = builder.build();
          addSnackBarListeners(picker);
          picker.show(getFragmentManager(), picker.toString());
        } catch (IllegalArgumentException e) {
          snackbar.setText(e.getMessage());
          snackbar.show();
        }
      });

  return view;
}
 
Example #13
Source File: MaterialComponentsViewInflaterTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureThatInflaterCreatesMaterialButton() {
  View view = testActivity.findViewById(R.id.test_button);
  assertThat(view).isInstanceOf(MaterialButton.class);
}
 
Example #14
Source File: MaterialComponentsViewInflater.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
protected AppCompatButton createButton(@NonNull Context context, @NonNull AttributeSet attrs) {
  return new MaterialButton(context, attrs);
}
 
Example #15
Source File: RewardListAdapter.java    From lbry-android with MIT License votes vote down vote up
void onCustomClaimButtonClicked(String code, EditText inputCustomCode, MaterialButton buttonClaim, View loadingView);