Android Open Source - iPhoroidUI Cover Flow Image Adapter Base






From Project

Back to project page iPhoroidUI.

License

The source code is released under:

Apache License

If you think the Android project iPhoroidUI 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  .  co m*/
 * Programmed by Naohide Sano
 */

package org.klab.iphoroid.widget.coverflow;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Shader.TileMode;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;


/**
 * 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 abstract class CoverFlowImageAdapterBase<T> extends BaseAdapter {
    /**
     * ????????????????????????
     */
    protected static int REFLECTION_GAP = 4;

    /**
     * ???????
     */
    protected Context mContext;

    /**
     * ?????????????????????????????
     */
    protected boolean mIsUserEffect;

    /**
     * ????????
     */
    protected Gallery.LayoutParams mLayoutParams;

    /**
     * ?????????? ID ???????
     */
    protected List<T> items;

    /**
     * ???????????????????????????????????????????????
     *
     * @param context ???????
     * @param items ?????????? ID ???????
     * @param width ?????????
     * @param height ????????????
     * @param isUserEffect ??????????????????????? true?????????? false?
     */
    public CoverFlowImageAdapterBase(Context context, List<T> items, int width, int height, boolean isUserEffect) {
        this.mContext = context;
        this.items = items;
        this.mIsUserEffect = isUserEffect;
        this.mLayoutParams = new Gallery.LayoutParams(width, height);
    }

    public int getCount() {
        return items.size();
    }

    public Object getItem(int position) {
        return items.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    /**
     * ???????????????????????
     *
     * @param position ????????????????????????????????????????
     * @param convertView ???????????????
     * @param parent ????????????
     */
    public abstract View getView(int position, View convertView, ViewGroup parent);

    /**
     * ???????????????????????????? Bitmap ??????????????
     *
     * @param src ????????????
     * @param gap ????????????????????????
     * @return ??????? Bitmap ???????????????? null ?????
     */
    protected Bitmap makeReflectedImage(Bitmap src, int gap) {
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);

        int width = src.getWidth();
        int height = src.getHeight();
        int destHeight = height + height / 2;
        Bitmap effect = Bitmap.createBitmap(src, 0, height / 2, width, height / 2, matrix, false);
//        Bitmap dest = Bitmap.createBitmap(width, destHeight, Config.ARGB_4444);
        Bitmap dest = Bitmap.createBitmap(width, destHeight, Config.ARGB_8888);
        Canvas canvas = new Canvas(dest);

        canvas.drawBitmap(src, 0, 0, null);
        canvas.drawRect(0, height, width, height + gap, new Paint());
        canvas.drawBitmap(effect, 0, height + gap, null);

        Paint paint = new Paint();
        paint.setShader(new LinearGradient(0, height, 0, destHeight + gap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP));
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
        canvas.drawRect(0, height, width, destHeight + gap, paint);

        if (effect != null && !effect.isRecycled()) {
          effect.recycle();
        }

        return dest;
    }

    /** */
    protected Bitmap makeResizedImage(Bitmap src, int width, int height) {
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);

//        Bitmap dest = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        Bitmap dest = Bitmap.createBitmap(width, height, Config.RGB_565);
        Canvas canvas = new Canvas(dest);
        canvas.drawBitmap(src, new Rect(0, 0, src.getWidth(), src.getHeight()), new Rect(0, 0, width, height), null);

        return dest;
    }

    /**
     * ???? ID ??????????????????????
     *
     * @param id ???? ID?
     * @return ??????? Bitmap ???????????????? null ?????
     */
    protected Bitmap decodeBitmap(int id) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(mContext.getResources(), id, options);

        int width = (options.outWidth / mLayoutParams.width) + 1;
        int height = (options.outHeight / mLayoutParams.height) + 1;
        int scale = Math.max(width, height);

        options.inJustDecodeBounds = false;
        options.inSampleSize = scale;

        return BitmapFactory.decodeResource(mContext.getResources(), id, options);
    }
}




Java Source Code List

org.klab.iphoroid.util.ActivityUtil.java
org.klab.iphoroid.util.Cache.java
org.klab.iphoroid.widget.adpterview.OnScrollListener.java
org.klab.iphoroid.widget.coverflow.CoverFlowGallery.java
org.klab.iphoroid.widget.coverflow.CoverFlowImageAdapterBase.java
org.klab.iphoroid.widget.flowview.CircleFlowIndicator.java
org.klab.iphoroid.widget.flowview.FlowIndicator.java
org.klab.iphoroid.widget.flowview.FlowView.java
org.klab.iphoroid.widget.flowview.TitleFlowIndicator.java
org.klab.iphoroid.widget.flowview.TitleProvider.java
org.klab.iphoroid.widget.gallery.ScrollDetectableGallery.java
org.klab.iphoroid.widget.listview.AdapterWrapper.java
org.klab.iphoroid.widget.listview.EndlessAdapter.java
org.klab.iphoroid.widget.listview.PullToRefreshEndlessListView.java
org.klab.iphoroid.widget.listview.PullToRefreshListView.java
org.klab.iphoroid.widget.listview.RefreshableArrayAdapter.java
org.klab.iphoroid.widget.support.DownloadTask.java
org.klab.iphoroid.widget.support.HasImage.java
org.klab.iphoroid.widget.support.ImageCache.java
org.klab.iphoroid.widget.support.ImageDownloadTask.java
org.klab.iphoroid.widget.support.SimpleImageDownloadTask.java