From c86d16e9d75d453bab02fe1b9a02e0f3254efbc4 Mon Sep 17 00:00:00 2001 From: Farshad Date: Tue, 8 Jan 2019 13:27:01 +0330 Subject: [PATCH] add loader option --- README.md | 2 +- .../com/shaygan/customalert/MainActivity.java | 3 + app/src/main/res/layout/loader_view.xml | 8 +++ .../main/java/com/waspar/falert/Falert.java | 56 ++++++++++++++++--- falert/src/main/res/layout/layout_falert.xml | 11 ++++ 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/layout/loader_view.xml diff --git a/README.md b/README.md index 9254612..8fb7475 100644 --- a/README.md +++ b/README.md @@ -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' } ``` diff --git a/app/src/main/java/com/shaygan/customalert/MainActivity.java b/app/src/main/java/com/shaygan/customalert/MainActivity.java index aff1cf1..8c39295 100644 --- a/app/src/main/java/com/shaygan/customalert/MainActivity.java +++ b/app/src/main/java/com/shaygan/customalert/MainActivity.java @@ -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("حذف") diff --git a/app/src/main/res/layout/loader_view.xml b/app/src/main/res/layout/loader_view.xml new file mode 100644 index 0000000..823466e --- /dev/null +++ b/app/src/main/res/layout/loader_view.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/falert/src/main/java/com/waspar/falert/Falert.java b/falert/src/main/java/com/waspar/falert/Falert.java index 32fc8b9..bbe3b2c 100644 --- a/falert/src/main/java/com/waspar/falert/Falert.java +++ b/falert/src/main/java/com/waspar/falert/Falert.java @@ -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; @@ -46,6 +46,7 @@ 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; @@ -53,7 +54,8 @@ public class Falert extends DialogFragment implements View.OnClickListener { 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; @@ -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); @@ -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); @@ -235,9 +242,9 @@ 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)); } @@ -245,8 +252,8 @@ public void onResume() { roottt.setBackground(bgShape); } - public Falert setBackgrounfColor(int backgrounfColor) { - this.backgrounfColor = backgrounfColor; + public Falert setBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; return this; } @@ -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; @@ -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() { @@ -413,6 +451,10 @@ public Falert show() { actionSetCustomView(); } + if (loaderView != null) { + actionSetLoaderView(); + } + if (iconDrawable != null) { actionSetIcon(); } diff --git a/falert/src/main/res/layout/layout_falert.xml b/falert/src/main/res/layout/layout_falert.xml index 7d2b72d..3b2ebdd 100644 --- a/falert/src/main/res/layout/layout_falert.xml +++ b/falert/src/main/res/layout/layout_falert.xml @@ -95,6 +95,17 @@ + + + + + +