Exemple #1
0
  @Override
  public CachedImage get(CachedImageKey key) {
    boolean isContain = containsKey(key);
    if (!isContain) {
      return null;
    }

    CachedImage cachedImage = memoryCache.get(key);
    if (cachedImage != null && cachedImage.getWrap() != null) {
      if (Logger.isDebug()) Log.v("ImageCache", "hit memory cache");
      return cachedImage;
    }

    CachedImage temp = read(key);
    Bitmap bitmap = null;
    if (temp != null) {
      bitmap = temp.getWrap();
      if (cachedImage != null) {
        cachedImage.setWrap(bitmap);
      } else {
        cachedImage = temp;
        memoryCache.put(key, cachedImage);
      }
      if (Logger.isDebug()) Log.v("ImageCache", "hit local cache");
    }

    return cachedImage;
  }
  @Override
  protected void onPostExecute(Boolean result) {
    super.onPostExecute(result);

    if (result) {
      if (Logger.isDebug())
        Toast.makeText(context, "reset remind successfully!", Toast.LENGTH_SHORT).show();
    }
    if (Logger.isDebug()) Log.v(TAG, "reset " + type + " remind count!" + result);
  }
  @Override
  protected User doInBackground(Void... params) {
    if (image == null) {
      return null;
    }

    Weibo microBlog = GlobalVars.getMicroBlog(accountId);
    if (microBlog == null) {
      return null;
    }

    User user = null;
    try {

      if (image != null) {
        String fileExtension = FileUtil.getFileExtensionFromName(image.getName());
        int size = ImageQuality.Low.getSize();
        ImageQuality quality = sheJiaoMao.getImageUploadQuality();
        if (quality == ImageQuality.High || GlobalVars.NET_TYPE == NetType.WIFI) {
          size = ImageQuality.High.getSize();
        } else if (quality == ImageQuality.Middle || quality == ImageQuality.Low) {
          size = quality.getSize();
          if (Logger.isDebug()) Log.d(TAG, "prefix size: " + size);
          // 对低速网络进行压缩
          if (GlobalVars.NET_TYPE == NetType.MOBILE_GPRS
              || GlobalVars.NET_TYPE == NetType.MOBILE_EDGE) {
            size = ImageQuality.Low.getSize();
          }
        }
        String destName =
            ImageCache.getTempFolder()
                + File.separator
                + System.currentTimeMillis()
                + "."
                + fileExtension;
        File dest = new File(destName);
        boolean isSuccess = ImageUtil.scaleImageFile(image, dest, size);
        if (isSuccess) {
          image = dest;
        }
        user = microBlog.updateProfileImage(image);
      }
    } catch (LibException e) {
      if (Logger.isDebug()) Log.e(TAG, "Task", e);
      resultMsg = ResourceBook.getResultCodeValue(e.getErrorCode(), context);
    }

    return user;
  }
  @Override
  protected Bitmap doInBackground(Void... params) {
    if (imageView == null || url == null) {
      return bitmap;
    }

    if (Logger.isDebug()) Log.i(LOG_TAG, "Get Header image from remote!");
    try {
      Bitmap newBitmap = ImageUtil.getBitmapByUrl(url);

      /** 加入cache中* */
      if (newBitmap != null) {
        // 生成mini图
        Bitmap scaleBitmap =
            ImageUtil.scaleBitmapTo(newBitmap, SheJiaoMaoApplication.getSmallAvatarSize());
        Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(scaleBitmap);
        if (scaleBitmap != newBitmap) {
          scaleBitmap.recycle();
        }

        CachedImage resultWrap = new CachedImage(roundBitmap);
        if (isMini) {
          bitmap = roundBitmap;
        }
        imageInfo.setCacheType(CachedImageKey.IMAGE_HEAD_MINI);
        imageCache.put(imageInfo, resultWrap);

        // 生成normal图
        scaleBitmap =
            ImageUtil.scaleBitmapTo(newBitmap, SheJiaoMaoApplication.getNormalAvatarSize());
        roundBitmap = ImageUtil.getRoundedCornerBitmap(scaleBitmap);
        scaleBitmap.recycle();

        resultWrap = new CachedImage(roundBitmap);
        imageInfo.setCacheType(CachedImageKey.IMAGE_HEAD_NORMAL);
        imageCache.put(imageInfo, resultWrap);

        newBitmap.recycle();
        if (!isMini) {
          bitmap = roundBitmap;
        }
      }
    } catch (LibException e) {
      if (Logger.isDebug()) Log.e(LOG_TAG, e.getMessage(), e);
    }

    return bitmap;
  }
Exemple #5
0
  @Override
  protected List<com.cattong.entity.Status> doInBackground(Void... params) {
    if (microBlog == null) {
      return null;
    }

    List<com.cattong.entity.Status> listStatus = null;
    paging = adapter.getPaging();
    com.cattong.entity.Status max = adapter.getMin();
    paging.setGlobalMax(max);

    if (paging.moveToNext()) {
      try {
        if (type == StatusCatalog.Hot_Retweet.getCatalogNo()) {
          listStatus = microBlog.getDailyHotRetweets(paging);
        } else {
          listStatus = microBlog.getDailyHotComments(paging);
        }
      } catch (LibException e) {
        if (Logger.isDebug()) Log.e(TAG, "Task", e);
        message = ResourceBook.getResultCodeValue(e.getErrorCode(), context);
        paging.moveToPrevious();
      }
    }
    ResponseCountUtil.getResponseCounts(listStatus, microBlog);

    return listStatus;
  }
  @Override
  protected void onPostExecute(Bitmap result) {
    super.onPostExecute(result);

    if (result != null) {
      imageView.setImageBitmap(result);
      if (Logger.isDebug()) Log.v(LOG_TAG, "update imageview");
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent == null) {
      return;
    }
    sheJiaoMao = (SheJiaoMaoApplication) context.getApplicationContext();

    Bundle bundle = intent.getExtras();
    account = (LocalAccount) bundle.getSerializable("ACCOUNT");
    entity = (NotificationEntity) bundle.getSerializable("NOTIFICATION_ENTITY");

    noticeNewBlog(context);
    if (Logger.isDebug()) Log.v(TAG, entity.toString());
  }
  @Override
  protected Boolean doInBackground(Void... params) {
    boolean isSuccess = false;
    if (microBlog == null || type == null) {
      return isSuccess;
    }

    try {
      isSuccess = microBlog.resetUnreadCount(type);
    } catch (LibException e) {
      if (Logger.isDebug()) e.printStackTrace();
    }

    return isSuccess;
  }
Exemple #9
0
  public CachedImage getMemoryCached(CachedImageKey key) {
    boolean isContain = containsKey(key);
    CachedImage cachedImage = null;
    if (!isContain) {
      return cachedImage;
    }

    cachedImage = memoryCache.get(key);
    if (cachedImage != null && cachedImage.getWrap() != null) {
      if (Logger.isDebug()) Log.v("ImageCache", "getMemoryCached hit memory cache");
      return cachedImage;
    } else {
      cachedImage = null;
    }

    return cachedImage;
  }
Exemple #10
0
  @Override
  public void write(CachedImageKey key, CachedImage value) {
    if (value == null) {
      return;
    }

    Bitmap bitmap = value.getWrap();
    if (bitmap == null) {
      return;
    }

    String fileName =
        File.separator + IMAGE_FOLDER[key.getCacheType()] + File.separator + key.getCachedName();
    File file = new File(filePath + fileName);
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      file = new File(secondaryFilePath + fileName);
    }
    if (file.exists()) {
      return;
    }
    if (Logger.isDebug())
      Log.v(TAG, file.getPath() + "|media state: " + Environment.getExternalStorageState());

    FileOutputStream fos = null;
    try {
      file.createNewFile();
      fos = new FileOutputStream(file);

      bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

      fos.flush();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (fos != null) {
        try {
          fos.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemple #11
0
  @Override
  public CachedImage read(CachedImageKey key) {
    long startRead = System.currentTimeMillis();
    String realPath = getRealPath(key);
    if (realPath == null) {
      return null;
    }

    File file = new File(realPath);
    byte[] fileBytes = null;
    InputStream fis = null;
    try {
      fis = new FileInputStream(file);
      fis = new BufferedInputStream(fis, 8192);
      int offset = 0;
      int byteCount = (int) file.length();
      int readCount = 0;

      fileBytes = new byte[byteCount];
      while ((readCount = fis.read(fileBytes, offset, byteCount)) > 0) {
        offset += readCount;
        byteCount -= readCount;
      }
    } catch (FileNotFoundException e) {
      if (Logger.isDebug()) e.printStackTrace();
    } catch (IOException e) {
      if (Logger.isDebug()) e.printStackTrace();
    } catch (Exception e) {
      if (Logger.isDebug()) e.printStackTrace();
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    // 先指定原始大小
    options.inSampleSize = 1;
    // 只进行大小判断
    options.inJustDecodeBounds = true;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    BitmapFactory.decodeByteArray(fileBytes, 0, fileBytes.length, options);

    long bitmapSize = ImageUtil.calculateBitmapSize(options);
    if (bitmapSize >= BIG_IMG_SIZE_LEVEL) {
      options.inSampleSize = ImageUtil.getScaleSampleSize(options, 120);
      if (Logger.isDebug()) Log.d(TAG, "compress local big bitmap");
    }
    options.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeByteArray(fileBytes, 0, fileBytes.length, options);

    CachedImage wrap = new CachedImage(bitmap);

    long endRead = System.currentTimeMillis();
    if (Logger.isDebug()) Log.d(TAG, "read local bitmap use time: " + (endRead - startRead) + "ms");
    return wrap;
  }