55import android .os .Looper ;
66import android .os .Message ;
77import android .support .annotation .DrawableRes ;
8- import android .support .v4 .view .ViewCompat ;
98import android .support .v4 .view .ViewPager ;
109import android .util .AttributeSet ;
1110import 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() {
0 commit comments