private void setIcon(String fileName) { final Bitmap icon = BitmapFactory.decodeFile(fileName); addBitmapToMemoryCache(item.getId(), icon); if (getImageView().getTag() == null || getImageView().getTag().toString().equals(item.getId())) { animateImageView(icon); } }
@Override public void run() { // cache the file in our cache directory and keep it around so we don't have to keep downloading // it every time we access the item String screenshot = (usage == Market.GetImageRequest.AppImageUsage.SCREENSHOT) ? ("_screenshot_" + imageNumber) : ""; final String fileName = getContext().getCacheDir() + "/" + item.getPackageName() + screenshot + ".png"; if (new File(fileName).exists()) { setIcon(fileName); } else { MarketSession session = new MarketSession(false); session.getContext().setAuthSubToken(getContext().getAuthToken().getAuthToken()); session.getContext().setAndroidId(getContext().getAuthToken().getAndroidId()); Market.GetImageRequest imgReq = Market.GetImageRequest.newBuilder() .setAppId(item.getId()) .setImageUsage(usage) .setImageId(Integer.toString(imageNumber)) .build(); session.append( imgReq, new MarketSession.Callback<Market.GetImageResponse>() { @Override public void onResult( Market.ResponseContext responseContext, Market.GetImageResponse response) { try { // save the image to the file name FileOutputStream fos = new FileOutputStream(fileName); fos.write(response.getImageData().toByteArray()); fos.close(); setIcon(fileName); } catch (Exception e) { e.printStackTrace(); } } }); session.flush(); } }