public void showProgressDialog(final int messageId) {
    try {
      final MainPanel panel = mFileSystemController.getActivePanel();
      panel
          .getActivity()
          .runOnUiThread(
              new Runnable() {
                @Override
                public void run() {
                  if (mProgressDialog != null && mProgressDialog.isShowing()) {
                    dismissProgressDialog();
                  }

                  mProgressDialog =
                      new Dialog(panel.getActivity(), android.R.style.Theme_Translucent);
                  mProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  mProgressDialog.setCancelable(false);
                  mProgressDialog.setContentView(R.layout.dialog_progress);
                  mProgressDialog.show();
                }
              });
      ((TextView) mProgressDialog.findViewById(R.id.progress_bar_text)).setText(messageId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 private void showErrorDialog(String message) {
   try {
     ErrorDialog.newInstance(message)
         .show(
             mFileSystemController.getActivePanel().getActivity().getSupportFragmentManager(),
             "errorDialog");
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
        @Override
        public void handleMessage(Message msg) {
          super.handleMessage(msg);

          MainPanel panel = mFileSystemController.getActivePanel();
          if (msg.what == FTP_CONNECTED) {
            mFileSystemController.openNetworkPanel(NetworkEnum.FTP);
          } else if (msg.what == SFTP_CONNECTED) {
            mFileSystemController.openNetworkPanel(NetworkEnum.SFTP);
          } else if (msg.what == SMB_CONNECTED) {
            mFileSystemController.openNetworkPanel(NetworkEnum.SMB);
          } else if (msg.what == YANDEX_DISK_CONNECTED) {
            mFileSystemController.openNetworkPanel(NetworkEnum.YandexDisk);
          } else if (msg.what == SMB_SCAN_NETWORK_REQUESTED) {
            final Dialog dialog = new NetworkScanDialog(panel.getActivity(), mInAppAuthHandler);
            dialog.show();
            adjustDialogSize(dialog, panel);
          } else if (msg.what == SMB_SCAN_CANCELED) {
            startSmbAuthentication(panel);
          } else if (msg.what == SMB_IP_SELECTED) {
            startSmbAuthentication((String) msg.obj, panel);
          } else if (msg.what == GoogleDriveAuthWindow.MSG_HIDE_LOADING_DIALOG) {
            GoogleDriveApi.GoogleDriveAccount account = null;
            if (msg.arg1 == GoogleDriveAuthWindow.MSG_ARG_SUCCESS) {
              GoogleDriveApi api = App.sInstance.getGoogleDriveApi();
              Pair<About, Token> data = (Pair<About, Token>) msg.obj;
              account =
                  (GoogleDriveApi.GoogleDriveAccount) api.saveAccount(data.first, data.second);
            } else {
              ToastNotification.makeText(
                      App.sInstance.getApplicationContext(),
                      App.sInstance.getString(R.string.google_drive_get_token_error),
                      Toast.LENGTH_LONG)
                  .show();
            }

            dismissProgressDialog();

            if (account != null) {
              App.sInstance.getGoogleDriveApi().setup(account);
              mFileSystemController.openNetworkPanel(NetworkEnum.GoogleDrive);
            }
          } else if (msg.what == GoogleDriveAuthWindow.MSG_SHOW_LOADING_DIALOG) {
            showProgressDialog(R.string.loading);
          } else if (msg.what == MEDIA_FIRE_CONNECTED) {
            mFileSystemController.openNetworkPanel(NetworkEnum.MediaFire);
          } else if (msg.what == WEBDAV_CONNECTED) {
            mFileSystemController.openNetworkPanel(NetworkEnum.WebDav);
          }
        }
 public void openAvailableCloudsList() {
   MainPanel panel = mFileSystemController.getActivePanel();
   if (NetworkUtil.isNetworkAvailable()) {
     showNetworksDialog();
   } else {
     if (panel != null && panel.getActivity() != null) {
       ToastNotification.makeText(
               panel.getActivity(),
               App.sInstance.getString(R.string.error_no_network),
               Toast.LENGTH_LONG)
           .show();
     }
   }
 }
 public void dismissProgressDialog() {
   mFileSystemController
       .getActivePanel()
       .getActivity()
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               if (mProgressDialog != null && mProgressDialog.isShowing()) {
                 mProgressDialog.dismiss();
                 mProgressDialog = null;
               }
             }
           });
 }
 private void handleInAppAuthError(final InAppAuthException e) {
   mFileSystemController
       .getActivePanel()
       .getActivity()
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               ToastNotification.makeText(
                       App.sInstance.getApplicationContext(),
                       e.getErrorMessage(),
                       Toast.LENGTH_LONG)
                   .show();
             }
           });
   dismissProgressDialog();
 }
 private void handleNetworkAuthError(Exception e) {
   mFileSystemController
       .getActivePanel()
       .getActivity()
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               ToastNotification.makeText(
                       App.sInstance.getApplicationContext(),
                       App.sInstance.getString(R.string.error_unknown_unexpected_error),
                       Toast.LENGTH_LONG)
                   .show();
             }
           });
   dismissProgressDialog();
   e.printStackTrace();
 }
 private void openNetworkPanel(NetworkEnum type, String path) {
   mFileSystemController.openNetworkPanel(type, path);
 }
 private void openNetworkAccount(Bookmark bookmark) {
   openNetworkAccount(
       bookmark.getNetworkAccount(),
       bookmark.getBookmarkPath(),
       mFileSystemController.getActivePanel());
 }
  /** Show dialog with available networks (clouds). */
  private void showNetworksDialog() {

    final MainPanel panel = mFileSystemController.getActivePanel();

    if (panel == null || panel.getActivity() == null) {
      // very weired situation; try to avoid crash.
      return;
    }

    final Dialog dialog = new Dialog(panel.getActivity(), R.style.Action_Dialog);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    View dialogView =
        View.inflate(App.sInstance.getApplicationContext(), R.layout.network_type_chooser, null);

    final ListView networks = (ListView) dialogView.findViewById(R.id.network_types);
    final NetworkChooserAdapter adapter = new NetworkChooserAdapter();
    networks.setAdapter(adapter);

    dialogView
        .findViewById(R.id.cancel)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                dialog.dismiss();
              }
            });

    networks.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            NetworkEnum network = (NetworkEnum) view.getTag();

            switch (network) {
              case FTP:
                openFTP(panel);
                break;
              case SFTP:
                openSFTP(panel);
                break;
              case SMB:
                openSmb(panel);
                break;
              case Dropbox:
                openDropbox(panel);
                break;
              case SkyDrive:
                openSkyDrive(panel);
                break;
              case YandexDisk:
                openYandexDisk(panel);
                break;
              case GoogleDrive:
                openGoogleDrive(panel);
                break;
              case MediaFire:
                openMediaFire(panel);
                break;
              case WebDav:
                openWebDav(panel);
                break;
            }

            if (dialog.isShowing()) {
              dialog.dismiss();
            }
          }
        });

    dialog.setContentView(dialogView);
    dialog.show();

    adjustDialogSize(dialog, panel);
  }