Beispiel #1
0
 @SuppressWarnings("ALL")
 public Bitmap decode(String path) {
   File file = new File(path);
   FileInputStream fis = null;
   byte[] bytes;
   try {
     bytes = new byte[(int) file.length()];
     fis = new FileInputStream(file);
     fis.read(bytes);
   } catch (Exception e) {
     return null;
   } finally {
     FileUtil.close(fis);
   }
   return decodeViaLibrary(bytes);
 }
Beispiel #2
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
   int key = intent.getIntExtra("key", 0);
   String path = intent.getStringExtra("path");
   int maxHeight = intent.getIntExtra("maxHeight", 0);
   Bitmap tmpBitmap = decode(path);
   Bitmap resBitmap = null;
   if (tmpBitmap != null) {
     if (maxHeight != 0) {
       resBitmap =
           scaleBitmap(
               tmpBitmap, calculateSize(tmpBitmap.getWidth(), tmpBitmap.getHeight(), maxHeight));
     } else {
       resBitmap = tmpBitmap;
     }
   }
   String tmpFile = FileUtil.createTmpPngFile(resBitmap);
   publishResults(tmpFile, key, path);
   return Service.START_NOT_STICKY;
 }
  @Override
  public void onBindViewHolder(Holder viewHolder, int i) {
    mIsVisible = true;
    View itemView = viewHolder.itemView;
    itemView.setTag(i);
    ImageView imageView = viewHolder.imageView;
    RelativeLayout.LayoutParams imageLP = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
    StickerMicroThumb stickerMicroThumb = mData.get(i);
    if (i == 0 || i == 1) {
      imageView.setImageResource(mData.get(i).resourceId);
      imageLP.width = RelativeLayout.LayoutParams.MATCH_PARENT;
      imageLP.height = RelativeLayout.LayoutParams.MATCH_PARENT;
      if (i == 0) {
        imageLP.leftMargin = EmojConstant.dp(14);
      } else {
        imageLP.leftMargin = 0;
      }
    } else {
      int size = EmojConstant.dp(28);
      imageLP.width = size;
      imageLP.height = size;
      imageLP.leftMargin = 0;
      if (stickerMicroThumb != null
          && stickerMicroThumb.sticker != null
          && stickerMicroThumb.sticker.thumb != null) {
        if (FileUtil.isTDFileLocal(stickerMicroThumb.sticker.thumb.photo)) {
          BitmapDrawable bitmapDrawable =
              FileManager.getManager()
                  .getStickerFromFile(
                      stickerMicroThumb.sticker.thumb.photo.path,
                      FileManager.TypeLoad.USER_STICKER_MICRO_THUMB,
                      itemView,
                      itemView.getTag().toString(),
                      imageView);
          if (bitmapDrawable != null && bitmapDrawable.getBitmap() != null) {
            imageView.setImageDrawable(bitmapDrawable);
          } else {
            imageView.setImageBitmap(null);
          }
        } else {
          int fileId = stickerMicroThumb.sticker.sticker.id;
          if (fileId > 0) {
            FileManager.getManager()
                .uploadFileAsync(
                    FileManager.TypeLoad.USER_STICKER_MICRO_THUMB,
                    stickerMicroThumb.sticker.thumb.photo.id,
                    i,
                    -1,
                    stickerMicroThumb.sticker,
                    imageView,
                    itemView,
                    itemView.getTag().toString());
            imageView.setImageBitmap(null);
          }
        }
      }
    }

    if (stickerMicroThumb != null && stickerMicroThumb.isSelected) {
      itemView.setBackgroundColor(0xFFE2E5E7);
    } else {
      itemView.setBackgroundColor(Color.TRANSPARENT);
    }
  }