Exemplo n.º 1
0
  private void startDownload(Resource resource) {
    mConfirmationInProgress = false;

    ActivityDelegate ad = getActivityDelegate();
    if (ad == null) {
      return;
    }

    resource.setDownloadDirectory(VizUtils.getDownloadDir());

    // check download directory in case sd card or whatever has been
    // unmounted and we can no longer write to it.
    File directory = resource.getDownloadDirectory();
    if (!Utils.directoryCreate(directory)) {
      new AlertDialog.Builder(ad)
          .setIcon(R.drawable.ic_launcher)
          .setTitle(VizApp.getResString(R.string.download_failed))
          .setMessage(VizApp.getResString(R.string.storage_error))
          .setNeutralButton(R.string.ok, null)
          .create()
          .show();
      return;
    }

    Uri uri =
        VizApp.getResolver().insert(VizContract.Downloads.CONTENT_URI, resource.toContentValues());
    if (uri == null) {
      Log.e("Could not add download to database error");
      Toast.makeText(
              VizApp.getContext(),
              VizApp.getResString(R.string.database_access_error),
              Toast.LENGTH_LONG)
          .show();
      return;
    }

    Log.d("(uri=" + uri + ")");

    resource.setDownloadUri(uri);

    Downloads downloads = ad.getDownloadsFragment();
    downloads.queue(resource);
  }
Exemplo n.º 2
0
  /** Return true if download should continue, otherwise false; */
  private boolean errorCheckPathAndFile(String filename) {
    if (TextUtils.isEmpty(filename)) {
      Toast.makeText(
              VizApp.getContext(),
              VizApp.getResString(R.string.invalid_filename),
              Toast.LENGTH_LONG)
          .show();
      return false;
    }

    File downloadDir = VizUtils.getDownloadDir();
    if (downloadDir == null || !downloadDir.exists()) {
      Toast.makeText(
              VizApp.getContext(),
              VizApp.getResString(R.string.directory_access_error),
              Toast.LENGTH_LONG)
          .show();
      return false;
    }
    if (!downloadDir.canWrite() || !downloadDir.canRead()) {
      Toast.makeText(
              VizApp.getContext(),
              VizApp.getResString(R.string.directory_access_error),
              Toast.LENGTH_LONG)
          .show();
      return false;
    }
    File file = VizUtils.getVideoFile(filename);
    if (file != null && file.exists()) {
      Toast.makeText(
              VizApp.getContext(),
              VizApp.getResString(R.string.file_exists_error),
              Toast.LENGTH_LONG)
          .show();
      return false;
    }
    return true;
  }