diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34a6d05 --- /dev/null +++ b/.gitignore @@ -0,0 +1,62 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +/.idea + +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties +.classpath +.project +.settings/ + +# Proguard folder generated by Eclipse +proguard/ + +#Log Files +*.log + +# OS X +.DS_Store + +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.war +*.ear +*.iml + +# IDEA Files +.idea/ +.settings/ +out/ + +# MAVEN COMPILE Files +target/ + +project.properties \ No newline at end of file diff --git a/ATTRIBUTES-ch.md b/ATTRIBUTES-ch.md new file mode 100644 index 0000000..adb2c0e --- /dev/null +++ b/ATTRIBUTES-ch.md @@ -0,0 +1,122 @@ +[Englis API](ATTRIBUTES.md) +### initIndicator + +初始化indicator,支持链式调用set属性,focusColor, normalColor是必设属性,否则indicator不会显示。 +#### 接口 +``` +IUltraIndicatorBuilder initIndicator(); +``` +--- +### setFocusColor setNormalColor +设置indicator 图标颜色。 +`focusColor` 被选中的indicator颜色 +`normalColor` 未被选中的indicator颜色 +#### 接口 +``` +IUltraIndicatorBuilder setFocusColor(int focusColor); +IUltraIndicatorBuilder setNormalColor(int normalColor); +``` +``` +ultraViewPager.getIndicator() + .setFocusColor(Color.GREEN) + .setNormalColor(Color.WHITE) + .setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); +``` + +![color](pics/20151203-0.png) +--- +### setFocusResId setNormalResId +设置indicator 图片资源。 +`focusResId` 被选中的indicator icon Id +`normalResId` 未被选中的indicator icon Id +#### 接口 +``` +IUltraIndicatorBuilder setFocusResId(int focusResId); +IUltraIndicatorBuilder setNormalResId(int normalResId); +``` +``` +ultraViewPager.getIndicator() +.setFocusResId(R.mipmap.tm_biz_lifemaster_indicator_selected) +.setNormalResId(R.mipmap.tm_biz_lifemaster_indicator_normal); +``` +![icon](pics/20151203-1.png) +--- +### setIndicatorPadding + +`indicatorPadding` indicator的item之间的间距,默认是item的宽度 + +#### 接口 +``` +IUltraIndicatorBuilder setIndicatorPadding(int indicatorPadding); +``` +--- +### build +设置完indicator属性后, 需调用`build`完成创建。 + +#### 接口 +``` +void build(); +``` +--- +### setMultiScreen +开启一屏多显模式,child view的宽度不占满全屏。 +#### 接口 +``` +void setMultiScreen(float ratio) +``` + +``` +ultraViewPager.setMultiScreen(0.5f); +ultraViewPager.setItemRatio(1.0f); +ultraViewPager.setAutoMeasureHeight(true); +``` + + + +--- +### setAutoMeasureHeight +使能该功能,UltraViewPager的高度会自动调整到child view的高度。`setRadio` 和 `setAutoMeasureHeight` 不应该同时使用。 +#### 接口 +``` +void setAutoMeasureHeight(boolean enable) +``` + +``` +ultraViewPager.setMultiScreen(1.0f);//single screen +ultraViewPager.setItemRatio(1.0f);//the aspect ratio of child view equals to 1.0f +ultraViewPager.setAutoMeasureHeight(false); +``` + + +``` +ultraViewPager.setMultiScreen(1.0f); +ultraViewPager.setItemRatio(1.0f); +ultraViewPager.setAutoMeasureHeight(true); +``` + + +--- +### setItemRatio +设置后会以此宽高比调整child view的高度。 +#### 接口 + +``` +void setItemRatio(double ratio) +``` + +--- + +### setRatio +以设定的宽高比来绘制UltraViewPager。`setRatio`优先级高于`setItemRatio`. +#### 接口 +``` +void setRatio(float ratio) +``` +``` +ultraViewPager.setMultiScreen(1.0f);//single screen +ultraViewPager.setRatio(2.0f);//the aspect ratio of viewpager equals to 2.0f +ultraViewPager.setAutoMeasureHeight(true); +``` + + + diff --git a/ATTRIBUTES.md b/ATTRIBUTES.md new file mode 100644 index 0000000..19ec202 --- /dev/null +++ b/ATTRIBUTES.md @@ -0,0 +1,129 @@ +[中文API](ATTRIBUTES-ch.md) +### initIndicator +Constructs a indicator with no options. This indicator supports calling set-method in chained mode. The arrtibutes of `focusColor` and `normalColor` are necessary, or the indicator won't be shown. + +#### API +``` +IUltraIndicatorBuilder initIndicator(); +``` +--- +### setFocusColor setNormalColor +Fill indicator with color. + +`focusColor` Set focused color for indicator. +`normalColor` Set normal color for indicator. + +#### API +``` +IUltraIndicatorBuilder setFocusColor(int focusColor); +IUltraIndicatorBuilder setNormalColor(int normalColor); +``` + +``` +ultraViewPager.getIndicator() + .setFocusColor(Color.GREEN) + .setNormalColor(Color.WHITE) + .setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); +``` + +![color](pics/20151203-0.png) + +--- +### setFocusResId setNormalResId +Fill indicator with bitmap or icon. +`focusResId` Set focused resource ID for indicator. +`normalResId` Set normal resource ID for indicator. + +#### API +``` +IUltraIndicatorBuilder setFocusResId(int focusResId); +IUltraIndicatorBuilder setNormalResId(int normalResId); +``` +``` +ultraViewPager.getIndicator() +.setFocusResId(R.mipmap.tm_biz_lifemaster_indicator_selected) +.setNormalResId(R.mipmap.tm_biz_lifemaster_indicator_normal); +``` +![icon](pics/20151203-1.png) +--- +### setIndicatorPadding + +`indicatorPadding` sets spacing between indicator items,the default value is item's height. + + +#### API +``` +IUltraIndicatorBuilder setIndicatorPadding(int indicatorPadding); +``` + + +--- +### build +After setting the indicator feature, call `build()` to complete. + +#### API +``` +void build(); +``` +--- +### setMultiScreen +set multi-screen feature, the width of the child view won't occupy full screen. +#### API +``` +void setMultiScreen(float ratio) +``` + +``` +ultraViewPager.setMultiScreen(0.5f); +ultraViewPager.setItemRatio(1.0f); +ultraViewPager.setAutoMeasureHeight(true); +``` + + +--- +### setAutoMeasureHeight +When enabled, the height of the UltraViewPager will be automatically adjusted to the height of child view. +Do not use `setRadio` and `setAutoMeasureHeight` at the same time. +#### API +``` +void setAutoMeasureHeight(boolean enable) +``` + +``` +ultraViewPager.setMultiScreen(1.0f);//single screen +ultraViewPager.setItemRatio(1.0f);//the aspect ratio of child view equals to 1.0f +ultraViewPager.setAutoMeasureHeight(false); +``` + + +``` +ultraViewPager.setMultiScreen(1.0f); +ultraViewPager.setItemRatio(1.0f); +ultraViewPager.setAutoMeasureHeight(true); +``` + + +--- +### setItemRatio +Adjust the height of child view with aspect `ratio`. +#### API + +``` +void setItemRatio(double ratio) +``` + +--- +### setRatio +Draw UltraViewPager with the aspect `ratio`. The priority of `setRatio` is higher than `setItemRatio` +#### API +``` +void setRatio(float ratio) +``` +``` +ultraViewPager.setMultiScreen(1.0f);//single screen +ultraViewPager.setRatio(2.0f);//the aspect ratio of viewpager equals to 2.0f +ultraViewPager.setAutoMeasureHeight(true); +``` + + + diff --git a/README-ch.md b/README-ch.md new file mode 100644 index 0000000..0cdcad9 --- /dev/null +++ b/README-ch.md @@ -0,0 +1,110 @@ +### UltraViewPager +[English Document](README.md) + +#### 简介 +UltraViewPager是一个封装多种特性的ViewPager,主要是为多页面切换场景提供统一解决方案。 + +![Example0](pics/example0.gif) +![Example1](pics/example1.gif) +![Example0](pics/example2.gif) +![Example1](pics/example3.gif) + +#### 主要功能 + +* 支持横向滑动/纵向滑动 +* 支持一屏内显示多页 +* 支持循环滚动 +* 支持定时滚动,计时器使用Handler实现 +* 支持设置ViewPager的最大宽高 +* setRatio按比例显示UltraviewPager +* 内置indicator,只需简单设置几个属性就可以完成展示,支持圆点和Icon; +* 内置两种页面切换动效 + +以上特性支持同时使用; + +#### 设计思路 +UltraViewPager继承自RelativeLayout,将ViewPager和indicator置于其中,同时UltraViewPager提供了一些ViewPager常用方法的代理,这样在日常使用上保持和ViewPager无差异,如果需要调用ViewPager的所有方法,可通过getViewPager()方法拿到真正的ViewPager进行操作. + +竖向滑动是通过在ViewPager的onInterceptTouchEvent和onTouchEvent中交换横竖向的event location,同时设置特殊PageTransformer实现,详见源码. + +#### 使用方法 +版本请参考mvn repository上的最新版本(目前最新版本是1.0.22),最新的 aar 都会发布到 jcenter 和 MavenCentral 上,确保配置了这两个仓库源,然后引入aar依赖: + +``` +//gradle +compile ('com.alibaba.android:ultraviewpager:1.0.22@aar') { + transitive = true +} + +``` + +或者maven + +``` +//pom.xml in maven + + com.alibaba.android + ultraviewpager + 1.0.22 + aar + + +``` + +在layout中使用UltraViewPager: +activity_pager.xml + +```xml + + +``` + +可以参考以下步骤使用UltraViewPager: + +``` +UltraViewPager ultraViewPager = (UltraViewPager)findViewById(R.id.ultra_viewpager); +ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL); +//UltraPagerAdapter 绑定子view到UltraViewPager +PagerAdapter adapter = new UltraPagerAdapter(false); +ultraViewPager.setAdapter(adapter); + +//内置indicator初始化 +ultraViewPager.initIndicator(); +//设置indicator样式 +ultraViewPager.getIndicator() + .setOrientation(UltraViewPager.Orientation.HORIZONTAL) + .setFocusColor(Color.GREEN) + .setNormalColor(Color.WHITE) + .setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); +//设置indicator对齐方式 +ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); +//构造indicator,绑定到UltraViewPager +ultraViewPager.getIndicator().build(); + +//设定页面循环播放 +ultraViewPager.setInfiniteLoop(true); +//设定页面自动切换  间隔2秒 +ultraViewPager.setAutoScroll(2000); + +``` +Api接口详情请参考[文档](ATTRIBUTES-ch.md) + +#### DEMO + +[Demo工程](https://github.com/alibaba/vlayout/tree/master/examples) + + +#### 开源许可证 + +UltraViewPager遵循MIT开源许可证协议。 + + + + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..855873c --- /dev/null +++ b/README.md @@ -0,0 +1,113 @@ +### UltraViewPager + +[中文文档](README-ch.md) + +Project`UltraViewPager` is a ViewPager extension that encapsulates multiple features, mainly to provide a unified solution for multi-page switching scenarios. + +![Example0](pics/example0.gif) +![Example1](pics/example1.gif) +![Example0](pics/example2.gif) +![Example1](pics/example3.gif) + + +#### Main Feature + +* support horizontal scrolling and vertical scrolling +* support multi views in one viewpager +* support switching views circularly. For example, if there are 3 views to display in a ViewPager, it should switch back to the first view after the third view. +* support auto-scrolling feature,implemented timer with Handler. +* support setting max-height and max-width for this ViewPager. +* support setting the aspect ratio for UltraViewPager. +* UltraViewPager has a built-in indicator. support circle and icon style. +* built-in two kind of page tansition animation. + +you can combine multiple features at the same time. + +#### Design +UltraViewPager is a super extension for ViewPager. +It's actually a RelativeLayout in order to display ViewPager and Indicator.UltraViewPager offers some common method delegate for ViewPager, you can also invoke more method by call getViewPager() and get the actual ViewPager. + +In order to achieve vertical scroll, through exchanging MotionEvent in onInterceptTouchEvent and onTouchEvent.For more details, you can read the source code. + +#### Usage + +Please find the latest version(1.0.0 so far) in maven repository. The newest version has been upload to jcenter and MavenCantral, make sure you have added at least one of these repositories. + +Using Gradle: + +``` +//gradle +compile ('com.alibaba.android:ultraviewpager:1.0.0@aar') { + transitive = true +} +``` +or grab via Maven: + +``` +//pom.xml in maven + + com.alibaba.android + ultraviewpager + 1.0.0 + aar + + +``` + +Create your own layout using a UltraViewPager: + +activity_pager.xml + +```xml + + +``` + +You can follow my tutorial below on how to use UltraViewPager: + +``` +UltraViewPager ultraViewPager = (UltraViewPager)findViewById(R.id.ultra_viewpager); +ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL); +//initialize UltraPagerAdapter,and add child view to UltraViewPager +PagerAdapter adapter = new UltraPagerAdapter(false); +ultraViewPager.setAdapter(adapter); + +//initialize built-in indicator +ultraViewPager.initIndicator(); +//set style of indicators +ultraViewPager.getIndicator() + .setOrientation(UltraViewPager.Orientation.HORIZONTAL) + .setFocusColor(Color.GREEN) + .setNormalColor(Color.WHITE) + .setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); +//set the alignment +ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); +//construct built-in indicator, and add it to UltraViewPager +ultraViewPager.getIndicator().build(); + +//set an infinite loop +ultraViewPager.setInfiniteLoop(true); +//enable auto-scroll mode +ultraViewPager.setAutoScroll(2000); + +``` +For other API reference,see [this](ATTRIBUTES.md) to read more. + +#### DEMO + +[Demo工程](https://github.com/alibaba/vlayout/tree/master/examples) + + +#### LICENSE +`UltraViewPager` is available under the MIT license. + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ff35bf9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,52 @@ +/* + * + * 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. + * + */ + +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + mavenCentral() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.3.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + maven{url'https://oss.sonatype.org/content/repositories/snapshots/'} + mavenCentral() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/deploy.gradle b/deploy.gradle new file mode 100644 index 0000000..a33af8b --- /dev/null +++ b/deploy.gradle @@ -0,0 +1,106 @@ +/* + * + * 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: 'maven' + +afterEvaluate { project -> + // add this statement + // androidJavadoc.classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + // androidJavadoc.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath + // androidJavadoc.classpath += files(project.getConfigurations().getByName('compile').asList()) + + task androidJavadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + classpath += files(project.getConfigurations().getByName('compile').asList()) + classpath += files(android.bootClasspath) + + options { + encoding "UTF-8" + charSet 'UTF-8' + author true + version true + links "http://d.android.com/reference/" + links "http://docs.oracle.com/javase/7/docs/api" + } + + include '**/*.java' + exclude '**/BuildConfig.java' + exclude '**/R.java' + exclude '**/pom.xml' + exclude '**/proguard_annotations.pro' + + + failOnError false + } + + task androidJavadocJar(type: Jar) { + classifier = 'javadoc' + from androidJavadoc.destinationDir + } + + task androidSourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.srcDirs + } + + android.libraryVariants.all { variant -> + def name = variant.name.capitalize() + task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) { + from variant.javaCompile.destinationDir + } + } + + + + artifacts.add('archives', androidJavadocJar) + artifacts.add('archives', androidSourcesJar) + + def configurePom = { pom -> + // repository(url: "${System.env.HOME}/.m2/repository") + def packageVersion = VERSION_NAME + + if (!project.hasProperty('doRelease')) { + packageVersion = packageVersion + '-SNAPSHOT' + } + + pom.project { + pom.groupId = GROUP + pom.artifactId = ARTIFACT + pom.version = packageVersion + pom.packaging = PACKAGING_TYPE + } + } + + task installArchives(type: Upload) { + configuration = configurations.archives + repositories.mavenDeployer { + repository url: "file://${System.properties['user.home']}/.m2/repository" + configurePom pom + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..c53e726 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,53 @@ +# +# +# 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. +# +# + +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true + +GROUP=com.alibaba.android +ARTIFACT=ultraviewpager +VERSION=10 +VERSION_NAME=1.0.22 +PACKAGING_TYPE=aar +systemProp.compileSdkVersion=23 +systemProp.targetSdkVersion=23 +systemProp.buildToolsVersion=23.0.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..05ef575 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..33d5c89 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,33 @@ +# +# +# 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. +# +# + +#Wed Oct 21 11:34:03 PDT 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip + diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/pics/20151203-0.png b/pics/20151203-0.png new file mode 100644 index 0000000..04a92ef Binary files /dev/null and b/pics/20151203-0.png differ diff --git a/pics/20151203-1.png b/pics/20151203-1.png new file mode 100644 index 0000000..f610f4c Binary files /dev/null and b/pics/20151203-1.png differ diff --git a/pics/20151203-2.png b/pics/20151203-2.png new file mode 100644 index 0000000..df27fd0 Binary files /dev/null and b/pics/20151203-2.png differ diff --git a/pics/api0.png b/pics/api0.png new file mode 100644 index 0000000..5de56e0 Binary files /dev/null and b/pics/api0.png differ diff --git a/pics/api1.png b/pics/api1.png new file mode 100644 index 0000000..5ecf5e3 Binary files /dev/null and b/pics/api1.png differ diff --git a/pics/api2.png b/pics/api2.png new file mode 100644 index 0000000..a95f276 Binary files /dev/null and b/pics/api2.png differ diff --git a/pics/api3.png b/pics/api3.png new file mode 100644 index 0000000..5534b81 Binary files /dev/null and b/pics/api3.png differ diff --git a/pics/demo_0.png b/pics/demo_0.png new file mode 100644 index 0000000..d17e350 Binary files /dev/null and b/pics/demo_0.png differ diff --git a/pics/demo_1.png b/pics/demo_1.png new file mode 100644 index 0000000..5e7e7e3 Binary files /dev/null and b/pics/demo_1.png differ diff --git a/pics/example0.gif b/pics/example0.gif new file mode 100644 index 0000000..622dfb8 Binary files /dev/null and b/pics/example0.gif differ diff --git a/pics/example1.gif b/pics/example1.gif new file mode 100644 index 0000000..e3e0fd2 Binary files /dev/null and b/pics/example1.gif differ diff --git a/pics/example2.gif b/pics/example2.gif new file mode 100644 index 0000000..ec308f7 Binary files /dev/null and b/pics/example2.gif differ diff --git a/pics/example3.gif b/pics/example3.gif new file mode 100644 index 0000000..ae07687 Binary files /dev/null and b/pics/example3.gif differ diff --git a/readme.html b/readme.html new file mode 100644 index 0000000..1fec454 --- /dev/null +++ b/readme.html @@ -0,0 +1,397 @@ + + + + + + + + +UltraViewPager + + + +

UltraViewPager

+ +
+ +

简介

+ +

UltraViewPager是一个聚合多种特性的ViewPager,主要目的是给一些频繁出现的场景提供一个高效统一的解决方案。
+UltraViewPager的特性包括:

+ + + + +

以上特性支持同时使用;

+ +
+ +

使用方法

+ +
1.设置横/竖向滑动
+ +
    /**
+     * 设置滚动模式,包括水平滚动和竖直滚动
+     *
+     * @param scrollMode 
+     */
+    void setScrollMode(UltraViewPager.ScrollMode scrollMode);
+
+ +

scrollMode的值是 UltraViewPager.ScrollMode.HORIZONTAL 或 UltraViewPager.ScrollMode.VERTICAL,默认横向滑动;

+ +
2. 一屏内显示多页
+ +
    /**
+     * 设置内部child的resId,用于获取child的大小,设置后会启用MultiScreen特性
+     *
+     * @param matchChildWithResId the child id
+     */
+    void setChildResId(int matchChildWithResId);
+
+ +

一屏内显示多页的一个条件是page中需要显示的view不是满屏,且有固定的宽高,使用时需用一个layout包裹需要显示的view,建议使用RelativeLayout嵌套view,然后把view设置center,setChildResId方法中的id是这里view的id;

+ +
3. 循环滚动
+ +
    /**
+     * 设置无限循环
+     *
+     * @param enable 是否开启
+     */
+    void setInfiniteLoop(boolean enable);
+
+ +

没什么好说明的,看接口文档应该不难理解;

+ +
4. 定时滚动
+ +
    /**
+     * 以特定的间隔时间开始自动翻页
+     *
+     * @param intervalInMillis page的自动翻页间隔时间
+     */
+    void setAutoScroll(int intervalInMillis);
+
+    /**
+     * 停止自动翻页
+     */
+    void disableAutoScroll();
+
+ +

注意setAutoScroll的参数单位是 毫秒;

+ +
5. 设置UltraViewPager的最大宽高
+ +
    /**
+     * 设置ViewPager的最大宽度
+     *
+     * @param width 宽度
+     */
+    void setMaxWidth(int width);
+
+    /**
+     * 设置ViewPager的最大高度
+     *
+     * @param height 高度
+     */
+    void setMaxHeight(int height);
+
+ +
6. 设置比例
+ +
    /**
+     * 以设定的 宽/高 比例来绘制UltraViewPager
+     *
+     * @param ratio
+     */
+    void setRatio(float ratio);
+
+ +
7. Indicator
+ +

UltraViewPager的indicator支持两种样式,圆点和Icon:
+
+
+indicator同样支持横向和竖向两种方式:
+
+initIndicator的调用会返回IUltraIndicatorBuilder,故indicator支持链式调用,不过需要注意的是调用完initIndicator之后需要调用build()完成indicator的建立;

+ +
/**
+ * 初始化indicator,支持链式set属性,focusColor, normalColor是必设属性,否则indicator不会显示
+ *
+ * @return
+ */
+IUltraIndicatorBuilder initIndicator();
+
+/**
+ * 使用一些基础值创建indicator, 需自己调用build完成创建
+ *
+ * @param focusColor    indicator被选中的颜色
+ * @param normalColor   indicator未被选中的颜色
+ * @param radiusInPixel indicator的半径
+ * @param gravity       indicator的布局位置,使用android.view.Gravity,支持组合使用,如:Gravity.BOTTOM | Gravity.RIGHT
+ */
+IUltraIndicatorBuilder initIndicator(int focusColor, int normalColor, int radiusInPixel, int gravity);
+
+/**
+ * 使用一些基础值创建indicator, 需自己调用build完成创建
+ *
+ * @param focusColor    indicator被选中的颜色
+ * @param normalColor   indicator未被选中的颜色
+ * @param strokeColor   边框颜色
+ * @param strokeWidth   边框大小
+ * @param radiusInPixel indicator的半径
+ * @param gravity       indicator的布局位置,使用android.view.Gravity,支持组合使用,如:Gravity.BOTTOM | Gravity.RIGHT
+ */
+IUltraIndicatorBuilder initIndicator(int focusColor, int normalColor, int strokeColor, int strokeWidth, int radiusInPixel, int gravity);
+
+/**
+ * 使用一些基础值创建indicator, 需自己调用build完成创建
+ *
+ * @param focusResId  indicator被选中的图片资源id
+ * @param normalResId indicator未被选中的图片资源id
+ * @param gravity     indicator的布局位置,使用android.view.Gravity,支持组合使用,如:Gravity.BOTTOM | Gravity.RIGHT
+ */
+IUltraIndicatorBuilder initIndicator(int focusResId, int normalResId, int gravity);
+
+/**
+ * 移除indicator
+ */
+void disableIndicator();
+
+ +

以下是IUltraIndicatorBuilder的相关接口方法:

+ +
IUltraIndicatorBuilder setFocusColor(int focusColor);
+
+IUltraIndicatorBuilder setNormalColor(int normalColor);
+
+IUltraIndicatorBuilder setStrokeColor(int strokeColor);
+
+IUltraIndicatorBuilder setStrokeWidth(int strokeWidth);
+
+/**
+ * indicator的item之间的间距,默认是item的宽度
+ * @param indicatorPadding
+ * @return
+ */
+IUltraIndicatorBuilder setIndicatorPadding(int indicatorPadding);
+
+IUltraIndicatorBuilder setRadius(int radius);
+
+IUltraIndicatorBuilder setOrientation(UltraViewPager.Orientation orientation);
+
+/**
+ * 使用android.view.Gravity,支持组合使用,如:Gravity.BOTTOM | Gravity.RIGHT
+ *
+ * @param gravity android.view.Gravity
+ * @return
+ */
+IUltraIndicatorBuilder setGravity(int gravity);
+
+IUltraIndicatorBuilder setFocusResId(int focusResId);
+
+IUltraIndicatorBuilder setNormalResId(int normalResId);
+
+IUltraIndicatorBuilder setMargin(int left, int top, int right, int bottom);
+
+void build();
+
+ +
8. PageTransformer
+ +

竖向滑动暂不支持设置PageTransformer,待后续解决;以下是几个demo:
+ +

+ +
+ +

组件设计说明

+ +

因需要把indicator内置,所以UltraViewPager的实现方式比较特殊,是继承自RelativeLayout,然后将ViewPager和indicator置于其中,同时UltraViewPager提供了一些ViewPager常用方法的代理,这样在日常使用上保持和ViewPager无差异,如果需要调用ViewPager的所有方法,可通过getViewPager()方法拿到真正的ViewPager进行操作.

+ +

竖向滑动是通过在ViewPager的onInterceptTouchEvent和onTouchEvent中交换横竖向的eventLocation,同时设置特殊PageTransformer实现,详见源码.

+ + \ No newline at end of file diff --git a/sample/.gitignore b/sample/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/sample/.gitignore @@ -0,0 +1 @@ +/build diff --git a/sample/build.gradle b/sample/build.gradle new file mode 100644 index 0000000..5504f75 --- /dev/null +++ b/sample/build.gradle @@ -0,0 +1,51 @@ +/* + * + * 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.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile project(':ultraviewpager') + +} diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro new file mode 100644 index 0000000..4ad4192 --- /dev/null +++ b/sample/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/mikeafc/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/sample/src/androidTest/java/com/tmall/ultraviewpager/ApplicationTest.java b/sample/src/androidTest/java/com/tmall/ultraviewpager/ApplicationTest.java new file mode 100644 index 0000000..c03d45b --- /dev/null +++ b/sample/src/androidTest/java/com/tmall/ultraviewpager/ApplicationTest.java @@ -0,0 +1,39 @@ +/* + * + * 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. + * + */ + +package com.tmall.ultraviewpager; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d7c16cc --- /dev/null +++ b/sample/src/main/AndroidManifest.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + diff --git a/sample/src/main/assets/ultraviewpager_config.xml b/sample/src/main/assets/ultraviewpager_config.xml new file mode 100644 index 0000000..7b82def --- /dev/null +++ b/sample/src/main/assets/ultraviewpager_config.xml @@ -0,0 +1,39 @@ + + + + + + com.tmall.ultraviewpager + com.tmall.ultraviewpager + UltraViewPager + 简单高效的 ViewPager! + 智闲 + 2015-12-04 + Views + + + \ No newline at end of file diff --git a/sample/src/main/java/com/tmall/ultraviewpager/sample/PagerActivity.java b/sample/src/main/java/com/tmall/ultraviewpager/sample/PagerActivity.java new file mode 100644 index 0000000..0405410 --- /dev/null +++ b/sample/src/main/java/com/tmall/ultraviewpager/sample/PagerActivity.java @@ -0,0 +1,295 @@ +/* + * + * 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. + * + */ + +package com.tmall.ultraviewpager.sample; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.view.PagerAdapter; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.RelativeLayout; +import android.widget.Spinner; + +import com.tmall.ultraviewpager.UltraViewPager; +import com.tmall.ultraviewpager.transformer.UltraDepthScaleTransformer; +import com.tmall.ultraviewpager.transformer.UltraScaleTransformer; + + +public class PagerActivity extends Activity implements AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener, View.OnClickListener { + private UltraViewPager ultraViewPager; + private PagerAdapter adapter; + + private Spinner indicatorStyle; + private Spinner indicatorGravityHor; + private Spinner indicatorGravityVer; + + private Button indicatorBuildBtn; + + private CheckBox loopCheckBox; + private CheckBox autoScrollCheckBox; + + private int gravity_hor; + private int gravity_ver; + private UltraViewPager.Orientation gravity_indicator; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_pager); + + int style = getIntent().getIntExtra("style", 1); + ultraViewPager = (UltraViewPager) findViewById(R.id.ultra_viewpager); + + switch (style){ + case 1: + setTitle("Horizontal Demo"); + break; + case 2: + setTitle("Vertical Demo"); + break; + case 3: + setTitle("MultiScreen_H Demo"); + break; + case 4: + setTitle("MultiScreen_V Demo"); + break; + case 5: + setTitle("ScaleTransformer Demo"); + break; + case 6: + setTitle("DepthTransformer Demo"); + break; + default: + break; + } + +// defaultUltraViewPager(); + + switch (style) { + case 1: + ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL); + adapter = new UltraPagerAdapter(false); + ultraViewPager.setAdapter(adapter); + gravity_indicator = UltraViewPager.Orientation.HORIZONTAL; + break; + case 2: + ultraViewPager.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.VERTICAL); + adapter = new UltraPagerAdapter(false); + ultraViewPager.setAdapter(adapter); + gravity_indicator = UltraViewPager.Orientation.VERTICAL; + break; + case 3: + case 5: + case 6: + ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL); + adapter = new UltraPagerAdapter(true); + ultraViewPager.setAdapter(adapter); + ultraViewPager.setMultiScreen(0.6f); + ultraViewPager.setItemRatio(1.0f); +// ultraViewPager.setRatio(2.0f); +// ultraViewPager.setMaxHeight(800); + ultraViewPager.setAutoMeasureHeight(true); + gravity_indicator = UltraViewPager.Orientation.HORIZONTAL; + if (style == 5) { + ultraViewPager.setPageTransformer(false, new UltraScaleTransformer()); + } + if (style == 6) { + ultraViewPager.setPageTransformer(false, new UltraDepthScaleTransformer()); + } + break; + case 4: + ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.VERTICAL); + ultraViewPager.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + adapter = new UltraPagerAdapter(true); + ultraViewPager.setAdapter(adapter); + ultraViewPager.setMultiScreen(1.0f); + ultraViewPager.setAutoMeasureHeight(true); + gravity_indicator = UltraViewPager.Orientation.VERTICAL; + break; + } + + initUI(); + } + + private void initUI() { + indicatorStyle = (Spinner) findViewById(R.id.indicator); + indicatorGravityHor = (Spinner) findViewById(R.id.indicator_gravity_hor); + indicatorGravityVer = (Spinner) findViewById(R.id.indicator_gravity_ver); + + ArrayAdapter indicatorAdapter = ArrayAdapter.createFromResource(this, R.array.indicator_style, android.R.layout.simple_spinner_item); + indicatorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + indicatorStyle.setAdapter(indicatorAdapter); + + ArrayAdapter indicatorGraHorAdapter = ArrayAdapter.createFromResource(this, R.array.indicator_gravity_hor, android.R.layout.simple_spinner_item); + indicatorGraHorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + indicatorGravityHor.setAdapter(indicatorGraHorAdapter); + + ArrayAdapter indicatorGraVerAdapter = ArrayAdapter.createFromResource(this, R.array.indicator_gravity_ver, android.R.layout.simple_spinner_item); + indicatorGraVerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + indicatorGravityVer.setAdapter(indicatorGraVerAdapter); + + indicatorStyle.setOnItemSelectedListener(this); + indicatorGravityHor.setOnItemSelectedListener(this); + indicatorGravityVer.setOnItemSelectedListener(this); + + loopCheckBox = (CheckBox) findViewById(R.id.loop); + loopCheckBox.setOnCheckedChangeListener(this); + + autoScrollCheckBox = (CheckBox) findViewById(R.id.autoscroll); + autoScrollCheckBox.setOnCheckedChangeListener(this); + + indicatorBuildBtn = (Button) findViewById(R.id.indicator_build); + indicatorBuildBtn.setOnClickListener(this); + } + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (ultraViewPager.getIndicator() == null) { + ultraViewPager.initIndicator(); + ultraViewPager.getIndicator().setOrientation(gravity_indicator); + } + if (parent == indicatorStyle) { + switch (position) { + case 0: + ultraViewPager.disableIndicator(); + break; + case 1: + ultraViewPager.getIndicator().setFocusResId(0).setNormalResId(0); + ultraViewPager.getIndicator().setFocusColor(Color.GREEN).setNormalColor(Color.WHITE) + .setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); + break; + case 2: + ultraViewPager.getIndicator().setFocusResId(R.mipmap.tm_biz_lifemaster_indicator_selected) + .setNormalResId(R.mipmap.tm_biz_lifemaster_indicator_normal); + break; + case 3: + break; + } + } + if (parent == indicatorGravityHor) { + switch (position) { + case 0: + gravity_hor = Gravity.LEFT; + break; + case 1: + gravity_hor = Gravity.RIGHT; + break; + case 2: + gravity_hor = Gravity.CENTER_HORIZONTAL; + break; + } + if (ultraViewPager.getIndicator() != null) { + if (gravity_ver != 0) { + ultraViewPager.getIndicator().setGravity(gravity_hor | gravity_ver); + } else { + ultraViewPager.getIndicator().setGravity(gravity_hor); + } + } + } + if (parent == indicatorGravityVer) { + switch (position) { + case 0: + gravity_ver = Gravity.TOP; + break; + case 1: + gravity_ver = Gravity.BOTTOM; + break; + case 2: + gravity_ver = Gravity.CENTER_VERTICAL; + break; + } + if (ultraViewPager.getIndicator() != null) { + if (gravity_hor != 0) { + ultraViewPager.getIndicator().setGravity(gravity_hor | gravity_ver); + } else { + ultraViewPager.getIndicator().setGravity(gravity_ver); + } + } + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (buttonView == loopCheckBox) { + ultraViewPager.setInfiniteLoop(isChecked); + } + if (buttonView == autoScrollCheckBox) { + if (isChecked) + ultraViewPager.setAutoScroll(2000); + else + ultraViewPager.disableAutoScroll(); + } + } + + @Override + public void onClick(View v) { + ultraViewPager.getIndicator().build(); + } + + /** + * + */ + private void defaultUltraViewPager(){ + UltraViewPager ultraViewPager = (UltraViewPager)findViewById(R.id.ultra_viewpager); + ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL); + //initialize UltraPagerAdapter,and add child view to UltraViewPager + PagerAdapter adapter = new UltraPagerAdapter(false); + ultraViewPager.setAdapter(adapter); + + //initialize built-in indicator + ultraViewPager.initIndicator(); + //set style of indicators + ultraViewPager.getIndicator() + .setOrientation(UltraViewPager.Orientation.HORIZONTAL) + .setFocusColor(Color.GREEN) + .setNormalColor(Color.WHITE) + .setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); + //set the alignment + ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); + //construct built-in indicator, and add it to UltraViewPager + ultraViewPager.getIndicator().build(); + + //set an infinite loop + ultraViewPager.setInfiniteLoop(true); + //enable auto-scroll mode + ultraViewPager.setAutoScroll(2000); + } +} diff --git a/sample/src/main/java/com/tmall/ultraviewpager/sample/UPVDemoActivity.java b/sample/src/main/java/com/tmall/ultraviewpager/sample/UPVDemoActivity.java new file mode 100644 index 0000000..6f529af --- /dev/null +++ b/sample/src/main/java/com/tmall/ultraviewpager/sample/UPVDemoActivity.java @@ -0,0 +1,75 @@ +/* + * + * 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. + * + */ + +package com.tmall.ultraviewpager.sample; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +public class UPVDemoActivity extends Activity { + private Intent intent; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_upvdemo); + + intent = new Intent(); + intent.setClass(this, PagerActivity.class); + } + + public void clickHorizontal(View view) { + intent.putExtra("style", 1); + startActivity(intent); + } + + public void clickVertical(View view) { + intent.putExtra("style", 2); + startActivity(intent); + } + + public void clickMultiScrHorizontal(View view) { + intent.putExtra("style", 3); + startActivity(intent); + } + + public void clickMultiScrVertical(View view) { + intent.putExtra("style", 4); + startActivity(intent); + } + + public void clickScaleTransformer(View view) { + intent.putExtra("style", 5); + startActivity(intent); + } + + public void clickDepthTransformer(View view) { + intent.putExtra("style", 6); + startActivity(intent); + } +} diff --git a/sample/src/main/java/com/tmall/ultraviewpager/sample/UltraPagerAdapter.java b/sample/src/main/java/com/tmall/ultraviewpager/sample/UltraPagerAdapter.java new file mode 100644 index 0000000..50eccc3 --- /dev/null +++ b/sample/src/main/java/com/tmall/ultraviewpager/sample/UltraPagerAdapter.java @@ -0,0 +1,92 @@ +/* + * + * 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. + * + */ + +package com.tmall.ultraviewpager.sample; + +import android.graphics.Color; +import android.support.v4.view.PagerAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +/** + * Created by mikeafc on 15/11/26. + */ +public class UltraPagerAdapter extends PagerAdapter { + private boolean isMultiScr; + + public UltraPagerAdapter(boolean isMultiScr) { + this.isMultiScr = isMultiScr; + } + + @Override + public int getCount() { + return 5; + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(container.getContext()).inflate(R.layout.layout_child, null); + //new LinearLayout(container.getContext()); + TextView textView = (TextView) linearLayout.findViewById(R.id.pager_textview); + textView.setText(position + ""); + linearLayout.setId(R.id.item_id); + switch (position) { + case 0: + linearLayout.setBackgroundColor(Color.parseColor("#2196F3")); + break; + case 1: + linearLayout.setBackgroundColor(Color.parseColor("#673AB7")); + break; + case 2: + linearLayout.setBackgroundColor(Color.parseColor("#009688")); + break; + case 3: + linearLayout.setBackgroundColor(Color.parseColor("#607D8B")); + break; + case 4: + linearLayout.setBackgroundColor(Color.parseColor("#F44336")); + break; + } + container.addView(linearLayout); +// linearLayout.getLayoutParams().width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, container.getContext().getResources().getDisplayMetrics()); +// linearLayout.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400, container.getContext().getResources().getDisplayMetrics()); + return linearLayout; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + LinearLayout view = (LinearLayout) object; + container.removeView(view); + } +} diff --git a/sample/src/main/res/layout/activity_pager.xml b/sample/src/main/res/layout/activity_pager.xml new file mode 100644 index 0000000..79b5525 --- /dev/null +++ b/sample/src/main/res/layout/activity_pager.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + +