コード例 #1
0
 private boolean compareFile(String file) {
   File f = new File(file);
   if (f.isFile()) {
     if (n.getFilesize() == f.length()) {
       return true;
     } else {
       FileUtil.delDir(file);
       return false;
     }
   } else {
     return false;
   }
 }
コード例 #2
0
  @Override
  public boolean download(String type) {

    String urlPath = n.getFilepath() + n.getHomework();
    String path = getsavepath(n.getHomework(), n.getClassname());
    final String saveZipPath = path + File.separator + n.getHomework();

    if (compareFile(saveZipPath)) {
      callback.success();
      currentDownload = "";
      return true;
    }
    HttpUtils http = new HttpUtils(5000);
    download =
        http.download(
            urlPath,
            saveZipPath,
            new RequestCallBack<File>() {

              @Override
              public void onStart() {
                nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

                mBuilder = new NotificationCompat.Builder(mContext);
                mBuilder.setAutoCancel(true);
                Intent intent = new Intent();
                PendingIntent pi =
                    PendingIntent.getActivity(
                        mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
                mBuilder.setContentIntent(pi);
                mBuilder.setContentTitle("обтьё╨" + n.getHomework()).setContentText("обть╫Ь╤хё╨");
                mBuilder.setLargeIcon(
                    BitmapFactory.decodeResource(
                        mContext.getResources(), R.drawable.ic_launcher_small));
                mBuilder.setSmallIcon(R.drawable.ic_launcher_small);
                nm.notify(0, mBuilder.build());
                super.onStart();
              }

              @Override
              public void onSuccess(ResponseInfo<File> arg0) {
                if (compareFile(saveZipPath)) {
                  callback.success();
                }
                currentDownload = "";
              }

              @Override
              public void onLoading(long total, long current, boolean isUploading) {
                mBuilder.setProgress((int) total, (int) current, false);
                nm.notify(0, mBuilder.build());
                super.onLoading(total, current, isUploading);
              }

              @Override
              public void onFailure(HttpException arg0, String arg1) {
                callback.failure();
                currentDownload = "";
              }

              @Override
              public void onCancelled() {
                currentDownload = "";
                super.onCancelled();
              }
            });
    return true;
  }