0

I would like to ask that how to implement countdown timer to load all the image on assets folder and display it according to the countdown time that had been set. For example, I have 5 images in my asset folder and I put them in the array. Every 5 second it will display each of the image. Eg: Image 1> 5second passed> image 2> 5 second passed > image 3 and so on...

Below is my code. Please share with me your knowledge or any way to implement it. Thanks.

public class MainActivity extends AppCompatActivity {

private VrPanoramaView mVRPanoramaView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   mVRPanoramaView = (VrPanoramaView) findViewById(R.id.vrPanoramaView);

    loadPhotoSphere();


}

private void loadPhotoSphere() {

    VrPanoramaView.Options options = new VrPanoramaView.Options();
    InputStream inputStream = null;


    AssetManager assetManager=getAssets(); // to reach asset
    try {
        String[] images = assetManager.list("img");// to get all item in img folder.

        options.inputType = VrPanoramaView.Options.TYPE_MONO;

        for (int i = 0; i < images.length; i++) // the loop read all image in img folder 
        {
            inputStream = getAssets().open("img/" + images[i]);

            mVRPanoramaView.loadImageFromBitmap(BitmapFactory.decodeStream(inputStream), options);

        }
        }catch (IOException e) {
            // you can print error or log.
            e.printStackTrace();
        }


}

}

Qwaser
  • 11
  • 3

1 Answers1

0

Solution:

You can accomplish this using a Handler as shown below:

Handler h = new Handler();
int delay = 5*1000; //1 second = 1000 milisecond, 5 * 1000 = 5seconds
Runnable runnable;

@Override
protected void onResume() {
   //start handler as activity become visible

    h.postDelayed( runnable = new Runnable() {
        public void run() {

            // do the setting of image here

            h.postDelayed(runnable, delay);
        }
    }, delay);

    super.onResume();
}

@Override
protected void onPause() {
    h.removeCallbacks(runnable); //stop handler when activity not visible
    super.onPause();
}

Hope this helps, please comment if any issues.

Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41
  • i tried but it doesn't work, could u try explain in detail? i have make some changes at the code, can you please look through and share your solution? Thanks – Qwaser Oct 24 '18 at 17:44