diff --git a/build.gradle b/build.gradle index 676f50a4..7dbb6afb 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,8 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:2.3.0' + } } diff --git a/demo/build.gradle b/demo/build.gradle index 36e00617..84db41a7 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 21 - buildToolsVersion "21.0.1" + buildToolsVersion "25.0.0" lintOptions { abortOnError false diff --git a/demo/src/com/sothree/slidinguppanel/demo/DemoActivity.java b/demo/src/com/sothree/slidinguppanel/demo/DemoActivity.java index d06a4229..f1f4820b 100644 --- a/demo/src/com/sothree/slidinguppanel/demo/DemoActivity.java +++ b/demo/src/com/sothree/slidinguppanel/demo/DemoActivity.java @@ -1,5 +1,9 @@ package com.sothree.slidinguppanel.demo; +import com.sothree.slidinguppanel.SlidingUpPanelLayout; +import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelSlideListener; +import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState; + import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -15,10 +19,6 @@ import android.widget.Button; import android.widget.TextView; -import com.sothree.slidinguppanel.SlidingUpPanelLayout; -import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelSlideListener; -import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState; - public class DemoActivity extends ActionBarActivity { private static final String TAG = "DemoActivity"; diff --git a/gradle.properties b/gradle.properties index 85cc1038..e4378188 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -VERSION_NAME=3.0.0 -VERSION_CODE=10 +VERSION_NAME=tt3.0.2-SNAPSHOT +VERSION_CODE=11 GROUP=com.sothree.slidinguppanel POM_DESCRIPTION=Android Sliding Up Panel Library diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2769648d..78875f93 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index 88689f1a..5c152e69 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,7 +5,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:1.1.0' } } @@ -20,7 +20,7 @@ dependencies { android { compileSdkVersion 21 - buildToolsVersion "21.0.1" + buildToolsVersion "25.0.0" lintOptions { abortOnError false } @@ -34,5 +34,10 @@ android { } } } - -apply from: '../maven_push.gradle' +// +apply from: 'maven_push.gradle' +task printProperties << { + println POM_DESCRIPTION // Local extra property + println version // Local extra property + println POM_NAME +} \ No newline at end of file diff --git a/library/maven_push.gradle b/library/maven_push.gradle new file mode 100644 index 00000000..3443460d --- /dev/null +++ b/library/maven_push.gradle @@ -0,0 +1,82 @@ +apply plugin: 'maven' +apply plugin: 'signing' + +def sonatypeRepositoryUrl +if (isReleaseBuild()) { + println 'RELEASE BUILD' + sonatypeRepositoryUrl = "http://nexus.huayu.nd/nexus/content/repositories/releases/" +} else { + println 'DEBUG BUILD' + sonatypeRepositoryUrl = "http://nexus.huayu.nd/nexus/content/repositories/snapshots/" +} + +afterEvaluate { project -> + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + pom.artifactId = POM_ARTIFACT_ID + + repository(url: sonatypeRepositoryUrl) { + authentication(userName: "deployment", password: "deployment123") + } + + pom.project { + name POM_NAME + packaging POM_PACKAGING + description POM_DESCRIPTION + url POM_URL + + scm { + url POM_SCM_URL + connection POM_SCM_CONNECTION + developerConnection POM_SCM_DEV_CONNECTION + } + + licenses { + license { + name POM_LICENCE_NAME + url POM_LICENCE_URL + distribution POM_LICENCE_DIST + } + } + + developers { + developer { + id POM_DEVELOPER_ID + name POM_DEVELOPER_NAME + } + } + } + } + } + } + + signing { + required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives + } + + task androidJavadocs(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + } + + task androidJavadocsJar(type: Jar) { + classifier = 'javadoc' + //basename = artifact_id + from androidJavadocs.destinationDir + } + + task androidSourcesJar(type: Jar) { + classifier = 'sources' + //basename = artifact_id + from android.sourceSets.main.java.srcDirs + } + + artifacts { + //archives packageReleaseJar + archives androidSourcesJar + archives androidJavadocsJar + } +} diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml index 2605d92e..6ad7367e 100644 --- a/library/res/values/attrs.xml +++ b/library/res/values/attrs.xml @@ -4,6 +4,10 @@ + + + + @@ -11,7 +15,12 @@ + + + + + diff --git a/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java b/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java index d0643a98..0624d8c8 100644 --- a/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java +++ b/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java @@ -1,5 +1,8 @@ package com.sothree.slidinguppanel; +import com.nineoldandroids.view.animation.AnimatorProxy; +import com.sothree.slidinguppanel.library.R; + import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; @@ -14,14 +17,17 @@ import android.support.v4.view.MotionEventCompat; import android.support.v4.view.ViewCompat; import android.util.AttributeSet; +import android.util.DisplayMetrics; import android.view.Gravity; import android.view.MotionEvent; +import android.view.VelocityTracker; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.view.accessibility.AccessibilityEvent; +import android.widget.ListView; -import com.nineoldandroids.view.animation.AnimatorProxy; -import com.sothree.slidinguppanel.library.R; +import java.lang.reflect.Field; public class SlidingUpPanelLayout extends ViewGroup { @@ -55,20 +61,23 @@ public class SlidingUpPanelLayout extends ViewGroup { /** * Default Minimum velocity that will be detected as a fling */ - private static final int DEFAULT_MIN_FLING_VELOCITY = 400; // dips per second + private static final int DEFAULT_MIN_FLING_VELOCITY = 400; // 400 dips per second + /** * Default is set to false because that is how it was written */ private static final boolean DEFAULT_OVERLAY_FLAG = false; + /** * Default is set to true for clip panel for performance reasons */ private static final boolean DEFAULT_CLIP_PANEL_FLAG = true; + /** * Default attributes for layout */ - private static final int[] DEFAULT_ATTRS = new int[] { - android.R.attr.gravity + private static final int[] DEFAULT_ATTRS = new int[]{ + android.R.attr.gravity }; /** @@ -101,6 +110,14 @@ public class SlidingUpPanelLayout extends ViewGroup { */ private int mPanelHeight = -1; + private int mContenHeight = -1; + + private int mOtherHeight = -1; + + private int mScreenHeight; + + private int mVscreenHeight = 0; + /** * The size of the shadow in pixels. */ @@ -138,6 +155,12 @@ public class SlidingUpPanelLayout extends ViewGroup { */ private int mDragViewResId = -1; + + private int mInnerScrollViewId = -1; + + + private int mViewContentResId = -1; + /** * The child view that can slide, if any. */ @@ -158,6 +181,7 @@ public enum PanelState { HIDDEN, DRAGGING } + private PanelState mSlideState = DEFAULT_SLIDE_STATE; /** @@ -196,7 +220,9 @@ public enum PanelState { private boolean mIsUsingDragViewTouchEvents; private float mInitialMotionX; + private float mInitialMotionY; + private float mAnchorPoint = 1.f; private PanelSlideListener mPanelSlideListener; @@ -216,32 +242,39 @@ public enum PanelState { * Listener for monitoring events about sliding panes. */ public interface PanelSlideListener { + /** * Called when a sliding pane's position changes. - * @param panel The child view that was moved + * + * @param panel The child view that was moved * @param slideOffset The new offset of this sliding pane within its range, from 0-1 */ public void onPanelSlide(View panel, float slideOffset); + /** * Called when a sliding panel becomes slid completely collapsed. + * * @param panel The child view that was slid to an collapsed position */ public void onPanelCollapsed(View panel); /** * Called when a sliding panel becomes slid completely expanded. + * * @param panel The child view that was slid to a expanded position */ public void onPanelExpanded(View panel); /** * Called when a sliding panel becomes anchored. + * * @param panel The child view that was slid to a anchored position */ public void onPanelAnchored(View panel); /** * Called when a sliding panel becomes completely hidden. + * * @param panel The child view that was slid to a hidden position */ public void onPanelHidden(View panel); @@ -252,23 +285,55 @@ public interface PanelSlideListener { * of the listener methods you can extend this instead of implement the full interface. */ public static class SimplePanelSlideListener implements PanelSlideListener { + @Override public void onPanelSlide(View panel, float slideOffset) { } + @Override public void onPanelCollapsed(View panel) { } + @Override public void onPanelExpanded(View panel) { } + @Override public void onPanelAnchored(View panel) { } + @Override public void onPanelHidden(View panel) { } } + public static int getRealDisplayHeight(Window window) { + Rect rect = new Rect(); + + window.getDecorView().getWindowVisibleDisplayFrame(rect); + return rect.height(); + } + + public static int getBarHeight(Context context) { + Class c = null; + Object obj = null; + Field field = null; + int x = 0, sbar = 38;//默认为38,貌似大部分是这样的 + + try { + c = Class.forName("com.android.internal.R$dimen"); + obj = c.newInstance(); + field = c.getField("status_bar_height"); + x = Integer.parseInt(field.get(obj).toString()); + sbar = context.getResources().getDimensionPixelSize(x); + + } catch (Exception e1) { + e1.printStackTrace(); + } + return sbar; + } + + public SlidingUpPanelLayout(Context context) { this(context, null); } @@ -280,7 +345,7 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs) { public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - if(isInEditMode()) { + if (isInEditMode()) { mShadowDrawable = null; mDragHelper = null; return; @@ -299,21 +364,66 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout); if (ta != null) { - mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoPanelHeight, -1); - mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoShadowHeight, -1); - mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoParalaxOffset, -1); - - mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_umanoFlingVelocity, DEFAULT_MIN_FLING_VELOCITY); - mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_umanoFadeColor, DEFAULT_FADE_COLOR); - - mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoDragView, -1); - - mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoOverlay, DEFAULT_OVERLAY_FLAG); - mClipPanel = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoClipPanel, DEFAULT_CLIP_PANEL_FLAG); - - mAnchorPoint = ta.getFloat(R.styleable.SlidingUpPanelLayout_umanoAnchorPoint, DEFAULT_ANCHOR_POINT); + mPanelHeight = ta + .getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoPanelHeight, + -1); + mShadowHeight = ta + .getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoShadowHeight, + -1); + mParallaxOffset = ta + .getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoParalaxOffset, + -1); + + mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_umanoFlingVelocity, + DEFAULT_MIN_FLING_VELOCITY); + mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_umanoFadeColor, + DEFAULT_FADE_COLOR); + + mDragViewResId = ta + .getResourceId(R.styleable.SlidingUpPanelLayout_umanoDragView, -1); + + mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoOverlay, + DEFAULT_OVERLAY_FLAG); + mClipPanel = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoClipPanel, + DEFAULT_CLIP_PANEL_FLAG); + + mAnchorPoint = ta.getFloat(R.styleable.SlidingUpPanelLayout_umanoAnchorPoint, + DEFAULT_ANCHOR_POINT); + + mSlideState = PanelState.values()[ta + .getInt(R.styleable.SlidingUpPanelLayout_umanoInitialState, + DEFAULT_SLIDE_STATE.ordinal())]; + + mInnerScrollViewId = ta + .getResourceId(R.styleable.SlidingUpPanelLayout_umanoInnerScrollView, -1); + + mContenHeight = ta + .getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoContentHeight, + -1); + mOtherHeight = ta + .getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoOtherHeight, + -1); + + mViewContentResId = ta + .getResourceId(R.styleable.SlidingUpPanelLayout_umanoContentView, -1); + DisplayMetrics dm = context.getResources() + .getDisplayMetrics(); + + int screenWidth = dm.widthPixels; + mScreenHeight = dm.heightPixels; + mVscreenHeight = getBarHeight(context); + // System.out.println("mVscreenHeight:"+mVscreenHeight); + if (mOtherHeight != -1 && mContenHeight != -1) { + mPanelHeight = mScreenHeight - mOtherHeight - mContenHeight - mVscreenHeight; + } + if(this.mContentView != null) { + if(this.mOtherHeight != -1) { + this.mPanelHeight = this.getMeasuredHeight() - this.mContentView.getMeasuredHeight(); + } else { + this.mPanelHeight = this.getMeasuredHeight() - this.mContentView.getMeasuredHeight(); + } + } - mSlideState = PanelState.values()[ta.getInt(R.styleable.SlidingUpPanelLayout_umanoInitialState, DEFAULT_SLIDE_STATE.ordinal())]; } ta.recycle(); @@ -349,15 +459,27 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { mIsTouchEnabled = true; } + /** * Set the Drag View after the view is inflated */ + private ViewGroup mInnerScrollView; + + private View mContentView; + @Override protected void onFinishInflate() { super.onFinishInflate(); if (mDragViewResId != -1) { setDragView(findViewById(mDragViewResId)); } + if (mInnerScrollViewId != -1) { + mInnerScrollView = (ViewGroup) findViewById(mInnerScrollViewId); + } + if (mViewContentResId != -1) { + mContentView = (View) findViewById(mViewContentResId); + } + } public void setGravity(int gravity) { @@ -390,6 +512,7 @@ public int getCoveredFadeColor() { /** * Set sliding enabled flag + * * @param enabled flag value */ public void setTouchEnabled(boolean enabled) { @@ -422,7 +545,7 @@ public void setPanelHeight(int val) { } } - protected void smoothToBottom(){ + protected void smoothToBottom() { smoothSlideTo(0, 0); } @@ -457,7 +580,7 @@ public int getPanelHeight() { */ public int getCurrentParalaxOffset() { // Clamp slide offset at zero for parallax computation; - int offset = (int)(mParallaxOffset * Math.max(mSlideOffset, 0)); + int offset = (int) (mParallaxOffset * Math.max(mSlideOffset, 0)); return mIsSlidingUp ? -offset : offset; } @@ -491,7 +614,6 @@ public void setMinFlingVelocity(int val) { /** * Sets the panel slide listener - * @param listener */ public void setPanelSlideListener(PanelSlideListener listener) { mPanelSlideListener = listener; @@ -514,8 +636,10 @@ public void setDragView(View dragView) { mDragView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - if (!isEnabled() || !isTouchEnabled()) return; - if (mSlideState != PanelState.EXPANDED && mSlideState != PanelState.ANCHORED) { + if (!isEnabled() || !isTouchEnabled()) { + return; + } + if (mSlideState != PanelState.EXPANDED && mSlideState != PanelState.ANCHORED) { if (mAnchorPoint < 1.0f) { setPanelState(PanelState.ANCHORED); } else { @@ -525,7 +649,7 @@ public void onClick(View v) { setPanelState(PanelState.COLLAPSED); } } - });; + }); } } @@ -562,7 +686,6 @@ public float getAnchorPoint() { /** * Sets whether or not the panel overlays the content - * @param overlayed */ public void setOverlayed(boolean overlayed) { mOverlayContent = overlayed; @@ -577,7 +700,6 @@ public boolean isOverlayed() { /** * Sets whether or not the main content is clipped to the top of the panel - * @param overlayed */ public void setClipPanel(boolean clip) { mClipPanel = clip; @@ -701,7 +823,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int childCount = getChildCount(); if (childCount != 2) { - throw new IllegalStateException("Sliding up panel layout must have exactly 2 children!"); + throw new IllegalStateException( + "Sliding up panel layout must have exactly 2 children!"); } mMainView = getChildAt(0); @@ -779,19 +902,20 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { if (mFirstLayout) { switch (mSlideState) { - case EXPANDED: - mSlideOffset = 1.0f; - break; - case ANCHORED: - mSlideOffset = mAnchorPoint; - break; - case HIDDEN: - int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight); - mSlideOffset = computeSlideOffset(newTop); - break; - default: - mSlideOffset = 0.f; - break; + case EXPANDED: + mSlideOffset = 1.0f; + break; + case ANCHORED: + mSlideOffset = mAnchorPoint; + break; + case HIDDEN: + int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight + : -mPanelHeight); + mSlideOffset = computeSlideOffset(newTop); + break; + default: + mSlideOffset = 0.f; + break; } } @@ -813,7 +937,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { if (!mIsSlidingUp) { if (child == mMainView && !mOverlayContent) { - childTop = computePanelTopPosition(mSlideOffset) + mSlideableView.getMeasuredHeight(); + childTop = computePanelTopPosition(mSlideOffset) + mSlideableView + .getMeasuredHeight(); } } final int childBottom = childTop + childHeight; @@ -834,10 +959,59 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); + // mPanelHeight = + // Recalculate sliding panes and their details if (h != oldh) { mFirstLayout = true; + System.out.println("111111111111"); } + + if (mContentView != null) { + if (mOtherHeight != -1) { + // mPanelHeight = mScreenHeight - mOtherHeight - mContentView.getMeasuredHeight() -mVscreenHeight; + mPanelHeight = getMeasuredHeight() - mContentView.getMeasuredHeight(); + + } else { + //mPanelHeight = mScreenHeight - mContentView.getMeasuredHeight() -mVscreenHeight; + mPanelHeight = getMeasuredHeight() - mContentView.getMeasuredHeight(); + } + } + System.out.println("111111111111:22222222:"+mPanelHeight); + } + + + public void onSizeChanged1() { + if (mContentView != null) { + if (mOtherHeight != -1) { + // mPanelHeight = mScreenHeight - mOtherHeight - mContentView.getHeight() -mVscreenHeight; + // System.out.println("mContentView.getHeight():"+mContentView.getHeight()); + mPanelHeight = getMeasuredHeight() - mContentView.getMeasuredHeight(); + + } else { + //mPanelHeight = mScreenHeight - mContentView.getHeight() -mVscreenHeight; + mPanelHeight = getMeasuredHeight() - mContentView.getMeasuredHeight(); + // System.out.println("mContentView.getHeight():"+mContentView.getHeight()); + } + } + + } + + public void onSizeChanged1(int contentViewHeight) { + if (mContentView != null) { + if (mOtherHeight != -1) { + // mPanelHeight = mScreenHeight - mOtherHeight - contentViewHeight -mVscreenHeight; + mPanelHeight = getMeasuredHeight() - contentViewHeight; + + // System.out.println("mContentView.getHeight():"+mContentView.getHeight()); + + } else { + mPanelHeight = getMeasuredHeight() - contentViewHeight; + //mPanelHeight = mScreenHeight - contentViewHeight - mVscreenHeight; + // System.out.println("mContentView.getHeight():"+mContentView.getHeight()); + } + } + } /** @@ -850,12 +1024,17 @@ public void setEnableDragViewTouchEvents(boolean enabled) { mIsUsingDragViewTouchEvents = enabled; } + private VelocityTracker mVelocityTracker; + + private int mMaximumVelocity, mMinimumVelocity; + + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); - - if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { + if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag + && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } @@ -867,37 +1046,145 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); + // System.out.println("y:"+y); + // System.out.println("x:"+x); switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; mInitialMotionX = x; mInitialMotionY = y; + // System.out.println("isDragViewUnder"+isDragViewUnder((int)mInitialMotionX,(int)mInitialMotionY)); break; } case MotionEvent.ACTION_MOVE: { final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); + final float ady1 = (y - mInitialMotionY);//大于0 向下 小于0 向上 final int dragSlop = mDragHelper.getTouchSlop(); + if (mInnerScrollView != null && mInnerScrollView instanceof ListView) { + ListView lv = (ListView) mInnerScrollView; + View c = lv.getChildAt(lv.getFirstVisiblePosition()); + if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) { + return super.onInterceptTouchEvent(ev); + } + if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) mInitialMotionX, + (int) mInitialMotionY)) { + mDragHelper.cancel(); + mIsUnableToDrag = true; + return false; + } + + if (!(mSlideState == PanelState.EXPANDED) && (c == null + || c != null && c.getTop() != 0) && ady1 > 0) { //打开时 + // System.out.println("ddddddddddddddd"); + return false;////交给子view处理 new 有头部 listView没在最顶端, 向下,这时交给子view处理 + + + }//有头部的 listview第一个不可见,不存在,这个时候 ady1 > 0向下 返回return false;listview获取到焦点 + + //有头部的 向上就截取 + + //mSlideState == PanelState.EXPANDED 这个状态是没有头部的 + //!(mSlideState == PanelState.EXPANDED) 有头部的 + + if (!(mSlideState == PanelState.EXPANDED) + && (c != null && ady1 < 0) && ady > 5) { //有头部,向上拦截 + // System.out.println("aaaaaaaaaaaaaaaaaa"); + + return true;//拦截掉自己处理 + } + if ((c != null && c.getTop() == 0 && (mSlideState == PanelState.EXPANDED) + && ady1 > 0) && ady > 5) { + //listView 第一个可见时,向下时,这是listview不获取焦点返回true 没有头部时, listView已经在第一个 向下 拦截 + //(有头部的) + + if (c != null) { + // System.out.println("c.getTop():"+ c.getTop()); + } + // mDragHelper.cancel(); + // return super.onInterceptTouchEvent(ev); + return true;//拦截掉自己处理 + } else { + mDragHelper.cancel(); + return false;//交给子view处理 + } + + } + // Handle any horizontal scrolling on the drag view. if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) { return super.onInterceptTouchEvent(ev); } - - if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int)mInitialMotionX, (int)mInitialMotionY)) { + if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) mInitialMotionX, + (int) mInitialMotionY)) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } + + // return true; + break; + } } return mDragHelper.shouldInterceptTouchEvent(ev); } + private int abc = 1; + + private float mLastMotionX; + + private float mLastMotionY; +// public boolean dispatchTouchEvent(MotionEvent ev) { +// final float x = ev.getX(); +// final float y = ev.getY(); +// switch (ev.getAction()) { +// case MotionEvent.ACTION_DOWN: +// getParent().requestDisallowInterceptTouchEvent(true); +// abc = 1; +// mLastMotionX = x; +// mLastMotionY = y; +// break; +// case MotionEvent.ACTION_MOVE: +// if (abc == 1) { +// final float ady1 = (y - mInitialMotionY); +// if (mInnerScrollView instanceof ListView) { +// ListView lv = (ListView) mInnerScrollView; +// View c = lv.getChildAt(lv.getFirstVisiblePosition()); +// if (!(mSlideState == PanelState.EXPANDED) +// || (c != null && c.getTop() == 0 && (mSlideState == PanelState.EXPANDED) && ady1 > 0)) { +// abc = 0; +// getParent().requestDisallowInterceptTouchEvent(true); +// }else{ +// +// getParent().requestDisallowInterceptTouchEvent(false); +// } +// } +// +//// if (Math.abs(x - mLastMotionX) < Math.abs(y - mLastMotionY)) { +//// abc = 0; +//// getParent().requestDisallowInterceptTouchEvent(false); +//// +//// } else { +//// getParent().requestDisallowInterceptTouchEvent(true); +//// } +// +// } +// break; +// case MotionEvent.ACTION_UP: +// case MotionEvent.ACTION_CANCEL: +// getParent().requestDisallowInterceptTouchEvent(false); +// break; +// } +// return super.dispatchTouchEvent(ev); +// } + + @Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled() || !isTouchEnabled()) { @@ -908,7 +1195,9 @@ public boolean onTouchEvent(MotionEvent ev) { } private boolean isDragViewUnder(int x, int y) { - if (mDragView == null) return false; + if (mDragView == null) { + return false; + } int[] viewLocation = new int[2]; mDragView.getLocationOnScreen(viewLocation); int[] parentLocation = new int[2]; @@ -947,6 +1236,7 @@ private float computeSlideOffset(int topPosition) { /** * Returns the current state of the panel as an enum. + * * @return the current panel state */ public PanelState getPanelState() { @@ -955,6 +1245,7 @@ public PanelState getPanelState() { /** * Change panel state to the given state with + * * @param state - new panel state */ public void setPanelState(PanelState state) { @@ -964,7 +1255,9 @@ public void setPanelState(PanelState state) { if (!isEnabled() || (!mFirstLayout && mSlideableView == null) || state == mSlideState - || mSlideState == PanelState.DRAGGING) return; + || mSlideState == PanelState.DRAGGING) { + return; + } if (mFirstLayout) { mSlideState = state; @@ -984,7 +1277,8 @@ public void setPanelState(PanelState state) { smoothSlideTo(1.0f, 0); break; case HIDDEN: - int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight); + int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight + : -mPanelHeight); smoothSlideTo(computeSlideOffset(newTop), 0); break; } @@ -1016,12 +1310,14 @@ private void onPanelDragged(int newTop) { dispatchOnPanelSlide(mSlideableView); // If the slide offset is negative, and overlay is not on, we need to increase the // height of the main content - LayoutParams lp = (LayoutParams)mMainView.getLayoutParams(); + LayoutParams lp = (LayoutParams) mMainView.getLayoutParams(); int defaultHeight = getHeight() - getPaddingBottom() - getPaddingTop() - mPanelHeight; if (mSlideOffset <= 0 && !mOverlayContent) { // expand the main view - lp.height = mIsSlidingUp ? (newTop - getPaddingBottom()) : (getHeight() - getPaddingBottom() - mSlideableView.getMeasuredHeight() - newTop); + lp.height = mIsSlidingUp ? (newTop - getPaddingBottom()) + : (getHeight() - getPaddingBottom() - mSlideableView.getMeasuredHeight() + - newTop); mMainView.requestLayout(); } else if (lp.height != defaultHeight && !mOverlayContent) { lp.height = defaultHeight; @@ -1052,8 +1348,10 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) { result = super.drawChild(canvas, child, drawingTime); if (mCoveredFadeColor != 0 && mSlideOffset > 0) { + final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; - final int imag = (int) (baseAlpha * mSlideOffset); + final int imag = (int) (baseAlpha * 0);//mSlideOffset + // System.out.println("mSlideOffset:"+mSlideOffset); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); @@ -1071,7 +1369,7 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) { * Smoothly animate mDraggingPane to the target X position within its range. * * @param slideOffset position to animate to - * @param velocity initial velocity in case of fling, or 0. + * @param velocity initial velocity in case of fling, or 0. */ boolean smoothSlideTo(float slideOffset, int velocity) { if (!isEnabled()) { @@ -1125,12 +1423,12 @@ public void draw(Canvas c) { /** * Tests scrollability within child views of v given a delta of dx. * - * @param v View to test for horizontal scrollability + * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false). - * @param dx Delta scrolled in pixels - * @param x X coordinate of the active touch point - * @param y Y coordinate of the active touch point + * @param dx Delta scrolled in pixels + * @param x X coordinate of the active touch point + * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { @@ -1275,6 +1573,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) { target = computePanelTopPosition(0.0f); } + System.out.println("111111target::"+target); mDragHelper.settleCapturedViewAt(releasedChild.getLeft(), target); invalidate(); } @@ -1297,8 +1596,9 @@ public int clampViewPositionVertical(View child, int top, int dy) { } public static class LayoutParams extends ViewGroup.MarginLayoutParams { - private static final int[] ATTRS = new int[] { - android.R.attr.layout_weight + + private static final int[] ATTRS = new int[]{ + android.R.attr.layout_weight }; public LayoutParams() { @@ -1331,6 +1631,7 @@ public LayoutParams(Context c, AttributeSet attrs) { } static class SavedState extends BaseSavedState { + PanelState mSlideState; SavedState(Parcelable superState) { @@ -1354,15 +1655,15 @@ public void writeToParcel(Parcel out, int flags) { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } + @Override + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } - @Override - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; + @Override + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; } } diff --git a/maven_push.gradle b/maven_push.gradle index 6d8fdbc3..3443460d 100644 --- a/maven_push.gradle +++ b/maven_push.gradle @@ -4,10 +4,10 @@ apply plugin: 'signing' def sonatypeRepositoryUrl if (isReleaseBuild()) { println 'RELEASE BUILD' - sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + sonatypeRepositoryUrl = "http://nexus.huayu.nd/nexus/content/repositories/releases/" } else { println 'DEBUG BUILD' - sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/" + sonatypeRepositoryUrl = "http://nexus.huayu.nd/nexus/content/repositories/snapshots/" } afterEvaluate { project -> @@ -19,7 +19,7 @@ afterEvaluate { project -> pom.artifactId = POM_ARTIFACT_ID repository(url: sonatypeRepositoryUrl) { - authentication(userName: nexusUsername, password: nexusPassword) + authentication(userName: "deployment", password: "deployment123") } pom.project {