Skip to content

Commit 1828e7e

Browse files
author
Edwin Wu
committed
代码修复优化更新 v2.1.8
1 parent 97937f9 commit 1828e7e

File tree

8 files changed

+34
-42
lines changed

8 files changed

+34
-42
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Step 2. Add the dependency
3535

3636
```groovy
3737
dependencies {
38-
compile 'com.github.why168:LoopViewPagerLayout:2.1.5'
38+
compile 'com.github.why168:LoopViewPagerLayout:2.1.8'
3939
}
4040
```
4141

@@ -219,6 +219,10 @@ public interface OnBannerItemClickListener {
219219
1. 优化总距离的计算方法。<a target="_blank" href="https://github.com/why168/LoopViewPagerLayout/issues/5"> issues 5</a>
220220
2. 请使用2.1.5稳定版发布
221221

222+
* 2018/2/27
223+
1. 代码修复优化更新
224+
2. 请使用2.1.8稳定版发布
225+
222226
223227
<br>
224228

app/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.edwin.loopviewpager"
99
minSdkVersion rootProject.minSdkVersion
1010
targetSdkVersion rootProject.targetSdkVersion
11-
versionCode 8
12-
versionName "2.1.5"
11+
versionCode 9
12+
versionName "2.1.8"
1313
}
1414

1515
buildTypes {
@@ -19,12 +19,6 @@ android {
1919
}
2020
}
2121

22-
allprojects {
23-
repositories {
24-
jcenter()
25-
maven { url "https://jitpack.io" }
26-
}
27-
}
2822
}
2923

3024
dependencies {

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
}
88
dependencies {
99
classpath 'com.android.tools.build:gradle:3.0.1'
10-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
@@ -25,6 +25,7 @@ allprojects {
2525
repositories {
2626
google()
2727
jcenter()
28+
maven { url "https://jitpack.io" }
2829
}
2930
}
3031

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
defaultConfig {
1010
minSdkVersion rootProject.minSdkVersion
1111
targetSdkVersion rootProject.targetSdkVersion
12-
versionCode 8
13-
versionName "2.1.5"
12+
versionCode 9
13+
versionName "2.1.8"
1414
}
1515

1616
buildTypes {

library/src/main/java/com/github/why168/LoopViewPagerLayout.java

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.os.Looper;
66
import android.os.Message;
77
import android.support.annotation.DrawableRes;
8-
import android.support.v4.view.ViewCompat;
98
import android.support.v4.view.ViewPager;
109
import android.util.AttributeSet;
1110
import android.view.Gravity;
@@ -119,7 +118,7 @@ private void initializeView() {
119118
LayoutParams loop_params = new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
120119
addView(loopViewPager, loop_params);
121120

122-
//TODO FrameLayout
121+
// FrameLayout
123122
FrameLayout indicatorFrameLayout = new FrameLayout(getContext());
124123
LayoutParams f_params = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ((int) (20 * density)));
125124
f_params.addRule(RelativeLayout.CENTER_HORIZONTAL);//android:layout_centerHorizontal="true"
@@ -139,14 +138,14 @@ private void initializeView() {
139138
f_params.setMargins(((int) (10 * density)), 0, ((int) (10 * density)), 0);
140139
addView(indicatorFrameLayout, f_params);
141140

142-
//TODO indicatorLayout
141+
// 指标的布局
143142
indicatorLayout = new LinearLayout(getContext());
144143
FrameLayout.LayoutParams ind_params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT);
145144
indicatorLayout.setGravity(Gravity.CENTER);
146145
indicatorLayout.setOrientation(LinearLayout.HORIZONTAL);
147146
indicatorFrameLayout.addView(indicatorLayout, ind_params);
148147

149-
//TODO animIndicatorLayout
148+
// 动画指标布局
150149
animIndicatorLayout = new LinearLayout(getContext());
151150
FrameLayout.LayoutParams ind_params2 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
152151
animIndicatorLayout.setGravity(Gravity.CENTER | Gravity.START);
@@ -155,19 +154,17 @@ private void initializeView() {
155154
}
156155

157156
/**
158-
* Be sure to initialize the Data
157+
* 确保初始化数据
159158
*
160159
* @param context context
161160
*/
162161
public void initializeData(Context context) {
163162
initializeView();
164163

165164
L.e("LoopViewPager ---> initializeData");
166-
//TODO To prevent the flower screen
167-
if (loop_duration > loop_ms)
165+
if (loop_duration > loop_ms) // 防止花屏
168166
loop_duration = loop_ms;
169167

170-
//TODO loop_duration
171168
try {
172169
Field mField = ViewPager.class.getDeclaredField("mScroller");
173170
mField.setAccessible(true);
@@ -189,28 +186,21 @@ public void initializeData(Context context) {
189186
e.printStackTrace();
190187
}
191188

192-
//TODO loop_style
193189
if (loop_style == 1) {
194190
loopViewPager.setPageTransformer(true, new DepthPageTransformer());
195191
} else if (loop_style == 2) {
196192
loopViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
197193
}
198194

199-
//TODO Listener
200195
loopViewPager.setOnTouchListener(new OnTouchListener() {
201196
@Override
202197
public boolean onTouch(View v, MotionEvent event) {
203198
switch (event.getAction()) {
204199
case MotionEvent.ACTION_DOWN:
205-
L.e("ACTION_DOWN");
206-
stopLoop();
207-
break;
208200
case MotionEvent.ACTION_MOVE:
209-
L.e("ACTION_MOVE");
210201
stopLoop();
211202
break;
212203
case MotionEvent.ACTION_UP:
213-
L.e("ACTION_UP");
214204
startLoop();
215205
break;
216206
default:
@@ -234,7 +224,7 @@ public void setLoopData(ArrayList<BannerInfo> bannerInfos) {
234224
throw new NullPointerException("LoopViewPagerLayout bannerInfos is null or bannerInfos.size() isEmpty");
235225
}
236226

237-
//TODO Initialize multiple times, clear images and little red dot
227+
// 防止初始化多次,清除图片和小红点。
238228
if (indicatorLayout.getChildCount() > 0) {
239229
indicatorLayout.removeAllViews();
240230
removeView(animIndicator);
@@ -317,7 +307,7 @@ public void setLoop_style(LoopStyle loop_style) {
317307
}
318308

319309
/**
320-
* indicator_location
310+
* 指示器的位置
321311
*
322312
* @param indicatorLocation (enum values[1:left,0:depth,2:right])
323313
*/
@@ -336,7 +326,7 @@ public void startLoop() {
336326

337327
/**
338328
* stopLoop
339-
* Be sure to in onDestory,To prevent a memory leak
329+
* 一定要在onDestroy中防止内存泄漏。
340330
*/
341331
public void stopLoop() {
342332
handler.removeMessages(MESSAGE_LOOP);
@@ -376,23 +366,23 @@ private class ViewPageChangeListener implements ViewPager.OnPageChangeListener {
376366
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
377367
if (loopPagerAdapterWrapper.getCount() > 0) {
378368
float length = ((position % bannerInfos.size()) + positionOffset) / (bannerInfos.size() - 1);
379-
//TODO To prevent the last picture the little red dot slip out.
369+
// 为了防止最后一小红点滑出去
380370
if (length >= 1)
381371
return;
382372
float path = length * totalDistance;
383373
// L.e("path " + path + " = length * " + length + " totalDistance " + totalDistance);
384-
ViewCompat.setTranslationX(animIndicator, path);
374+
// ViewCompat.setTranslationX(animIndicator, path);
375+
animIndicator.setTranslationX(path);
385376
}
386377
}
387378

388379
@Override
389380
public void onPageSelected(int position) {
390381
int i = position % bannerInfos.size();
391382
if (i == 0) {
392-
ViewCompat.setTranslationX(animIndicator, totalDistance * 0.0f);
393-
}
394-
if (i == bannerInfos.size() - 1) {
395-
ViewCompat.setTranslationX(animIndicator, totalDistance * 1.0f);
383+
animIndicator.setTranslationX(totalDistance * 0.0f);
384+
} else if (i == bannerInfos.size() - 1) {
385+
animIndicator.setTranslationX(totalDistance * 1.0f);
396386
}
397387
}
398388

@@ -402,7 +392,6 @@ public void onPageScrollStateChanged(int state) {
402392
}
403393
}
404394

405-
406395
// private class IndicatorPreDrawListener implements ViewTreeObserver.OnPreDrawListener {
407396
// @Override
408397
// public boolean onPreDraw() {

library/src/main/java/com/github/why168/adapter/LoopPagerAdapterWrapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.why168.adapter;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import android.support.v4.view.PagerAdapter;
56
import android.view.View;
67
import android.view.ViewGroup;
@@ -39,17 +40,18 @@ public int getCount() {
3940
}
4041

4142
@Override
42-
public boolean isViewFromObject(View view, Object object) {
43+
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
4344
return view == object;
4445
}
4546

4647
@Override
47-
public void destroyItem(ViewGroup container, int position, Object object) {
48+
public void destroyItem(@NonNull ViewGroup container, int position,@NonNull Object object) {
4849
container.removeView((View) object);
4950
}
5051

52+
@NonNull
5153
@Override
52-
public Object instantiateItem(ViewGroup container, int position) {
54+
public Object instantiateItem(@NonNull ViewGroup container, int position) {
5355
final int index = position % bannerInfos.size();
5456
final BannerInfo bannerInfo = bannerInfos.get(index);
5557
ImageView child = null;

library/src/main/java/com/github/why168/animate/DepthPageTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.why168.animate;
22

3+
import android.support.annotation.NonNull;
34
import android.support.v4.view.ViewPager;
45
import android.view.View;
56

@@ -15,7 +16,7 @@ public class DepthPageTransformer implements ViewPager.PageTransformer {
1516
private static final float MIN_SCALE = 0.75f;
1617

1718
@Override
18-
public void transformPage(View view, float position) {
19+
public void transformPage(@NonNull View view, float position) {
1920
int pageWidth = view.getWidth();
2021

2122
if (position < -1) { // [-Infinity,-1)

library/src/main/java/com/github/why168/animate/ZoomOutPageTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.why168.animate;
22

3+
import android.support.annotation.NonNull;
34
import android.support.v4.view.ViewPager;
45
import android.view.View;
56

@@ -16,7 +17,7 @@ public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
1617
private static final float MIN_ALPHA = 0.5f;
1718

1819
@Override
19-
public void transformPage(View view, float position) {
20+
public void transformPage(@NonNull View view, float position) {
2021
int pageWidth = view.getWidth();
2122
int pageHeight = view.getHeight();
2223

0 commit comments

Comments
 (0)