/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package org.appcelerator.kroll;

import java.util.List;

import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiLifecycle.OnLifecycleEvent;

import android.app.Activity;

@Kroll.module(name="KrollModule")
public class KrollModule extends KrollProxy
	implements KrollProxyListener, OnLifecycleEvent
{
	private static final String TAG = "KrollModule";

	public KrollModule() {
		super();

		modelListener = this;
	}

	public KrollModule(String name) {
		this();

		// Register module with TiApplication if a name is provided.
		TiApplication.getInstance().registerModuleInstance(name, this);
	}

	@Override
	protected void initActivity(Activity activity)
	{
		super.initActivity(activity);

		if (activity instanceof TiBaseActivity) {
			((TiBaseActivity) getActivity()).addOnLifecycleEventListener(this);
		}
	}

	// TODO @Override
	public void onResume(Activity activity) {
	}

	// TODO @Override
	public void onPause(Activity activity) {
	}
	
	// TODO @Override
	public void onDestroy(Activity activity) {
	}
	
	// TODO @Override
	public void onStart(Activity activity) {
	}
	
	// TODO @Override
	public void onStop(Activity activity) {	
	}
	
	// TODO @Override
	public void listenerAdded(String type, int count, KrollProxy proxy) {
	}
	
	// TODO @Override
	public void listenerRemoved(String type, int count, KrollProxy proxy) {
	}
	
	// TODO @Override
	public void processProperties(KrollDict d) {
	}
	
	// TODO @Override
	public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
	}
	
	// TODO @Override
	public void propertiesChanged(List<KrollPropertyChange> changes, KrollProxy proxy) {
		for (KrollPropertyChange change : changes) {
			propertyChanged(change.getName(), change.getOldValue(), change.getNewValue(), proxy);
		}
	}
}

@@ -491,16 +491,65 @@
 leEvent;
+%0Aimport org.appcelerator.titanium.TiRootActivity;
 %0A%0Aimport
@@ -1063,71 +1063,230 @@
 %7B%0A%09%09
-super.initActivity(activity);%0A%0A%09%09if (activity instanceof TiBase
+// modules should use the root activity rather than the current activity at %0A%09%09// the time the module is lazy loaded%0A%09%09TiRootActivity rootActivity = TiApplication.getInstance().getRootActivity();%0A%0A%09%09super.initActivity(root
 Acti
@@ -1294,34 +1294,46 @@
 ity)
- %7B%0A%09%09%09((TiBaseActivity) ge
+;%0A%09%09if (rootActivity != null) %7B%0A%09%09%09roo
 tAct
@@ -1341,11 +1341,8 @@
 vity
-())
 .add

fix modules to use the root activity rather than the current activity when they are lazy loaded