@@ -103,7 +103,7 @@ public class ScrollGalleryView extends LinearLayout implements OnDoubleTapListen
103103
104104 private FragmentManager fragmentManager ;
105105 private ScreenSlidePagerAdapter imageViewPagerAdapter ;
106- private List <File > mListOfMedia = new LinkedList <>() ;
106+ private ArrayList <File > mListOfMedia ;
107107 private int sizeMediaFiles ;
108108
109109 private int thumbnailSize = 54 ; // width and height in pixels
@@ -123,7 +123,7 @@ public class ScrollGalleryView extends LinearLayout implements OnDoubleTapListen
123123 private String orderType = "" ;
124124 private String asc = "" ;
125125
126- static boolean SLIDESHOW = false ;
126+ private boolean SLIDESHOW = false ;
127127 //static int DELAY = 1000;
128128 static ABaseTransformer [] transforms = new ABaseTransformer []{
129129 new DefaultTransformer (),
@@ -162,7 +162,7 @@ public class ScrollGalleryView extends LinearLayout implements OnDoubleTapListen
162162
163163 protected ThumbnailAdapter thumbnailRecyclerAdapter ;
164164 protected LinearLayoutManager mLayoutManager ;
165- protected String [] mDataset ;
165+
166166 boolean scrolledByViewPager = true ;
167167
168168 public ScrollGalleryView (final Context context ) {
@@ -258,8 +258,13 @@ public ScrollGalleryView(final Context context, final AttributeSet attrs, final
258258 public Parcelable onSaveInstanceState () {
259259 Log .d (TAG , "onSaveInstanceState " );
260260 final Bundle bundle = new Bundle ();
261+
261262 bundle .putParcelable ("instanceState" , super .onSaveInstanceState ());
262263 bundle .putBoolean ("SLIDESHOW" , SLIDESHOW );
264+ bundle .putBoolean ("hidden" , hidden );
265+ bundle .putSerializable ("mListOfMedia" , mListOfMedia );
266+ bundle .putInt ("thumbnailSize" , thumbnailSize );
267+ bundle .putInt ("pageSelected" , pageSelected );
263268 removeCallbacks (runSlideshow );
264269 return bundle ;
265270 }
@@ -270,11 +275,19 @@ public void onRestoreInstanceState(Parcelable state) {
270275 if (state != null && state instanceof Bundle ) {
271276 final Bundle bundle = (Bundle ) state ;
272277 SLIDESHOW = bundle .getBoolean ("SLIDESHOW" , false );
273- postDelayed (runSlideshow , ImageFragment .curDelay );
274- super .onRestoreInstanceState (bundle .getParcelable ("instanceState" ));
278+ hidden = bundle .getBoolean ("hidden" , false );
279+ mListOfMedia = (ArrayList <File >) bundle .getSerializable ("mListOfMedia" );
280+ sizeMediaFiles = mListOfMedia .size ();
281+ thumbnailSize = bundle .getInt ("thumbnailSize" , 54 );
282+ pageSelected = bundle .getInt ("pageSelected" , pageSelected );
283+
284+ super .onRestoreInstanceState (bundle .getParcelable ("instanceState" ));
275285 } else {
276286 super .onRestoreInstanceState (state );
277287 }
288+ hideThumbnails (hidden );
289+ initializeViewPager ();
290+ runSlideshow .run ();
278291 }
279292
280293 private Runnable runSorting = new Runnable () {
@@ -290,7 +303,6 @@ public void run() {
290303 final int newpos = pageSelected == 0 ? (sizeMediaFiles - 1 ) : pageSelected == (sizeMediaFiles + 1 ) ? 0 : (pageSelected - 1 );
291304 final ImageView childAt = (ImageView ) mLayoutManager .findViewByPosition (newpos );
292305 scrollRecycler (newpos , childAt );
293- //setupBar(newpos);
294306 }
295307 };
296308
@@ -329,7 +341,7 @@ public void onPageSelected(int pagerPos) {
329341 final int measuredWidth = getMeasuredWidth ();
330342 final int mid = (measuredWidth - thumbnailSize ) / 2 ;
331343 Log .d (TAG , "onPageSelected pagerPos " + pagerPos + ", mediaPos " + mediaPos + ", mid " + mid + ", childCount " + childCount );
332- if ((mediaPos ) <= mid / thumbnailSize || sizeMediaFiles == 1 ) {
344+ if ((mediaPos ) <= mid / thumbnailSize ) {
333345 thumbnailsRecyclerView .setPadding (Math .max (mid - (mediaPos ) * thumbnailSize , 0 ), 0 , 0 , 0 );
334346 } else if ((sizeMediaFiles - 1 - (mediaPos )) <= childCount / 2 ) {
335347 thumbnailsRecyclerView .setPadding (0 , 0 , Math .max (mid - (sizeMediaFiles - 1 - (mediaPos )) * thumbnailSize , 0 ), 0 );
@@ -379,21 +391,21 @@ public void onScrolled(final RecyclerView recyclerView, final int dx, final int
379391 final int paddingLeft = thumbnailsRecyclerView .getPaddingLeft ();
380392 final int measuredWidth = getMeasuredWidth ();
381393 final int childCount = mLayoutManager .getChildCount ();
382- Log .d (TAG , "onScrolled dx " + dx + ", dy " + dy + ", PaddingLeft " + paddingLeft + ", measuredWidth " + measuredWidth + ", thumbnailSize " + thumbnailSize + ", pageSelected " + pageSelected + ", childCount " + childCount );
394+ // Log.d(TAG, "onScrolled dx " + dx + ", PaddingLeft " + paddingLeft + ", measuredWidth " + measuredWidth + ", thumbnailSize " + thumbnailSize + ", pageSelected " + pageSelected + ", childCount " + childCount);
383395 if (paddingLeft > 0 ) {
384396 thumbnailsRecyclerView .setPadding (Math .min (Math .max (paddingLeft - dx , 0 ), (measuredWidth - thumbnailSize ) / 2 ), 0 , 0 , 0 );
385397 }
386398 int paddingRight = thumbnailsRecyclerView .getPaddingRight ();
387- Log .d (TAG , "onScrolled dx " + dx + ", dy " + dy + ", PaddingRight " + paddingLeft + ", pageSelected " + pageSelected );
399+ // Log.d(TAG, "onScrolled dx " + dx + ", paddingRight " + paddingRight + ", pageSelected " + pageSelected);
388400 if (paddingRight > 0 ) {
389401 //Log.d(TAG, "(measuredWidth - thumbnailSize) / 2) " + (measuredWidth - thumbnailSize) / 2);
390402 ///Log.d(TAG, "Math.min(Math.max(dl + dx, 0), (measuredWidth - thumbnailSize) / 2) " + Math.min(Math.max(dl + dx, 0), (measuredWidth - thumbnailSize) / 2));
391403 thumbnailsRecyclerView .setPadding (0 , 0 , Math .min (Math .max (paddingRight + dx , 0 ), (measuredWidth - thumbnailSize ) / 2 ), 0 );
392404 }
393405 //paddingLeft = thumbnailsRecyclerView.getPaddingLeft();
394- Log .d (TAG , "onScrolled dx " + dx + ", dy " + dy + ", PaddingLeft " + paddingLeft + ", PaddingRight " + thumbnailsRecyclerView .getPaddingRight ());
406+ // Log.d(TAG, "onScrolled dx " + dx + ", PaddingLeft " + paddingLeft + ", PaddingRight " + thumbnailsRecyclerView.getPaddingRight());
395407 final int mid ;
396- //if (paddingLeft > thumbnailSize / 2) {
408+ //de - thumbnailSize là bi chay lui
397409 mid = ((measuredWidth ) / 2 - paddingLeft ) / thumbnailSize ;//
398410 //} else {
399411 // mid = ((measuredWidth + thumbnailSize) / 2 - paddingLeft) / thumbnailSize;
@@ -405,7 +417,7 @@ public void onScrolled(final RecyclerView recyclerView, final int dx, final int
405417 childAt = (ImageView ) mLayoutManager .getChildAt (mid - 1 );
406418 }
407419 int mediaPos = Integer .valueOf (childAt .getContentDescription () + "" );
408- Log .d (TAG , "onScrolled paddingLeft " + paddingLeft + ", mid " + mid + ", mediaPos " + mediaPos + ", childAt " + childAt );
420+ // Log.d(TAG, "onScrolled paddingLeft " + paddingLeft + ", mid " + mid + ", mediaPos " + mediaPos + ", childAt " + childAt);
409421 setCurrentItem (mediaPos + 1 , false );
410422
411423 }
@@ -420,11 +432,12 @@ public void onScrollStateChanged(final RecyclerView recyclerView, final int newS
420432 case RecyclerView .SCROLL_STATE_IDLE :
421433 final int mid = (getMeasuredWidth () + thumbnailSize ) / 2 ;//
422434 final ImageView childAt = (ImageView ) mLayoutManager .getChildAt (mid / thumbnailSize );
423- final int pos = Integer .valueOf (childAt .getContentDescription () + "" );
424- //Log.d(TAG, "onScrollStateChanged newState " + newState + ", mid " + mid + ", thumbnailSize " + thumbnailSize + ", pos " + pos);
425- scrollRecycler (pos , childAt );
426- setCurrentItem (pos + 1 , false );
427- //setupBar(pos);
435+ if (childAt != null ) {
436+ final int pos = Integer .valueOf (childAt .getContentDescription () + "" );
437+ //Log.d(TAG, "onScrollStateChanged newState " + newState + ", mid " + mid + ", thumbnailSize " + thumbnailSize + ", pos " + pos);
438+ scrollRecycler (pos , childAt );
439+ setCurrentItem (pos + 1 , false );
440+ }
428441 break ;
429442// case RecyclerView.SCROLL_STATE_SETTLING:
430443// break;
@@ -536,7 +549,7 @@ public boolean onSingleTapConfirmed(final MotionEvent event) {
536549//// rightRecycler.setLayoutParams(lp);
537550// }
538551
539- public void setFileMedia (final List <File > infos ) {//, final List<String> mimes, final String parentPath
552+ public void setFileMedia (final ArrayList <File > infos ) {
540553 SLIDESHOW = false ;
541554 mListOfMedia = infos ;
542555 sizeMediaFiles = mListOfMedia .size ();
@@ -639,13 +652,13 @@ public void run() {
639652 setupBar (mediaPos );
640653 }
641654
642- private void setupBar (final int pos ) {
655+ private void setupBar (final int mediaPos ) {
643656 if (infoLayout .getVisibility () == VISIBLE ) {
644- final File file = mListOfMedia .get (pos );
657+ final File file = mListOfMedia .get (mediaPos );
645658 fileNameTV .setText ((orderType .equals ("Name" ) ? asc : "" ) + file .getName ());
646659 fileSizeTV .setText ((orderType .equals ("Size" ) ? asc : "" ) + Util .nf .format (file .length ()) + " B" );
647660 fileDateTV .setText ((orderType .equals ("Date" ) ? asc : "" ) + Util .dtf .format (file .lastModified ()));
648- fileOrderTV .setText ((pos + 1 ) + "/" + sizeMediaFiles );
661+ fileOrderTV .setText ((mediaPos + 1 ) + "/" + sizeMediaFiles );
649662
650663 final BitmapFactory .Options bitmapDimesions = BitmapUtil .getBitmapDimesions (file .getAbsolutePath ());
651664 //final TouchImageView image = pagerAdapter.fragMap.get(pos).getImage();
@@ -710,9 +723,6 @@ public void run() {
710723 };
711724 GeneralDialogCreation .deleteFilesDialog (mContext , //getLayoutElements(),
712725 (ThemedActivity )mContext , ele , ((ThemedActivity )mContext ).getAppTheme (), r );
713- //}
714- //new Futils().deleteFiles(ele, (ExplorerActivity)mContext, /*positions, */((ThemedActivity)mContext).getAppTheme());
715-
716726 break ;
717727 case R .id .slideshowButton :
718728 if (sizeMediaFiles > 1 ) {
@@ -932,7 +942,7 @@ public final void setBitmapToView(Bitmap bmp, String name) {
932942 //Log.v( TAG, "Bitmap is ready" );
933943 //hideWait();
934944 if (bmp != null ) {
935- TouchImageView image = (( ImageFragment ) imageViewPagerAdapter .getCurrentItem () ).getImage ();
945+ TouchImageView image = imageViewPagerAdapter .getCurrentItem ().getImage ();
936946 image .setVisibility (View .VISIBLE );
937947 image .setImageBitmap (bmp );
938948
0 commit comments