Android Open Source - PullToRefresh Action Bar Pull To Refresh






From Project

Back to project page PullToRefresh.

License

The source code is released under:

Apache License

If you think the Android project PullToRefresh 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 2013 Chris Banes/*from  w ww.j a  v  a2  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.
 */

package uk.co.senab.actionbarpulltorefresh.library;


import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;
import uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ViewDelegate;

public class ActionBarPullToRefresh {

    public static SetupWizard from(Activity activity) {
        return new SetupWizard(activity);
    }

    public static final class SetupWizard {
        private final Activity mActivity;
        private Options mOptions;
        private int[] refreshableViewIds;
        private View[] refreshableViews;
        private OnRefreshListener mOnRefreshListener;
        private ViewGroup mViewGroupToInsertInto;
        private HashMap<Class, ViewDelegate> mViewDelegates;

        private SetupWizard(Activity activity) {
            mActivity = activity;
        }

        public SetupWizard options(Options options) {
            mOptions = options;
            return this;
        }

        public SetupWizard allChildrenArePullable() {
            refreshableViewIds = null;
            refreshableViews = null;
            return this;
        }

        public SetupWizard theseChildrenArePullable(int... viewIds) {
            refreshableViewIds = viewIds;
            refreshableViews = null;
            return this;
        }

        public SetupWizard theseChildrenArePullable(View... views) {
            refreshableViews = views;
            refreshableViewIds = null;
            return this;
        }

        public SetupWizard useViewDelegate(Class<?> viewClass, ViewDelegate delegate) {
            if (mViewDelegates == null) {
                mViewDelegates = new HashMap<Class, ViewDelegate>();
            }
            mViewDelegates.put(viewClass, delegate);
            return this;
        }

        public SetupWizard listener(OnRefreshListener listener) {
            mOnRefreshListener = listener;
            return this;
        }

        public SetupWizard insertLayoutInto(ViewGroup viewGroup) {
            mViewGroupToInsertInto = viewGroup;
            return this;
        }

        public void setup(PullToRefreshLayout pullToRefreshLayout) {
            PullToRefreshAttacher attacher = pullToRefreshLayout.createPullToRefreshAttacher(
                    mActivity, mOptions);
            attacher.setOnRefreshListener(mOnRefreshListener);

            if (mViewGroupToInsertInto != null) {
                insertLayoutIntoViewGroup(mViewGroupToInsertInto, pullToRefreshLayout);
            }

            pullToRefreshLayout.setPullToRefreshAttacher(attacher);

            // First add the pullable child views
            if (refreshableViewIds != null) {
                pullToRefreshLayout.addChildrenAsPullable(refreshableViewIds);
            } else if (refreshableViews != null) {
                pullToRefreshLayout.addChildrenAsPullable(refreshableViews);
            } else {
                pullToRefreshLayout.addAllChildrenAsPullable();
            }

            // Now set any custom view delegates
            if (mViewDelegates != null) {
                final Set<Map.Entry<Class, ViewDelegate>> entries = mViewDelegates.entrySet();
                for (final Map.Entry<Class, ViewDelegate> entry : entries) {
                    attacher.useViewDelegate(entry.getKey(), entry.getValue());
                }
            }
        }

        private static void insertLayoutIntoViewGroup(ViewGroup viewGroup,
                PullToRefreshLayout pullToRefreshLayout) {
            // Move all children to PullToRefreshLayout. This code looks a bit silly but the child
            // indices change every time we remove a View (so we can't just iterate through)
            View child = viewGroup.getChildAt(0);
            while (child != null) {
                viewGroup.removeViewAt(0);
                pullToRefreshLayout.addView(child);
                child = viewGroup.getChildAt(0);
            }

            viewGroup.addView(pullToRefreshLayout, ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
        }
    }
}




Java Source Code List

android.support.v7.appcompat.BuildConfig.java
android.support.v7.appcompat.BuildConfig.java
android.support.v7.gridlayout.BuildConfig.java
android.support.v7.gridlayout.BuildConfig.java
fr.castorflex.android.smoothprogressbar.BuildConfig.java
fr.castorflex.android.smoothprogressbar.BuildConfig.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.AbcDefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.AbcPullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.BuildConfig.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.AbsDefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.AbsPullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh.java
uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh.java
uk.co.senab.actionbarpulltorefresh.library.BuildConfig.java
uk.co.senab.actionbarpulltorefresh.library.BuildConfig.java
uk.co.senab.actionbarpulltorefresh.library.DefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.DefaultHeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.EnvironmentDelegate.java
uk.co.senab.actionbarpulltorefresh.library.EnvironmentDelegate.java
uk.co.senab.actionbarpulltorefresh.library.HeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.HeaderTransformer.java
uk.co.senab.actionbarpulltorefresh.library.InstanceCreationUtils.java
uk.co.senab.actionbarpulltorefresh.library.InstanceCreationUtils.java
uk.co.senab.actionbarpulltorefresh.library.Options.java
uk.co.senab.actionbarpulltorefresh.library.Options.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout.java
uk.co.senab.actionbarpulltorefresh.library.listeners.HeaderViewListener.java
uk.co.senab.actionbarpulltorefresh.library.listeners.HeaderViewListener.java
uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener.java
uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatBase.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatBase.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV11.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV11.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV16.java
uk.co.senab.actionbarpulltorefresh.library.sdk.CompatV16.java
uk.co.senab.actionbarpulltorefresh.library.sdk.Compat.java
uk.co.senab.actionbarpulltorefresh.library.sdk.Compat.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.AbsListViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.AbsListViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ScrollYDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ScrollYDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.WebViewDelegate.java
uk.co.senab.actionbarpulltorefresh.library.viewdelegates.WebViewDelegate.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.BaseSampleActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.Constants.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.FragmentTabPager.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.FragmentTabsActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.FragmentTabsViewPagerActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.GridViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.ListViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.MainActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.ScrollViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarcompat.WebViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.BaseSampleActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.Constants.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.FragmentTabPager.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.FragmentTabsActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.FragmentTabsViewPagerActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.GridViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.ListViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.MainActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.ScrollViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock.WebViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.BaseSampleActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.Constants.java
uk.co.senab.actionbarpulltorefresh.samples.stock.FragmentTabsActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.GridViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.ListViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.MainActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.ScrollViewActivity.java
uk.co.senab.actionbarpulltorefresh.samples.stock.WebViewActivity.java