├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xhdpi │ │ │ │ └── splash01.jpg │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── layout │ │ │ │ ├── list_head_zoom_view.xml │ │ │ │ └── activity_pull_to_zoom_list_view.xml │ │ │ └── menu │ │ │ │ └── list_view.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── xf │ │ │ └── pullbezierzoomview │ │ │ ├── lib │ │ │ ├── IPullToZoom.java │ │ │ ├── BezierView.java │ │ │ ├── PullToZoomBase.java │ │ │ └── PullToZoomListViewEx.java │ │ │ └── PullToZoomListActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── xf │ │ │ └── pullbezierzoomview │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── xf │ │ └── pullbezierzoomview │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | PullBezierZoomView -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/splash01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/app/src/main/res/drawable-xhdpi/splash01.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-FAN/PullBezierZoomView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 13 09:30:44 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/xf/pullbezierzoomview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/list_head_zoom_view.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/xf/pullbezierzoomview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PullBezierZoomView 3 | Normal 4 | Parallax 5 | Show Head 6 | Hide Head 7 | Disable Zoom 8 | Enable Zoom 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_pull_to_zoom_list_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.xf.pullbezierzoomview" 9 | minSdkVersion 14 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.2.0' 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PullBezierZoomView 2 | 3 | 该控件效果基于[PullZoomView](https://github.com/Frank-Zhu/PullZoomView)源码改动的而来,感谢**Frank-Zhu**的开源代码.该控件具有下拉放大背景图和贝塞尔曲线的效果. 4 | 5 | This widget is based on [PullZoomView](https://github.com/Frank-Zhu/PullZoomView),thanks to **Frank-Zhu**.This widget has zoom and bezier function. 6 | 7 | 8 | **Attr:** 9 | 10 | ``` 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ``` 19 | 20 | **gif:** 21 | 22 | ![Alt Text](https://github.com/X-FAN/resource/blob/master/gif/bezier.gif) 23 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/res/menu/list_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 12 | 17 | 18 | 23 | 24 | 29 | 30 | 35 | 36 | 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/xf/pullbezierzoomview/lib/IPullToZoom.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview.lib; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 2014/11/7 14:21. 7 | * Description: 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 2014/11/7 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | 15 | import android.content.res.TypedArray; 16 | import android.view.View; 17 | 18 | public interface IPullToZoom { 19 | /** 20 | * Get the Wrapped Zoom View. Anything returned here has already been 21 | * added to the content view. 22 | * 23 | * @return The View which is currently wrapped 24 | */ 25 | public View getZoomView(); 26 | 27 | public View getHeaderView(); 28 | 29 | /** 30 | * Get the Wrapped root View. 31 | * 32 | * @return The View which is currently wrapped 33 | */ 34 | public T getPullRootView(); 35 | 36 | /** 37 | * Whether Pull-to-Refresh is enabled 38 | * 39 | * @return enabled 40 | */ 41 | public boolean isPullToZoomEnabled(); 42 | 43 | /** 44 | * Returns whether the Widget is currently in the Zooming state 45 | * 46 | * @return true if the Widget is currently zooming 47 | */ 48 | public boolean isZooming(); 49 | 50 | /** 51 | * Returns whether the Widget is currently in the Zooming anim type 52 | * 53 | * @return true if the anim is parallax 54 | */ 55 | public boolean isParallax(); 56 | 57 | public boolean isHideHeader(); 58 | 59 | public void handleStyledAttributes(TypedArray a); 60 | } 61 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | C:\Users\TC\AppData\Roaming\Subversion 48 | 49 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/xf/pullbezierzoomview/lib/BezierView.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview.lib; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Path; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | 11 | /** 12 | * Created by X-FAN on 2016/7/19. 13 | */ 14 | public class BezierView extends View { 15 | 16 | private int mWidth = 500; 17 | private int mHeight = 500; 18 | private float mMaxHeight = Integer.MAX_VALUE; 19 | private float mY = 0; 20 | 21 | private Paint mPaint; 22 | private Path mPath; 23 | 24 | 25 | public BezierView(Context context) { 26 | this(context, null); 27 | } 28 | 29 | public BezierView(Context context, AttributeSet attrs) { 30 | this(context, attrs, 0); 31 | } 32 | 33 | public BezierView(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | mPath = new Path(); 36 | mPaint = new Paint(); 37 | mPaint.setAntiAlias(true); 38 | mPaint.setColor(Color.WHITE); 39 | } 40 | 41 | @Override 42 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 43 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 44 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 45 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 46 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); 47 | int width; 48 | int height; 49 | 50 | if (widthMode == MeasureSpec.EXACTLY) { 51 | width = widthSize; 52 | } else if (widthMode == MeasureSpec.AT_MOST) { 53 | width = Math.min(mWidth, widthSize); 54 | } else { 55 | width = mWidth; 56 | } 57 | 58 | if (heightMode == MeasureSpec.EXACTLY) { 59 | height = heightSize; 60 | } else if (heightMode == MeasureSpec.AT_MOST) { 61 | height = Math.min(mHeight, heightSize); 62 | } else { 63 | height = mHeight; 64 | } 65 | setMeasuredDimension(width, height); 66 | } 67 | 68 | 69 | @Override 70 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 71 | super.onSizeChanged(w, h, oldw, oldh); 72 | mWidth = w; 73 | mHeight = h; 74 | } 75 | 76 | 77 | @Override 78 | protected void onDraw(Canvas canvas) { 79 | super.onDraw(canvas); 80 | mPath.reset(); 81 | mPath.moveTo(0, mHeight - mY); 82 | mPath.quadTo(mWidth / 2, mHeight + mY, mWidth, mHeight - mY); 83 | mPath.lineTo(mWidth, mHeight); 84 | mPath.lineTo(0, mHeight); 85 | mPath.close(); 86 | canvas.drawPath(mPath, mPaint); 87 | } 88 | 89 | public void setArcHeight(float height) { 90 | if (Math.abs(height) < mMaxHeight) { 91 | mY = height; 92 | invalidate(); 93 | } 94 | } 95 | 96 | public float getArcHeight() { 97 | return mY; 98 | } 99 | 100 | public void setColor(int color) { 101 | mPaint.setColor(color); 102 | } 103 | 104 | public void setMaxHeight(float height) { 105 | mMaxHeight = height; 106 | } 107 | 108 | 109 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xf/pullbezierzoomview/PullToZoomListActivity.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.ActionBarActivity; 5 | import android.util.DisplayMetrics; 6 | import android.util.Log; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import android.widget.AbsListView; 11 | import android.widget.AdapterView; 12 | import android.widget.ArrayAdapter; 13 | 14 | import com.xf.pullbezierzoomview.lib.PullToZoomListViewEx; 15 | 16 | 17 | public class PullToZoomListActivity extends ActionBarActivity { 18 | 19 | private PullToZoomListViewEx listView; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_pull_to_zoom_list_view); 25 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 26 | 27 | listView = (PullToZoomListViewEx) findViewById(R.id.listview); 28 | 29 | String[] adapterData = new String[]{"Activity", "Service", "Content Provider", "Intent", "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", 30 | "DDMS", "Android Studio", "Fragment", "Loader", "Activity", "Service", "Content Provider", "Intent", 31 | "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", "Activity", "Service", "Content Provider", "Intent", 32 | "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient"}; 33 | 34 | listView.setAdapter(new ArrayAdapter(PullToZoomListActivity.this, android.R.layout.simple_list_item_1, adapterData)); 35 | listView.getPullRootView().setOnItemClickListener(new AdapterView.OnItemClickListener() { 36 | @Override 37 | public void onItemClick(AdapterView parent, View view, int position, long id) { 38 | Log.e("zhuwenwu", "position = " + position); 39 | } 40 | }); 41 | listView.getPullRootView().setDivider(null); 42 | 43 | 44 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 45 | @Override 46 | public void onItemClick(AdapterView parent, View view, int position, long id) { 47 | Log.e("zhuwenwu", "position = " + position); 48 | } 49 | }); 50 | 51 | DisplayMetrics localDisplayMetrics = new DisplayMetrics(); 52 | getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics); 53 | int mScreenHeight = localDisplayMetrics.heightPixels; 54 | int mScreenWidth = localDisplayMetrics.widthPixels; 55 | AbsListView.LayoutParams localObject = new AbsListView.LayoutParams(mScreenWidth, (int) (9.0F * (mScreenWidth / 16.0F))); 56 | listView.setHeaderLayoutParams(localObject); 57 | } 58 | 59 | @Override 60 | public boolean onCreateOptionsMenu(Menu menu) { 61 | getMenuInflater().inflate(R.menu.list_view, menu); 62 | return true; 63 | } 64 | 65 | @Override 66 | public boolean onOptionsItemSelected(MenuItem item) { 67 | int id = item.getItemId(); 68 | if (id == android.R.id.home) { 69 | finish(); 70 | return true; 71 | } else if (id == R.id.action_normal) { 72 | listView.setParallax(false); 73 | return true; 74 | } else if (id == R.id.action_parallax) { 75 | listView.setParallax(true); 76 | return true; 77 | } else if (id == R.id.action_show_head) { 78 | listView.setHideHeader(false); 79 | return true; 80 | } else if (id == R.id.action_hide_head) { 81 | listView.setHideHeader(true); 82 | return true; 83 | } else if (id == R.id.action_disable_zoom) { 84 | listView.setZoomEnabled(false); 85 | return true; 86 | } else if (id == R.id.action_enable_zoom) { 87 | listView.setZoomEnabled(true); 88 | return true; 89 | } 90 | return super.onOptionsItemSelected(item); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/xf/pullbezierzoomview/lib/PullToZoomBase.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview.lib; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.support.annotation.NonNull; 7 | import android.util.AttributeSet; 8 | import android.util.DisplayMetrics; 9 | import android.view.Gravity; 10 | import android.view.LayoutInflater; 11 | import android.view.MotionEvent; 12 | import android.view.View; 13 | import android.view.ViewConfiguration; 14 | import android.view.ViewGroup; 15 | import android.widget.LinearLayout; 16 | 17 | import com.xf.pullbezierzoomview.R; 18 | 19 | /** 20 | * Base on https://github.com/Frank-Zhu/PullZoomView 21 | * Thanks to Frank-Zhu 22 | */ 23 | public abstract class PullToZoomBase extends LinearLayout implements IPullToZoom { 24 | private static final float FRICTION = 2.0f; 25 | 26 | protected int mScreenHeight; 27 | protected int mScreenWidth; 28 | 29 | private boolean isZoomEnabled = true; 30 | private boolean isParallax = true; 31 | private boolean isZooming = false; 32 | private boolean isHideHeader = false; 33 | private boolean isBezier = false; 34 | private boolean mIsBeingDragged = false; 35 | 36 | private int mTouchSlop; 37 | 38 | private float mLastMotionY; 39 | private float mLastMotionX; 40 | private float mInitialMotionY; 41 | private float mInitialMotionX; 42 | 43 | private OnPullZoomListener onPullZoomListener; 44 | protected View mHeaderView;//头部View 45 | protected View mZoomView;//缩放拉伸View 46 | protected BezierView mBezierView; 47 | protected T mRootView; 48 | 49 | 50 | public PullToZoomBase(Context context) { 51 | this(context, null); 52 | } 53 | 54 | public PullToZoomBase(Context context, AttributeSet attrs) { 55 | super(context, attrs); 56 | 57 | init(context, attrs); 58 | } 59 | 60 | private void init(Context context, AttributeSet attrs) { 61 | setGravity(Gravity.CENTER); 62 | 63 | ViewConfiguration config = ViewConfiguration.get(context); 64 | mTouchSlop = config.getScaledTouchSlop(); 65 | 66 | DisplayMetrics localDisplayMetrics = new DisplayMetrics(); 67 | ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics); 68 | mScreenHeight = localDisplayMetrics.heightPixels; 69 | mScreenWidth = localDisplayMetrics.widthPixels; 70 | 71 | // Refreshable View 72 | // By passing the attrs, we can add ListView/GridView params via XML 73 | mRootView = createRootView(context, attrs); 74 | 75 | if (attrs != null) { 76 | LayoutInflater mLayoutInflater = LayoutInflater.from(getContext()); 77 | //初始化状态View 78 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PullBezierZoomView); 79 | 80 | int zoomViewResId = a.getResourceId(R.styleable.PullBezierZoomView_zoomView, 0); 81 | if (zoomViewResId > 0) { 82 | mZoomView = mLayoutInflater.inflate(zoomViewResId, null, false); 83 | } 84 | int headerViewResId = a.getResourceId(R.styleable.PullBezierZoomView_headerView, 0); 85 | if (headerViewResId > 0) { 86 | mHeaderView = mLayoutInflater.inflate(headerViewResId, null, false); 87 | } 88 | isParallax = a.getBoolean(R.styleable.PullBezierZoomView_isHeaderParallax, true); 89 | isBezier = a.getBoolean(R.styleable.PullBezierZoomView_isBezier, false); 90 | int color = a.getColor(R.styleable.PullBezierZoomView_bezierColor, 0xFFFFFFFF); 91 | float maxHeight = a.getDimension(R.styleable.PullBezierZoomView_maxBezierHeight, 0); 92 | if (isBezier) { 93 | mBezierView = new BezierView(getContext()); 94 | mBezierView.setColor(color); 95 | if (maxHeight > 0) { 96 | mBezierView.setMaxHeight(maxHeight); 97 | } 98 | } 99 | 100 | 101 | // Let the derivative classes have a go at handling attributes, then 102 | // recycle them... 103 | handleStyledAttributes(a); 104 | a.recycle(); 105 | } 106 | addView(mRootView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 107 | } 108 | 109 | public void setOnPullZoomListener(OnPullZoomListener onPullZoomListener) { 110 | this.onPullZoomListener = onPullZoomListener; 111 | } 112 | 113 | @Override 114 | public T getPullRootView() { 115 | return mRootView; 116 | } 117 | 118 | @Override 119 | public View getZoomView() { 120 | return mZoomView; 121 | } 122 | 123 | @Override 124 | public View getHeaderView() { 125 | return mHeaderView; 126 | } 127 | 128 | @Override 129 | public boolean isPullToZoomEnabled() { 130 | return isZoomEnabled; 131 | } 132 | 133 | @Override 134 | public boolean isZooming() { 135 | return isZooming; 136 | } 137 | 138 | @Override 139 | public boolean isParallax() { 140 | return isParallax; 141 | } 142 | 143 | @Override 144 | public boolean isHideHeader() { 145 | return isHideHeader; 146 | } 147 | 148 | public void setZoomEnabled(boolean isZoomEnabled) { 149 | this.isZoomEnabled = isZoomEnabled; 150 | } 151 | 152 | public void setParallax(boolean isParallax) { 153 | this.isParallax = isParallax; 154 | } 155 | 156 | public void setHideHeader(boolean isHideHeader) {//header显示才能Zoom 157 | this.isHideHeader = isHideHeader; 158 | } 159 | 160 | @Override 161 | public boolean onInterceptTouchEvent(MotionEvent event) { 162 | if (!isPullToZoomEnabled() || isHideHeader()) { 163 | return false; 164 | } 165 | 166 | final int action = event.getAction(); 167 | 168 | if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { 169 | mIsBeingDragged = false; 170 | return false; 171 | } 172 | 173 | if (action != MotionEvent.ACTION_DOWN && mIsBeingDragged) { 174 | return true; 175 | } 176 | switch (action) { 177 | case MotionEvent.ACTION_MOVE: { 178 | if (isReadyForPullStart()) { 179 | final float y = event.getY(), x = event.getX(); 180 | final float diff, oppositeDiff, absDiff; 181 | 182 | // We need to use the correct values, based on scroll 183 | // direction 184 | diff = y - mLastMotionY; 185 | oppositeDiff = x - mLastMotionX; 186 | absDiff = Math.abs(diff); 187 | 188 | if (absDiff > mTouchSlop && absDiff > Math.abs(oppositeDiff)) { 189 | if (diff >= 1f && isReadyForPullStart()) { 190 | mLastMotionY = y; 191 | mLastMotionX = x; 192 | mIsBeingDragged = true; 193 | } 194 | } 195 | } 196 | break; 197 | } 198 | case MotionEvent.ACTION_DOWN: { 199 | if (isReadyForPullStart()) { 200 | mLastMotionY = mInitialMotionY = event.getY(); 201 | mLastMotionX = mInitialMotionX = event.getX(); 202 | mIsBeingDragged = false; 203 | } 204 | break; 205 | } 206 | } 207 | 208 | return mIsBeingDragged; 209 | } 210 | 211 | @Override 212 | public boolean onTouchEvent(@NonNull MotionEvent event) { 213 | if (!isPullToZoomEnabled() || isHideHeader()) { 214 | return false; 215 | } 216 | 217 | if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) { 218 | return false; 219 | } 220 | 221 | switch (event.getAction()) { 222 | case MotionEvent.ACTION_MOVE: { 223 | if (mIsBeingDragged) { 224 | mLastMotionY = event.getY(); 225 | mLastMotionX = event.getX(); 226 | pullEvent(); 227 | isZooming = true; 228 | return true; 229 | } 230 | break; 231 | } 232 | 233 | case MotionEvent.ACTION_DOWN: { 234 | if (isReadyForPullStart()) { 235 | mLastMotionY = mInitialMotionY = event.getY(); 236 | mLastMotionX = mInitialMotionX = event.getX(); 237 | return true; 238 | } 239 | break; 240 | } 241 | 242 | case MotionEvent.ACTION_CANCEL: 243 | case MotionEvent.ACTION_UP: { 244 | if (mIsBeingDragged) { 245 | mIsBeingDragged = false; 246 | // If we're already refreshing, just scroll back to the top 247 | if (isZooming()) { 248 | smoothScrollToTop(); 249 | if (onPullZoomListener != null) { 250 | onPullZoomListener.onPullZoomEnd(); 251 | } 252 | isZooming = false; 253 | return true; 254 | } 255 | return true; 256 | } 257 | break; 258 | } 259 | } 260 | return false; 261 | } 262 | 263 | private void pullEvent() { 264 | final int newScrollValue; 265 | final float initialMotionValue, lastMotionValue; 266 | 267 | initialMotionValue = mInitialMotionY; 268 | lastMotionValue = mLastMotionY; 269 | 270 | newScrollValue = Math.round(Math.min(initialMotionValue - lastMotionValue, 0) / FRICTION); 271 | 272 | pullHeaderToZoom(newScrollValue); 273 | if (onPullZoomListener != null) { 274 | onPullZoomListener.onPullZooming(newScrollValue); 275 | } 276 | } 277 | 278 | protected abstract void pullHeaderToZoom(int newScrollValue); 279 | 280 | public abstract void setHeaderView(BezierView headerView); 281 | 282 | public abstract void setZoomView(View zoomView); 283 | 284 | protected abstract T createRootView(Context context, AttributeSet attrs); 285 | 286 | protected abstract void smoothScrollToTop(); 287 | 288 | protected abstract boolean isReadyForPullStart(); 289 | 290 | public interface OnPullZoomListener { 291 | public void onPullZooming(int newScrollValue); 292 | 293 | public void onPullZoomEnd(); 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /app/src/main/java/com/xf/pullbezierzoomview/lib/PullToZoomListViewEx.java: -------------------------------------------------------------------------------- 1 | package com.xf.pullbezierzoomview.lib; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.os.SystemClock; 6 | import android.util.AttributeSet; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.view.animation.Interpolator; 11 | import android.widget.AbsListView; 12 | import android.widget.Adapter; 13 | import android.widget.AdapterView; 14 | import android.widget.FrameLayout; 15 | import android.widget.ListAdapter; 16 | import android.widget.ListView; 17 | 18 | /** 19 | * Base on https://github.com/Frank-Zhu/PullZoomView 20 | * Thanks to Frank-Zhu 21 | */ 22 | public class PullToZoomListViewEx extends PullToZoomBase implements AbsListView.OnScrollListener { 23 | 24 | private static final String TAG = PullToZoomListViewEx.class.getSimpleName(); 25 | private float mOldValue; 26 | private float mD; 27 | private int mHeaderHeight; 28 | private FrameLayout mHeaderContainer; 29 | private ScalingRunnable mScalingRunnable; 30 | 31 | 32 | private static final Interpolator sInterpolator = new Interpolator() { 33 | public float getInterpolation(float paramAnonymousFloat) { 34 | float f = paramAnonymousFloat - 1.0F; 35 | return 1.0F + f * (f * (f * (f * f))); 36 | } 37 | }; 38 | 39 | public PullToZoomListViewEx(Context context) { 40 | this(context, null); 41 | } 42 | 43 | public PullToZoomListViewEx(Context context, AttributeSet attrs) { 44 | super(context, attrs); 45 | mRootView.setOnScrollListener(this); 46 | mScalingRunnable = new ScalingRunnable(); 47 | } 48 | 49 | /** 50 | * 是否显示headerView 51 | * 52 | * @param isHideHeader true: show false: hide 53 | */ 54 | @Override 55 | public void setHideHeader(boolean isHideHeader) { 56 | if (isHideHeader != isHideHeader()) { 57 | super.setHideHeader(isHideHeader); 58 | if (isHideHeader) { 59 | removeHeaderView(); 60 | } else { 61 | updateHeaderView(); 62 | } 63 | } 64 | } 65 | 66 | 67 | @Override 68 | public void setHeaderView(BezierView headerView) { 69 | if (headerView != null) { 70 | this.mHeaderView = headerView; 71 | updateHeaderView(); 72 | } 73 | } 74 | 75 | @Override 76 | public void setZoomView(View zoomView) { 77 | if (zoomView != null) { 78 | this.mZoomView = zoomView; 79 | updateHeaderView(); 80 | } 81 | } 82 | 83 | private void removeHeaderView() { 84 | if (mHeaderContainer != null) { 85 | mRootView.removeHeaderView(mHeaderContainer); 86 | } 87 | } 88 | 89 | private void updateHeaderView() { 90 | if (mHeaderContainer != null) { 91 | mRootView.removeHeaderView(mHeaderContainer); 92 | 93 | mHeaderContainer.removeAllViews(); 94 | 95 | if (mZoomView != null) { 96 | mHeaderContainer.addView(mZoomView); 97 | } 98 | 99 | if (mHeaderView != null) { 100 | mHeaderContainer.addView(mHeaderView); 101 | } 102 | 103 | if (mBezierView != null) { 104 | mHeaderContainer.addView(mBezierView); 105 | } 106 | 107 | mHeaderHeight = mHeaderContainer.getHeight(); 108 | mRootView.addHeaderView(mHeaderContainer); 109 | } 110 | } 111 | 112 | public void setAdapter(ListAdapter adapter) { 113 | mRootView.setAdapter(adapter); 114 | } 115 | 116 | public void setOnItemClickListener(AdapterView.OnItemClickListener listener) { 117 | mRootView.setOnItemClickListener(listener); 118 | } 119 | 120 | @Override 121 | protected ListView createRootView(Context context, AttributeSet attrs) { 122 | ListView lv = new ListView(context, attrs); 123 | // Set it to this so it can be used in ListActivity/ListFragment 124 | lv.setId(android.R.id.list); 125 | return lv; 126 | } 127 | 128 | /** 129 | * 重置动画,自动滑动到顶部 130 | */ 131 | @Override 132 | protected void smoothScrollToTop() { 133 | Log.d(TAG, "smoothScrollToTop --> "); 134 | mScalingRunnable.startAnimation(200L); 135 | } 136 | 137 | @Override 138 | protected void pullHeaderToZoom(int newScrollValue) { 139 | Log.d(TAG, "pullHeaderToZoom --> newScrollValue = " + newScrollValue); 140 | Log.d(TAG, "pullHeaderToZoom --> mHeaderHeight = " + mHeaderHeight); 141 | if (mScalingRunnable != null && !mScalingRunnable.isFinished()) { 142 | mScalingRunnable.abortAnimation(); 143 | } 144 | 145 | ViewGroup.LayoutParams localLayoutParams = mHeaderContainer.getLayoutParams(); 146 | localLayoutParams.height = Math.abs(newScrollValue) + mHeaderHeight; 147 | mHeaderContainer.setLayoutParams(localLayoutParams); 148 | } 149 | 150 | 151 | @Override 152 | protected boolean isReadyForPullStart() { 153 | return isFirstItemVisible(); 154 | } 155 | 156 | private boolean isFirstItemVisible() { 157 | final Adapter adapter = mRootView.getAdapter(); 158 | 159 | if (null == adapter || adapter.isEmpty()) { 160 | return true; 161 | } else { 162 | /** 163 | * This check should really just be: 164 | * mRootView.getFirstVisiblePosition() == 0, but PtRListView 165 | * internally use a HeaderView which messes the positions up. For 166 | * now we'll just add one to account for it and rely on the inner 167 | * condition which checks getTop(). 168 | */ 169 | if (mRootView.getFirstVisiblePosition() <= 1) { 170 | final View firstVisibleChild = mRootView.getChildAt(0); 171 | if (firstVisibleChild != null) { 172 | return firstVisibleChild.getTop() >= mRootView.getTop(); 173 | } 174 | } 175 | } 176 | 177 | return false; 178 | } 179 | 180 | @Override 181 | public void handleStyledAttributes(TypedArray a) { 182 | mHeaderContainer = new FrameLayout(getContext()); 183 | if (mZoomView != null) { 184 | mHeaderContainer.addView(mZoomView); 185 | } 186 | if (mHeaderView != null) { 187 | mHeaderContainer.addView(mHeaderView); 188 | } 189 | if (mBezierView != null) { 190 | mHeaderContainer.addView(mBezierView); 191 | } 192 | 193 | mRootView.addHeaderView(mHeaderContainer); 194 | } 195 | 196 | /** 197 | * 设置HeaderView高度 198 | * 199 | * @param width 200 | * @param height 201 | */ 202 | public void setHeaderViewSize(int width, int height) { 203 | if (mHeaderContainer != null) { 204 | Object localObject = mHeaderContainer.getLayoutParams(); 205 | if (localObject == null) { 206 | localObject = new AbsListView.LayoutParams(width, height); 207 | } 208 | ((ViewGroup.LayoutParams) localObject).width = width; 209 | ((ViewGroup.LayoutParams) localObject).height = height; 210 | mHeaderContainer.setLayoutParams((ViewGroup.LayoutParams) localObject); 211 | mHeaderHeight = height; 212 | } 213 | } 214 | 215 | public void setHeaderLayoutParams(AbsListView.LayoutParams layoutParams) { 216 | if (mHeaderContainer != null) { 217 | mHeaderContainer.setLayoutParams(layoutParams); 218 | mHeaderHeight = layoutParams.height; 219 | } 220 | } 221 | 222 | protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, 223 | int paramInt3, int paramInt4) { 224 | super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4); 225 | Log.d(TAG, "onLayout --> "); 226 | if (mHeaderHeight == 0 && mHeaderContainer != null) { 227 | mHeaderHeight = mHeaderContainer.getHeight(); 228 | } 229 | } 230 | 231 | @Override 232 | public void onScrollStateChanged(AbsListView view, int scrollState) { 233 | Log.d(TAG, "onScrollStateChanged --> "); 234 | } 235 | 236 | @Override 237 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 238 | if (mZoomView != null && !isHideHeader() && isPullToZoomEnabled()) { 239 | float f = mHeaderHeight - mHeaderContainer.getBottom(); 240 | mD = f - mOldValue; 241 | mOldValue = f; 242 | Log.d(TAG, "onScroll --> f = " + f); 243 | if (mBezierView != null) { 244 | mBezierView.setArcHeight(mBezierView.getArcHeight() - mD); 245 | } 246 | if (isParallax()) { 247 | if ((f > 0.0F) && (f < mHeaderHeight)) { 248 | int i = (int) (0.65D * f); 249 | mHeaderContainer.scrollTo(0, -i); 250 | } else if (mHeaderContainer.getScrollY() != 0) { 251 | mHeaderContainer.scrollTo(0, 0); 252 | } 253 | } 254 | } 255 | } 256 | 257 | 258 | class ScalingRunnable implements Runnable { 259 | protected long mDuration; 260 | protected boolean mIsFinished = true; 261 | protected float mScale; 262 | protected long mStartTime; 263 | 264 | ScalingRunnable() { 265 | } 266 | 267 | public void abortAnimation() { 268 | mIsFinished = true; 269 | } 270 | 271 | public boolean isFinished() { 272 | return mIsFinished; 273 | } 274 | 275 | public void run() { 276 | if (mZoomView != null) { 277 | float f2; 278 | ViewGroup.LayoutParams localLayoutParams; 279 | if ((!mIsFinished) && (mScale > 1.0D)) { 280 | float f1 = ((float) SystemClock.currentThreadTimeMillis() - (float) mStartTime) / (float) mDuration; 281 | f2 = mScale - (mScale - 1.0F) * PullToZoomListViewEx.sInterpolator.getInterpolation(f1); 282 | localLayoutParams = mHeaderContainer.getLayoutParams(); 283 | 284 | if (f2 > 1.0F) { 285 | localLayoutParams.height = ((int) (f2 * mHeaderHeight)); 286 | mHeaderContainer.setLayoutParams(localLayoutParams); 287 | post(this); 288 | return; 289 | } 290 | mIsFinished = true; 291 | } 292 | } 293 | } 294 | 295 | public void startAnimation(long paramLong) { 296 | if (mZoomView != null) { 297 | mStartTime = SystemClock.currentThreadTimeMillis(); 298 | mDuration = paramLong; 299 | mScale = ((float) (mHeaderContainer.getBottom()) / mHeaderHeight); 300 | mIsFinished = false; 301 | post(this); 302 | } 303 | } 304 | } 305 | } 306 | --------------------------------------------------------------------------------