Пример #1
0
  public void getProfilePic(String username, ImageView imgV) {
    Bitmap bitmap = null;
    SoftReference<Bitmap> bitmapSoft = profilePicCache.get(username);
    if (bitmapSoft == null) {
      String pathName;
      if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

        pathName = context.getExternalFilesDir(null).getAbsolutePath() + "/pgim/" + username;

      } else pathName = context.getCacheDir().getAbsolutePath() + "/pgim/" + username;

      if (new File(pathName).exists()) {
        Log.e(TAG, "Get pic from local");
        bitmap = BitmapUtil.getBitmapFromLocal(pathName);
        profilePicCache.put(username, new SoftReference<Bitmap>(bitmap));
      } else {
        new ProfileImageLoader(imgV, pathName).execute(username);
        return;
      }
    } else {
      if (bitmapSoft.get() == null) {
        System.out.println("soft bitmap null");
        String pathName;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

          pathName = context.getExternalFilesDir(null).getAbsolutePath() + "/pgim/" + username;
        } else pathName = context.getCacheDir().getAbsolutePath() + "/pgim/" + username;
        if (new File(pathName).exists()) {
          Log.e(TAG, "Get pic from local");
          bitmap = BitmapUtil.getBitmapFromLocal(pathName);
          profilePicCache.put(username, new SoftReference<Bitmap>(bitmap));
        } else {
          new ProfileImageLoader(imgV, pathName).execute(username);
          return;
        }

      } else {
        Log.e(TAG, "Get pic from softreference");
        bitmap = bitmapSoft.get();
      }
    }
    if (bitmap != null) {
      imgV.setImageBitmap(bitmap);
    }
  }
Пример #2
0
 @Override
 protected Bitmap doInBackground(String... params) {
   Log.i("Contact", "sdf");
   Bitmap bitmap = null;
   String username = params[0];
   bitmap = loadProfileImageWithVCard(username);
   if (bitmap != null) {
     profilePicCache.put(username, new SoftReference<Bitmap>(bitmap));
     BitmapUtil.saveBitmapToLocal(pathName, bitmap);
   }
   return bitmap;
 }
Пример #3
0
  private Bitmap loadProfileImageWithVCard(String username) {
    Bitmap bitmap = null;
    Log.e(TAG, "Get pic from server");
    VCard vCard = new VCard();
    try {
      vCard.load(JabberConnection.getInstance().getConnection(), username + "@pc-pc");
      byte[] bytes = vCard.getAvatar();
      bitmap = BitmapUtil.getBitmapFromBytes(bytes);

    } catch (SmackException.NoResponseException e) {
      e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
      e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
      e.printStackTrace();
    }
    return bitmap;
  }