Ejemplo n.º 1
0
  public static ProgressDialog buildProgressDialog(Context context, boolean cancelble) {
    final ProgressDialog dialog =
        new ProgressDialog(context, ResourceUtils.getStyleId(context, "LoadingDialog"));
    // 设置window type
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
    } else {
      dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
    }

    try {
      if (context instanceof Activity) {
        if (!((Activity) context).isFinishing()) {
          dialog.show();
        }
      } else {
        dialog.show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    dialog.setContentView(ResourceUtils.getLayoutId(context, "pj_layout_progressbar"));
    ImageView loading = (ImageView) dialog.findViewById(ResourceUtils.getId(context, "iv_loading"));
    AnimationDrawable anim = (AnimationDrawable) loading.getBackground();
    anim.start();
    dialog.setCancelable(cancelble);
    return dialog;
  }
Ejemplo n.º 2
0
 public static ProgressDialog buildProgressDialog(Context context, String msg, boolean cancelble) {
   final ProgressDialog dialog =
       new ProgressDialog(context, ResourceUtils.getStyleId(context, "LoadingDialog"));
   // 设置window type
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
     dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
   } else {
     dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
   }
   dialog.show();
   dialog.setContentView(ResourceUtils.getLayoutId(context, "pj_layout_progressbar"));
   ImageView loading = (ImageView) dialog.findViewById(ResourceUtils.getId(context, "iv_loading"));
   AnimationDrawable anim = (AnimationDrawable) loading.getBackground();
   anim.start();
   ((TextView) dialog.findViewById(ResourceUtils.getId(context, "tv_progressbar_message")))
       .setText(msg);
   dialog.setCancelable(cancelble);
   return dialog;
 }