下面列出了怎么用android.support.v4.view.NestedScrollingChildHelper的API类实例代码及写法,或者点击链接到github查看源代码。
public NestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.mTempRect = new Rect();
this.mIsLayoutDirty = true;
this.mIsLaidOut = false;
this.mChildToScrollTo = null;
this.mIsBeingDragged = false;
this.mSmoothScrollingEnabled = true;
this.mActivePointerId = -1;
this.mScrollOffset = new int[2];
this.mScrollConsumed = new int[2];
initScrollView();
TypedArray a = context.obtainStyledAttributes(attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);
setFillViewport(a.getBoolean(0, false));
a.recycle();
this.mParentHelper = new NestedScrollingParentHelper(this);
this.mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
ViewCompat.setAccessibilityDelegate(this, ACCESSIBILITY_DELEGATE);
}
public NestedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
WebSettings webSettings = getSettings();
webSettings.setJavaScriptEnabled(true);
// 通过注入方法,优化横滑体验
addJavascriptInterface(new NestScrollHelper(), "Android_NestScrollHelper");
// 不过渡滑动
setOverScrollMode(OVER_SCROLL_NEVER);
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
mScroller = new OverScroller(getContext());
}
/**
*/
@SuppressWarnings("deprecation")
public AbsRefreshLayout(View listView) {
this(listView.getContext());
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
mTargetView = listView;
ViewGroup group = (ViewGroup) mTargetView.getParent();
if (group != null) {
LayoutParams params = mTargetView.getLayoutParams();
int index = group.indexOfChild(listView);
group.removeView(listView);
group.addView(this, index, params);
}
mTargetView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
super.addView(mTargetView);
}
/**
* @param context
* @param attrs
* @param defStyleAttr
*/
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
mScroller = new Scroller(context, new DecelerateInterpolator());
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.AbsRefreshLayout, defStyleAttr, 0);
final int N = a.getIndexCount();
int resFooter = R.layout.layout_loadmore;
for (int i = 0; i < N; i++) {
int attr = a.getIndex(i);
if (attr == R.styleable.AbsRefreshLayout_footerNestLayout) {
resFooter = a.getResourceId(attr, resFooter);
break;
}
}
a.recycle();
/**
* Convert values in dp to values in px;
*/
setFooterView(inflate(context, resFooter, null));
}
public NestedFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
mParentHelper = new NestedScrollingParentHelper(this);
setNestedScrollingEnabled(true);
}
public LWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mScroller = new Scroller(getContext());
mChildHelper = new NestedScrollingChildHelper(this);
mPosIndicator = new PosIndicator(false);
ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
mPosIndicator.setTouchSlop(viewConfiguration.getScaledTouchSlop());
DENSITY = context.getResources().getDisplayMetrics().density;
mMaximumVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
mMinimumVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
setNestedScrollingEnabled(true);
}
public CommentExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setNestedScrollingEnabled(true);
}
}
public CommentExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setNestedScrollingEnabled(true);
}
}
public TwinklingRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TwinklingRefreshLayout, defStyleAttr, 0);
try {
mMaxHeadHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_max_head_height, (int) DensityUtil.dp2px(context, 120));
mHeadHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_head_height, (int) DensityUtil.dp2px(context, 80));
mMaxBottomHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_max_bottom_height, (int) DensityUtil.dp2px(context, 120));
mBottomHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_bottom_height, (int) DensityUtil.dp2px(context, 60));
mOverScrollHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_overscroll_height, (int) mHeadHeight);
enableRefresh = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_refresh, true);
enableLoadmore = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_loadmore, true);
isPureScrollModeOn = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_pureScrollMode_on, false);
isOverScrollTopShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_top_show, true);
isOverScrollBottomShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_bottom_show, true);
enableOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_overscroll, true);
floatRefresh = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_floatRefresh, false);
autoLoadMore = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_autoLoadMore, false);
enableKeepIView = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_keepIView, true);
showRefreshingWhenOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_showRefreshingWhenOverScroll, true);
showLoadingWhenOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_showLoadingWhenOverScroll, true);
} finally {
a.recycle();
}
cp = new CoContext();
addHeader();
addFooter();
setFloatRefresh(floatRefresh);
setAutoLoadMore(autoLoadMore);
setEnableRefresh(enableRefresh);
setEnableLoadmore(enableLoadmore);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
private void init() {
setWillNotDraw(false);
startScrollerTask();
setOverScrollMode(View.OVER_SCROLL_NEVER);
childHelper = new NestedScrollingChildHelper(this);
childHelper.setNestedScrollingEnabled(true);
}
/**
* Constructor that is called when inflating ISwipeRefreshLayout from XML.
*
* @param context
* @param attrs
*/
public ISwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mMediumAnimationDuration = getResources().getInteger(
android.R.integer.config_mediumAnimTime);
setWillNotDraw(false);
mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
final DisplayMetrics metrics = getResources().getDisplayMetrics();
mRefreshViewHeight = (int) (DEFAULT_HEADER_HEIGHT * metrics.density);
HEADER_VIEW_MIN_HEIGHT = mRefreshViewHeight;
ViewCompat.setChildrenDrawingOrderEnabled(this, true);
mTotalDragDistance = (int) (DEFAULT_HEADER_TARGET * metrics.density);
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
setEnabled(a.getBoolean(0, true));
a.recycle();
//add default refreshview
setRefreshHeaderView(new ClassicIRefreshHeaderView(getContext()));
}
private void i() {
helper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
// Add a dummy view that will receive inner touch events.
View dummyView = new View(getContext());
dummyBehavior = new DummyBehavior();
// I *think* this is needed for dummyView to be identified as "topmost" and receive events
// before any other view.
ViewCompat.setElevation(dummyView, ViewCompat.getElevation(this));
// Make sure it does not fit windows, or it will consume insets before the AppBarLayout.
dummyView.setFitsSystemWindows(false);
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.setBehavior(dummyBehavior);
addView(dummyView, params);
}
/**
* Constructor that is called when inflating SwipeRefreshLayout from XML.
*
* @param context
* @param attrs
*/
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mMediumAnimationDuration = getResources().getInteger(
android.R.integer.config_mediumAnimTime);
setWillNotDraw(false);
mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
final DisplayMetrics metrics = getResources().getDisplayMetrics();
mCircleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);
createProgressView();
ViewCompat.setChildrenDrawingOrderEnabled(this, true);
// the absolute offset has to take into account that the circle starts at an offset
mSpinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density);
mTotalDragDistance = mSpinnerOffsetEnd;
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
mOriginalOffsetTop = mCurrentTargetOffsetTop = -mCircleDiameter;
moveToStart(1.0f);
final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
setEnabled(a.getBoolean(0, true));
a.recycle();
}
private void init() {
setWillNotDraw(false);
startScrollerTask();
setOverScrollMode(View.OVER_SCROLL_NEVER);
childHelper = new NestedScrollingChildHelper(this);
childHelper.setNestedScrollingEnabled(true);
}
public TwinklingRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TwinklingRefreshLayout, defStyleAttr, 0);
try {
mMaxHeadHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_max_head_height, (int) DensityUtil.dp2px(context, 120));
mHeadHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_head_height, (int) DensityUtil.dp2px(context, 80));
mMaxBottomHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_max_bottom_height, (int) DensityUtil.dp2px(context, 120));
mBottomHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_bottom_height, (int) DensityUtil.dp2px(context, 60));
mOverScrollHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_overscroll_height, (int) mHeadHeight);
enableRefresh = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_refresh, true);
enableLoadmore = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_loadmore, true);
isPureScrollModeOn = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_pureScrollMode_on, false);
isOverScrollTopShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_top_show, true);
isOverScrollBottomShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_bottom_show, true);
enableOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_overscroll, true);
floatRefresh = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_floatRefresh, false);
autoLoadMore = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_autoLoadMore, false);
enableKeepIView = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_keepIView, true);
showRefreshingWhenOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_showRefreshingWhenOverScroll, true);
showLoadingWhenOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_showLoadingWhenOverScroll, true);
} finally {
a.recycle();
}
cp = new CoContext();
addHeader();
addFooter();
setFloatRefresh(floatRefresh);
setAutoLoadMore(autoLoadMore);
setEnableRefresh(enableRefresh);
setEnableLoadmore(enableLoadmore);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
public NestedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
final ViewConfiguration vc = ViewConfiguration.get(context);
mTouchSlop = vc.getScaledTouchSlop();
}
private void initAttrs(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.QRefreshLayout);
float resistance = typedArray.getFloat(R.styleable.QRefreshLayout_resistance, 0.65f);
setResistance(resistance);
typedArray.recycle();
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
mNestedChildHelper = new NestedScrollingChildHelper(this);
mNestedParentHelper = new NestedScrollingParentHelper(this);
mParentOffsetInWindow = new int[2];
}
private void init() {
setWillNotDraw(false);
startScrollerTask();
setOverScrollMode(View.OVER_SCROLL_NEVER);
childHelper = new NestedScrollingChildHelper(this);
childHelper.setNestedScrollingEnabled(true);
}
private void init() {
this.mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
ViewConfiguration configuration = ViewConfiguration.get(getContext());
this.mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
this.mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
this.mTouchSlop = configuration.getScaledTouchSlop();
this.directionDetector = new DirectionDetector();
this.density = getScale();
setOverScrollMode(View.OVER_SCROLL_NEVER);
this.settings = getSettings();
// addJavascriptInterface(new JSGetContentHeight(), "InjectedObject");
Log.i(TAG, "max -- min Velocity = " + this.mMaximumVelocity + " -- " + this.mMinimumVelocity + " touchSlop = " + this.mTouchSlop);
}
public HeaderRefreshLayout(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
header = new TouchCircleView(getContext());
header.addLoadingListener(this);
float density = context.getResources().getDisplayMetrics().density;
addView(header, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (density * 120)));
}
public HeadViewFrameLayout(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
public PullHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
int headerHeight = DEFAULT_HEIGHT;
int headerExpandHeight = DEFAULT_EXPAND;
int headerShrinkHeight = DEFAULT_SHRINK;
if (attrs != null) {
TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.PullHeaderLayout);
headerHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_height,
DEFAULT_HEIGHT);
headerExpandHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_expand_height,
DEFAULT_EXPAND);
headerShrinkHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_shrink_height,
DEFAULT_SHRINK);
mHeaderId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_header, mHeaderId);
mContentId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_content, mContentId);
mActionDrawable = arr.getDrawable(R.styleable.PullHeaderLayout_phl_action);
arr.recycle();
}
mHeaderController = new HeaderController(headerHeight, headerExpandHeight, headerShrinkHeight);
final ViewConfiguration conf = ViewConfiguration.get(getContext());
mParentHelper = new NestedScrollingParentHelper(this);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
init();
}
public NestedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOverScrollMode(WebView.OVER_SCROLL_NEVER);
initScrollView();
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
private void initView(Context context, AttributeSet attrs) {
setClipToPadding(false);
mScreenHeightPixels = context.getResources().getDisplayMetrics().heightPixels;
mReboundInterpolator = new ViscousFluidInterpolator();
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
DensityUtil density = new DensityUtil();
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SmartRefreshLayout);
ViewCompat.setNestedScrollingEnabled(this, ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableNestedScrolling, false));
mDragRate = ta.getFloat(R.styleable.SmartRefreshLayout_srlDragRate, mDragRate);
mHeaderMaxDragRate = ta.getFloat(R.styleable.SmartRefreshLayout_srlHeaderMaxDragRate, mHeaderMaxDragRate);
mFooterMaxDragRate = ta.getFloat(R.styleable.SmartRefreshLayout_srlFooterMaxDragRate, mFooterMaxDragRate);
mEnableRefresh = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableRefresh, mEnableRefresh);
mReboundDuration = ta.getInt(R.styleable.SmartRefreshLayout_srlReboundDuration, mReboundDuration);
mEnableLoadmore = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableLoadmore, mEnableLoadmore);
mHeaderHeight = ta.getDimensionPixelOffset(R.styleable.SmartRefreshLayout_srlHeaderHeight, density.dip2px(100));
mFooterHeight = ta.getDimensionPixelOffset(R.styleable.SmartRefreshLayout_srlFooterHeight, density.dip2px(60));
mDisableContentWhenRefresh = ta.getBoolean(R.styleable.SmartRefreshLayout_srlDisableContentWhenRefresh, mDisableContentWhenRefresh);
mDisableContentWhenLoading = ta.getBoolean(R.styleable.SmartRefreshLayout_srlDisableContentWhenLoading, mDisableContentWhenLoading);
mEnableHeaderTranslationContent = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableHeaderTranslationContent, mEnableHeaderTranslationContent);
mEnableFooterTranslationContent = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableFooterTranslationContent, mEnableFooterTranslationContent);
mEnablePreviewInEditMode = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnablePreviewInEditMode, mEnablePreviewInEditMode);
mEnableAutoLoadmore = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableAutoLoadmore, mEnableAutoLoadmore);
mEnableOverScrollBounce = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableAutoLoadmore, mEnableOverScrollBounce);
mEnablePureScrollMode = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnablePureScrollMode, mEnablePureScrollMode);
mEnableScrollContentWhenLoaded = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableScrollContentWhenLoaded, mEnableScrollContentWhenLoaded);
mFixedHeaderViewId = ta.getResourceId(R.styleable.SmartRefreshLayout_srlFixedHeaderViewId, View.NO_ID);
mFixedFooterViewId = ta.getResourceId(R.styleable.SmartRefreshLayout_srlFixedFooterViewId, View.NO_ID);
mManualLoadmore = ta.hasValue(R.styleable.SmartRefreshLayout_srlEnableLoadmore);
mManualNestedScrolling = ta.hasValue(R.styleable.SmartRefreshLayout_srlEnableNestedScrolling);
mHeaderHeightStatus = ta.hasValue(R.styleable.SmartRefreshLayout_srlHeaderHeight) ? DimensionStatus.XmlLayoutUnNotify : mHeaderHeightStatus;
mFooterHeightStatus = ta.hasValue(R.styleable.SmartRefreshLayout_srlFooterHeight) ? DimensionStatus.XmlLayoutUnNotify : mFooterHeightStatus;
mFooterExtendHeight = (int) Math.max((mFooterHeight * (mHeaderMaxDragRate - 1)), 0);
mHeaderExtendHeight = (int) Math.max((mHeaderHeight * (mHeaderMaxDragRate - 1)), 0);
int accentColor = ta.getColor(R.styleable.SmartRefreshLayout_srlAccentColor, 0);
int primaryColor = ta.getColor(R.styleable.SmartRefreshLayout_srlPrimaryColor, 0);
if (primaryColor != 0) {
if (accentColor != 0) {
mPrimaryColors = new int[]{primaryColor, accentColor};
} else {
mPrimaryColors = new int[]{primaryColor};
}
}
ta.recycle();
}
private void init() {
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
private void init() {
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
/**
* @see WebView(Context, AttributeSet, int)
*/
public ProWebView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
scrollChildHelper = new NestedScrollingChildHelper(this);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ProWebView);
try {
setAboutBlankHtml(array.getString(R.styleable.ProWebView_blankHtml));
setHomeUrl(array.getString(R.styleable.ProWebView_home));
CharSequence[] blacklist = array.getTextArray(R.styleable.ProWebView_blacklist);
if (blacklist!=null) {
for (CharSequence sequence : blacklist)
this.blacklist.add(sequence.toString());
}
setPrivateBrowsingEnabled(array.getBoolean(R.styleable.ProWebView_privateMode, false));
blockAds(array.getBoolean(R.styleable.ProWebView_blockAds, false));
setGeolocationEnabled(array.getBoolean(R.styleable.ProWebView_locationEnabled, false));
getSettings().setJavaScriptEnabled(array.getBoolean(R.styleable.ProWebView_javascriptEnabled, true));
switch (array.getInt(R.styleable.ProWebView_locationMode, 1)){
case 1:
setLocationMode(LocationMode.MODE_BOTH);
break;
case 2:
setLocationMode(LocationMode.MODE_FINE);
break;
case 3:
setLocationMode(LocationMode.MODE_COARSE);
break;
}
setCookiesEnabled(array.getBoolean(R.styleable.ProWebView_cookiesEnabled, true));
if (Build.VERSION.SDK_INT>=21)
setThirdPartyCookiesEnabled(array.getBoolean(R.styleable.ProWebView_thirdPartyCookiesEnabled, true));
switch (array.getInt(R.styleable.ProWebView_cacheMode, 3)) {
case 1:
getSettings().setCacheMode(LOAD_CACHE_ELSE_NETWORK);
break;
case 2:
getSettings().setCacheMode(LOAD_CACHE_ONLY);
break;
case 3:
getSettings().setCacheMode(LOAD_DEFAULT);
break;
case 4:
getSettings().setCacheMode(LOAD_NO_CACHE);
break;
}
setNestedScrollingEnabled(array.getBoolean(R.styleable.ProWebView_nestedScrollingEnabled, true));
String protocol = array.getString(R.styleable.ProWebView_defaultProtocol);
if (protocol!=null)
setDefaultProtocol(protocol);
} finally {
array.recycle();
}
}
public NestedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
public ListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
public ListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}