Пример #1
0
 protected void handleImage(List<AdInfo> adinfos) {
   DisplayImageOptions options;
   if (UtilsTools.hasDiskCache()) {
     options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).build();
   } else {
     options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(false).build();
   }
   Log.i(TAG, "source infos size : " + adinfos.size());
   for (AdInfo adinfo : adinfos) {
     Log.i(TAG, "source url : " + adinfo.getPic_url());
     changeImagePos(adinfo);
     ImageSize targetSize =
         new ImageSize(
             mContext.getResources().getInteger(R.integer.ad_target_image_width),
             mContext.getResources().getInteger(R.integer.ad_target_image_height));
     final int t = adinfo.getDismiss_time();
     ImageLoader.getInstance()
         .loadImage(
             adinfo.getPic_url(),
             targetSize,
             options,
             new SimpleImageLoadingListener() {
               @Override
               public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                 mAdView.setImageBitmap(loadedImage);
                 mRefreshHandler.removeMessages(DISMISS_AD);
                 mRefreshHandler.sendEmptyMessageDelayed(DISMISS_AD, t);
                 if (mB != null && loadedImage != mB) {
                   mB.recycle();
                 }
                 mB = loadedImage;
               }
             });
   }
 }
Пример #2
0
 private void changeImagePos(AdInfo adinfo) {
   RelativeLayout.LayoutParams lp =
       new RelativeLayout.LayoutParams(
           RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
   lp.height = mContext.getResources().getInteger(R.integer.ad_target_image_height);
   lp.width = mContext.getResources().getInteger(R.integer.ad_target_image_width);
   switch (mContext.getResources().getConfiguration().densityDpi) {
     case Constants.DENSITY_1280:
       lp.setMargins(adinfo.getPos_x(), adinfo.getPos_y(), 0, 0);
       break;
     case Constants.DENSITY_1920:
       lp.setMargins((int) (adinfo.getPos_x() * 1.5), (int) (adinfo.getPos_y() * 1.5), 0, 0);
       break;
     default:
   }
   mAdView.setLayoutParams(lp);
 }