Android Open Source - android-tools Header List View






From Project

Back to project page android-tools.

License

The source code is released under:

MIT License

If you think the Android project android-tools 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

package net.comfreeze.lib.views;
/*www.  ja  v  a  2 s .  c  om*/
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;

import net.comfreeze.lib.adapter.HeaderListAdapter;

public class HeaderListView extends ListView {
    private static final String TAG = HeaderListView.class.getSimpleName();
    private static final int MAX_ALPHA = 255;
    public static boolean silent = false;
    private HeaderListAdapter adapter;
    private View headerView;
    private boolean headerViewVisible;
    private int headerViewWidth;
    private int headerViewHeight;

    public HeaderListView(Context context) {
        super(context);
    }

    public HeaderListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

//    public HeaderListView(Context context, AttributeSet attrs, int defStyle) {
//  super(context, attrs, defStyle);
//    }

    public HeaderListView setHeaderView(View view) {
        headerView = view;

        // Disable vertical fading when the header is present
        if (headerView != null) {
            setFadingEdgeLength(0);
        }
        requestLayout();
        return this;
    }

    @Override
    public void setAdapter(ListAdapter adapter) {
        super.setAdapter(adapter);
        if (!silent)
            Log.d(TAG, "Setting adapter");
        this.adapter = (HeaderListAdapter) adapter;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (headerView != null && !isInEditMode()) {
            if (!silent)
                Log.d(TAG, "Header view found, measuring!");
            measureChild(headerView, widthMeasureSpec, heightMeasureSpec);
            headerViewWidth = headerView.getMeasuredWidth();
            headerViewHeight = headerView.getMeasuredHeight();
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (headerView != null && !isInEditMode()) {
            if (!silent)
                Log.d(TAG, "Header view found, laying out!");
            // headerView.requestLayout();
            headerView.layout(0, 0, headerViewWidth, headerViewHeight);
            configureHeaderView(getFirstVisiblePosition());
        }
    }

    public void configureHeaderView(int position) {
        if (headerView == null) {
            if (!silent)
                Log.d(TAG, "Header view not found, skipping configuration!");
            return;
        }
        if (!silent)
            Log.d(TAG, "Header view found, configuring!");

        switch (adapter.getHeaderState(position)) {
            case GONE:
                if (!silent)
                    Log.d(TAG, "Header view hiding!");
                headerViewVisible = false;
                break;

            case VISIBLE:
                if (!silent)
                    Log.d(TAG, "Header view showing!");
                adapter.configureHeader(headerView, position, MAX_ALPHA);
                if (headerView.getTop() != 0) {
                    headerView.layout(0, 0, headerViewWidth, headerViewHeight);
                }
                headerViewVisible = true;
                break;

            case PUSHED_UP:
                if (!silent)
                    Log.d(TAG, "Header view pushed up!");
                View firstView = getChildAt(0);
                if (firstView != null) {
                    int bottom = firstView.getBottom();
                    int headerHeight = headerView.getHeight();
                    int y;
                    int alpha;
                    if (bottom < headerHeight) {
                        y = (bottom - headerHeight);
                        alpha = MAX_ALPHA * (headerHeight + y) / headerHeight;
                    } else {
                        y = 0;
                        alpha = MAX_ALPHA;
                    }
                    adapter.configureHeader(headerView, position, alpha);
                    if (headerView.getTop() != y) {
                        // headerView.requestLayout();
                        headerView.layout(0, y, headerViewWidth, headerViewHeight + y);
                    }
                    headerViewVisible = true;
                } else if (!silent)
                    Log.e(TAG, "First child was null!");
                break;
        }
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (!isInEditMode()) {
            if (headerViewVisible) {
                drawChild(canvas, headerView, getDrawingTime());
            }
        }
    }
}




Java Source Code List

net.comfreeze.lib.BundleBuilder.java
net.comfreeze.lib.CFZApplication.java
net.comfreeze.lib.ContentValueBuilder.java
net.comfreeze.lib.FragmentMap.java
net.comfreeze.lib.adapter.HeaderListAdapter.java
net.comfreeze.lib.adapter.IHeaderListAdapter.java
net.comfreeze.lib.adapter.SeparatedListAdapter.java
net.comfreeze.lib.api.BaseAPI.java
net.comfreeze.lib.api.RestAPI.java
net.comfreeze.lib.api.XMLAPI.java
net.comfreeze.lib.api.helper.CursorHelper.java
net.comfreeze.lib.api.helper.JSONHelper.java
net.comfreeze.lib.api.helper.ModelHelper.java
net.comfreeze.lib.api.xml.WordpressAPI.java
net.comfreeze.lib.audio.SoundManager.java
net.comfreeze.lib.db.DatabaseHelper.java
net.comfreeze.lib.db.DatabaseTable.java
net.comfreeze.lib.db.helper.HelperCursor.java
net.comfreeze.lib.db.model.CFZModel.java
net.comfreeze.lib.db.model.FieldColumnMap.java
net.comfreeze.lib.fragments.CFZListFragment.java
net.comfreeze.lib.provider.CFZSimpleProvider.java
net.comfreeze.lib.service.CFZService.java
net.comfreeze.lib.ui.SupportFragmentActivity.java
net.comfreeze.lib.ui.dialog.CFZDialogProgress.java
net.comfreeze.lib.ui.fragment.CFZFragmentBase.java
net.comfreeze.lib.views.BiScrollView.java
net.comfreeze.lib.views.CFZViewHelper.java
net.comfreeze.lib.views.FlowLayout.java
net.comfreeze.lib.views.GestureHelper.java
net.comfreeze.lib.views.HeaderListView.java
net.comfreeze.lib.views.ResizingView.java
net.comfreeze.lib.views.ViewCollection.java
net.comfreeze.lib.views.ViewUtils.java
net.comfreeze.lib.xml.XMLParser.java
net.comfreeze.lib.xml.wordpress.FeedXmlParser.java