Android Open Source - ElyTheme Silk Grid View






From Project

Back to project page ElyTheme.

License

The source code is released under:

GNU General Public License

If you think the Android project ElyTheme 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 com.afollestad.silk.views.list;
//w ww  . j  av a 2 s  .c om
import android.content.Context;
import android.util.AttributeSet;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import com.afollestad.silk.adapters.ScrollStatePersister;
import com.afollestad.silk.adapters.SilkAdapter;
import com.afollestad.silk.adapters.SilkCursorAdapter;

/**
 * A {@link android.widget.ListView} that connects to a {@link com.afollestad.silk.adapters.SilkAdapter} and notifies the adapter of its scroll state.
 * <p/>
 * When the ListView becomes idle (is no longer being scrolled or flinged), it notifies the adapter causing it to update.
 * <p/>
 * You can use getScrollState() from within a {@link com.afollestad.silk.adapters.SilkAdapter} to only load images when the ListView isn't scrolling.
 *
 * @author Aidan Follestad (afollestad)
 */
public class SilkGridView extends GridView {

    private int lastState;
    private OnSilkScrollListener mScrollListener;

    public SilkGridView(Context context) {
        super(context);
        init();
    }

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

    public SilkGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        setOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (lastState == scrollState) return;
                lastState = scrollState;
                if (getAdapter() instanceof ScrollStatePersister) {
                    ((ScrollStatePersister) getAdapter()).setScrollState(scrollState);
                    if (scrollState == SCROLL_STATE_IDLE && getAdapter() instanceof BaseAdapter) {
                        // When the list is idle, notify the adapter to update (causing images to load)
                        ((BaseAdapter) getAdapter()).notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if (mScrollListener != null && visibleItemCount < totalItemCount) {
                    if (firstVisibleItem == 0)
                        mScrollListener.onScrollToTop();
                    else if (firstVisibleItem == (totalItemCount - visibleItemCount))
                        mScrollListener.onScrollToBottom();
                }
            }
        });
    }

    /**
     * @deprecated Use {@link #setAdapter(com.afollestad.silk.adapters.SilkAdapter)} instead.
     */
    @Override
    public void setAdapter(ListAdapter adapter) {
        if (adapter instanceof SilkAdapter) {
            setAdapter((SilkAdapter) adapter);
            return;
        } else if (adapter instanceof SilkCursorAdapter) {
            setAdapter((SilkCursorAdapter) adapter);
            return;
        }
        throw new RuntimeException("The SilkListView only accepts SilkAdapters.");
    }

    /**
     * Sets the list's adapter, enforces the use of only a SilkAdapter.
     */
    public void setAdapter(SilkAdapter adapter) {
        super.setAdapter(adapter);
    }

    /**
     * Sets the list's adapter, enforces the use of only a SilkCursorAdapter.
     */
    public void setAdapter(SilkCursorAdapter adapter) {
        super.setAdapter(adapter);
    }

    public void setOnSilkScrollListener(OnSilkScrollListener listener) {
        mScrollListener = listener;
    }
}




Java Source Code List

com.afollestad.cardsui.ApplicationTest.java
com.afollestad.cardsui.CardAdapter.java
com.afollestad.cardsui.CardBase.java
com.afollestad.cardsui.CardCenteredHeader.java
com.afollestad.cardsui.CardCompressed.java
com.afollestad.cardsui.CardCursorAdapter.java
com.afollestad.cardsui.CardHeader.java
com.afollestad.cardsui.CardListView.java
com.afollestad.cardsui.CardTheme.java
com.afollestad.cardsui.Card.java
com.afollestad.silk.ApplicationTest.java
com.afollestad.silk.SilkComparable.java
com.afollestad.silk.SilkCursorItem.java
com.afollestad.silk.Silk.java
com.afollestad.silk.activities.SilkDrawerActivity.java
com.afollestad.silk.adapters.ScrollStatePersister.java
com.afollestad.silk.adapters.SilkAdapter.java
com.afollestad.silk.adapters.SilkCursorAdapter.java
com.afollestad.silk.adapters.SilkSpinnerAdapter.java
com.afollestad.silk.dialogs.SilkDialog.java
com.afollestad.silk.fragments.feed.SilkCursorFeedFragment.java
com.afollestad.silk.fragments.feed.SilkFeedFragment.java
com.afollestad.silk.fragments.list.SilkCursorListFragment.java
com.afollestad.silk.fragments.list.SilkListFragment.java
com.afollestad.silk.http.SilkHttpBase.java
com.afollestad.silk.http.SilkHttpBody.java
com.afollestad.silk.http.SilkHttpCallback.java
com.afollestad.silk.http.SilkHttpClient.java
com.afollestad.silk.http.SilkHttpException.java
com.afollestad.silk.http.SilkHttpHeader.java
com.afollestad.silk.http.SilkHttpResponse.java
com.afollestad.silk.utilities.IOUtils.java
com.afollestad.silk.utilities.TimeUtils.java
com.afollestad.silk.views.ClickableToast.java
com.afollestad.silk.views.list.OnSilkScrollListener.java
com.afollestad.silk.views.list.SilkGridView.java
com.afollestad.silk.views.list.SilkListView.java
com.afollestad.silk.views.time.SilkDatePicker.java
it.gcaliendo.elytheme.Adw.java
it.gcaliendo.elytheme.ApplicationTest.java
it.gcaliendo.elytheme.DocksProvider.java
it.gcaliendo.elytheme.Docks.java
it.gcaliendo.elytheme.IconActivity.java
it.gcaliendo.elytheme.IconPack.java
it.gcaliendo.elytheme.IconsProvider.java
it.gcaliendo.elytheme.Icons.java
it.gcaliendo.elytheme.RequestActivity.java
it.gcaliendo.elytheme.ThemeActivity.java
it.gcaliendo.elytheme.Wallpaper.java
it.gcaliendo.elytheme.fragments.FragmentAbout.java
it.gcaliendo.elytheme.fragments.FragmentContact.java
it.gcaliendo.elytheme.fragments.FragmentExtras.java
it.gcaliendo.elytheme.fragments.FragmentTheme.java
it.gcaliendo.elytheme.helper.AppInfo.java
it.gcaliendo.elytheme.iconfragment.IconFragmentGames.java
it.gcaliendo.elytheme.iconfragment.IconFragmentLatest.java
it.gcaliendo.elytheme.iconfragment.IconFragmentMisc.java
it.gcaliendo.elytheme.iconfragment.IconFragmentPlay.java
it.gcaliendo.elytheme.iconfragment.IconFragmentSystem.java