Skip to content

Commit

Permalink
add loader option
Browse files Browse the repository at this point in the history
  • Loading branch information
Far5had70 committed Jan 8, 2019
1 parent d5a1727 commit c86d16e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Add it in your root build.gradle at the end of repositories:

```gradle
dependencies {
implementation 'com.github.Far5had70:Falert:3.0.0'
implementation 'com.github.Far5had70:Falert:3.1.0'
}
```

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/shaygan/customalert/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ public void onClick(View v) {
private void doubleAction() {
LayoutInflater inflaterr = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customView = inflaterr.inflate(R.layout.custom_view, null, false);
View loaderView = inflaterr.inflate(R.layout.loader_view, null, false);

falert = new Falert(this)
.setButtonType(FalertButtonType.Double_BUTTON)
.customView(customView)
.loaderView(loaderView)
.setLoaderBackgroundColor(getResources().getColor(R.color.falert_red))
.setAutoDismiss(false)
.setPositiveText("مشاهده")
.setNegativeText("حذف")
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/loader_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/falert_red">

</android.support.constraint.ConstraintLayout>
56 changes: 49 additions & 7 deletions falert/src/main/java/com/waspar/falert/Falert.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Falert extends DialogFragment implements View.OnClickListener {
private int buttonType;
private View roottt, view, icon, buttonRoot;
private TextView positiveSingleButton, negativeButton, positiveButton;
private FrameLayout frameLayout;
private FrameLayout frameLayout , frameLayoutLoader;
private CircularImageView imageView;

private GradientDrawable positiveButtonBackground;
Expand All @@ -46,14 +46,16 @@ public class Falert extends DialogFragment implements View.OnClickListener {
private int alertRadius = 40;
private int buttonRadius = 80;
private View customView;
private View loaderView;
private Drawable iconDrawable = null;
private int positiveButtonColor = 0;
private int negativeButtonColor = 0;
private int singleButtonColor = 0;
private int PositiveButtonTextColor = 0;
private int NegativeButtonTextColor = 0;
private int SingleButtonTextColor = 0;
private int backgrounfColor = -1;
private int backgroundColor = -1;
private int loaderBackgroundColor = -1;
private int strokeButtonsSize = 2;
private int strokePositiveButtonColor = 0;
private int strokeNegativeButtonColor = 0;
Expand Down Expand Up @@ -84,6 +86,7 @@ private void init() {
negativeButton = view.findViewById(R.id.falert_negative_button);
positiveButton = view.findViewById(R.id.falert_positive_button);
frameLayout = view.findViewById(R.id.frameLayoutFalert);
frameLayoutLoader = view.findViewById(R.id.frameLayoutLoader);
imageView = view.findViewById(R.id.falert_icon);
imageView.setOnClickListener(this);
icon = view.findViewById(R.id.frameLayout2);
Expand Down Expand Up @@ -119,6 +122,10 @@ private void actionSetCustomView() {
frameLayout.addView(customView);
}

private void actionSetLoaderView() {
frameLayoutLoader.addView(loaderView);
}

private void actionSingleButtun() {
negativeButton.setVisibility(View.GONE);
positiveButton.setVisibility(View.GONE);
Expand Down Expand Up @@ -235,18 +242,18 @@ public void onResume() {
GradientDrawable bgShape = new GradientDrawable();

bgShape.setCornerRadius(alertRadius);
if (backgrounfColor != -1){
bgShape.setColor(backgrounfColor);
imageView.setBorderColor(backgrounfColor);
if (backgroundColor != -1){
bgShape.setColor(backgroundColor);
imageView.setBorderColor(backgroundColor);
}else {
bgShape.setColor(getActivity().getResources().getColor(R.color.falert_white));
}

roottt.setBackground(bgShape);
}

public Falert setBackgrounfColor(int backgrounfColor) {
this.backgrounfColor = backgrounfColor;
public Falert setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
return this;
}

Expand Down Expand Up @@ -310,6 +317,11 @@ public Falert customView(View customView) {
return this;
}

public Falert loaderView(View loaderView) {
this.loaderView = loaderView;
return this;
}

public Falert setHeaderIcon(Drawable iconDrawable) {
this.iconDrawable = iconDrawable;
return this;
Expand Down Expand Up @@ -390,18 +402,44 @@ public Falert setCancelableTouchOutside(boolean cancelable) {
return this;
}

public Falert setLoaderBackgroundColor(int loaderBackgroundColor) {
this.loaderBackgroundColor = loaderBackgroundColor;
return this;
}

public void startAnimationImageClick(boolean enable) {
animateEnable = enable;
if (enable){
imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_cycle));
imageView.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.rotate_indefinitely));
if (loaderView != null){
GradientDrawable bgShape2 = new GradientDrawable();
setCornerRadius(bgShape2 , alertRadius , alertRadius , 0 , 0);
if (loaderBackgroundColor == -1){
bgShape2.setColor(context.getResources().getColor(R.color.falert_green));
}else {
bgShape2.setColor(loaderBackgroundColor);
}
frameLayoutLoader.setBackground(bgShape2);
loaderView.setBackground(bgShape2);
frameLayoutLoader.setVisibility(View.VISIBLE);
}
}else {
imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.luncher));
imageView.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.rotate));
if (loaderView != null){
frameLayoutLoader.setVisibility(View.GONE);
}
}

}

private void setCornerRadius(GradientDrawable drawable, float topLeft,
float topRight, float bottomRight, float bottomLeft) {
drawable.setCornerRadii(new float[] { topLeft, topLeft, topRight, topRight,
bottomRight, bottomRight, bottomLeft, bottomLeft });
}



public Falert show() {
Expand All @@ -413,6 +451,10 @@ public Falert show() {
actionSetCustomView();
}

if (loaderView != null) {
actionSetLoaderView();
}

if (iconDrawable != null) {
actionSetIcon();
}
Expand Down
11 changes: 11 additions & 0 deletions falert/src/main/res/layout/layout_falert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@

</android.support.constraint.ConstraintLayout>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frameLayoutLoader"
android:visibility="gone"
android:layout_above="@+id/button_root">



</FrameLayout>

</RelativeLayout>


Expand Down

0 comments on commit c86d16e

Please sign in to comment.