Exemplo n.º 1
0
  public <T extends View> void display(
      T container, String uri, BitmapDisplayConfig displayConfig, BitmapLoadCallBack<T> callBack) {
    if (container == null) {
      return;
    }

    container.clearAnimation();

    if (callBack == null) {
      callBack = new SimpleBitmapLoadCallBack<T>();
    }

    if (displayConfig == null || displayConfig == defaultDisplayConfig) {
      displayConfig = defaultDisplayConfig.cloneNew();
    }

    // Optimize Max Size
    BitmapSize size = displayConfig.getBitmapMaxSize();
    displayConfig.setBitmapMaxSize(
        BitmapCommonUtils.optimizeMaxSizeByView(container, size.getWidth(), size.getHeight()));

    callBack.onPreLoad(container, uri, displayConfig);

    if (TextUtils.isEmpty(uri)) {
      callBack.onLoadFailed(container, uri, displayConfig.getLoadFailedDrawable());
      return;
    }

    Bitmap bitmap = globalConfig.getBitmapCache().getBitmapFromMemCache(uri, displayConfig);

    if (bitmap != null) {
      callBack.onLoadStarted(container, uri, displayConfig);
      callBack.onLoadCompleted(container, uri, bitmap, displayConfig, BitmapLoadFrom.MEMORY_CACHE);
    } else if (!bitmapLoadTaskExist(container, uri, callBack)) {

      final BitmapLoadTask<T> loadTask =
          new BitmapLoadTask<T>(container, uri, displayConfig, callBack);
      // set loading image
      final AsyncDrawable<T> asyncDrawable =
          new AsyncDrawable<T>(displayConfig.getLoadingDrawable(), loadTask);
      callBack.setDrawable(container, asyncDrawable);

      // load bitmap from uri or diskCache
      loadTask.executeOnExecutor(globalConfig.getBitmapLoadExecutor());
    }
  }
Exemplo n.º 2
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image);

    ViewUtils.inject(this);

    String imgUrl = getIntent().getStringExtra("url");

    bitmapUtils = BitmapFragment.bitmapUtils;
    if (bitmapUtils == null) {
      bitmapUtils = BitmapHelp.getBitmapUtils(this.getApplicationContext());
    }

    bigPicDisplayConfig = new BitmapDisplayConfig();
    // bigPicDisplayConfig.setShowOriginal(true); // 显示原始图片,不压缩, 尽量不要使用, 图片太大时容易OOM。
    bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);
    bigPicDisplayConfig.setBitmapMaxSize(BitmapCommonUtils.getScreenSize(this));

    BitmapLoadCallBack<ImageView> callback =
        new SimpleBitmapLoadCallBack<ImageView>() {
          @Override
          public void onLoadStarted(ImageView container, String uri, BitmapDisplayConfig config) {
            super.onLoadStarted(container, uri, config);
            Toast.makeText(getApplicationContext(), uri, 300).show();
          }

          @Override
          public void onLoadCompleted(
              ImageView container,
              String url,
              Bitmap bitmap,
              BitmapDisplayConfig config,
              BitmapLoadFrom from) {
            super.onLoadCompleted(container, url, bitmap, config, from);
            Toast.makeText(
                    getApplicationContext(), bitmap.getWidth() + "*" + bitmap.getHeight(), 300)
                .show();
          }
        };
    callback.setBitmapSetter(BitmapCommonUtils.sDefaultImageViewSetter);

    bitmapUtils.display(bigImage, imgUrl, bigPicDisplayConfig, callback);
  }
  private void initView() {
    initHomeWorkDetailsData();

    bitmapUtils = new BitmapUtils(this);
    bigPicDisplayConfig = new BitmapDisplayConfig();
    bigPicDisplayConfig.setLoadingDrawable(getResources().getDrawable(R.drawable.defaulticon));
    bigPicDisplayConfig.setLoadFailedDrawable(getResources().getDrawable(R.drawable.msg_point));
    bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);
    bigPicDisplayConfig.setBitmapMaxSize(BitmapCommonUtils.getScreenSize(mContext));

    bitmapUtils.display(
        imghead, listHomeWorDetailsData.get(0).get("imghead").toString(), bigPicDisplayConfig);
    txtusername.setText(listHomeWorDetailsData.get(0).get("username").toString());
    txtgrade.setText(listHomeWorDetailsData.get(0).get("grade").toString());
    txttime.setText(listHomeWorDetailsData.get(0).get("time").toString());
    txtquestionname.setText(listHomeWorDetailsData.get(0).get("questionname").toString());
    txtquestiondetail.setText(listHomeWorDetailsData.get(0).get("questiondetail").toString());

    imgquestionpic1.setVisibility(View.GONE);
    imgquestionpic2.setVisibility(View.GONE);
    imgquestionpic3.setVisibility(View.GONE);
    imgquestionpic4.setVisibility(View.GONE);

    Map<Integer, Object> map =
        (Map<Integer, Object>) listHomeWorDetailsData.get(0).get("questionpic");

    for (Integer key : map.keySet()) {
      System.out.println("_____" + key + "____" + map.get(key).toString());

      switch (key) {
        case 0:
          imgquestionpic1.setVisibility(View.VISIBLE);
          bitmapUtils.display(imgquestionpic1, map.get(key).toString(), bigPicDisplayConfig);

          break;
        case 1:
          imgquestionpic2.setVisibility(View.VISIBLE);
          bitmapUtils.display(imgquestionpic2, map.get(key).toString(), bigPicDisplayConfig);

          break;
        case 2:
          imgquestionpic3.setVisibility(View.VISIBLE);
          bitmapUtils.display(imgquestionpic3, map.get(key).toString(), bigPicDisplayConfig);

          break;
        case 3:
          imgquestionpic4.setVisibility(View.VISIBLE);
          bitmapUtils.display(imgquestionpic4, map.get(key).toString(), bigPicDisplayConfig);

          break;

        default:
          imgquestionpic1.setVisibility(View.GONE);
          imgquestionpic2.setVisibility(View.GONE);
          imgquestionpic3.setVisibility(View.GONE);
          imgquestionpic4.setVisibility(View.GONE);
          break;
      }
    }

    HomeWorkDetails_Adapter homewordetails_adapter =
        new HomeWorkDetails_Adapter(
            (List<Map<String, Object>>) listHomeWorDetailsData.get(0).get("answerteachers"),
            this,
            listhomeworkdetails);

    listhomeworkdetails.setAdapter(homewordetails_adapter);
  }