From 274108a3121870647db05ea9d7f1f3ccedefc8fd Mon Sep 17 00:00:00 2001 From: longerian Date: Sun, 6 Aug 2017 17:42:20 +0800 Subject: [PATCH 1/7] add api to reset bg --- .../vlayout/example/VLayoutActivity.java | 26 +++++- .../alibaba/android/vlayout/LayoutHelper.java | 8 ++ .../android/vlayout/LayoutManagerHelper.java | 7 ++ .../android/vlayout/VirtualLayoutManager.java | 18 ++++ .../vlayout/layout/BaseLayoutHelper.java | 40 +++++++++ .../vlayout/layout/FixAreaLayoutHelper.java | 7 ++ .../vlayout/layout/LinearLayoutHelper.java | 85 ++++++++++--------- .../vlayout/layout/RangeGridLayoutHelper.java | 5 ++ .../android/vlayout/layout/RangeStyle.java | 46 ++++++++++ 9 files changed, 198 insertions(+), 44 deletions(-) diff --git a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java index ed1fbb08..fe57e1f3 100644 --- a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java +++ b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java @@ -240,14 +240,34 @@ public void onBindViewHolder(MainViewHolder holder, int position) { if (LINEAR_LAYOUT) { LinearLayoutHelper layoutHelper1 = new LinearLayoutHelper(); + layoutHelper1.setBgColor(Color.YELLOW); layoutHelper1.setAspectRatio(2.0f); + layoutHelper1.setMargin(10, 10, 10, 10); + layoutHelper1.setPadding(10, 10, 10, 10); LinearLayoutHelper layoutHelper2 = new LinearLayoutHelper(); layoutHelper2.setAspectRatio(4.0f); layoutHelper2.setDividerHeight(10); - layoutHelper2.setMargin(10, 30, 10, 10); - layoutHelper2.setPadding(10, 30, 10, 10); + layoutHelper2.setMargin(10, 0, 10, 10); + layoutHelper2.setPadding(10, 0, 10, 10); layoutHelper2.setBgColor(0xFFF5A623); - adapters.add(new SubAdapter(this, layoutHelper1, 1)); + final Handler mainHandler = new Handler(Looper.getMainLooper()); + adapters.add(new SubAdapter(this, layoutHelper1, 1) { + @Override + public void onBindViewHolder(final MainViewHolder holder, int position) { + super.onBindViewHolder(holder, position); + final SubAdapter subAdapter = this; + //mainHandler.postDelayed(new Runnable() { + // @Override + // public void run() { + // //delegateAdapter.removeAdapter(subAdapter); + // //notifyItemRemoved(1); + // holder.itemView.setVisibility(View.GONE); + // notifyItemChanged(1); + // layoutManager.runAdjustLayout(); + // } + //}, 2000L); + } + }); adapters.add(new SubAdapter(this, layoutHelper2, 6) { @Override diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutHelper.java index 6c135e3b..64d43dff 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutHelper.java @@ -270,6 +270,14 @@ public abstract void afterLayout(RecyclerView.Recycler recycler, RecyclerView.St int startPosition, int endPosition, int scrolled, LayoutManagerHelper helper); + /** + * Run to adjust layoutHelper's background area + * @param startPosition + * @param endPosition + * @param helper + */ + public abstract void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper); + public void onItemsChanged(LayoutManagerHelper helper) { } diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutManagerHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutManagerHelper.java index f8b6a6a9..1f76d155 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutManagerHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/LayoutManagerHelper.java @@ -284,5 +284,12 @@ public interface LayoutManagerHelper { */ int findLastVisibleItemPosition(); + int getDecoratedLeft(View child); + + int getDecoratedTop(View child); + + int getDecoratedRight(View child); + + int getDecoratedBottom(View child); } diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java b/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java index 2c2ca144..6f3510fe 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java @@ -379,6 +379,24 @@ private void runPostLayout(RecyclerView.Recycler recycler, RecyclerView.State st } } + public void runAdjustLayout() { + final int startPosition = findFirstVisibleItemPosition(); + final LayoutHelper firstLayoutHelper = mHelperFinder.getLayoutHelper(startPosition); + final int endPosition = findLastVisibleItemPosition(); + final LayoutHelper lastLayoutHelper = mHelperFinder.getLayoutHelper(endPosition); + List totalLayoutHelpers = mHelperFinder.getLayoutHelpers(); + final int start = totalLayoutHelpers.indexOf(firstLayoutHelper); + final int end = totalLayoutHelpers.indexOf(lastLayoutHelper); + for (int i = start; i <= end; i++) { + try { + totalLayoutHelpers.get(i).adjustLayout(startPosition, endPosition, this); + } catch (Exception e) { + if (VirtualLayoutManager.sDebuggable) { + throw e; + } + } + } + } @Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/BaseLayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/BaseLayoutHelper.java index 89659466..526a77d9 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/BaseLayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/BaseLayoutHelper.java @@ -33,6 +33,7 @@ import android.graphics.Rect; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v7.widget.OrientationHelper; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; @@ -224,6 +225,45 @@ public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state } + @Override + public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) { + if (requireLayoutView()) { + View refer = null; + Rect tempRect = new Rect(); + final OrientationHelper orientationHelper = helper.getMainOrientationHelper(); + for (int i = 0; i < helper.getChildCount(); i++) { + refer = helper.getChildAt(i); + int anchorPos = helper.getPosition(refer); + if (getRange().contains(anchorPos)) { + if (refer.getVisibility() == View.GONE) { + tempRect.setEmpty(); + } else { + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) + refer.getLayoutParams(); + if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) { + tempRect.union(helper.getDecoratedLeft(refer) - params.leftMargin, + orientationHelper.getDecoratedStart(refer), + helper.getDecoratedRight(refer) + params.rightMargin, + orientationHelper.getDecoratedEnd(refer)); + } else { + tempRect.union(orientationHelper.getDecoratedStart(refer), + helper.getDecoratedTop(refer) - params.topMargin, orientationHelper.getDecoratedEnd(refer), + helper.getDecoratedBottom(refer) + params.bottomMargin); + } + } + } + } + if (!tempRect.isEmpty()) { + mLayoutRegion.set(tempRect.left - mPaddingLeft, tempRect.top - mPaddingTop, + tempRect.right + mPaddingRight, tempRect.bottom + mPaddingBottom); + } else { + mLayoutRegion.setEmpty(); + } + if (mLayoutView != null) { + mLayoutView.layout(mLayoutRegion.left, mLayoutRegion.top, mLayoutRegion.right, mLayoutRegion.bottom); + } + } + } /** * Called when {@link com.alibaba.android.vlayout.LayoutHelper} get dropped diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/FixAreaLayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/FixAreaLayoutHelper.java index 400b7990..e3ebbc60 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/FixAreaLayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/FixAreaLayoutHelper.java @@ -24,6 +24,8 @@ package com.alibaba.android.vlayout.layout; +import com.alibaba.android.vlayout.LayoutManagerHelper; + import android.view.View; import android.view.ViewPropertyAnimator; @@ -44,6 +46,11 @@ public void setFixViewAnimatorHelper( mFixViewAnimatorHelper = fixViewAnimatorHelper; } + @Override + public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) { + + } + public interface FixViewAnimatorHelper { ViewPropertyAnimator onGetFixViewAppearAnimator(View fixView); diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/LinearLayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/LinearLayoutHelper.java index e63bcff8..d5d81cba 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/LinearLayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/LinearLayoutHelper.java @@ -138,50 +138,53 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state helper.measureChildWithMargins(view, widthSpec, heightSpec); OrientationHelper orientationHelper = helper.getMainOrientationHelper(); - result.mConsumed = orientationHelper.getDecoratedMeasurement(view) + startSpace + endSpace + gap; - int left, top, right, bottom; - if (helper.getOrientation() == VERTICAL) { - // not support RTL now - if (helper.isDoLayoutRTL()) { - right = helper.getContentWidth() - helper.getPaddingRight() - mMarginRight - mPaddingRight; - left = right - orientationHelper.getDecoratedMeasurementInOther(view); - } else { - left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft; - right = left + orientationHelper.getDecoratedMeasurementInOther(view); - } - - // whether this layout pass is layout to start or to end - if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) { - // fill start, from bottom to top - bottom = layoutState.getOffset() - startSpace - (isStartLine ? 0 : mDividerHeight); - top = bottom - orientationHelper.getDecoratedMeasurement(view); - } else { - // fill end, from top to bottom - top = layoutState.getOffset() + startSpace + (isStartLine ? 0 : mDividerHeight); - bottom = top + orientationHelper.getDecoratedMeasurement(view); - } + if (view.getVisibility() == View.GONE) { + result.mConsumed = startSpace + endSpace + gap; } else { - top = helper.getPaddingTop() + mMarginTop + mPaddingTop; - bottom = top + orientationHelper.getDecoratedMeasurementInOther(view); - - if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) { - // fill left, from right to left - right = layoutState.getOffset() - startSpace - (isStartLine ? 0 : mDividerHeight); - left = right - orientationHelper.getDecoratedMeasurement(view); + result.mConsumed = orientationHelper.getDecoratedMeasurement(view) + startSpace + endSpace + gap; + int left, top, right, bottom; + if (helper.getOrientation() == VERTICAL) { + // not support RTL now + if (helper.isDoLayoutRTL()) { + right = helper.getContentWidth() - helper.getPaddingRight() - mMarginRight - mPaddingRight; + left = right - orientationHelper.getDecoratedMeasurementInOther(view); + } else { + left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft; + right = left + orientationHelper.getDecoratedMeasurementInOther(view); + } + + // whether this layout pass is layout to start or to end + if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) { + // fill start, from bottom to top + bottom = layoutState.getOffset() - startSpace - (isStartLine ? 0 : mDividerHeight); + top = bottom - orientationHelper.getDecoratedMeasurement(view); + } else { + // fill end, from top to bottom + top = layoutState.getOffset() + startSpace + (isStartLine ? 0 : mDividerHeight); + bottom = top + orientationHelper.getDecoratedMeasurement(view); + } } else { - // fill right, from left to right - left = layoutState.getOffset() + startSpace + (isStartLine ? 0 : mDividerHeight); - right = left + orientationHelper.getDecoratedMeasurement(view); + top = helper.getPaddingTop() + mMarginTop + mPaddingTop; + bottom = top + orientationHelper.getDecoratedMeasurementInOther(view); + + if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) { + // fill left, from right to left + right = layoutState.getOffset() - startSpace - (isStartLine ? 0 : mDividerHeight); + left = right - orientationHelper.getDecoratedMeasurement(view); + } else { + // fill right, from left to right + left = layoutState.getOffset() + startSpace + (isStartLine ? 0 : mDividerHeight); + right = left + orientationHelper.getDecoratedMeasurement(view); + } + } + // We calculate everything with View's bounding box (which includes decor and margins) + // To calculate correct layout position, we subtract margins. + layoutChild(view, left, top, right, bottom, helper); + if (DEBUG) { + Log.d(TAG, "laid out child at position " + helper.getPosition(view) + ", with l:" + + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" + + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin)); } - } - // We calculate everything with View's bounding box (which includes decor and margins) - // To calculate correct layout position, we subtract margins. - layoutChild(view, left, top, right, bottom, helper); - - if (DEBUG) { - Log.d(TAG, "laid out child at position " + helper.getPosition(view) + ", with l:" - + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" - + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin)); } handleStateOnResult(result, view); diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeGridLayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeGridLayoutHelper.java index 020d1a12..15f610b3 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeGridLayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeGridLayoutHelper.java @@ -697,6 +697,11 @@ public void afterLayout(Recycler recycler, State state, int startPosition, int e mRangeStyle.afterLayout(recycler, state, startPosition, endPosition, scrolled, helper); } + @Override + public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) { + mRangeStyle.adjustLayout(startPosition, endPosition, helper); + } + @Override public int computeAlignOffset(int offset, boolean isLayoutEnd, boolean useAnchor, LayoutManagerHelper helper) { final boolean layoutInVertical = helper.getOrientation() == VERTICAL; diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeStyle.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeStyle.java index 23c61f69..048489cf 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeStyle.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/RangeStyle.java @@ -13,6 +13,7 @@ import android.support.annotation.NonNull; import android.support.v4.util.ArrayMap; import android.support.v4.util.SimpleArrayMap; +import android.support.v7.widget.OrientationHelper; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; @@ -499,6 +500,51 @@ public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state } } + public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) { + if (!isChildrenEmpty()) { + for (int i = 0, size = mChildren.size(); i < size; i++) { + RangeStyle rangeStyle = mChildren.valueAt(i); + rangeStyle.adjustLayout(startPosition, endPosition, helper); + } + } + if (requireLayoutView()) { + View refer = null; + Rect tempRect = new Rect(); + final OrientationHelper orientationHelper = helper.getMainOrientationHelper(); + for (int i = 0; i < helper.getChildCount(); i++) { + refer = helper.getChildAt(i); + int anchorPos = helper.getPosition(refer); + if (getRange().contains(anchorPos)) { + if (refer.getVisibility() == View.GONE) { + tempRect.setEmpty(); + } else { + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) + refer.getLayoutParams(); + if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) { + tempRect.union(helper.getDecoratedLeft(refer) - params.leftMargin, + orientationHelper.getDecoratedStart(refer), + helper.getDecoratedRight(refer) + params.rightMargin, + orientationHelper.getDecoratedEnd(refer)); + } else { + tempRect.union(orientationHelper.getDecoratedStart(refer), + helper.getDecoratedTop(refer) - params.topMargin, orientationHelper.getDecoratedEnd(refer), + helper.getDecoratedBottom(refer) + params.bottomMargin); + } + } + } + } + if (!tempRect.isEmpty()) { + mLayoutRegion.set(tempRect.left - mPaddingLeft, tempRect.top - mPaddingTop, + tempRect.right + mPaddingRight, tempRect.bottom + mPaddingBottom); + } else { + mLayoutRegion.setEmpty(); + } + if (mLayoutView != null) { + mLayoutView.layout(mLayoutRegion.left, mLayoutRegion.top, mLayoutRegion.right, mLayoutRegion.bottom); + } + } + } + private void hideLayoutViews(LayoutManagerHelper helper) { if (isRoot()) { if (mLayoutView != null) { From e59e2df00901af967a6236d319f63284c734e83a Mon Sep 17 00:00:00 2001 From: longerian Date: Wed, 9 Aug 2017 21:09:18 +0800 Subject: [PATCH 2/7] add deploy script --- .gitignore | 4 +- build.gradle | 3 + jcenterDeploy.gradle | 151 ++++++++++++++++++++++++++++++++++++++++++ jcenterInstall.gradle | 66 ++++++++++++++++++ 4 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 jcenterDeploy.gradle create mode 100644 jcenterInstall.gradle diff --git a/.gitignore b/.gitignore index 82360df8..7a08bb31 100644 --- a/.gitignore +++ b/.gitignore @@ -48,5 +48,5 @@ target/ lint.xml deploy.gradle -jcenterDeploy.gradle -jcenterInstall.gradle \ No newline at end of file +#jcenterDeploy.gradle +#jcenterInstall.gradle \ No newline at end of file diff --git a/build.gradle b/build.gradle index a64b9256..8cb50e9e 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ buildscript { repositories { maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } + maven { url "http://oss.jfrog.org/oss-snapshot-local/" } mavenCentral() jcenter() } @@ -34,6 +35,7 @@ buildscript { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.github.xfumihiro.view-inspector:view-inspector-plugin:0.1.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' + classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } } @@ -41,6 +43,7 @@ buildscript { allprojects { repositories { maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } + maven { url "http://oss.jfrog.org/oss-snapshot-local/" } jcenter() mavenLocal() } diff --git a/jcenterDeploy.gradle b/jcenterDeploy.gradle new file mode 100644 index 00000000..fcb5618a --- /dev/null +++ b/jcenterDeploy.gradle @@ -0,0 +1,151 @@ +/* + * MIT License + * + * Copyright (c) 2017 Alibaba Group + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +apply plugin: 'com.jfrog.bintray' +apply plugin: 'com.jfrog.artifactory' + +version = libraryVersion + +if (project.hasProperty('deployVersion')) { + version = project.getProperty('deployVersion') +} + +if (project.hasProperty("android")) { // Android libraries + task sourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.srcDirs + } + +// task javadoc(type: Javadoc) { +// source = android.sourceSets.main.java.srcDirs +// classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + +// android.libraryVariants.all { variant -> +// println variant.javaCompile.classpath.files +// if(variant.name == 'release') { //我们只需 release 的 javadoc +// task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) { +// // title = '' +// // description = '' +// source = variant.javaCompile.source +// classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath()) +// options { +// encoding "utf-8" +// links "http://docs.oracle.com/javase/7/docs/api/" +// linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference" +// } +// exclude '**/BuildConfig.java' +// exclude '**/R.java' +// } +// task("javadoc${variant.name.capitalize()}Jar", type: Jar, dependsOn: "generate${variant.name.capitalize()}Javadoc") { +// classifier = 'javadoc' +// from tasks.getByName("generate${variant.name.capitalize()}Javadoc").destinationDir +// } +// artifacts { +// archives tasks.getByName("javadoc${variant.name.capitalize()}Jar") +// } +// } +// } +// +// } +} else { // Java libraries + task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + } +} + +//task javadocJar(type: Jar, dependsOn: javadoc) { +// classifier = 'javadoc' +// from javadoc.destinationDir +//} + +artifacts { +// archives javadocJar + archives sourcesJar +} + +// Bintray +//Properties properties = new Properties() +//properties.load(project.rootProject.file('local.properties').newDataInputStream()) + +bintray { +// user = properties.getProperty("bintray.user") +// key = properties.getProperty("bintray.apikey") + user = project.hasProperty('bintrayUser') ? project.getProperty('bintrayUser') : "" + key = project.hasProperty('bintrayApikey') ? project.getProperty('bintrayApikey') : "" + + configurations = ['archives'] + pkg { + repo = bintrayRepo + name = bintrayName + desc = libraryDescription + websiteUrl = siteUrl + vcsUrl = gitUrl + licenses = allLicenses + publish = true + publicDownloadNumbers = true + version { + desc = libraryDescription + gpg { + sign = true //Determines whether to GPG sign the files. The default is false +// passphrase = properties.getProperty("bintray.gpg.password") + passphrase = project.hasProperty('bintrayGPG') ? project.getProperty('bintrayGPG') : "" + //Optional. The passphrase for GPG signing' + } + } + } +} + +artifactory { + contextUrl = 'http://oss.jfrog.org/artifactory' //The base Artifactory URL if not overridden by the publisher/resolver + resolve { + repository { + repoKey = 'libs-release' + } + } + publish { + repository { + repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to + username = bintray.user + password = bintray.key + maven = true + } + defaults { +// the name is the same with that defined in bintray.configurations + publishConfigs('archives') + } + } +} + +bintrayUpload.onlyIf { + !version.endsWith("-SNAPSHOT") +} + +artifactoryPublish.onlyIf { + version.endsWith("-SNAPSHOT") +} + +task deploy(dependsOn: ['install', 'bintrayUpload', 'artifactoryPublish']) << { + println "deploy ...." +} \ No newline at end of file diff --git a/jcenterInstall.gradle b/jcenterInstall.gradle new file mode 100644 index 00000000..f7a7da46 --- /dev/null +++ b/jcenterInstall.gradle @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (c) 2017 Alibaba Group + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +apply plugin: 'com.github.dcendents.android-maven' + +group = GROUP + +install { + repositories.mavenInstaller { + // This generates POM.xml with proper parameters + pom { + project { + packaging 'aar' + groupId publishedGroupId + artifactId artifact + + // Add your description here + name libraryName + description libraryDescription + url siteUrl + + // Set your license + licenses { + license { + name licenseName + url licenseUrl + } + } + developers { + developer { + id developerId + name developerName + email developerEmail + } + } + scm { + connection gitUrl + developerConnection gitUrl + url siteUrl + + } + } + } + } +} \ No newline at end of file From 524dc639abdaafdd4923decdd2e273bdc52145e8 Mon Sep 17 00:00:00 2001 From: longerian Date: Fri, 11 Aug 2017 18:22:28 +0800 Subject: [PATCH 3/7] update gradle --- docs/VLayoutFAQ.md | 4 ++++ vlayout/build.gradle | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/VLayoutFAQ.md b/docs/VLayoutFAQ.md index 6bf8098f..bd32b39c 100644 --- a/docs/VLayoutFAQ.md +++ b/docs/VLayoutFAQ.md @@ -56,3 +56,7 @@ RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListen 在使用方的图片加载成功回调函数里设置一下图片加载成功的状态,可以自行维护一个map或者给View设置一个tag标记。 我们提供了一个简单的`DefaultLayoutViewHelper`封装了这个逻辑,可以参考使用。 + +## 在可滚动区域里嵌套使用vlayout的RecyclerView + +不太建议嵌套滚动,除非手势不冲突;如果要完全展开vlayout里的内容,牺牲滚动复用,可以调用`VirtualLayoutManager`的`public void setNestedScrolling(boolean nestedScrolling, int maxMeasureSize)`方法设置一下, 第一个参数为true,第二个参数是计算vlayout区域的最大高度(最终会修正成实际高度)。 \ No newline at end of file diff --git a/vlayout/build.gradle b/vlayout/build.gradle index 66bc5ff9..1a2e32cd 100644 --- a/vlayout/build.gradle +++ b/vlayout/build.gradle @@ -77,7 +77,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // compile project(':extension') - if (useNewSupportLibrary) { + if (useNewSupportLibrary == true) { compile 'com.android.support:recyclerview-v7:25.2.0@aar' compile('com.android.support:support-v4:25.2.0@aar') compile 'com.android.support:support-annotations:25.2.0' From 4654c819db80a9c2a4369d6fe0ed1a2e49cc3795 Mon Sep 17 00:00:00 2001 From: longerian Date: Fri, 11 Aug 2017 18:22:42 +0800 Subject: [PATCH 4/7] add api for delegateAdapter --- .../main/java/com/alibaba/android/vlayout/DelegateAdapter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/DelegateAdapter.java b/vlayout/src/main/java/com/alibaba/android/vlayout/DelegateAdapter.java index 1fbf37a1..dfee12cb 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/DelegateAdapter.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/DelegateAdapter.java @@ -414,6 +414,9 @@ public void clear() { mIndexAry.clear(); } + public int getAdaptersCount(){ + return mAdapters == null ? 0 : mAdapters.size(); + } @Nullable public Pair findAdapterByPosition(int position) { From 10ddf0aa383fbd72cd4953b9220afda604d7e776 Mon Sep 17 00:00:00 2001 From: longerian Date: Sat, 12 Aug 2017 14:07:23 +0800 Subject: [PATCH 5/7] update FAQ --- docs/VLayoutFAQ.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/VLayoutFAQ.md b/docs/VLayoutFAQ.md index bd32b39c..577afa53 100644 --- a/docs/VLayoutFAQ.md +++ b/docs/VLayoutFAQ.md @@ -59,4 +59,8 @@ RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListen ## 在可滚动区域里嵌套使用vlayout的RecyclerView -不太建议嵌套滚动,除非手势不冲突;如果要完全展开vlayout里的内容,牺牲滚动复用,可以调用`VirtualLayoutManager`的`public void setNestedScrolling(boolean nestedScrolling, int maxMeasureSize)`方法设置一下, 第一个参数为true,第二个参数是计算vlayout区域的最大高度(最终会修正成实际高度)。 \ No newline at end of file +不太建议嵌套滚动,除非手势不冲突;如果要完全展开vlayout里的内容,牺牲滚动复用,可以调用`VirtualLayoutManager`的`setNoScrolling(true);`方法设置一下。 + +## 为GridLayoutHelper的设置自定义SpanSizeLookup + +在SpanSizeLookup中,public int getSpanSize(int position)方法参数的position是整个页面的position信息,需要获取当前layoutHelper内的相对位置,需要减去一个偏移量,即position - getStartPosition()。 \ No newline at end of file From ab149b3e0c00f42254cac3b1f66bbf96ad0bd154 Mon Sep 17 00:00:00 2001 From: longerian Date: Sat, 12 Aug 2017 16:31:50 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix=20#164=EF=BC=8Ccheck=20for=20gaps=20whe?= =?UTF-8?q?n=20staggedGridLayout=20state=20changed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layout/StaggeredGridLayoutHelper.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java index e6738070..8bc1fa1a 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java @@ -30,6 +30,7 @@ import java.util.BitSet; import com.alibaba.android.vlayout.BuildConfig; +import com.alibaba.android.vlayout.LayoutHelper; import com.alibaba.android.vlayout.LayoutManagerHelper; import com.alibaba.android.vlayout.Range; import com.alibaba.android.vlayout.VirtualLayoutManager; @@ -193,7 +194,7 @@ public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state if (!state.isPreLayout() && helper.getChildCount() > 0) { // call after doing layout, to check whether there is a gap between staggered layout and other layouts // TODO ask for help? why there's a gap here, as far as know, it happens only when there's a sticky upon staggered which is in abnormal status - //ViewCompat.postOnAnimation(helper.getChildAt(0), checkForGapsRunnable); comment by longerian + ViewCompat.postOnAnimation(helper.getChildAt(0), checkForGapsRunnable); //comment by longerian } } @@ -382,7 +383,7 @@ public void onScrollStateChanged(int state, int startPosition, } if (state == RecyclerView.SCROLL_STATE_IDLE) { - //checkForGaps(); + checkForGaps(); } } @@ -512,6 +513,22 @@ private void checkForGaps() { View child = layoutManager.getChildAt(i - 1); alignLine = orientationHelper.getDecoratedEnd(child) + layoutManager.obtainExtraMargin(child, true) - layoutManager.obtainExtraMargin(view, false); + int viewStart = orientationHelper.getDecoratedStart(view); + if (alignLine == viewStart) { + //actually not gap here skip; + viewAnchor = Integer.MIN_VALUE; + } else { + int nextPosition = layoutManager.getPosition(child); + if (nextPosition != alignPos - 1) { + //may has sticky layout, add extra space occur by stickyLayoutHelper + LayoutHelper layoutHelper = layoutManager.findLayoutHelperByPosition(alignPos - 1); + if (layoutHelper != null && layoutHelper instanceof StickyLayoutHelper) { + if (layoutHelper.getFixedView() != null) { + alignLine += layoutHelper.getFixedView().getMeasuredHeight(); + } + } + } + } } break; } From 6f7a24c678e7cd5cd9f1d605cfa45841c5ec35c5 Mon Sep 17 00:00:00 2001 From: longerian Date: Sat, 12 Aug 2017 18:19:11 +0800 Subject: [PATCH 7/7] update demo --- examples/build.gradle | 1 + .../vlayout/example/VLayoutActivity.java | 33 ++++++++------- examples/src/main/res/layout/card_item.xml | 41 +++++++++++++++++++ .../layout/StaggeredGridLayoutHelper.java | 3 +- 4 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 examples/src/main/res/layout/card_item.xml diff --git a/examples/build.gradle b/examples/build.gradle index d4e67f41..ad01da20 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -54,4 +54,5 @@ dependencies { compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.android.support:support-annotations:21.0.0' + compile 'com.android.support:cardview-v7:23.1.1' } diff --git a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java index fe57e1f3..55b449e7 100644 --- a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java +++ b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java @@ -295,22 +295,25 @@ public void onBindViewHolder(MainViewHolder holder, int position) { adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } + //{ + // final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(3, 10); + // helper.setBgColor(0xFF86345A); + // adapters.add(new SubAdapter(this, helper, 4) { + // + // @Override + // public void onBindViewHolder(MainViewHolder holder, int position) { + // super.onBindViewHolder(holder, position); + // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); + // if (position % 2 == 0) { + // layoutParams.mAspectRatio = 1.0f; + // } else { + // layoutParams.height = 340 + position % 7 * 20; + // } + // holder.itemView.setLayoutParams(layoutParams); + // } + // }); + //} { - //final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(3, 10); - //helper.setBgColor(0xFF86345A); - //adapters.add(new SubAdapter(this, helper, 4) { - // @Override - // public void onBindViewHolder(MainViewHolder holder, int position) { - // super.onBindViewHolder(holder, position); - // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); - // if (position % 2 == 0) { - // layoutParams.mAspectRatio = 1.0f; - // } else { - // layoutParams.height = 340 + position % 7 * 20; - // } - // holder.itemView.setLayoutParams(layoutParams); - // } - //}); final GridLayoutHelper helper = new GridLayoutHelper(3, 4); helper.setBgColor(0xFF86345A); diff --git a/examples/src/main/res/layout/card_item.xml b/examples/src/main/res/layout/card_item.xml new file mode 100644 index 00000000..88a22649 --- /dev/null +++ b/examples/src/main/res/layout/card_item.xml @@ -0,0 +1,41 @@ + + + + + + + \ No newline at end of file diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java index 8bc1fa1a..75930305 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/layout/StaggeredGridLayoutHelper.java @@ -193,8 +193,7 @@ public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state } if (!state.isPreLayout() && helper.getChildCount() > 0) { // call after doing layout, to check whether there is a gap between staggered layout and other layouts - // TODO ask for help? why there's a gap here, as far as know, it happens only when there's a sticky upon staggered which is in abnormal status - ViewCompat.postOnAnimation(helper.getChildAt(0), checkForGapsRunnable); //comment by longerian + ViewCompat.postOnAnimation(helper.getChildAt(0), checkForGapsRunnable); } }