Android Open Source - iPhoroidUI Cover Flow Gallery






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) 2007 The Android Open Source Project
 *//w w  w  .ja  v  a  2 s  . c o m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This code is base on the Android Gallery widget and was modify
 * by Neil Davies neild001 'at' gmail dot com to be a Coverflow widget
 */

package org.klab.iphoroid.widget.coverflow;

import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.ImageView;

import org.klab.iphoroid.widget.gallery.ScrollDetectableGallery;


/**
 * CoverFlow ???? Gallery ?????????????????
 *
 * @author Neil Davies
 * @author <a href="mailto:sano-n@klab.jp">Naohide Sano</a> (sano-n)
 * @version Neil Davies original
 * @version sano-n {@link ScrollDetectableGallery} ????????????????????
 */
public class CoverFlowGallery extends ScrollDetectableGallery {
    /**
     * ImageView ??????????????????????
     */
    private Camera mCamera = new Camera();

    /**
     * ????????????????????
     */
    private int mMaxRotationAngle = 60;

    /**
     * ????
     */
    private int mMaxZoom = -120;

    /**
     * CoverFlow ???????????????
     */
    private int mCoveflowCenter;

    /**
     * ?????????????????????
     * 
     * @param context ???????
     */
    public CoverFlowGallery(Context context) {
        super(context);
        this.setStaticTransformationsEnabled(true);
    }

    /**
     * ?????????????????????
     * 
     * @param context ???????
     * @param attrs ????? XML ????????????????????????????????
     */
    public CoverFlowGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setStaticTransformationsEnabled(true);
    }

    /**
     * ?????????????????????
     * 
     * @param context ???????
     * @param attrs ????? XML ????????????????????????????????
     * @param defStyle ?????????????????????
     */
    public CoverFlowGallery(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.setStaticTransformationsEnabled(true);
    }

    /**
     * CoverFlow ?????????? X ????????????????????????
     * 
     * @return ????
     */
    private int getCenterOfCoverflow() {
        int left = this.getPaddingLeft();
        return (getWidth() - left - getPaddingRight()) / 2 + left;
    }

    /**
     * View ?????????? X ????????????????????????
     * 
     * @param view ???????????? View?
     * 
     * @return ????
     */
    private static int getCenterOfView(View view) {
        return view.getLeft() + view.getWidth() / 2;
    }

    /**
     * CoverFlow ?????????? View ??????????????????
     * 
     * @param child ?????? View?
     * @param t ?????
     * 
     * @return getChildDrawingOrder ??????????????????????????????? true?????????? false?
     */
    @Override
    protected boolean getChildStaticTransformation(View child, Transformation t) {
        final int center = getCenterOfView(child);
        final int width = child.getWidth();
        int angle = 0;

        t.clear();
        t.setTransformationType(Transformation.TYPE_MATRIX);

        if (center == mCoveflowCenter) {
            this.transformImageBitmap((ImageView) child, t, 0);

        } else {
            angle = (int) (((float) (this.mCoveflowCenter - center) / width) * this.mMaxRotationAngle);
            if (Math.abs(angle) > this.mMaxRotationAngle) {
                angle = (angle < 0) ? -this.mMaxRotationAngle : this.mMaxRotationAngle;
            }
//Log.d("CoverFlowGallery", "angle: " + angle + ", mCoveflowCenter: " + mCoveflowCenter + ", center: " + center + ", width: " + width + ", mMaxRotationAngle: " + mMaxRotationAngle);

            this.transformImageBitmap((ImageView) child, t, angle);
        }

        return true;
    }

    /**
     * ?????????????????????????
     * 
     * @return ???
     */
    public int getMaxRotationAngle() {
        return this.mMaxRotationAngle;
    }

    /**
     * ???????????????????????
     * 
     * @param angle ???
     */
    public void setMaxRotationAngle(int angle) {
        this.mMaxRotationAngle = angle;
    }

    /**
     * ??????????????????
     * 
     * @return ????
     */
    public int getMaxZoom() {
        return this.mMaxZoom;
    }

    /**
     * ????????????????
     * 
     * @param zoom ????
     */
    public void setMaxZoom(int zoom) {
        this.mMaxZoom = zoom;
    }

    /**
     * ????????????????????????????????????????
     * 
     * @param w ?????????
     * @param h ????????????
     * @param oldw ????????????????????
     * @param oldh ???????????????????????
     */
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        this.mCoveflowCenter = this.getCenterOfCoverflow();
        super.onSizeChanged(w, h, oldw, oldh);
    }

    /**
     * ???????????????????
     * 
     * @param child ??????????????????? View?
     * @param t ?????
     * @param angle ????????????
     */
    private void transformImageBitmap(ImageView child, Transformation t, int angle) {
        this.mCamera.save();

        final Matrix matrix = t.getMatrix();
        final int imageHeight = child.getLayoutParams().height;
        final int imageWidth = child.getLayoutParams().width;
        final int rotation = Math.abs(angle);

        this.mCamera.translate(0.0f, 0.0f, 100.0f);

        // ????????
        if (rotation < this.mMaxRotationAngle) {
            float zoom = (float) (this.mMaxZoom + (rotation * 1.5));
            this.mCamera.translate(0.0f, 0.0f, zoom);
        }

        this.mCamera.rotateY(angle);
        this.mCamera.getMatrix(matrix);
        matrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
        matrix.postTranslate((imageWidth / 2), (imageHeight / 2));
        this.mCamera.restore();
    }

    @Override
    protected int getChildDrawingOrder(int childCount, int i) {
        int selectedIndex = getSelectedItemPosition() - getFirstVisiblePosition();

        // Just to be safe
        if (selectedIndex < 0) {
            return i;
        }

        if (i == childCount - 1) {
            // Draw the selected child last
            return selectedIndex;
        } else if (i >= selectedIndex) {
            // Move the children to the right of the selected child earlier one
            int index = childCount - 1 - (i - selectedIndex);

            return index;
        } else {
            // Keep the children to the left of the selected child the same
            return i;
        }
    }
}




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