Beispiel #1
0
    @Override
    public void onSuccess(JSONObject response) {
      try {
        String capture = response.toString();

        JSONObject jsonData = response.getJSONObject("data");
        String userName = jsonData.getString("ads_creator_name");
        String userAvatar = jsonData.getString("ads_creator_avatar_url");
        String adUrl = jsonData.getString("ads_url");
        String adImage = jsonData.getString("banner_image_url");
        ad = new Ad(userAvatar, userName, adImage, adUrl);

        float viewWidth = header.getWidth();
        if (getActivity() == null) return;
        float density = getResources().getDisplayMetrics().density;
        float dipWidth = viewWidth / density;

        Integer finalWidth = (int) ((dipWidth < 380.0) ? dipWidth - 20 : 360);
        float aspect = (float) ((float) finalWidth / 360.0);
        Integer finalHeight = (int) (aspect * 100 * density);
        finalWidth = (int) (finalWidth * density);

        ImageWorker iWork = new ImageWorker(getActivity());

        ImageView adImageView = (ImageView) header.findViewById(R.id.ad_ad);
        adImageView.setBackgroundColor(0x00000000);

        iWork.loadBitmap(ad.getAdImage(), adImageView, finalWidth, finalHeight);

        ImageView aview = (ImageView) header.findViewById(R.id.ad_ad);
        aview.setOnClickListener(
            new OnClickListener() {

              public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(ad.getAdUrl()));
                try {
                  startActivity(i);
                } catch (ActivityNotFoundException e) {

                }
              }
            });
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }