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//www.java2s.com
*
* 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;
/**
* Allows you to specify a number of configuration options when setting up a {@link PullToRefreshLayout}.
*/publicfinalclass Options {
/* Default configuration values */privatestaticfinalint DEFAULT_HEADER_LAYOUT = R.layout.default_header;
privatestaticfinalfloat DEFAULT_REFRESH_SCROLL_DISTANCE = 0.5f;
privatestaticfinalboolean DEFAULT_REFRESH_ON_UP = false;
privatestaticfinalint DEFAULT_REFRESH_MINIMIZED_DELAY = 1 * 1000;
privatestaticfinalboolean DEFAULT_REFRESH_MINIMIZE = true;
publicstatic Builder create() {
returnnew Builder();
}
Options() {}
EnvironmentDelegate environmentDelegate = null;
int headerLayout = DEFAULT_HEADER_LAYOUT;
HeaderTransformer headerTransformer = null;
float refreshScrollDistance = DEFAULT_REFRESH_SCROLL_DISTANCE;
boolean refreshOnUp = DEFAULT_REFRESH_ON_UP;
int refreshMinimizeDelay = DEFAULT_REFRESH_MINIMIZED_DELAY;
/**
* Enable or disable the header 'minimization', which by default means that the majority of
* the header is hidden, leaving only the progress bar still showing.
* <p/>
* If set to true, the header will be minimized after the delay set in
* {@link #refreshMinimizeDelay}. If set to false then the whole header will be displayed
* until the refresh is finished.
*/boolean refreshMinimize = DEFAULT_REFRESH_MINIMIZE;
publicstaticclass Builder {
final Options mOptions = new Options();
/**
* EnvironmentDelegate instance which will be used. If null, we will
* create an instance of the default class.
*/public Builder environmentDelegate(EnvironmentDelegate environmentDelegate) {
mOptions.environmentDelegate = environmentDelegate;
returnthis;
}
/**
* The layout resource ID which should be inflated to be displayed above
* the Action Bar
*/public Builder headerLayout(int headerLayoutId) {
mOptions.headerLayout = headerLayoutId;
returnthis;
}
/**
* The header transformer to be used to transfer the header view. If
* null, an instance of {@link DefaultHeaderTransformer} will be used.
*/public Builder headerTransformer(HeaderTransformer headerTransformer) {
mOptions.headerTransformer = headerTransformer;
returnthis;
}
/**
* The percentage of the refreshable view that needs to be scrolled
* before a refresh is initiated.
*/public Builder scrollDistance(float refreshScrollDistance) {
mOptions.refreshScrollDistance = refreshScrollDistance;
returnthis;
}
/**
* Whether a refresh should only be initiated when the user has finished
* the touch event.
*/public Builder refreshOnUp(boolean enabled) {
mOptions.refreshOnUp = enabled;
returnthis;
}
/**
* Disable the header 'minimization', which by default means that the majority of
* the header is hidden, leaving only the progress bar still showing.
*/public Builder noMinimize() {
mOptions.refreshMinimize = false;
returnthis;
}
/**
* Enable header 'minimization', which by default means that the majority of
* the header is hidden, leaving only the progress bar still showing.
*/public Builder minimize() {
return minimize(DEFAULT_REFRESH_MINIMIZED_DELAY);
}
/**
* Enable header 'minimization' and set the delay.
*/public Builder minimize(int delay) {
mOptions.refreshMinimizeDelay = delay;
mOptions.refreshMinimize = true;
returnthis;
}
/**
* @return the built {@link Options} instance.
*/public Options build() {
return mOptions;
}
}
}