/*
 * Copyright (C) 2011 Michael Imamura
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lugatgt.zoogie.introtoandroid;

import android.content.Context;

import org.lugatgt.zoogie.introtoandroid.slide.*;
import org.lugatgt.zoogie.present.Presentation;
import org.lugatgt.zoogie.present.Slide;
import org.lugatgt.zoogie.present.SlideTransition;
import org.lugatgt.zoogie.present.Transitions;
import org.lugatgt.zoogie.present.ui.SlideFragment;


public class MainPresentation extends Presentation {
    
    private enum Slides implements Slide {
        
        TITLE(TitleSlide.class, "Intro to Android Development", Transitions.SLIDE_LEFT),
        //INTRO(TitleSlide.class, "Introduction"),
        PARTS(PartsSlide.class, "Anatomy of an Android App", Transitions.SLIDE_LEFT),
        API_HISTORY(ApiHistorySlide.class, "API History", Transitions.FADE),
        FORK_THIS(ForkThisSlide.class, "Fork This Presentation!", Transitions.SLIDE_LEFT);
        
        private Class<? extends SlideFragment> fragmentClass;
        private String title;
        private SlideTransition transition;
        
        private Slides(Class<?> fragmentClass, String title, SlideTransition transition) {
            this.fragmentClass = fragmentClass.asSubclass(SlideFragment.class);
            this.title = title;
            this.transition = transition;
        }
        
        @Override
        public String getName() {
            return toString();
        }
        
        @Override
        public String getTitle(Context ctx) {
            return title;
        }
        
        @Override
        public SlideFragment createFragment() throws InstantiationException, IllegalAccessException {
            return fragmentClass.newInstance();
        }
        
        @Override
        public SlideTransition getTransition() {
            return transition;
        }
        
    }
    
    // CONSTRUCTORS ////////////////////////////////////////////////////////////
    
    public MainPresentation() {
        super(Slides.values());
    }
    
}

@@ -640,16 +640,69 @@
 droid;%0A%0A
+import java.lang.reflect.InvocationTargetException;%0A%0A
 import a
@@ -1220,59 +1220,8 @@
 T),%0A
-        //INTRO(TitleSlide.class, %22Introduction%22),%0A
     
@@ -1607,32 +1607,72 @@
 ion transition;%0A
+        private int%5B%5D contentResources;%0A
         %0A       
@@ -1751,16 +1751,41 @@
 ansition
+, int... contentResources
 ) %7B%0A    
@@ -1884,32 +1884,86 @@
 .title = title;%0A
+            this.contentResources = contentResources;%0A
             this
@@ -2339,58 +2339,1082 @@
 tion
- %7B%0A            return fragmentClass.newInstance();
+, InvocationTargetException %7B%0A            if (contentResources == null %7C%7C contentResources.length == 0) %7B%0A                return fragmentClass.newInstance();%0A            %7D else %7B%0A                // Use reflection to find a constructor that takes the same%0A                // number of int arguments as contentResources.%0A                Class%3C?%3E%5B%5D paramTypes = new Class%3C?%3E%5BcontentResources.length%5D;%0A                Object%5B%5D params = new Object%5BcontentResources.length%5D;%0A                for (int i = 0; i %3C paramTypes.length; i++) %7B%0A                    paramTypes%5Bi%5D = Integer.TYPE;%0A                    params%5Bi%5D = contentResources%5Bi%5D;%0A                %7D%0A                try %7B%0A                    return fragmentClass.getConstructor(paramTypes).newInstance(params);%0A                %7D catch (NoSuchMethodException e) %7B%0A                    throw new InstantiationException(%0A                        %22Class %22 + fragmentClass + %22 does not have a constructor that %22 +%0A                        %22takes %22 + contentResources.length + %22 int parameter(s).%22);%0A                %7D%0A            %7D
 %0A   

Support SlideFragment classes which take constructor params.