Skip to content

Commit

Permalink
初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
open-android committed Mar 12, 2017
1 parent 89539e8 commit dd34d4c
Show file tree
Hide file tree
Showing 57 changed files with 11,096 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
.idea
130 changes: 129 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,129 @@
# ViewPager
# YViewPagerDemo
YViewPager,support horizontal and vertical,based on `support.v4.view.ViewPager`

[中文版点这里](https://github.com/youngkaaa/YViewPagerDemo/blob/master/README_CH.md)

## Usage

### Gradle

```
compile 'cn.youngkaaa:yviewpager:0.2'
```

### Maven

```
<dependency>
<groupId>cn.youngkaaa</groupId>
<artifactId>yviewpager</artifactId>
<version>0.2</version>
<type>pom</type>
</dependency>
```

## Intro
The `YViewPager` is modified from the official `support.v4.view.ViewPager`,which support the direction of horizontal and vertical(new direction).You can use this lib just like the official `support.v4.view.ViewPager`,include the features of `setPageTransformer()``addOnPageChangeListener()``setOffscreenPageLimit()` and so on,And also supported the `TabLayout`.


## Feature

### Direction

On the base of the `support.v4.view.ViewPager`,add the property of `direction`. You can use it by:

#### xml

```
<cn.youngkaaa.yviewpager.YViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:orientation="vertical"/>
```

just like the above xml.you can add the property `app:orientation` in `YViewPager` tag, the value of this property is `horizontal` and `vertical`.


#### java code
```
mViewPager.setDirection(YViewPager.VERTICAL);
mViewPager.setDirection(YViewPager.HORIZONTAL);
```

you can change the direction by calling the `YViewPager.setDirection()`

Tip:It's not recommended that change the direction when your application is running,which include a inflated `YViewPager`,because at this time the `YViewPager` may included the Fragments,which may has the deeply view hierarchy,and when you call the `setDriection()` may invaliate the layout,so may cause the application ANR or bad layout.but it's just not recommended,not unsupport!

### Circulatory

in `v1.2`,add the property of `circulatory`.you can use it by:

#### xml

```
<cn.youngkaaa.yviewpager.YViewPager
android:id="@+id/viewpager1"
android:layout_width="match_parent"
android:layout_height="188dp"
app:circulatory="true"
app:orientation="horizontal"/>
```

yeah,you just need to add one line.

#### java

sorry,the property of `circulatory` do not support to change by using java code.


## Version

### v0.2

add the `circulatory` property,which support the direction of horizontal and vertical (`2017-2-26`)

### v0.1

support the direction of vertical and horizontal(`2017-2-22`


## Finally

Because the `FragmentPagerAdapter``FragmentStatePagerAdapter` and `PagerAdapter` has some methods are not br called in `YViewPager`,so I copy the code in this lib named `YFragmentPagerAdapter``YFragmentStatePagerAdapter` and `YPagerAdapter`,you can choose the `YxxxxxAdapter` in this lib which you needed!

The running screenshot:

> v0.1
![](https://github.com/youngkaaa/YViewPagerDemo/blob/master/screens/record.gif)

> v0.2
![](https://github.com/youngkaaa/YViewPagerDemo/blob/master/screens/record_circle.gif)


If you think this lib help you,you can give me a star to encourage me! thanks a lot

# License
```
Copyright 2017 youngkaaa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```



127 changes: 127 additions & 0 deletions README_CH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# YViewPagerDemo
YViewPager,support horizontal and vertical,based on `support.v4.view.ViewPager`

# Preview
![horizontal](gif/horizontal.gif)

![vertical](gif/vertical.gif)

## 使用

### Gradle

```
compile 'cn.youngkaaa:yviewpager:0.2'
```

### Maven

```
<dependency>
<groupId>cn.youngkaaa</groupId>
<artifactId>yviewpager</artifactId>
<version>0.2</version>
<type>pom</type>
</dependency>
```

## 简介
支持水平方向上滑动和竖直方向上的滑动,直接修改的官方提供的`ViewPager`的源码,注入了方向判断,使用起来和官方的`ViewPager`基本一样,还有监听事件也是一样的,支持`setOffscreenPageLimit()`可以放心滑动,以及`TabLayout`等。

## 特性

### 方向

在官方原有特性下,新增加`direction`属性。可以通过两种方式来设置:

#### xml

```
<cn.youngkaaa.yviewpager.YViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:orientation="vertical"/>
```

就像上面这样,只需要设置`app:orientation`属性,该属性可选值为:`vertical``horizontal`,分别代表竖直方向上滑动和水平方向上滑动。

#### java代码

```
mViewPager.setDirection(YViewPager.VERTICAL);
mViewPager.setDirection(YViewPager.HORIZONTAL);
```

具体意思同上
注意,设计的起始是想着在`YViewPager`一开始inflate时就应该确定了方向,如果在后期app运行时(即在`YViewPager`创建显示后)通过代码来修改方向的话,这种做法不推荐,因为`YViewPager`内部可能有很深View结构的`Fragment`,所以在此时修改`YViewPager``direction`的话,会通知刷新`YViewPager`,会造成顿时卡顿,所以不推荐此做法,但是不代表不可以这样做,如果您的需求确实是这样那么这样做也是可以的。

### 循环滚动

`v1.2`版本开始增添了`circulatory`属性,你可以这样使用:

#### xml

```
<cn.youngkaaa.yviewpager.YViewPager
android:id="@+id/viewpager1"
android:layout_width="match_parent"
android:layout_height="188dp"
app:circulatory="true"
app:orientation="horizontal"/>
```
是的,就只需要一句代码就可以了。

#### java

对不起,暂时不支持使用java代码动态修改`circulatory`属性。因为一般循环与否都是在xml中提前决定好的,所以就仅仅支持xml修改

## 版本


### v0.2

加入循环属性,同样支持水平和竖直两个方向上的循环。

### v0.1

支持水平和竖直方向上得滑动切换

## 最后

为什么我要在官方原有的`ViewPager`源码的基础上来修改,是因为官方在做`ViewPager`中做了很多优化和提升,所以我只修改了原有的源码的事件逻辑,并没有大的修改,所以官方的心血还是保留了的。但是这样带来的也有缺点,那就是官方的那些`FragmentPagerAdapter``FragmentStatePagerAdapter`以及`PagerAdapter`都不能直接调用了,因为这些类里面有一些方法不支持外部类调用,所以我拷贝了这三个类到本仓库中,代码和官方的是一样的,只是改了类名以保证可以在`YViewPager`中调用而已,所以你可以按照官方的方式来使用,你可以在你的项目中需要哪一个`XXXXAdapter`就拷贝该类到你的项目中去。

最后附上运行图:


> v0.1
![](https://github.com/youngkaaa/YViewPagerDemo/blob/master/screens/record.gif)

> v0.2
![](https://github.com/youngkaaa/YViewPagerDemo/blob/master/screens/record_circle.gif)

如果你觉得本仓库对你有用的话请给个star表示鼓励吧

具体的关于`ViewPager`的源码简单分析可以看我的博客

# License
```
Copyright 2016 youngkaaa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

7 changes: 7 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gradle/
.idea/
*/build/
build/
gradle/
local.properties
*.iml
30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "cn.youngkaaa.yviewpagerdemo"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
compile project(path: ':yviewpager')
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in H:\Android_SDK\adt-bundle-windows-x86_64-20131030\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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cn.youngkaaa.yviewpagerdemo;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("cn.youngkaaa.yviewpagerdemo", appContext.getPackageName());
}
}
20 changes: 20 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.youngkaaa.yviewpagerdemo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit dd34d4c

Please sign in to comment.