Search in sources :

Example 1 with ImageBean

use of com.lauren.simplenews.beans.ImageBean in project SimpleNews by liuling07.

the class ImageJsonUtils method readJsonImageBeans.

/**
     * 将获取到的json转换为图片列表对象
     * @param res
     * @return
     */
public static List<ImageBean> readJsonImageBeans(String res) {
    List<ImageBean> beans = new ArrayList<ImageBean>();
    try {
        JsonParser parser = new JsonParser();
        JsonArray jsonArray = parser.parse(res).getAsJsonArray();
        for (int i = 1; i < jsonArray.size(); i++) {
            JsonObject jo = jsonArray.get(i).getAsJsonObject();
            ImageBean news = JsonUtils.deserialize(jo, ImageBean.class);
            beans.add(news);
        }
    } catch (Exception e) {
        LogUtils.e(TAG, "readJsonImageBeans error", e);
    }
    return beans;
}
Also used : JsonArray(com.google.gson.JsonArray) ArrayList(java.util.ArrayList) ImageBean(com.lauren.simplenews.beans.ImageBean) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 2 with ImageBean

use of com.lauren.simplenews.beans.ImageBean in project SimpleNews by liuling07.

the class ImageAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ImageAdapter.ItemViewHolder holder, int position) {
    ImageBean imageBean = mData.get(position);
    if (imageBean == null) {
        return;
    }
    holder.mTitle.setText(imageBean.getTitle());
    float scale = (float) imageBean.getWidth() / (float) mMaxWidth;
    int height = (int) (imageBean.getHeight() / scale);
    if (height > mMaxHeight) {
        height = mMaxHeight;
    }
    holder.mImage.setLayoutParams(new LinearLayout.LayoutParams(mMaxWidth, height));
    ImageLoaderUtils.display(mContext, holder.mImage, imageBean.getThumburl());
}
Also used : ImageBean(com.lauren.simplenews.beans.ImageBean) LinearLayout(android.widget.LinearLayout)

Aggregations

ImageBean (com.lauren.simplenews.beans.ImageBean)2 LinearLayout (android.widget.LinearLayout)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ArrayList (java.util.ArrayList)1