Android Open Source - iPhoroidUI-demo Cover Flow Image Adapter






From Project

Back to project page iPhoroidUI-demo.

License

The source code is released under:

Apache License

If you think the Android project iPhoroidUI-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2011 by KLab Inc., All rights reserved.
 */*  w  w w  .  j  ava2  s  .  c  o m*/
 * Programmed by Naohide Sano
 */

package org.klab.ui_demo;

import java.io.IOException;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import org.klab.iphoroid.widget.coverflow.CoverFlowImageAdapterBase;
import org.klab.iphoroid.widget.support.HasImage;
import org.klab.iphoroid.widget.support.ImageCache;
import org.klab.iphoroid.widget.support.SimpleImageDownloadTask;
import org.klab.ui_demo.model.Item;
import org.klab.ui_demo.net.HTTPClient;


/**
 * CoverFlow ??????????????????????????????????
 *
 * @author <a href="mailto:sano-n@klab.jp">Naohide Sano</a> (sano-n)
 * @version 0.00 2011/06/23 sano-n initial version <br>
 */
public class CoverFlowImageAdapter extends CoverFlowImageAdapterBase<Item> {

    /**
     * ???????????????????????????????????????????????
     *
     * @param context ???????
     * @param items ?????????? ID ???????
     * @param width ?????????
     * @param height ????????????
     * @param isUserEffect ??????????????????????? true?????????? false?
     */
    public CoverFlowImageAdapter(Context context, List<Item> items, int width, int height, boolean isUserEffect) {
        super(context, items, width, height, isUserEffect);
    }

    /** */
    private static final String CACHE_KEY_POSTFIX = "CF";

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ImageView view = new ImageView(this.mContext);

        final String url = items.get(position).getImageUrl();
        HasImage.Util.setImage(mContext, url, view, new SimpleImageDownloadTask(mContext) {
            @Override
            public void setResult(Bitmap bitmap) {
                if (bitmap != null) {
                    Bitmap image;
                    Bitmap resizedImage = makeResizedImage(bitmap, mLayoutParams.width, mLayoutParams.width);
                    if (mIsUserEffect) {
                        image = makeReflectedImage(resizedImage, REFLECTION_GAP);
                        if (!resizedImage.isRecycled()) {
                          resizedImage.recycle();
                        }
                    } else {
                        image = resizedImage;
                    }
                    view.setImageBitmap(image);
                    ImageCache.setImage(url + CACHE_KEY_POSTFIX, image);
                } else {
                    view.setImageDrawable(ListViewActivity.noImageCoverflowIcon);
                }
            }
            @Override
            public Bitmap getBitmap(String url) throws IOException {
                return HTTPClient.getImage(url);
            }
            @Override
            public void showProgress() {
                view.setImageDrawable(ListViewActivity.loadingIcon);
                // don't show dialog
            }
            @Override
            public void dismissProgress() {
                // don't show dialog
            }
        }, CACHE_KEY_POSTFIX);

        view.setLayoutParams(mLayoutParams);
        view.setScaleType(ScaleType.CENTER_INSIDE);

//        BitmapDrawable drawable = (BitmapDrawable) view.getDrawable();
//        drawable.setAntiAlias(true);

        return view;
    }
}




Java Source Code List

org.klab.ui_demo.CoverFlowImageAdapter.java
org.klab.ui_demo.FlowViewAndCoverFlowActivity.java
org.klab.ui_demo.FlowViewItemAdapter.java
org.klab.ui_demo.GridViewActivity.java
org.klab.ui_demo.GridViewItemAdapter.java
org.klab.ui_demo.ListViewActivity.java
org.klab.ui_demo.ListViewItemAdapter.java
org.klab.ui_demo.OptionsMenuUtil.java
org.klab.ui_demo.dao.ItemDao.java
org.klab.ui_demo.dao.ListViewItemDao.java
org.klab.ui_demo.model.Item.java
org.klab.ui_demo.net.HTTPClient.java