diff --git a/.idea/misc.xml b/.idea/misc.xml index 9e762bb..e8ee3d9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -35,7 +35,7 @@ - + diff --git a/README.md b/README.md index 2e8a4fe..9ebdcdd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,133 @@ -# FancyGifDialog-Android -Make your native android Dialog Fancy and Gify. A library that takes the standard Android Dialog to the next level with a variety of styling options and Gif's. Style your dialog from code. +# FancyAlertDialog-Android +[![platform](https://img.shields.io/badge/platform-Android-yellow.svg)](https://www.android.com) +[![API](https://img.shields.io/badge/API-15%2B-brightgreen.svg?style=plastic)](https://android-arsenal.com/api?level=15) +[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0.html) +[![](https://jitpack.io/v/Shashank02051997/FancyGifDialog-Android.svg)](https://jitpack.io/#Shashank02051997/FancyGifDialog-Android) +[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-FancyGifDialog-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6652) + + + Get it on Google Play + + +## Prerequisites + +Add this in your root `build.gradle` file (**not** your module `build.gradle` file): + +```gradle +allprojects { + repositories { + ... + maven { url "https://jitpack.io" } + } +} +``` + +## Dependency + +Add this to your module's `build.gradle` file (make sure the version matches the JitPack badge above): + +```gradle +dependencies { + ... + implementation 'com.github.Shashank02051997:FancyGifDialog-Android:1.2' +} +``` +## Fancy Gif Dialog + +Dialog with two buttons: + +``` java +new FancyGifDialog.Builder(this) + .setTitle("Granny eating chocolate dialog box") + .setMessage("This is a granny eating chocolate dialog box. This library is used to help you easily create fancy gify dialog.") + .setNegativeBtnText("Cancel") + .setPositiveBtnBackground("#FF4081") + .setPositiveBtnText("Ok") + .setNegativeBtnBackground("#FFA9A7A8") + .setGifResource(R.drawable.gif1) //Pass your Gif here + .isCancellable(true) + .OnPositiveClicked(new FancyGifDialogListener() { + @Override + public void OnClick() { + Toast.makeText(MainActivity.this,"Ok",Toast.LENGTH_SHORT).show(); + } + }) + .OnNegativeClicked(new FancyGifDialogListener() { + @Override + public void OnClick() { + Toast.makeText(MainActivity.this,"Cancel",Toast.LENGTH_SHORT).show(); + } + }) + .build(); +``` + +Dialog with one button: + +``` java +new FancyGifDialog.Builder(this) + .setTitle("Granny eating chocolate dialog box") + .setMessage("This is a granny eating chocolate dialog box. This library is used to help you easily create fancy gify dialog.") + .setPositiveBtnText("Ok") + .setPositiveBtnBackground("#FF4081") + .setGifResource(R.drawable.gif1) //Pass your Gif here + .isCancellable(true) + .OnPositiveClicked(new FancyGifDialogListener() { + @Override + public void OnClick() { + Toast.makeText(MainActivity.this,"Ok",Toast.LENGTH_SHORT).show(); + } + }) + .build(); +``` + +## Screenshots + +**Please click the image below to enlarge.** + + + + + + + + +## Dependencies + +This project use this libraries ~ Thanks to them. + + [android-gif-drawable](https://github.com/koral--/android-gif-drawable) + +## Contributing + +Please fork this repository and contribute back using +[pull requests](https://github.com/Shashank02051997/FancyGifDialog-Android/pulls). + +Any contributions, large or small, major features, bug fixes, are welcomed and appreciated +but will be thoroughly reviewed . + +### Contact - Let's become friend +- [Twitter](https://twitter.com/shashank020597) +- [Github](https://github.com/Shashank02051997) +- [Linkedin](https://www.linkedin.com/in/shashank-singhal-a87729b5/) +- [Facebook](https://www.facebook.com/shashanksinghal02) + +## License + +* [Apache Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) + +``` +Copyright 2018 Shashank Singhal + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/Screenshot/Screenshot_2018-01-07-10-24-37.png b/Screenshot/Screenshot_2018-01-07-10-24-37.png new file mode 100644 index 0000000..112ac63 Binary files /dev/null and b/Screenshot/Screenshot_2018-01-07-10-24-37.png differ diff --git a/Screenshot/Screenshot_2018-01-07-10-25-07.png b/Screenshot/Screenshot_2018-01-07-10-25-07.png new file mode 100644 index 0000000..b4e2a98 Binary files /dev/null and b/Screenshot/Screenshot_2018-01-07-10-25-07.png differ diff --git a/Screenshot/Screenshot_2018-01-07-10-25-26.png b/Screenshot/Screenshot_2018-01-07-10-25-26.png new file mode 100644 index 0000000..83c1688 Binary files /dev/null and b/Screenshot/Screenshot_2018-01-07-10-25-26.png differ diff --git a/app/src/main/java/com/shashank/sony/fancygifdialoglibrary/MainActivity.java b/app/src/main/java/com/shashank/sony/fancygifdialoglibrary/MainActivity.java index bbd0ad5..295bb5a 100644 --- a/app/src/main/java/com/shashank/sony/fancygifdialoglibrary/MainActivity.java +++ b/app/src/main/java/com/shashank/sony/fancygifdialoglibrary/MainActivity.java @@ -11,34 +11,36 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button b1; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - b1=findViewById(R.id.button); + b1 = findViewById(R.id.button); b1.setOnClickListener(this); } + @Override public void onClick(View view) { new FancyGifDialog.Builder(this) .setTitle("Granny eating chocolate dialog box") .setMessage("This is a granny eating chocolate dialog box. This library is used to help you easily create fancy gify dialog.") - .setNegativeBtnText("Cancel") .setPositiveBtnBackground("#FF4081") .setPositiveBtnText("Ok") + .setNegativeBtnText("Cancel") .setNegativeBtnBackground("#FFA9A7A8") .setGifResource(R.drawable.gif1) .isCancellable(true) .OnPositiveClicked(new FancyGifDialogListener() { @Override public void OnClick() { - Toast.makeText(MainActivity.this,"Ok",Toast.LENGTH_SHORT).show(); + Toast.makeText(MainActivity.this, "Ok", Toast.LENGTH_SHORT).show(); } }) .OnNegativeClicked(new FancyGifDialogListener() { @Override public void OnClick() { - Toast.makeText(MainActivity.this,"Cancel",Toast.LENGTH_SHORT).show(); + Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show(); } }) .build(); diff --git a/fancygifdialoglib/src/main/java/com/shashank/sony/fancygifdialoglib/FancyGifDialog.java b/fancygifdialoglib/src/main/java/com/shashank/sony/fancygifdialoglib/FancyGifDialog.java index 3a72d74..019e62c 100644 --- a/fancygifdialoglib/src/main/java/com/shashank/sony/fancygifdialoglib/FancyGifDialog.java +++ b/fancygifdialoglib/src/main/java/com/shashank/sony/fancygifdialoglib/FancyGifDialog.java @@ -8,7 +8,6 @@ import android.view.View; import android.view.Window; import android.widget.Button; -import android.widget.ImageView; import android.widget.TextView; import pl.droidsonroids.gif.GifImageView; @@ -18,99 +17,76 @@ */ public class FancyGifDialog { - - private String title,message,positiveBtnText,negativeBtnText,pBtnColor,nBtnColor; - private Activity activity; - private FancyGifDialogListener pListener,nListener; - private boolean cancel; - int gifImageResource; - - - private FancyGifDialog(Builder builder){ - this.title=builder.title; - this.message=builder.message; - this.activity=builder.activity; - this.pListener=builder.pListener; - this.nListener=builder.nListener; - this.pBtnColor=builder.pBtnColor; - this.nBtnColor=builder.nBtnColor; - this.positiveBtnText=builder.positiveBtnText; - this.negativeBtnText=builder.negativeBtnText; - this.gifImageResource=builder.gifImageResource; - this.cancel=builder.cancel; - } - - - public static class Builder{ - private String title,message,positiveBtnText,negativeBtnText,pBtnColor,nBtnColor; + public static class Builder { + private String title, message, positiveBtnText, negativeBtnText, pBtnColor, nBtnColor; private Activity activity; - private FancyGifDialogListener pListener,nListener; + private FancyGifDialogListener pListener, nListener; private boolean cancel; int gifImageResource; - public Builder(Activity activity){ - this.activity=activity; + public Builder(Activity activity) { + this.activity = activity; } - public Builder setTitle(String title){ - this.title=title; + + public Builder setTitle(String title) { + this.title = title; return this; } - public Builder setMessage(String message){ - this.message=message; + public Builder setMessage(String message) { + this.message = message; return this; } - public Builder setPositiveBtnText(String positiveBtnText){ - this.positiveBtnText=positiveBtnText; + public Builder setPositiveBtnText(String positiveBtnText) { + this.positiveBtnText = positiveBtnText; return this; } - public Builder setPositiveBtnBackground(String pBtnColor){ - this.pBtnColor=pBtnColor; + public Builder setPositiveBtnBackground(String pBtnColor) { + this.pBtnColor = pBtnColor; return this; } - public Builder setNegativeBtnText(String negativeBtnText){ - this.negativeBtnText=negativeBtnText; + public Builder setNegativeBtnText(String negativeBtnText) { + this.negativeBtnText = negativeBtnText; return this; } - public Builder setNegativeBtnBackground(String nBtnColor){ - this.nBtnColor=nBtnColor; + public Builder setNegativeBtnBackground(String nBtnColor) { + this.nBtnColor = nBtnColor; return this; } //set Positive listener - public Builder OnPositiveClicked(FancyGifDialogListener pListener){ - this.pListener=pListener; + public Builder OnPositiveClicked(FancyGifDialogListener pListener) { + this.pListener = pListener; return this; } //set Negative listener - public Builder OnNegativeClicked(FancyGifDialogListener nListener){ - this.nListener=nListener; + public Builder OnNegativeClicked(FancyGifDialogListener nListener) { + this.nListener = nListener; return this; } - public Builder isCancellable(boolean cancel){ - this.cancel=cancel; + public Builder isCancellable(boolean cancel) { + this.cancel = cancel; return this; } - public Builder setGifResource(int gifImageResource){ - this.gifImageResource=gifImageResource; + + public Builder setGifResource(int gifImageResource) { + this.gifImageResource = gifImageResource; return this; } - public FancyGifDialog build(){ - TextView message1,title1; - ImageView iconImg; - Button nBtn,pBtn; + public FancyGifDialog build() { + TextView message1, title1; + Button nBtn, pBtn; GifImageView gifImageView; - final Dialog dialog; - dialog=new Dialog(activity); + final Dialog dialog = new Dialog(activity); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.setCancelable(cancel); @@ -118,62 +94,53 @@ public FancyGifDialog build(){ //getting resources - title1= (TextView) dialog.findViewById(R.id.title); - message1=(TextView)dialog.findViewById(R.id.message); - nBtn=(Button)dialog.findViewById(R.id.negativeBtn); - pBtn=(Button)dialog.findViewById(R.id.positiveBtn); - gifImageView=dialog.findViewById(R.id.gifImageView); + title1 = dialog.findViewById(R.id.title); + message1 = dialog.findViewById(R.id.message); + nBtn = dialog.findViewById(R.id.negativeBtn); + pBtn = dialog.findViewById(R.id.positiveBtn); + gifImageView = dialog.findViewById(R.id.gifImageView); gifImageView.setImageResource(gifImageResource); title1.setText(title); message1.setText(message); - if(positiveBtnText!=null) - pBtn.setText(positiveBtnText); - if(negativeBtnText!=null) - nBtn.setText(negativeBtnText); - if(pBtnColor!=null) - { GradientDrawable bgShape = (GradientDrawable)pBtn.getBackground(); - bgShape.setColor(Color.parseColor(pBtnColor)); - } - if(nBtnColor!=null) - { GradientDrawable bgShape = (GradientDrawable)nBtn.getBackground(); - bgShape.setColor(Color.parseColor(nBtnColor)); - } - if(pListener!=null) { - pBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - pListener.OnClick(); - dialog.dismiss(); - } - }); - } - else{ + if (positiveBtnText != null) { + pBtn.setText(positiveBtnText); + if (pBtnColor != null) { + GradientDrawable bgShape = (GradientDrawable) pBtn.getBackground(); + bgShape.setColor(Color.parseColor(pBtnColor)); + } + pBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (pListener != null) pListener.OnClick(); dialog.dismiss(); } }); + } else { + pBtn.setVisibility(View.GONE); } - - if(nListener!=null){ - nBtn.setVisibility(View.VISIBLE); + if (negativeBtnText != null) { + nBtn.setText(negativeBtnText); nBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - nListener.OnClick(); - + if (nListener != null) nListener.OnClick(); dialog.dismiss(); } }); + if (nBtnColor != null) { + GradientDrawable bgShape = (GradientDrawable) nBtn.getBackground(); + bgShape.setColor(Color.parseColor(nBtnColor)); + } + } else { + nBtn.setVisibility(View.GONE); } - dialog.show(); - return new FancyGifDialog(this); + return new FancyGifDialog(); } } diff --git a/fancygifdialoglib/src/main/res/layout/fancygifdialog.xml b/fancygifdialoglib/src/main/res/layout/fancygifdialog.xml index f9e660c..c94b513 100644 --- a/fancygifdialoglib/src/main/res/layout/fancygifdialog.xml +++ b/fancygifdialoglib/src/main/res/layout/fancygifdialog.xml @@ -1,6 +1,7 @@