com.google.android.material.R Java Examples
The following examples show how to use
com.google.android.material.R.
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: MaterialButtonTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void setIcon_iconUpdated_whenCalledTwice() { MaterialButton materialButton = new MaterialButton(context); materialButton.setText("test"); Drawable drawable1 = ContextCompat.getDrawable(context, android.R.drawable.btn_plus); setIcon(materialButton, makeMeasureSpec(200), drawable1); Drawable unwrapDrawable = DrawableCompat.unwrap(materialButton.getIcon()); assertThat(unwrapDrawable).isEqualTo(drawable1); Drawable drawable2 = ContextCompat.getDrawable(context, android.R.drawable.btn_minus); setIcon(materialButton, makeMeasureSpec(200), drawable2); unwrapDrawable = DrawableCompat.unwrap(materialButton.getIcon()); assertThat(unwrapDrawable).isEqualTo(drawable2); }
Example #2
Source File: MaterialContainerTransformSharedElementCallback.java From material-components-android with Apache License 2.0 | 6 votes |
@Override public void onSharedElementStart( @NonNull List<String> sharedElementNames, @NonNull List<View> sharedElements, @NonNull List<View> sharedElementSnapshots) { if (!sharedElements.isEmpty() && !sharedElementSnapshots.isEmpty()) { // Set up the snapshot view tag so that the transform knows when to use the snapshot view // instead of the view provided by TransitionValues. sharedElements.get(0).setTag(R.id.mtrl_motion_snapshot_view, sharedElementSnapshots.get(0)); } if (!entering && !sharedElements.isEmpty() && returnEndBounds != null) { // Counteract the manipulation of the shared element view's bounds in the framework's // ExitTransitionCoordinator so that the return animation starts from the correct location. View sharedElement = sharedElements.get(0); int widthSpec = MeasureSpec.makeMeasureSpec(returnEndBounds.width(), MeasureSpec.EXACTLY); int heightSpec = MeasureSpec.makeMeasureSpec(returnEndBounds.height(), MeasureSpec.EXACTLY); sharedElement.measure(widthSpec, heightSpec); sharedElement.layout( returnEndBounds.left, returnEndBounds.top, returnEndBounds.right, returnEndBounds.bottom); } }
Example #3
Source File: FloatingActionButton.java From material-components-android with Apache License 2.0 | 6 votes |
private int getSizeDimension(@Size final int size) { if (customSize != NO_CUSTOM_SIZE) { return customSize; } final Resources res = getResources(); switch (size) { case SIZE_AUTO: // If we're set to auto, grab the size from resources and refresh final int width = res.getConfiguration().screenWidthDp; final int height = res.getConfiguration().screenHeightDp; return Math.max(width, height) < AUTO_MINI_LARGEST_SCREEN_WIDTH ? getSizeDimension(SIZE_MINI) : getSizeDimension(SIZE_NORMAL); case SIZE_MINI: return res.getDimensionPixelSize(R.dimen.design_fab_size_mini); case SIZE_NORMAL: default: return res.getDimensionPixelSize(R.dimen.design_fab_size_normal); } }
Example #4
Source File: TextInputLayout.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Set the box's stroke color state list. * * @param boxStrokeColorStateList the color state list to use for the box's stroke */ public void setBoxStrokeColorStateList(@NonNull ColorStateList boxStrokeColorStateList) { if (boxStrokeColorStateList.isStateful()) { defaultStrokeColor = boxStrokeColorStateList.getDefaultColor(); disabledColor = boxStrokeColorStateList.getColorForState(new int[] {-android.R.attr.state_enabled}, -1); hoveredStrokeColor = boxStrokeColorStateList.getColorForState( new int[] {android.R.attr.state_hovered, android.R.attr.state_enabled}, -1); focusedStrokeColor = boxStrokeColorStateList.getColorForState( new int[] {android.R.attr.state_focused, android.R.attr.state_enabled}, -1); } else if (focusedStrokeColor != boxStrokeColorStateList.getDefaultColor()) { // If attribute boxStrokeColor is not a color state list but only a single value, its value // will be applied to the box's focus state. focusedStrokeColor = boxStrokeColorStateList.getDefaultColor(); } updateTextInputBoxState(); }
Example #5
Source File: ViewUtilsLollipop.java From material-components-android with Apache License 2.0 | 6 votes |
/** Creates and sets a {@link StateListAnimator} with a custom elevation value */ static void setDefaultAppBarLayoutStateListAnimator( @NonNull final View view, final float elevation) { final int dur = view.getResources().getInteger(R.integer.app_bar_elevation_anim_duration); final StateListAnimator sla = new StateListAnimator(); // Enabled and liftable, but not lifted means not elevated sla.addState( new int[] {android.R.attr.enabled, R.attr.state_liftable, -R.attr.state_lifted}, ObjectAnimator.ofFloat(view, "elevation", 0f).setDuration(dur)); // Default enabled state sla.addState( new int[] {android.R.attr.enabled}, ObjectAnimator.ofFloat(view, "elevation", elevation).setDuration(dur)); // Disabled state sla.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0).setDuration(0)); view.setStateListAnimator(sla); }
Example #6
Source File: TextInputLayout.java From material-components-android with Apache License 2.0 | 6 votes |
private void updateStrokeErrorColor(boolean hasFocus, boolean isHovered) { int defaultStrokeErrorColor = strokeErrorColor.getDefaultColor(); int hoveredStrokeErrorColor = strokeErrorColor.getColorForState( new int[] {android.R.attr.state_hovered, android.R.attr.state_enabled}, defaultStrokeErrorColor); int focusedStrokeErrorColor = strokeErrorColor.getColorForState( new int[] {android.R.attr.state_activated, android.R.attr.state_enabled}, defaultStrokeErrorColor); if (hasFocus) { boxStrokeColor = focusedStrokeErrorColor; } else if (isHovered) { boxStrokeColor = hoveredStrokeErrorColor; } else { boxStrokeColor = defaultStrokeErrorColor; } }
Example #7
Source File: NavigationMenuItemView.java From material-components-android with Apache License 2.0 | 6 votes |
@Override public void setIcon(@Nullable Drawable icon) { if (icon != null) { if (hasIconTintList) { Drawable.ConstantState state = icon.getConstantState(); icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate(); DrawableCompat.setTintList(icon, iconTintList); } icon.setBounds(0, 0, iconSize, iconSize); } else if (needsEmptyIcon) { if (emptyDrawable == null) { emptyDrawable = ResourcesCompat.getDrawable( getResources(), R.drawable.navigation_empty_icon, getContext().getTheme()); if (emptyDrawable != null) { emptyDrawable.setBounds(0, 0, iconSize, iconSize); } } icon = emptyDrawable; } TextViewCompat.setCompoundDrawablesRelative(textView, icon, null, null, null); }
Example #8
Source File: Chip.java From material-components-android with Apache License 2.0 | 6 votes |
@Override protected void onPopulateNodeForVirtualView( int virtualViewId, @NonNull AccessibilityNodeInfoCompat node) { if (virtualViewId == CLOSE_ICON_VIRTUAL_ID) { CharSequence closeIconContentDescription = getCloseIconContentDescription(); if (closeIconContentDescription != null) { node.setContentDescription(closeIconContentDescription); } else { CharSequence chipText = getText(); node.setContentDescription( getContext() .getString( R.string.mtrl_chip_close_icon_content_description, !TextUtils.isEmpty(chipText) ? chipText : "") .trim()); } node.setBoundsInParent(getCloseIconTouchBoundsInt()); node.addAction(AccessibilityActionCompat.ACTION_CLICK); node.setEnabled(isEnabled()); } else { node.setContentDescription(""); node.setBoundsInParent(EMPTY_BOUNDS); } }
Example #9
Source File: MaterialDatePicker.java From material-components-android with Apache License 2.0 | 6 votes |
private static int getDialogPickerHeight(@NonNull Context context) { Resources resources = context.getResources(); int navigationHeight = resources.getDimensionPixelSize(R.dimen.mtrl_calendar_navigation_height) + resources.getDimensionPixelOffset(R.dimen.mtrl_calendar_navigation_top_padding) + resources.getDimensionPixelOffset(R.dimen.mtrl_calendar_navigation_bottom_padding); int daysOfWeekHeight = resources.getDimensionPixelSize(R.dimen.mtrl_calendar_days_of_week_height); int calendarHeight = MonthAdapter.MAXIMUM_WEEKS * resources.getDimensionPixelSize(R.dimen.mtrl_calendar_day_height) + (MonthAdapter.MAXIMUM_WEEKS - 1) * resources.getDimensionPixelOffset(R.dimen.mtrl_calendar_month_vertical_padding); int calendarPadding = resources.getDimensionPixelOffset(R.dimen.mtrl_calendar_bottom_padding); return navigationHeight + daysOfWeekHeight + calendarHeight + calendarPadding; }
Example #10
Source File: BottomNavigationItemView.java From material-components-android with Apache License 2.0 | 6 votes |
@Override public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); if (badgeDrawable != null && badgeDrawable.isVisible()) { CharSequence customContentDescription = itemData.getTitle(); if (!TextUtils.isEmpty(itemData.getContentDescription())) { customContentDescription = itemData.getContentDescription(); } info.setContentDescription( customContentDescription + ", " + badgeDrawable.getContentDescription()); } AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info); infoCompat.setCollectionItemInfo( CollectionItemInfoCompat.obtain( /* rowIndex= */ 0, /* rowSpan= */ 1, /* columnIndex= */ getItemPosition(), /* columnSpan= */ 1, /* heading= */ false, /* selected= */ isSelected())); if (isSelected()) { infoCompat.setClickable(false); infoCompat.removeAction(AccessibilityActionCompat.ACTION_CLICK); } infoCompat.setRoleDescription(getResources().getString(R.string.item_view_role_description)); }
Example #11
Source File: MaterialButtonTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @Config(minSdk = 23, maxSdk = 28) public void setIcon_iconNotUpdated_whenPositionChanged() { callCount = 0; MaterialButton materialButton = new MaterialButton(context) { @Override public void setCompoundDrawablesRelative(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { super.setCompoundDrawablesRelative(left, top, right, bottom); callCount++; } }; Drawable drawable = ContextCompat.getDrawable(context, android.R.drawable.btn_plus); setIcon(materialButton, makeMeasureSpec(200), drawable); setIcon(materialButton, makeMeasureSpec(300), drawable); assertThat(callCount).isEqualTo(1); }
Example #12
Source File: YearGridAdapter.java From material-components-android with Apache License 2.0 | 6 votes |
@Override public void onBindViewHolder(@NonNull YearGridAdapter.ViewHolder viewHolder, int position) { int year = getYearForPosition(position); String navigateYear = viewHolder .textView .getContext() .getString(R.string.mtrl_picker_navigate_to_year_description); viewHolder.textView.setText(String.format(Locale.getDefault(), "%d", year)); viewHolder.textView.setContentDescription(String.format(navigateYear, year)); CalendarStyle styles = materialCalendar.getCalendarStyle(); Calendar calendar = UtcDates.getTodayCalendar(); CalendarItemStyle style = calendar.get(Calendar.YEAR) == year ? styles.todayYear : styles.year; for (Long day : materialCalendar.getDateSelector().getSelectedDays()) { calendar.setTimeInMillis(day); if (calendar.get(Calendar.YEAR) == year) { style = styles.selectedYear; } } style.styleItem(viewHolder.textView); viewHolder.textView.setOnClickListener(createYearClickListener(year)); }
Example #13
Source File: NavigationMenuPresenter.java From material-components-android with Apache License 2.0 | 6 votes |
@Override public MenuView getMenuView(ViewGroup root) { if (menuView == null) { menuView = (NavigationMenuView) layoutInflater.inflate(R.layout.design_navigation_menu, root, false); menuView.setAccessibilityDelegateCompat( new NavigationMenuViewAccessibilityDelegate(menuView)); if (adapter == null) { adapter = new NavigationMenuAdapter(); } if (overScrollMode != -1) { menuView.setOverScrollMode(overScrollMode); } headerLayout = (LinearLayout) layoutInflater.inflate(R.layout.design_navigation_item_header, menuView, false); menuView.setAdapter(adapter); } return menuView; }
Example #14
Source File: ClearTextEndIconDelegate.java From material-components-android with Apache License 2.0 | 6 votes |
@Override void initialize() { textInputLayout.setEndIconDrawable( AppCompatResources.getDrawable(context, R.drawable.mtrl_ic_cancel)); textInputLayout.setEndIconContentDescription( textInputLayout.getResources().getText(R.string.clear_text_end_icon_content_description)); textInputLayout.setEndIconOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Editable text = textInputLayout.getEditText().getText(); if (text != null) { text.clear(); } textInputLayout.refreshEndIconDrawableState(); } }); textInputLayout.addOnEditTextAttachedListener(clearTextOnEditTextAttachedListener); textInputLayout.addOnEndIconChangedListener(endIconChangedListener); initAnimators(); }
Example #15
Source File: ExtendedFloatingActionButton.java From material-components-android with Apache License 2.0 | 6 votes |
@SuppressWarnings("argument.type.incompatible") public ExtendedFloatingActionButtonBehavior( @NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.ExtendedFloatingActionButton_Behavior_Layout); autoHideEnabled = a.getBoolean( R.styleable.ExtendedFloatingActionButton_Behavior_Layout_behavior_autoHide, AUTO_HIDE_DEFAULT); autoShrinkEnabled = a.getBoolean( R.styleable.ExtendedFloatingActionButton_Behavior_Layout_behavior_autoShrink, AUTO_SHRINK_DEFAULT); a.recycle(); }
Example #16
Source File: MonthsPagerAdapter.java From material-components-android with Apache License 2.0 | 5 votes |
ViewHolder(@NonNull LinearLayout container, boolean showLabel) { super(container); monthTitle = container.findViewById(R.id.month_title); ViewCompat.setAccessibilityHeading(monthTitle, true); monthGrid = container.findViewById(R.id.month_grid); if (!showLabel) { monthTitle.setVisibility(View.GONE); } }
Example #17
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void createBottomSheet_withIntegerRefOffset_hasCorrectOffset() { AttributeSet attributes = Robolectric.buildAttributeSet() .addAttribute(R.attr.behavior_expandedOffset, "@integer/abc_config_activityDefaultDur") .addAttribute(R.attr.behavior_fitToContents, "false") .build(); BottomSheetBehavior<View> behavior = new BottomSheetBehavior<>(activity, attributes); assertThat(behavior.getExpandedOffset()).isEqualTo(220); }
Example #18
Source File: MaterialTextViewTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void ensureThatViewAppliesLineHeightWhenSettingTextAppearance() { context.setTheme(R.style.Theme_AppCompat); MaterialTextView textView = new MaterialTextView(context); textView.setTextAppearance(context, R.style.TestStyleWithLineHeight); assertThat(textView.getLineHeight()).isEqualTo(testLineHeight); }
Example #19
Source File: MaterialCardViewHelper.java From material-components-android with Apache License 2.0 | 5 votes |
@NonNull private Drawable createCompatRippleDrawable() { StateListDrawable rippleDrawable = new StateListDrawable(); compatRippleDrawable = createForegroundShapeDrawable(); compatRippleDrawable.setFillColor(rippleColor); rippleDrawable.addState(new int[] {android.R.attr.state_pressed}, compatRippleDrawable); return rippleDrawable; }
Example #20
Source File: ScrimInsetsFrameLayout.java From material-components-android with Apache License 2.0 | 5 votes |
public ScrimInsetsFrameLayout( @NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = ThemeEnforcement.obtainStyledAttributes( context, attrs, R.styleable.ScrimInsetsFrameLayout, defStyleAttr, R.style.Widget_Design_ScrimInsetsFrameLayout); insetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground); a.recycle(); setWillNotDraw(true); // No need to draw until the insets are adjusted ViewCompat.setOnApplyWindowInsetsListener( this, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets( View v, @NonNull WindowInsetsCompat insets) { if (null == ScrimInsetsFrameLayout.this.insets) { ScrimInsetsFrameLayout.this.insets = new Rect(); } ScrimInsetsFrameLayout.this.insets.set( insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); onInsetsChanged(insets); setWillNotDraw(!insets.hasSystemWindowInsets() || insetForeground == null); ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this); return insets.consumeSystemWindowInsets(); } }); }
Example #21
Source File: BaseSlider.java From material-components-android with Apache License 2.0 | 5 votes |
@NonNull private String startOrEndDescription(int virtualViewId) { List<Float> values = slider.getValues(); if (virtualViewId == values.size() - 1) { return slider.getContext().getString(R.string.material_slider_range_end); } if (virtualViewId == 0) { return slider.getContext().getString(R.string.material_slider_range_start); } return ""; }
Example #22
Source File: MaterialThemeOverlayTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void wrap_hasCorrectAttributes_withThemeOverlay() { AttributeSet attributes = Robolectric.buildAttributeSet() .addAttribute(R.attr.materialThemeOverlay, "@style/ThemeOverlayColorAccentRed") .build(); assertAttributesWithColor(attributes, Color.RED); }
Example #23
Source File: MaterialCheckBoxTest.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Tests for {@link MaterialCheckBox} and the android:buttonTint attribute. This should only be * run for API 22+. */ @Test @Config(sdk = VERSION_CODES.M) public void testThemeableAndroidButtonTint() { testThemeableButtonTint( (CheckBox) checkboxes.findViewById(R.id.test_checkbox_android_button_tint)); }
Example #24
Source File: SlideDistanceProvider.java From material-components-android with Apache License 2.0 | 5 votes |
private int getSlideDistanceOrDefault(Context context) { if (slideDistance != DEFAULT_DISTANCE) { return slideDistance; } return context .getResources() .getDimensionPixelSize(R.dimen.mtrl_transition_shared_axis_slide_distance); }
Example #25
Source File: TimePickerTextInputPresenter.java From material-components-android with Apache License 2.0 | 5 votes |
private void updateSelection() { if (toggle == null) { return; } toggle.check( time.period == AM ? R.id.material_clock_period_am_button : R.id.material_clock_period_pm_button); }
Example #26
Source File: NavigationMenuPresenter.java From material-components-android with Apache License 2.0 | 5 votes |
@Override public void initForMenu(@NonNull Context context, @NonNull MenuBuilder menu) { layoutInflater = LayoutInflater.from(context); this.menu = menu; Resources res = context.getResources(); paddingSeparator = res.getDimensionPixelOffset(R.dimen.design_navigation_separator_vertical_padding); }
Example #27
Source File: MaterialDatePicker.java From material-components-android with Apache License 2.0 | 5 votes |
static boolean isFullscreen(@NonNull Context context) { int calendarStyle = MaterialAttributes.resolveOrThrow( context, R.attr.materialCalendarStyle, MaterialCalendar.class.getCanonicalName()); int[] attrs = {android.R.attr.windowFullscreen}; TypedArray a = context.obtainStyledAttributes(calendarStyle, attrs); boolean fullscreen = a.getBoolean(0, false); a.recycle(); return fullscreen; }
Example #28
Source File: TextInputLayout.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Sets the box's background color state list. * * <p>Note: The background color is only supported for filled boxes. When used with box variants * other than {@link BoxBackgroundMode#BOX_BACKGROUND_FILLED}, the box background color may not * work as intended. * * @param boxBackgroundColorStateList the color state list to use for the box's background color */ public void setBoxBackgroundColorStateList(@NonNull ColorStateList boxBackgroundColorStateList) { defaultFilledBackgroundColor = boxBackgroundColorStateList.getDefaultColor(); boxBackgroundColor = defaultFilledBackgroundColor; disabledFilledBackgroundColor = boxBackgroundColorStateList.getColorForState(new int[] {-android.R.attr.state_enabled}, -1); focusedFilledBackgroundColor = boxBackgroundColorStateList.getColorForState( new int[] {android.R.attr.state_focused, android.R.attr.state_enabled}, -1); hoveredFilledBackgroundColor = boxBackgroundColorStateList.getColorForState( new int[] {android.R.attr.state_hovered, android.R.attr.state_enabled}, -1); applyBoxAttributes(); }
Example #29
Source File: SingleDateSelector.java From material-components-android with Apache License 2.0 | 5 votes |
@NonNull @Override public String getSelectionDisplayString(@NonNull Context context) { Resources res = context.getResources(); if (selectedItem == null) { return res.getString(R.string.mtrl_picker_date_header_unselected); } String startString = DateStrings.getYearMonthDay(selectedItem); return res.getString(R.string.mtrl_picker_date_header_selected, startString); }
Example #30
Source File: TimePickerDialog.java From material-components-android with Apache License 2.0 | 5 votes |
@NonNull @Override public final Dialog onCreateDialog(@Nullable Bundle bundle) { Dialog dialog = super.onCreateDialog(bundle); Context context = dialog.getContext(); int surfaceColor = MaterialAttributes.resolveOrThrow( context, R.attr.colorSurface, TimePickerDialog.class.getCanonicalName()); MaterialShapeDrawable background = new MaterialShapeDrawable( context, null, 0, R.style.Widget_MaterialComponents_TimePicker); background.initializeElevationOverlay(context); background.setFillColor(ColorStateList.valueOf(surfaceColor)); Window window = dialog.getWindow(); window.setBackgroundDrawable(background); window.requestFeature(Window.FEATURE_NO_TITLE); // On some Android APIs the dialog won't wrap content by default. Explicitly update here. window.setLayout( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); return dialog; }