Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq3 committed Oct 7, 2018
1 parent 67e1f75 commit eac2cfa
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 62 deletions.
35 changes: 29 additions & 6 deletions app/src/main/java/com/mti/gif_dialog/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,56 @@

public class MainActivity extends AppCompatActivity {

private GifDialog gifDialog;

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

//Initializing Dialog
final GifDialog gifDialog= new GifDialog.Builder(this)
gifDialog= new GifDialog.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")

.setTitleTextColor("#FF4081")
.setMessageTextColor("#F57F17")

.setPositiveBtnText("pos")//iF WE NEED TO hIDE ANY BUTTON JUST DON'T ADD THIS LINE , NO TEXT MEANS NO BUTTON
.setPositiveBtnBackground("#FF4081")

.setNegativeBtnText("cancel")
.setNegativeBtnBackground("#FFA9A7A8")


.setOkBtnText("OK")
.setOkBtnBackground("#FFA9A7A8")

.setGifResource(R.drawable.gif_dialog_gif1) //Pass your Gif here


.isCancellable(false)


.OnPositiveClicked(new GifDialogListener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this,"Ok",Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this,"Done",Toast.LENGTH_SHORT).show();
}
})
.OnNegativeClicked(new GifDialogListener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this,"Cancel",Toast.LENGTH_SHORT).show();

}
})
.OnOkClicked(new GifDialogListener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this,"OK",Toast.LENGTH_SHORT).show();
}
})
.build();

//Showing Dialog
Expand Down
1 change: 1 addition & 0 deletions gifdialog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ dependencies {
implementation 'com.android.support:cardview-v7:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
119 changes: 109 additions & 10 deletions gifdialog/src/main/java/com/mti/gifdialog/GifDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
* Created by Tareq on 06,October,2018.
*/
public class GifDialog {
private String title,message,positiveBtnText,negativeBtnText,pBtnColor,nBtnColor;
private String title,message,positiveBtnText,okButtonText,negativeBtnText,pBtnColor,nBtnColor,oBtnColor,tTextColor,mTextColor;
private Activity activity;
private GifDialogListener pListener,nListener;
private GifDialogListener pListener,nListener,oListener;
private boolean cancel;

int gifImageResource;
public static Dialog mDialog;

Expand All @@ -35,11 +36,16 @@ private GifDialog(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.oBtnColor=builder.oBtnColor;
this.tTextColor=builder.tTextColor;
this.mTextColor=builder.mTextColor;
this.positiveBtnText=builder.positiveBtnText;
this.okButtonText=builder.okButtonText;
this.negativeBtnText=builder.negativeBtnText;
this.gifImageResource=builder.gifImageResource;
this.cancel=builder.cancel;
Expand All @@ -54,10 +60,12 @@ public void show(){
mDialog.show();
}



public static class Builder{
private String title,message,positiveBtnText,negativeBtnText,pBtnColor,nBtnColor;
private String title,message,positiveBtnText,okButtonText,negativeBtnText,pBtnColor,oBtnColor,nBtnColor,tTextColor,mTextColor;
private Activity activity;
private GifDialogListener pListener,nListener;
private GifDialogListener pListener,nListener,oListener;
private boolean cancel;
int gifImageResource;

Expand All @@ -80,6 +88,12 @@ public Builder setPositiveBtnText(String positiveBtnText){
return this;
}

public Builder setOkBtnText(String okBtnText){
this.okButtonText=okBtnText;
return this;
}


public Builder setPositiveBtnBackground(String pBtnColor){
this.pBtnColor=pBtnColor;
return this;
Expand All @@ -96,12 +110,31 @@ public Builder setNegativeBtnBackground(String nBtnColor){
return this;
}

public Builder setOkBtnBackground(String oBtnColor){
this.oBtnColor=oBtnColor;
return this;
}
public Builder setTitleTextColor(String tTextColor){
this.tTextColor=tTextColor;
return this;
}

public Builder setMessageTextColor(String mTextColor){
this.mTextColor=mTextColor;
return this;
}
//set Positive listener
public Builder OnPositiveClicked(GifDialogListener pListener){
this.pListener=pListener;
return this;
}

//set Positive listener
public Builder OnOkClicked(GifDialogListener oListener){
this.oListener=oListener;
return this;
}

//set Negative listener
public Builder OnNegativeClicked(GifDialogListener nListener){
this.nListener=nListener;
Expand All @@ -121,7 +154,7 @@ public Builder setGifResource(int gifImageResource){
public GifDialog build(){
TextView message1,title1;
ImageView iconImg;
Button nBtn,pBtn;
Button nBtn,pBtn,oBtn;
GifImageView gifImageView;


Expand All @@ -137,15 +170,47 @@ public GifDialog build(){
message1=(TextView)mDialog.findViewById(R.id.message);
nBtn=(Button)mDialog.findViewById(R.id.negativeBtn);
pBtn=(Button)mDialog.findViewById(R.id.positiveBtn);
oBtn=mDialog.findViewById(R.id.okBtn);

gifImageView=mDialog.findViewById(R.id.gifImageView);
gifImageView.setImageResource(gifImageResource);

title1.setText(title);
message1.setText(message);
if(positiveBtnText!=null)
pBtn.setText(positiveBtnText);
else
pBtn.setVisibility(View.GONE);

if(okButtonText!=null)
oBtn.setText(okButtonText);
else
oBtn.setVisibility(View.GONE);


if(negativeBtnText!=null)
nBtn.setText(negativeBtnText);
else
nBtn.setVisibility(View.GONE);

if(message==null){
message1.setVisibility(View.GONE);
}
if(title==null){
title1.setVisibility(View.GONE);
}

if(tTextColor!=null){

title1.setTextColor(Color.parseColor(tTextColor));
}

if(mTextColor!=null){

message1.setTextColor(Color.parseColor(mTextColor));
}


if(pBtnColor!=null)
{ GradientDrawable bgShape = (GradientDrawable)pBtn.getBackground();
bgShape.setColor(Color.parseColor(pBtnColor));
Expand All @@ -154,6 +219,12 @@ public GifDialog build(){
{ GradientDrawable bgShape = (GradientDrawable)nBtn.getBackground();
bgShape.setColor(Color.parseColor(nBtnColor));
}

if(oBtnColor!=null)
{ GradientDrawable bgShape = (GradientDrawable)oBtn.getBackground();
bgShape.setColor(Color.parseColor(oBtnColor));
}

if(pListener!=null) {
pBtn.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -173,17 +244,45 @@ public void onClick(View view) {
});
}

if(nListener!=null){
nBtn.setVisibility(View.VISIBLE);
nBtn.setOnClickListener(new View.OnClickListener() {

if(oListener!=null) {
oBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
nListener.onClick();

oListener.onClick();
mDialog.dismiss();
}
});
}
else{
oBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDialog.dismiss();
}

});
}
if (nListener != null) {

nBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
nListener.onClick();

mDialog.dismiss();
}
});

}else{
nBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

mDialog.dismiss();
}
});
}


// mDialog.show();
Expand Down
Loading

0 comments on commit eac2cfa

Please sign in to comment.