Skip to content

Commit

Permalink
Reworking design and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmmedrejowan committed Sep 21, 2022
1 parent 45632f9 commit 3f9f4e9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);

}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
100 changes: 41 additions & 59 deletions CuteDialog/src/main/res/layout/cute_dialog_main_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center">

<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/whole_card"
android:layout_width="300dp"
android:layout_height="wrap_content"
Expand All @@ -25,7 +25,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -91,6 +90,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:padding="5dp"
Expand All @@ -109,10 +109,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:gravity="center"
android:padding="5dp"
android:text="@string/demo_des"
android:textColor="@color/cute_dialog_text"
android:textSize="14sp" />
Expand All @@ -127,82 +126,65 @@
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">

<androidx.cardview.widget.CardView
android:id="@+id/negative_button_border"
<com.google.android.material.card.MaterialCardView
android:id="@+id/negative_button"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center"
app:cardBackgroundColor="@color/cute_dialog_main"
app:cardCornerRadius="10dp">

<androidx.cardview.widget.CardView
android:id="@+id/negative_button"
android:layout_width="98dp"
android:layout_height="38dp"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">

<TextView
android:id="@+id/negative_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/demo_negative_text"
android:textColor="@color/cute_dialog_text"
android:textSize="16sp" />
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">

<TextView
android:id="@+id/negative_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/demo_negative_text"
android:textColor="@color/cute_dialog_text"
android:textSize="16sp" />

</androidx.cardview.widget.CardView>

</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>

<View
android:id="@+id/padding4"
android:layout_width="15dp"
android:layout_height="10dp" />


<androidx.cardview.widget.CardView
android:id="@+id/positive_button_border"
<com.google.android.material.card.MaterialCardView
android:id="@+id/positive_button"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardBackgroundColor="@color/cute_dialog_main"
app:cardCornerRadius="10dp">
app:cardCornerRadius="10dp"
app:strokeColor="@color/cute_dialog_main"
app:strokeWidth="1dp">

<androidx.cardview.widget.CardView
android:id="@+id/positive_button"
android:layout_width="98dp"
android:layout_height="38dp"
android:layout_gravity="center"
app:cardBackgroundColor="@color/cute_dialog_main"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">

<TextView
android:id="@+id/positive_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/demo_positive_text"
android:textColor="#fff"
android:textSize="16sp" />
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/positive_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/demo_positive_text"
android:textColor="#fff" />

</com.google.android.material.card.MaterialCardView>


</LinearLayout>
Expand All @@ -216,6 +198,6 @@
</LinearLayout>


</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>

</RelativeLayout>
2 changes: 2 additions & 0 deletions CuteDialog/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<resources>
<color name="cute_dialog_main">#398AB9</color>
<color name="cute_dialog_text">#222222</color>
<color name="black">#000000</color>
<color name="white">#ffffff</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -86,17 +87,17 @@ 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)
.setHeader(CuteDialog.HEADER_ICON)
.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)
Expand All @@ -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());




}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">

<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/design1"
android:layout_width="0dp"
android:layout_height="100dp"
Expand Down Expand Up @@ -56,7 +56,7 @@

</LinearLayout>

</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>

<androidx.cardview.widget.CardView
android:id="@+id/design2"
Expand Down

0 comments on commit 3f9f4e9

Please sign in to comment.