Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrajabzadeh committed Jan 10, 2021
1 parent a2e3f81 commit 3d7030b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 17 deletions.
31 changes: 31 additions & 0 deletions app/src/main/java/ir/amirrajabzadeh/alertdialog/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,45 @@
import androidx.appcompat.app.AppCompatActivity;
import ir.amirrajabzadeh.rayanalert.RayanAlert;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.LayoutDirection;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final RayanAlert alert=new RayanAlert(this);

findViewById(R.id.btnShow).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alert
.setLayoutDirection(LayoutDirection.LTR)
.setTitle("Title")
.setMessage("This is a message")
.setImageLoading(getResources().getDrawable(R.drawable.ic_github))
.setTextPositiveButton("ok")
.setTextNegativeButton("dismiss")
.showLoading(true)
.show(new RayanAlert.OnClickListener() {
@Override
public void onPositiveButtonClick() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
alert.dismiss();
}
},5000);
}
});
}
});

}
}
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_github.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#008577" android:pathData="M255.968,5.329C114.624,5.329 0,120.401 0,262.353c0,113.536 73.344,209.856 175.104,243.872c12.8,2.368 17.472,-5.568 17.472,-12.384c0,-6.112 -0.224,-22.272 -0.352,-43.712c-71.2,15.52 -86.24,-34.464 -86.24,-34.464c-11.616,-29.696 -28.416,-37.6 -28.416,-37.6c-23.264,-15.936 1.728,-15.616 1.728,-15.616c25.696,1.824 39.2,26.496 39.2,26.496c22.848,39.264 59.936,27.936 74.528,21.344c2.304,-16.608 8.928,-27.936 16.256,-34.368c-56.832,-6.496 -116.608,-28.544 -116.608,-127.008c0,-28.064 9.984,-51.008 26.368,-68.992c-2.656,-6.496 -11.424,-32.64 2.496,-68c0,0 21.504,-6.912 70.4,26.336c20.416,-5.696 42.304,-8.544 64.096,-8.64c21.728,0.128 43.648,2.944 64.096,8.672c48.864,-33.248 70.336,-26.336 70.336,-26.336c13.952,35.392 5.184,61.504 2.56,68c16.416,17.984 26.304,40.928 26.304,68.992c0,98.72 -59.84,120.448 -116.864,126.816c9.184,7.936 17.376,23.616 17.376,47.584c0,34.368 -0.32,62.08 -0.32,70.496c0,6.88 4.608,14.88 17.6,12.352C438.72,472.145 512,375.857 512,262.353C512,120.401 397.376,5.329 255.968,5.329z"/>
</vector>
18 changes: 10 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
<Button
android:layout_width="match_parent"
android:layout_height="70dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

android:layout_margin="@dimen/margin_32"
android:text="show rayan alert"
android:textSize="@dimen/font_20"
android:background="@color/colorPrimary"
android:textColor="@color/colorWhite"
android:id="@+id/btnShow"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public RayanAlert(Context context) {

}


public interface OnClickListener {
void onPositiveButtonClicked();
void onPositiveButtonClick();

// void onNegativeButtonClicked();
}
Expand All @@ -78,12 +78,11 @@ public void show(final OnClickListener clickListener) {
btnYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickListener.onPositiveButtonClicked();
clickListener.onPositiveButtonClick();

if (checkShowLoading) {
showLoading();
}
else {
} else {
alertDialog.dismiss();
}
}
Expand All @@ -93,7 +92,6 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
alertDialog.dismiss();
// clickListener.onNegativeButtonClicked();
}
});

Expand All @@ -105,16 +103,17 @@ public RayanAlert showLoading(boolean isShow) {
return this;
}

public void dismissAlertDialog() {
public void dismiss() {
alertDialog.dismiss();
dismissLoading();
}

public void showLoading() {
cl.setVisibility(View.GONE);
clLoading.setVisibility(View.VISIBLE);
}

public void hideLoading() {
public void dismissLoading() {
cl.setVisibility(View.VISIBLE);
clLoading.setVisibility(View.GONE);
}
Expand All @@ -129,16 +128,78 @@ public RayanAlert setTextNegativeButton(String s) {
return this;
}

public RayanAlert setBackgroundPositiveButton(int color) {
btnYes.setBackgroundColor(color);
return this;
}

public RayanAlert setFocusBackgroundColorPositiveButton(int color) {
btnYes.setFocusBackgroundColor(color);
return this;
}

public RayanAlert setBorderColorPositiveButton(int color) {
btnYes.setBorderColor(color);
return this;
}

public RayanAlert setBorderWidthPositiveButton(int width) {
btnYes.setBorderWidth(width);
return this;
}

public RayanAlert setTextColorPositiveButton(int color) {
tvYesButton.setTextColor(color);
return this;
}


public RayanAlert setBackgroundNegativeButton(int color) {
btnNo.setBackgroundColor(color);
return this;
}

public RayanAlert setFocusBackgroundColorNegativeButton(int color) {
btnNo.setFocusBackgroundColor(color);
return this;
}

public RayanAlert setBorderColorNegativeButton(int color) {
btnNo.setBorderColor(color);
return this;
}

public RayanAlert setBorderWidthNegativeButton(int width) {
btnNo.setBorderWidth(width);
return this;
}

public RayanAlert setTextColorNegativeButton(int color) {
tvNoButton.setTextColor(color);
return this;
}


public RayanAlert setTitle(String title) {
tvTitle.setText(title);
return this;
}

public RayanAlert setColorTitle(int color) {
tvTitle.setTextColor(color);
return this;
}

public RayanAlert setMessage(String message) {
tvMessage.setText(message);
return this;
}

public RayanAlert setColorMessage(int color) {
tvMessage.setTextColor(color);
return this;
}

public RayanAlert setImageLoading(Drawable image) {
imgLoading.setImageDrawable(image);
return this;
Expand All @@ -163,4 +224,10 @@ public RayanAlert setLayoutDirection(int layoutDirection) {
return this;
}

public RayanAlert setTitleBackground(int color) {
header.setBackgroundColor(color);
return this;
}


}
1 change: 0 additions & 1 deletion rayanalert/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<item name="fb_focusColor">@color/colorAccent</item>
<item name="fb_radius">50dp</item>
<item name="fb_borderColor">@color/colorPrimaryDark</item>
<!-- <item name="fb_borderWidth">1dp</item>-->
<item name="fb_textColor">@color/colorWhite</item>
<item name="fb_textFontRes">@font/iransans_bold</item>
</style>
Expand Down

0 comments on commit 3d7030b

Please sign in to comment.