From 3f9f4e93508a970c7625b69da824f3f8d19af163 Mon Sep 17 00:00:00 2001 From: ahmmedrejowan Date: Wed, 21 Sep 2022 20:13:47 +0600 Subject: [PATCH] Reworking design and functions --- .../cutelibs/cutedialog/CuteDialog.java | 59 +++++++---- .../res/layout/cute_dialog_main_layout.xml | 100 +++++++----------- CuteDialog/src/main/res/values/colors.xml | 2 + .../cutelibs/cutedialogdemo/MainActivity.java | 27 +++-- app/src/main/res/layout/activity_main.xml | 4 +- 5 files changed, 96 insertions(+), 96 deletions(-) diff --git a/CuteDialog/src/main/java/io/github/cutelibs/cutedialog/CuteDialog.java b/CuteDialog/src/main/java/io/github/cutelibs/cutedialog/CuteDialog.java index 6869294..90124b5 100644 --- a/CuteDialog/src/main/java/io/github/cutelibs/cutedialog/CuteDialog.java +++ b/CuteDialog/src/main/java/io/github/cutelibs/cutedialog/CuteDialog.java @@ -124,15 +124,16 @@ private void inits() { // positive button style binding.positiveButton.setRadius(BUTTON_CORNER_RADIUS_DEFAULT * 4); - binding.positiveButtonBorder.setRadius(BUTTON_CORNER_RADIUS_DEFAULT * 4); binding.positiveButton.setCardBackgroundColor(BUTTON_BACKGROUND_COLOR_DEFAULT); - binding.positiveButtonBorder.setCardBackgroundColor(BUTTON_BACKGROUND_COLOR_DEFAULT); + binding.positiveButton.setStrokeColor(BUTTON_BACKGROUND_COLOR_DEFAULT); + binding.positiveButton.setStrokeWidth(1); // negative button style binding.negativeButton.setRadius(BUTTON_CORNER_RADIUS_DEFAULT * 4); - binding.negativeButtonBorder.setRadius(BUTTON_CORNER_RADIUS_DEFAULT * 4); binding.negativeButton.setCardBackgroundColor(WHOLE_BACKGROUND_COLOR_DEFAULT); - binding.negativeButtonBorder.setCardBackgroundColor(BUTTON_BACKGROUND_COLOR_DEFAULT); + binding.negativeButton.setStrokeColor(BUTTON_BACKGROUND_COLOR_DEFAULT); + binding.negativeButton.setStrokeWidth(1); + // button text binding.positiveText.setTextSize(TypedValue.COMPLEX_UNIT_SP, BUTTON_TEXT_SIZE_DEFAULT); @@ -349,11 +350,10 @@ public CuteDialog setDesc(String descText, int textSizeInSP, int textColor, int return this; } - public CuteDialog setPositiveButtonStyle(int radiusOfButton, int bgColorOfButton, int outlineOfButton, int textSizeInSP) { + public CuteDialog setPositiveButtonStyle(int radiusOfButton, int bgColorOfButton, int outlineOfButton, int borderWidth, int textSizeInSP) { if (radiusOfButton != 0) { binding.positiveButton.setRadius(radiusOfButton * 4); - binding.positiveButtonBorder.setRadius(radiusOfButton * 4); } if (bgColorOfButton != 0) { @@ -364,21 +364,27 @@ public CuteDialog setPositiveButtonStyle(int radiusOfButton, int bgColorOfButton } } - if (outlineOfButton != 0) { try { - binding.positiveButtonBorder.setCardBackgroundColor(ContextCompat.getColor(context, outlineOfButton)); + binding.positiveButton.setStrokeColor(ContextCompat.getColor(context, outlineOfButton)); } catch (Resources.NotFoundException e) { - binding.positiveButtonBorder.setCardBackgroundColor(outlineOfButton); + binding.positiveButton.setStrokeColor(outlineOfButton); } } else { - try { - binding.positiveButtonBorder.setCardBackgroundColor(ContextCompat.getColor(context, bgColorOfButton)); - } catch (Resources.NotFoundException e) { - binding.positiveButtonBorder.setCardBackgroundColor(bgColorOfButton); + if (bgColorOfButton != 0) { + try { + binding.positiveButton.setStrokeColor(ContextCompat.getColor(context, bgColorOfButton)); + } catch (Resources.NotFoundException e) { + binding.positiveButton.setStrokeColor(bgColorOfButton); + } } } + if (borderWidth != 0) { + binding.positiveButton.setStrokeWidth(borderWidth); + } + + if (textSizeInSP != 0) { binding.positiveText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSizeInSP); } @@ -387,10 +393,9 @@ public CuteDialog setPositiveButtonStyle(int radiusOfButton, int bgColorOfButton return this; } - public CuteDialog setNegativeButtonStyle(int radiusOfButton, int bgColorOfButton, int outlineOfButton, int textSizeInSP) { + public CuteDialog setNegativeButtonStyle(int radiusOfButton, int bgColorOfButton, int outlineOfButton, int borderWidth, int textSizeInSP) { if (radiusOfButton != 0) { - binding.negativeButtonBorder.setRadius(radiusOfButton * 4); binding.negativeButton.setRadius(radiusOfButton * 4); } @@ -405,12 +410,24 @@ public CuteDialog setNegativeButtonStyle(int radiusOfButton, int bgColorOfButton if (outlineOfButton != 0) { try { - binding.negativeButtonBorder.setCardBackgroundColor(ContextCompat.getColor(context, outlineOfButton)); + binding.negativeButton.setStrokeColor(ContextCompat.getColor(context, outlineOfButton)); } catch (Resources.NotFoundException e) { - binding.negativeButtonBorder.setCardBackgroundColor(outlineOfButton); + binding.negativeButton.setStrokeColor(outlineOfButton); + } + } else { + if (bgColorOfButton != 0) { + try { + binding.negativeButton.setStrokeColor(ContextCompat.getColor(context, bgColorOfButton)); + } catch (Resources.NotFoundException e) { + binding.negativeButton.setStrokeColor(bgColorOfButton); + } } } + if (borderWidth != 0) { + binding.negativeButton.setStrokeWidth(borderWidth); + } + if (textSizeInSP != 0) { binding.negativeText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSizeInSP); @@ -494,15 +511,15 @@ public CuteDialog setVisibilityOptions(boolean hideCloseIcon, boolean hideTitle, } if (hidePositiveButton) { - binding.positiveButtonBorder.setVisibility(View.GONE); + binding.positiveButton.setVisibility(View.GONE); } else { - binding.positiveButtonBorder.setVisibility(View.VISIBLE); + binding.positiveButton.setVisibility(View.VISIBLE); } if (hideNegativeButton) { - binding.negativeButtonBorder.setVisibility(View.GONE); + binding.negativeButton.setVisibility(View.GONE); } else { - binding.negativeButtonBorder.setVisibility(View.VISIBLE); + binding.negativeButton.setVisibility(View.VISIBLE); } if (hideNegativeButton || hidePositiveButton) { diff --git a/CuteDialog/src/main/res/layout/cute_dialog_main_layout.xml b/CuteDialog/src/main/res/layout/cute_dialog_main_layout.xml index ae0b864..a763cb6 100644 --- a/CuteDialog/src/main/res/layout/cute_dialog_main_layout.xml +++ b/CuteDialog/src/main/res/layout/cute_dialog_main_layout.xml @@ -6,7 +6,7 @@ android:layout_height="wrap_content" android:layout_gravity="center"> - - @@ -127,43 +126,35 @@ android:id="@+id/button_holder" android:layout_width="match_parent" android:layout_height="50dp" - android:layout_marginTop="10dp" - android:layout_marginBottom="5dp" + android:layout_marginTop="15dp" + android:layout_marginBottom="10dp" android:gravity="center" android:orientation="horizontal"> - - - - - + android:clickable="true" + android:focusable="true" + android:foreground="?selectableItemBackground" + app:cardBackgroundColor="@color/white" + app:cardCornerRadius="10dp" + app:strokeColor="@color/cute_dialog_main" + app:strokeWidth="1dp"> + - - + - + app:cardCornerRadius="10dp" + app:strokeColor="@color/cute_dialog_main" + app:strokeWidth="1dp"> - - - - - + + + + @@ -216,6 +198,6 @@ - + \ No newline at end of file diff --git a/CuteDialog/src/main/res/values/colors.xml b/CuteDialog/src/main/res/values/colors.xml index 7565e28..5327ee0 100644 --- a/CuteDialog/src/main/res/values/colors.xml +++ b/CuteDialog/src/main/res/values/colors.xml @@ -2,4 +2,6 @@ #398AB9 #222222 + #000000 + #ffffff \ No newline at end of file diff --git a/app/src/main/java/io/github/cutelibs/cutedialogdemo/MainActivity.java b/app/src/main/java/io/github/cutelibs/cutedialogdemo/MainActivity.java index 9ed9a62..4f9df69 100644 --- a/app/src/main/java/io/github/cutelibs/cutedialogdemo/MainActivity.java +++ b/app/src/main/java/io/github/cutelibs/cutedialogdemo/MainActivity.java @@ -61,21 +61,22 @@ protected void onCreate(Bundle savedInstanceState) { .setHeader(CuteDialog.HEADER_ANIMATION) .setHeaderAnimation(R.raw.anim3) .setDesc("Message Sent Successfully!", 0, 0, 0) - .setVisibilityOptions(false, true, false, false, false) + .setVisibilityOptions(false, true, false, false, true) + .setPositiveButtonText("Okay", 0, 0) .show()); binding.design7.setOnClickListener(v -> new CuteDialog(this) - .setDialogStyle(Color.WHITE,10,CuteDialog.POSITION_CENTER,10) + .setDialogStyle(Color.WHITE, 10, CuteDialog.POSITION_CENTER, 10) .isCancelable(true) - .setCloseIconStyle(0,30,Color.DKGRAY) + .setCloseIconStyle(0, 30, Color.DKGRAY) .setHeader(CuteDialog.HEADER_IMAGE) .setHeaderImage(R.drawable.image_4) .setTitle("Something is Wrong", 0, R.color.design1, 0) .setDesc("I don't know what went wrong, but there is a problem.", 0, 0, 0) - .setPositiveButtonText("Try Again", R.color.design1, 0) - .setNegativeButtonText("Cancel", R.color.design1, 0) - .setPositiveButtonStyle(0, R.color.design1, 0, 0) - .setNegativeButtonStyle(0, 0, R.color.design1, 0) + .setPositiveButtonText("Try Again", R.color.white, 0) + .setNegativeButtonText("Cancel", R.color.design1, 0) + .setPositiveButtonStyle(0, R.color.design1, Color.RED, 2, 0) + .setNegativeButtonStyle(0, 0, R.color.design1, 5, 0) .setPositiveButtonListener(v1 -> Toast.makeText(this, "Positive Button Clicked", Toast.LENGTH_SHORT).show()) .setNegativeButtonListener(v12 -> Toast.makeText(this, "Negative Button Clicked", Toast.LENGTH_SHORT).show()) .setCloseListener(v13 -> Toast.makeText(this, "Close Icon Clicked", Toast.LENGTH_SHORT).show()) @@ -86,8 +87,8 @@ protected void onCreate(Bundle savedInstanceState) { .setHeaderImage(R.drawable.image_5) .setTitle("Time for Study", 0, R.color.design2, 0) .setDesc("It's time for some reading and writing. Take a break from phone.", 0, 0, 0) - .setPositiveButtonStyle(0, R.color.design2,0, 0) - .setNegativeButtonStyle(0, 0, R.color.design2, 0) + .setPositiveButtonStyle(0, R.color.design2, 0, 0, 0) + .setNegativeButtonStyle(0, 0, R.color.design2, 0, 0) .show()); binding.design9.setOnClickListener(v -> new CuteDialog(this) @@ -95,8 +96,8 @@ protected void onCreate(Bundle savedInstanceState) { .setHeaderIcon(R.drawable.icon_5) .setTitle("Idea!", 0, R.color.design3, 0) .setDesc("Do you want to save this idea?", 0, 0, 0) - .setPositiveButtonStyle(0, R.color.design3,0, 0) - .setNegativeButtonStyle(0, 0, R.color.design3, 0) + .setPositiveButtonStyle(0, R.color.design3, 0, 0, 0) + .setNegativeButtonStyle(0, 0, R.color.design3, 0, 0) .show()); binding.design10.setOnClickListener(v -> new CuteDialog(this) @@ -111,11 +112,9 @@ protected void onCreate(Bundle savedInstanceState) { .setHeaderAnimation(R.raw.anim5) .setTitle("Planning for a tour?", 0, 0, 0) .setDesc("You can plan your tour with us.", 0, 0, 0) - .setNegativeButtonStyle(0, 0, Color.parseColor("#111111"), 0) + .setNegativeButtonStyle(0, 0, Color.parseColor("#111111"), 0, 0) .show()); - - } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 57d1c9e..71f61d5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,7 +18,7 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - - +