Search in sources :

Example 1 with ShapeAppearanceModel

use of com.google.android.material.shape.ShapeAppearanceModel in project Carbon by ZieIony.

the class Carbon method initCornerCutRadius.

public static void initCornerCutRadius(ShapeModelView shapeModelView, TypedArray a, int[] ids) {
    int carbon_cornerRadiusTopStart = ids[0];
    int carbon_cornerRadiusTopEnd = ids[1];
    int carbon_cornerRadiusBottomStart = ids[2];
    int carbon_cornerRadiusBottomEnd = ids[3];
    int carbon_cornerRadius = ids[4];
    int carbon_cornerCutTopStart = ids[5];
    int carbon_cornerCutTopEnd = ids[6];
    int carbon_cornerCutBottomStart = ids[7];
    int carbon_cornerCutBottomEnd = ids[8];
    int carbon_cornerCut = ids[9];
    float cornerRadius = Math.max(a.getDimension(carbon_cornerRadius, 0), 0.1f);
    float cornerRadiusTopStart = a.getDimension(carbon_cornerRadiusTopStart, cornerRadius);
    float cornerRadiusTopEnd = a.getDimension(carbon_cornerRadiusTopEnd, cornerRadius);
    float cornerRadiusBottomStart = a.getDimension(carbon_cornerRadiusBottomStart, cornerRadius);
    float cornerRadiusBottomEnd = a.getDimension(carbon_cornerRadiusBottomEnd, cornerRadius);
    float cornerCut = a.getDimension(carbon_cornerCut, 0);
    float cornerCutTopStart = a.getDimension(carbon_cornerCutTopStart, cornerCut);
    float cornerCutTopEnd = a.getDimension(carbon_cornerCutTopEnd, cornerCut);
    float cornerCutBottomStart = a.getDimension(carbon_cornerCutBottomStart, cornerCut);
    float cornerCutBottomEnd = a.getDimension(carbon_cornerCutBottomEnd, cornerCut);
    ShapeAppearanceModel model = ShapeAppearanceModel.builder().setTopLeftCorner(cornerCutTopStart >= cornerRadiusTopStart ? new CutCornerTreatment(cornerCutTopStart) : new RoundedCornerTreatment(cornerRadiusTopStart)).setTopRightCorner(cornerCutTopEnd >= cornerRadiusTopEnd ? new CutCornerTreatment(cornerCutTopEnd) : new RoundedCornerTreatment(cornerRadiusTopEnd)).setBottomLeftCorner(cornerCutBottomStart >= cornerRadiusBottomStart ? new CutCornerTreatment(cornerCutBottomStart) : new RoundedCornerTreatment(cornerRadiusBottomStart)).setBottomRightCorner(cornerCutBottomEnd >= cornerRadiusBottomEnd ? new CutCornerTreatment(cornerCutBottomEnd) : new RoundedCornerTreatment(cornerRadiusBottomEnd)).build();
    shapeModelView.setShapeModel(model);
}
Also used : RoundedCornerTreatment(com.google.android.material.shape.RoundedCornerTreatment) CutCornerTreatment(com.google.android.material.shape.CutCornerTreatment) ShapeAppearanceModel(com.google.android.material.shape.ShapeAppearanceModel)

Example 2 with ShapeAppearanceModel

use of com.google.android.material.shape.ShapeAppearanceModel in project Signal-Android by WhisperSystems.

the class ReactWithAnyEmojiBottomSheetDialogFragment method onCreateDialog.

@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
    dialog.getBehavior().setPeekHeight((int) (getResources().getDisplayMetrics().heightPixels * 0.50));
    ShapeAppearanceModel shapeAppearanceModel = ShapeAppearanceModel.builder().setTopLeftCorner(CornerFamily.ROUNDED, ViewUtil.dpToPx(requireContext(), 18)).setTopRightCorner(CornerFamily.ROUNDED, ViewUtil.dpToPx(requireContext(), 18)).build();
    MaterialShapeDrawable dialogBackground = new MaterialShapeDrawable(shapeAppearanceModel);
    dialogBackground.setTint(ContextCompat.getColor(requireContext(), R.color.react_with_any_background));
    dialog.getBehavior().addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (bottomSheet.getBackground() != dialogBackground) {
                ViewCompat.setBackground(bottomSheet, dialogBackground);
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    });
    boolean shadows = requireArguments().getBoolean(ARG_SHADOWS, true);
    if (!shadows) {
        Window window = dialog.getWindow();
        if (window != null) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
    }
    return dialog;
}
Also used : Window(android.view.Window) BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) MaterialShapeDrawable(com.google.android.material.shape.MaterialShapeDrawable) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) KeyboardPageSearchView(org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmojiPageView(org.thoughtcrime.securesms.components.emoji.EmojiPageView) ShapeAppearanceModel(com.google.android.material.shape.ShapeAppearanceModel) NonNull(androidx.annotation.NonNull)

Example 3 with ShapeAppearanceModel

use of com.google.android.material.shape.ShapeAppearanceModel in project Signal-Android by signalapp.

the class ReactWithAnyEmojiBottomSheetDialogFragment method onCreateDialog.

@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
    dialog.getBehavior().setPeekHeight((int) (getResources().getDisplayMetrics().heightPixels * 0.50));
    ShapeAppearanceModel shapeAppearanceModel = ShapeAppearanceModel.builder().setTopLeftCorner(CornerFamily.ROUNDED, ViewUtil.dpToPx(requireContext(), 18)).setTopRightCorner(CornerFamily.ROUNDED, ViewUtil.dpToPx(requireContext(), 18)).build();
    MaterialShapeDrawable dialogBackground = new MaterialShapeDrawable(shapeAppearanceModel);
    dialogBackground.setTint(ContextCompat.getColor(requireContext(), R.color.react_with_any_background));
    dialog.getBehavior().addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (bottomSheet.getBackground() != dialogBackground) {
                ViewCompat.setBackground(bottomSheet, dialogBackground);
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    });
    boolean shadows = requireArguments().getBoolean(ARG_SHADOWS, true);
    if (!shadows) {
        Window window = dialog.getWindow();
        if (window != null) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
    }
    return dialog;
}
Also used : Window(android.view.Window) BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) MaterialShapeDrawable(com.google.android.material.shape.MaterialShapeDrawable) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) KeyboardPageSearchView(org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmojiPageView(org.thoughtcrime.securesms.components.emoji.EmojiPageView) ShapeAppearanceModel(com.google.android.material.shape.ShapeAppearanceModel) NonNull(androidx.annotation.NonNull)

Aggregations

ShapeAppearanceModel (com.google.android.material.shape.ShapeAppearanceModel)3 View (android.view.View)2 Window (android.view.Window)2 NonNull (androidx.annotation.NonNull)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 BottomSheetBehavior (com.google.android.material.bottomsheet.BottomSheetBehavior)2 BottomSheetDialog (com.google.android.material.bottomsheet.BottomSheetDialog)2 MaterialShapeDrawable (com.google.android.material.shape.MaterialShapeDrawable)2 EmojiPageView (org.thoughtcrime.securesms.components.emoji.EmojiPageView)2 KeyboardPageSearchView (org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView)2 CutCornerTreatment (com.google.android.material.shape.CutCornerTreatment)1 RoundedCornerTreatment (com.google.android.material.shape.RoundedCornerTreatment)1