package com.marvinlabs.widget.slideshow.demo;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

import com.marvinlabs.widget.slideshow.SlideShowAdapter;
import com.marvinlabs.widget.slideshow.SlideShowView;
import com.marvinlabs.widget.slideshow.adapter.RemoteBitmapAdapter;
import com.marvinlabs.widget.slideshow.adapter.ResourceBitmapAdapter;

import java.util.Arrays;


public class SlideShowActivity extends Activity {

    private SlideShowView slideShowView;
    private SlideShowAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Go fullscreen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Activity layout
        setContentView(R.layout.activity_slideshow);

        slideShowView = (SlideShowView) findViewById(R.id.slideshow);
    }

    private SlideShowAdapter createRemoteAdapter() {
        String[] slideUrls = new String[]{
                "http://lorempixel.com/1280/720/sports",
                "http://lorempixel.com/1280/720/nature",
                "http://lorempixel.com/1280/720/people",
                "http://lorempixel.com/1280/720/city",
            };
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = 2;
        adapter = new RemoteBitmapAdapter(this, Arrays.asList(slideUrls), opts);
        return adapter;
    }

    private SlideShowAdapter createResourceAdapter() {
        int[] slideResources = new int[]{R.raw.slide_01, R.raw.slide_02, R.raw.slide_03, R.raw.slide_04};
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = 2;
        adapter = new ResourceBitmapAdapter(this, slideResources, opts);
        return adapter;
    }

    @Override
    protected void onResume() {
        super.onResume();
        startSlideShow();
    }

    @Override
    protected void onStop() {
        if (adapter instanceof RemoteBitmapAdapter) {
            ((RemoteBitmapAdapter) adapter).stopAllDownloads();
        }
        super.onStop();
    }

    private void startSlideShow() {
        // Create an adapter
        // slideShowView.setAdapter(createResourceAdapter());
        slideShowView.setAdapter(createRemoteAdapter());

        // Optional customisation follows
        // slideShowView.setTransitionFactory(new SlideAndZoomTransitionFactory());

        // Then attach the adapter
        slideShowView.play();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.slideshow, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

@@ -134,16 +134,41 @@
 Bundle;%0A
+import android.util.Log;%0A
 import a
@@ -185,16 +185,16 @@
 w.Menu;%0A
-
 import a
@@ -277,16 +277,45 @@
 Manager;
+%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -556,16 +556,97 @@
 Adapter;
+%0Aimport com.marvinlabs.widget.slideshow.transition.SlideAndZoomTransitionFactory;
 %0A%0Aimport
@@ -2712,35 +2712,32 @@
  follows%0A       
- //
  slideShowView.s
@@ -2790,17 +2790,195 @@
 Factory(
-)
+2000));%0A%0A        // Some listeners if needed%0A        slideShowView.setOnSlideShowEventListener(slideShowListener);%0A        slideShowView.setOnSlideClickListener(slideClickListener
 );%0A%0A    
@@ -3718,17 +3718,1248 @@
 (item);%0A
-
     %7D%0A%0A
+    private SlideShowView.OnSlideClickListener slideClickListener = new SlideShowView.OnSlideClickListener() %7B%0A        @Override%0A        public void onItemClick(SlideShowView parent, int position) %7B%0A            Toast.makeText(SlideShowActivity.this, %22Slide clicked: %22 + position, Toast.LENGTH_SHORT).show();%0A        %7D%0A    %7D;%0A%0A    private SlideShowView.OnSlideShowEventListener slideShowListener = new SlideShowView.OnSlideShowEventListener() %7B%0A        @Override%0A        public void beforeSlideShown(SlideShowView parent, int position) %7B%0A            Log.d(%22SlideShowDemo%22, %22OnSlideShowEventListener.beforeSlideShown: %22 + position);%0A        %7D%0A%0A        @Override%0A        public void onSlideShown(SlideShowView parent, int position) %7B%0A            Log.d(%22SlideShowDemo%22, %22OnSlideShowEventListener.onSlideShown: %22 + position);%0A        %7D%0A%0A        @Override%0A        public void beforeSlideHidden(SlideShowView parent, int position) %7B%0A            Log.d(%22SlideShowDemo%22, %22OnSlideShowEventListener.beforeSlideHidden: %22 + position);%0A        %7D%0A%0A        @Override%0A        public void onSlideHidden(SlideShowView parent, int position) %7B%0A            Log.d(%22SlideShowDemo%22, %22OnSlideShowEventListener.onSlideHidden: %22 + position);%0A        %7D%0A    %7D;%0A%0A
 %7D%0A

Add some feedback to event listeners in demo (toast on slide click and debug log for slide events)