全局ProgressDialog---DialogManager
来源:互联网 发布:win10 sql sever 编辑:程序博客网 时间:2024/06/14 21:59
public class ProgressDialog extends Dialog { private Context mContext; private String mMessage; private int mLayoutId; private TextView message; private com.rey.material.widget.ProgressView progressView; public ProgressDialog(Context context, int style, int layout) { super(context, style); mContext = context; mLayoutId = layout; WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.width = WindowManager.LayoutParams.FILL_PARENT; layoutParams.height = WindowManager.LayoutParams.FILL_PARENT; getWindow().setAttributes(layoutParams); } public ProgressDialog(Context context, int layout, String msg) { this(context, R.style.easy_dialog_style, layout); setMessage(msg); } public ProgressDialog(Context context, String msg) { this(context, R.style.easy_dialog_style, R.layout.dialog_easy_progress); setMessage(msg); } public void updateLoadingMessage(String msg) { mMessage = msg; showMessage(); } public void setMessage(String msg) { mMessage = msg; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(mLayoutId); progressView = (com.rey.material.widget.ProgressView) findViewById(R.id.easy_progress_bar); message = (TextView) findViewById(R.id.easy_progress_dialog_message); showMessage(); progressView.start(); } protected void showMessage() { if (message != null && !TextUtils.isEmpty(mMessage)) { message.setVisibility(View.VISIBLE); message.setText(mMessage); } }}
XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/nim_dialog_toast_bg" android:gravity="center"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <com.rey.material.widget.ProgressView android:id="@+id/easy_progress_bar" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="center" app:v_styleId="@array/pv_circular"/> <TextView android:id="@+id/easy_progress_dialog_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/easy_progress_bar" android:layout_centerHorizontal="true" android:gravity="center" android:paddingTop="14dip" android:textColor="@android:color/white" android:textSize="18sp" android:visibility="gone"/> </RelativeLayout></FrameLayout>Style
<style name="easy_dialog_style" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <!-- 边框 --> <item name="android:windowIsFloating">true</item> <!-- 是否浮现在activity之上 --> <item name="android:windowIsTranslucent">true</item> <!-- 半透明 --> <item name="android:windowNoTitle">true</item> <!-- 无标题 --> <item name="android:windowBackground">@color/transparent</item> <!-- 背景透明 --> <item name="android:backgroundDimEnabled">true</item> <!-- 后面的activity变暗 --> </style>Dialog 全局管理
public class DialogManager { private static ProgressDialog bejiaProgressDialog; public static ProgressDialog showProgressDialog(Context context, String message) { return showProgressDialog(context, null, message, true, null); } public static ProgressDialog showProgressDialog(Context context, String message, boolean cancelable) { return showProgressDialog(context, null, message, cancelable, null); } @Deprecated public static ProgressDialog showProgressDialog(Context context, String title, String message, boolean canCancelable, DialogInterface .OnCancelListener listener) { if (bejiaProgressDialog == null) { bejiaProgressDialog = new ProgressDialog(context, message); } else if (bejiaProgressDialog.getContext() != context) { LogUtil.e("dialog", "there is a leaked window here,orign context: " + bejiaProgressDialog.getContext() + " now: " + context); dismissProgressDialog(); bejiaProgressDialog = new ProgressDialog(context, message); } bejiaProgressDialog.setCancelable(canCancelable); bejiaProgressDialog.setOnCancelListener(listener); bejiaProgressDialog.show(); return bejiaProgressDialog; } public static void dismissProgressDialog() { if (bejiaProgressDialog == null) { return; } if (bejiaProgressDialog.isShowing()) { try { bejiaProgressDialog.dismiss(); bejiaProgressDialog = null; } catch (Exception e) { } } } public static void setMessage(String message) { if (null != bejiaProgressDialog && bejiaProgressDialog.isShowing() && !TextUtils.isEmpty(message)) { bejiaProgressDialog.setMessage(message); } } public static void updateLoadingMessage(String message) { if (null != bejiaProgressDialog && bejiaProgressDialog.isShowing() && !TextUtils.isEmpty(message)) { bejiaProgressDialog.updateLoadingMessage(message); } } public static boolean isShowing() { return (bejiaProgressDialog != null && bejiaProgressDialog.isShowing()); }}
调用方式
DialogManager.showProgressDialog(mContext, null, "登陆中", true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (loginRequest != null) { loginRequest.abort(); onLoginDone(); } }}).setCanceledOnTouchOutside(false);
以上内容仿照云信IM中Dialog...
0 0
- 全局ProgressDialog---DialogManager
- 书写全局 ProgressDialog
- Unity客户端架构-DialogManager
- ProgressDialog
- ProgressDialog
- ProgressDialog
- progressDialog
- ProgressDialog
- ProgressDialog
- progressDialog
- ProgressDialog
- ProgressDialog
- ProgressDialog
- ProgressDialog
- ProgressDialog
- 【progressDialog】自定义progressDialog
- ProgressDialog使用
- ProgressDialog使用
- C#设计模式笔记(1)
- Java动态修改Enum实例
- bzoj 1509 逃学的小孩
- MyISAM转为InnoDB并在ThinkPHP中使用存储过程
- nyoj 1248 海岛争霸 (并查集)
- 全局ProgressDialog---DialogManager
- Java千百问_07JVM架构(010)_什么是老生代的标记算法
- struts2的java.lang.NoSuchMethodException异常处理
- 分数加减法
- 谈谈java中锁
- 29.vim高效使用方法之buffer、window和tab
- leetcode Intersection of Two Arrays II
- 函数指针和回调函数
- LA 4847 binary search tree