Last active
March 8, 2017 12:00
-
-
Save PepDevils/04710ef86c936f543803c30d833d3517 to your computer and use it in GitHub Desktop.
Criação de varios tipos de dialogs, progressDialogs, exitDialogs etc....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//progress Dialogs | |
//res/style | |
<!--https://www.laurivan.com/make-dialogs-obey-your-material-theme/--> | |
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog"> | |
<item name="android:windowBackground">@color/white_overlay</item> // @null | |
<item name="android:windowContentOverlay">@null</item> | |
<item name="android:windowIsFloating">true</item> | |
<item name="android:windowCloseOnTouchOutside">false</item> | |
</style> | |
//java - PROGRESSBAR dialog | |
import android.app.Dialog; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.view.View; | |
import android.view.Window; | |
public class PepeProgressDialog extends Dialog implements DialogInterface { | |
//VARIAVEIS | |
private Context mContext; | |
private View mDialogView; | |
private static PepeProgressDialog instance; | |
//CONSTRUTORES | |
public PepeProgressDialog(Context context, int theme) { | |
super(context, theme); | |
init(context); | |
this.mContext = context; | |
} | |
//INSTANCIADOR PUBLICO | |
public static PepeProgressDialog getInstance(Context context) { | |
instance = new PepeProgressDialog(context, R.style.MyDialogTheme); //Theme.AppCompat.Light | |
instance.setCanceledOnTouchOutside(false); | |
return instance; | |
} | |
//INICIALIZADOR PRIVADO, APENAS "GETINSTANCE" ACEDE | |
private void init(Context context) { | |
mDialogView = View.inflate(context, R.layout.progress_dialog_layout,null); | |
this.setCanceledOnTouchOutside(false); | |
this.requestWindowFeature(Window.FEATURE_NO_TITLE); | |
setContentView(mDialogView); | |
} | |
@Override | |
public void onBackPressed() { | |
//PARA não poder sair | |
// super.onBackPressed(); | |
} | |
} | |
//CUSTOM ALERT DIALOGS COMUNICATIONS | |
//res/layout | |
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/main" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:paddingLeft="@dimen/dialog_padding" | |
android:paddingRight="@dimen/dialog_padding"> | |
<LinearLayout | |
android:id="@+id/parentPanel" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_centerInParent="true" | |
android:background="@drawable/dialog_draw" | |
android:clickable="false" | |
android:orientation="vertical" | |
android:visibility="visible"> | |
<LinearLayout | |
android:id="@+id/topPanel" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<RelativeLayout | |
android:id="@+id/title_template" | |
android:layout_width="match_parent" | |
android:layout_height="70dp" | |
android:layout_marginEnd="16dp" | |
android:layout_marginStart="16dp"> | |
<ImageView | |
android:id="@+id/icon" | |
android:layout_width="48dp" | |
android:layout_height="48dp" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_margin="1dip" | |
android:scaleType="centerInside" | |
android:src="@null" /> | |
<TextView | |
android:id="@+id/alertTitle" | |
style="@style/DialogWindowTitle" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:textColor="@color/colorPrimary" | |
android:layout_marginLeft="4dp" | |
android:layout_marginRight="4dp" | |
android:ellipsize="end" | |
android:gravity="center" | |
android:maxLines="1" | |
android:singleLine="true" /> | |
</RelativeLayout> | |
<View | |
android:id="@+id/titleDivider" | |
android:layout_width="match_parent" | |
android:layout_height="1.5dp" | |
android:background="@color/colorPrimary" | |
android:visibility="visible" /> | |
</LinearLayout> | |
<LinearLayout | |
android:id="@+id/contentPanel" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:id="@+id/message" | |
style="?android:attr/textAppearanceMedium" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="24dp" | |
android:layout_marginLeft="16dp" | |
android:layout_marginRight="16dp" | |
android:layout_marginTop="24dp" | |
android:textColor="@color/colorPrimary" | |
android:textIsSelectable="true" /> | |
</LinearLayout> | |
<FrameLayout | |
android:id="@+id/customPanel" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:visibility="gone"> | |
</FrameLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginEnd="8dp" | |
android:layout_marginStart="8dp"> | |
<Button | |
android:id="@+id/button1" | |
style="@style/my_dialog_btn" | |
android:layout_margin="8dp" | |
android:text="OK" | |
android:visibility="gone" /> | |
<Button | |
android:id="@+id/button2" | |
style="@style/my_dialog_btn" | |
android:layout_margin="8dp" | |
android:text="Cancel" | |
android:visibility="gone" /> | |
</LinearLayout> | |
</LinearLayout> | |
</RelativeLayout> | |
//res/style | |
<style name="dialog_tran" parent="android:style/Theme.Dialog"> | |
<item name="android:windowFrame">@null</item> | |
<item name="android:windowNoTitle">true</item> | |
<item name="android:windowBackground">@android:color/transparent</item> | |
<item name="android:windowIsFloating">true</item> | |
<item name="android:windowContentOverlay">@null</item> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:backgroundDimEnabled">false</item> | |
<item name="android:backgroundDimAmount">0.4</item> | |
</style> | |
<style name="dialog_untran" parent="dialog_tran"> | |
<item name="android:backgroundDimEnabled">true</item> | |
</style> | |
// java/domain/custom/PepeDialogBuilder.java | |
import android.app.Activity; | |
import android.app.Dialog; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.graphics.Color; | |
import android.graphics.drawable.Drawable; | |
import android.view.Gravity; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
import android.widget.FrameLayout; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.RelativeLayout; | |
import android.widget.TextView; | |
public class PepeDialogBuilder extends Dialog implements DialogInterface { | |
private final String defTextColor = "#FFFFFFFF"; | |
private final String defDividerColor = "#11000000"; | |
private final String defMsgColor = "#FFFFFFFF"; | |
private final String defDialogColor = "#FFE74C3C"; | |
private LinearLayout mLinearLayoutView; | |
private RelativeLayout mRelativeLayoutView; | |
private LinearLayout mLinearLayoutMsgView; | |
private LinearLayout mLinearLayoutTopView; | |
private FrameLayout mFrameLayoutCustomView; | |
private View mDialogView; | |
private View mDivider; | |
private TextView mTitle; | |
private TextView mMessage; | |
private ImageView mIcon; | |
private Button mButton1; | |
private Button mButton2; | |
//private int mDuration = -1; | |
private int mTimeOut = 0; | |
//private static int mOrientation = 1; | |
private boolean isCancelable = true; | |
private static PepeDialogBuilder instance; | |
private Context mContext; | |
//CONSTRUTOR | |
public PepeDialogBuilder(Context context) { | |
super(context); | |
} | |
private PepeDialogBuilder(Context context, int theme) { | |
super(context, theme); | |
this.mContext = context; | |
init(context); | |
} | |
public static PepeDialogBuilder getInstance(Context context) { | |
instance = new PepeDialogBuilder(context, com.gitonway.lee.niftymodaldialogeffects.lib.R.style.dialog_untran); | |
//instance = new PepeDialogBuilder(context, R.style.MyDialogTheme); | |
return instance; | |
} | |
//INICIALIZADOR DA UI | |
private void init(Context context) { | |
mDialogView = View.inflate(context, R.layout.dialog_layout, null); | |
mLinearLayoutView = (LinearLayout) mDialogView.findViewById(R.id.parentPanel); | |
mRelativeLayoutView = (RelativeLayout) mDialogView.findViewById(R.id.main); | |
mLinearLayoutTopView = (LinearLayout) mDialogView.findViewById(R.id.topPanel); | |
mLinearLayoutMsgView = (LinearLayout) mDialogView.findViewById(R.id.contentPanel); | |
mFrameLayoutCustomView = (FrameLayout) mDialogView.findViewById(R.id.customPanel); | |
mTitle = (TextView) mDialogView.findViewById(R.id.alertTitle); | |
mMessage = (TextView) mDialogView.findViewById(R.id.message); | |
mIcon = (ImageView) mDialogView.findViewById(R.id.icon); | |
mDivider = mDialogView.findViewById(R.id.titleDivider); | |
mButton1 = (Button) mDialogView.findViewById(R.id.button1); | |
mButton2 = (Button) mDialogView.findViewById(R.id.button2); | |
setContentView(mDialogView); | |
this.setOnShowListener(new OnShowListener() { | |
@Override | |
public void onShow(DialogInterface dialogInterface) { | |
mLinearLayoutView.setVisibility(View.VISIBLE); | |
} | |
}); | |
mRelativeLayoutView.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (isCancelable) dismiss(); | |
} | |
}); | |
} | |
/* public void toDefault() { | |
mTitle.setTextColor(Color.parseColor(defTextColor)); | |
mDivider.setBackgroundColor(Color.parseColor(defDividerColor)); | |
mMessage.setTextColor(Color.parseColor(defMsgColor)); | |
mLinearLayoutView.setBackgroundColor(Color.parseColor(defDialogColor)); | |
}*/ | |
public PepeDialogBuilder withDividerColor(String colorString) { | |
mDivider.setBackgroundColor(Color.parseColor(colorString)); | |
return this; | |
} | |
/* public PepeDialogBuilder withDividerColor(int color) { | |
mDivider.setBackgroundColor(color); | |
return this; | |
}*/ | |
public PepeDialogBuilder withTitle(CharSequence title) { | |
toggleView(mLinearLayoutTopView, title); | |
mTitle.setText(title); | |
return this; | |
} | |
public PepeDialogBuilder withTitleColor(String colorString) { | |
mTitle.setTextColor(Color.parseColor(colorString)); | |
return this; | |
} | |
/* public PepeDialogBuilder withTitleColor(int color) { | |
mTitle.setTextColor(color); | |
return this; | |
}*/ | |
/* public PepeDialogBuilder withMessage(int textResId) { | |
toggleView(mLinearLayoutMsgView, textResId); | |
mMessage.setText(textResId); | |
return this; | |
}*/ | |
public PepeDialogBuilder withMessage(CharSequence msg) { | |
toggleView(mLinearLayoutMsgView, msg); | |
mMessage.setText(msg); | |
return this; | |
} | |
public PepeDialogBuilder withMessageCenter(boolean centered) { | |
if (centered) { | |
mMessage.setGravity(Gravity.CENTER); | |
} | |
return this; | |
} | |
public PepeDialogBuilder withMessageColor(String colorString) { | |
mMessage.setTextColor(Color.parseColor(colorString)); | |
return this; | |
} | |
/* public PepeDialogBuilder withMessageColor(int color) { | |
mMessage.setTextColor(color); | |
return this; | |
}*/ | |
public PepeDialogBuilder withDialogColor(String colorString) { | |
mLinearLayoutView.getBackground().setColorFilter(Helper.getColorFilter(Color.parseColor(colorString))); | |
return this; | |
} | |
/* public PepeDialogBuilder withDialogColor(int color) { | |
mLinearLayoutView.getBackground().setColorFilter(Helper.getColorFilter(color)); | |
return this; | |
} | |
public PepeDialogBuilder withIcon(int drawableResId) { | |
mIcon.setImageResource(drawableResId); | |
return this; | |
}*/ | |
public PepeDialogBuilder withIcon(Drawable icon) { | |
mIcon.setImageDrawable(icon); | |
return this; | |
} | |
/* public PepeDialogBuilder withDuration(int duration) { | |
this.mDuration = duration; | |
return this; | |
}*/ | |
/* public PepeDialogBuilder withTimeOut(int duration) { | |
this.mTimeOut = duration; | |
if(mTimeOut <= 0){ | |
return this; | |
}else{ | |
try { | |
Helper.TimerDelayRemoveDialog((Activity) mContext, duration, this); | |
return this; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
return this; | |
}*/ | |
/* public PepeDialogBuilder withEffect(Effectstype type) { | |
this.type = type; | |
return this; | |
}*/ | |
/* public PepeDialogBuilder withButtonDrawable(int resid) { | |
mButton1.setBackgroundResource(resid); | |
mButton2.setBackgroundResource(resid); | |
return this; | |
}*/ | |
public PepeDialogBuilder withButton1Text(CharSequence text) { | |
mButton1.setVisibility(View.VISIBLE); | |
mButton1.setText(text); | |
return this; | |
} | |
public PepeDialogBuilder withButton2Text(CharSequence text) { | |
mButton2.setVisibility(View.VISIBLE); | |
mButton2.setText(text); | |
return this; | |
} | |
public PepeDialogBuilder setButton1Click(View.OnClickListener click) { | |
mButton1.setOnClickListener(click); | |
return this; | |
} | |
public PepeDialogBuilder setButton2Click(View.OnClickListener click) { | |
mButton2.setOnClickListener(click); | |
return this; | |
} | |
/* public PepeDialogBuilder setCustomView(int resId, Context context) { | |
View customView = View.inflate(context, resId, null); | |
if (mFrameLayoutCustomView.getChildCount() > 0) { | |
mFrameLayoutCustomView.removeAllViews(); | |
} | |
mFrameLayoutCustomView.addView(customView); | |
return this; | |
} | |
public PepeDialogBuilder setCustomView(View view, Context context) { | |
if (mFrameLayoutCustomView.getChildCount() > 0) { | |
mFrameLayoutCustomView.removeAllViews(); | |
} | |
mFrameLayoutCustomView.addView(view); | |
return this; | |
}*/ | |
public PepeDialogBuilder isCancelableOnTouchOutside(boolean cancelable) { | |
this.isCancelable = cancelable; | |
this.setCanceledOnTouchOutside(cancelable); | |
return this; | |
} | |
/* public PepeDialogBuilder isCancelable(boolean cancelable) { | |
this.isCancelable = cancelable; | |
this.setCancelable(cancelable); | |
return this; | |
}*/ | |
private void toggleView(View view, Object obj) { | |
if (obj == null) { | |
view.setVisibility(View.GONE); | |
} else { | |
view.setVisibility(View.VISIBLE); | |
} | |
} | |
@Override | |
public void show() { | |
super.show(); | |
} | |
/* private void start(Effectstype type) { | |
BaseEffects animator = type.getAnimator(); | |
if (mDuration != -1) { | |
animator.setDuration(Math.abs(mDuration)); | |
} | |
animator.start(mRelativeLayoutView); | |
}*/ | |
@Override | |
public void dismiss() { | |
super.dismiss(); | |
mButton1.setVisibility(View.GONE); | |
mButton2.setVisibility(View.GONE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment