AndroidImageSlider icon indicating copy to clipboard operation
AndroidImageSlider copied to clipboard

Current count of the page in TextSlider?

Open Chirag-Galani opened this issue 12 years ago • 28 comments

I am loading all images using Picasso into TextSlider. I want to set wallpaper using onSliderClick(BaseSliderView slider) method. But, there is no such method. I am storing all the URLs in an array. So, i need the current position so that I can pass it in array and save the particular image.

Chirag-Galani avatar Jul 04 '14 20:07 Chirag-Galani

I managed to solve the issue by using the below workaround: mDemoSlider2.getCurrentSlider().getUrl() I get the URL directly instead of the array count. If possible could you code a method that will return the current page count? Thanks for the library.

Chirag-Galani avatar Jul 04 '14 22:07 Chirag-Galani

Ok, thanks your advise, I'll add some new method today. :-D btw, welcome to contribute your code.

daimajia avatar Jul 05 '14 00:07 daimajia

Hi, bro. I think you can use this method:

textSliderView.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
                @Override
                public void onSliderClick(BaseSliderView slider) {

                }
            })

And I added a new method getCurrentSlider.

daimajia avatar Jul 05 '14 01:07 daimajia

Thanks for the new method. I'll look into its code and implementation. But, the code u mentioned wouldn't work for me as i plan to save the current slide's image via options in menu. If i implement that code, only the last picture is selected each time. As the text slider object which i pass from the method points only to the last image.

Chirag-Galani avatar Jul 05 '14 06:07 Chirag-Galani

Oh, I think I get your point.

daimajia avatar Jul 06 '14 00:07 daimajia

Hi, bro. Is this that you really need?

https://github.com/daimajia/AndroidImageSlider/blob/master/library%2Fsrc%2Fmain%2Fjava%2Fcom%2Fdaimajia%2Fslider%2Flibrary%2FSliderLayout.java#L595-L602

daimajia avatar Jul 06 '14 00:07 daimajia

Yeah. Thanks for that. And now , i tried implementing setCurrentPosition() via the below code in SlideLayout with reference to ViewPagerEx. This method when called hangs the app for 15 seconds. Also, Sometimes crashes. But, it does the job after a delay of more than 15-20 seconds and it doesn't load the picture from URL via Picasso at that Instance. If I move to next image and come back the image appears. Hoping for a solution. Thanks.

public void setCurrentPosition(int position,boolean smoothScroll) {

    if(getRealAdapter() == null)
        throw new IllegalStateException("You did not set a slider adapter");
    mViewPager.setCurrentItem(position,smoothScroll);

}

Chirag-Galani avatar Jul 06 '14 14:07 Chirag-Galani

The code you provided seems have some small bugs.. I'll check tomorrow and add setCurrenPosition method . Thanks.

daimajia avatar Jul 06 '14 14:07 daimajia

Ok Thanks mate I had some query, why are pauseAutoCycle() and RecoverAutoCycle() private methods? The pauseAutoCycle() method can be used to pause the cycle if another activity opens upon it. If pause is not used then the cycle continues to move on infinitely in background. Thus, loosing the original image which was loaded behind the over-ridding activity. As a temporary workaround we can use getCurrentPosition() method before opening another activity via menu OnClickListener and store it as an integer. And, later we can use setCurrentPosition() to jump to the particular slide. Though, it will be a comparatively expensive operation in terms of resources due to Infinite AutoCycle.

This below code if you find bug-free can be placed in SliderLayout.java for getting the current state of the AutoCycle. It will help in changing the text from "Start AutoCycle" to "Stop AutoCycle" dynamically as per the result in the Menu .

    public boolean getAutoCycleState() {

           return mCycling;

    } 

Thank you for this awesome library. I have messaged you on hangouts. If you don't mind we can interact there also. :)

Chirag-Galani avatar Jul 06 '14 21:07 Chirag-Galani

Is it possible that the Cycle stops after loosing Focus and starts again after user returns to the TextSlider? I tried below code but it didn't work

mDemoSlider.setOnFocusChangeListener(new OnFocusChangeListener() {  

    public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus)
       {
            mDemoSlider.stopAutoCycle();  
                //  mDemoSlider.pauseAutoCycle();
       }
      else  if(hasFocus)
       {
            mDemoSlider.startAutoCycle();  
                //  mDemoSlider.RecoverAutoCycle();   
       }
    }
});

I used both the commented and the original methods after changing the access specifiers to public in SliderLayout but it didn't work. Hope you find a solution to this. Thanks.

Chirag-Galani avatar Jul 06 '14 21:07 Chirag-Galani

You can use these two methods startAutoCycle, stopAutoCycle instead of pauseAutoCycle and recoverAutoCycle. pauseAutoCycle is used when user touch the slider, slider should be paused. recoverAutoCycle is used to recover cycle when user finger leaves, it will wait 6 seconds to recover the cycle.

daimajia avatar Jul 07 '14 00:07 daimajia

I also noticed that the slider will continue to move even it's in background.... but I don't have any good methods to handle it....

daimajia avatar Jul 07 '14 00:07 daimajia

Ok mate no issues. Even, I am trying to find a workaround for the same. Now, can you add getAutoCycleState() and setCurrentPosition() methods in the library with reference to the below links (previous comments). They might be buggy.

getAutoCycleState():- https://github.com/daimajia/AndroidImageSlider/issues/17#issuecomment-48127466 setCurrentPosition(): https://github.com/daimajia/AndroidImageSlider/issues/17#issuecomment-48113680

Thanks for this library and continuous support. :+1:

Chirag-Galani avatar Jul 08 '14 15:07 Chirag-Galani

Ok, I'll add these two methods today. :-D Thanks your support too.

daimajia avatar Jul 09 '14 03:07 daimajia

Hi buddy. I spent whole afternoon to add these methods, while, I found that setCurrentItem is buggy... there is some weird behaviors.. I may spend more time on it.

daimajia avatar Jul 09 '14 08:07 daimajia

So, before i solve this problem, i will not add these two method to release version considering the bugs.

daimajia avatar Jul 09 '14 08:07 daimajia

Hi, did you get a chance to work on the setCurrentPosition method. It get stuck for atleast 20 seconds when called.

nitin84india avatar Nov 16 '14 15:11 nitin84india

Hi all , I'm looking for setCurrentPosition function too. Any tips or suggestions, would be grateful. :)

RichardHan avatar Nov 23 '14 07:11 RichardHan

pull request here, https://github.com/daimajia/AndroidImageSlider/pull/52 I help implement two methods to control slide position (prev & next).

RichardHan avatar Nov 24 '14 12:11 RichardHan

Hey guys, @Chirag-Galani @nitin84india @RichardHan @johnjohndoe @shekibobo :

I'm so sorry for being silent on this issue, cause I'm really busy last few month.

I spent 15 minutes to add the new method setCurrentPosition, hope you can enjoy it.

daimajia avatar Nov 24 '14 15:11 daimajia