<commit_before>package androidemu.app;

import java.util.Stack;

import androidemu.content.Intent;
import androidemu.util.Log;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

public class ActivityManager {
	public final static String TAG = "ActivityManager";

	public final static int STATUS_NEW = 0;
	public final static int STATUS_CREATED = 1;
	public final static int STATUS_RESUMED = 2;
	public final static int STATUS_PAUSED = 3;
	public final static int STATUS_DESTROYED = 4;

	public static Stack<Activity> activityStack = new Stack<Activity>();
	static Button backButton, menuButton;

	// static {
	// History.addValueChangeHandler(new ValueChangeHandler<String>() {
	// @Override
	// public void onValueChange(ValueChangeEvent<String> event) {
	// // TODO We manage only back press
	// if (activityStack.size() > 1) {
	// // If is back, must match the previous activity in the stack
	// if (event.getValue().equals(activityStack.get(activityStack.size() -
	// 2).getClass().getName())) {
	// finish(activityStack.peek());
	// }
	// }
	// }
	// });
	// }

	public static void setup() {
		if (RootPanel.get("BackButton") != null) {
			backButton = Button.wrap(RootPanel.get("BackButton").getElement());
			backButton.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					ActivityManager.back();
				}
			});
		}
		if (RootPanel.get("MenuButton") != null) {
			menuButton = Button.wrap(RootPanel.get("MenuButton").getElement());
			menuButton.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					ActivityManager.openOptionsMenu();
				}
			});
		}
	}

	public static void startActivity(Intent intent, Integer requestCode) {
		Log.d(TAG, "Start activity " + intent.activity.getClass().getName());
		activityStack.push(intent.activity);
		intent.activity.requestCode = requestCode;
		checkActivityStackDeferred();
	}

	public static void finish(final Activity activity) {
		Log.d(TAG, "Finish activity " + activity.getClass().getName());
		activity.targetStatus = STATUS_DESTROYED;
		checkActivityStackDeferred();
	}

	public static void back() {
		activityStack.peek().onBackPressed();
		if (activityStack.size() > 1) {
			finish(activityStack.peek());
		}
	}<commit_msg>DOM.getElementById is much more efficient than creating RootPanels<commit_after>package androidemu.app;

import java.util.Stack;

import androidemu.content.Intent;
import androidemu.util.Log;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Button;

public class ActivityManager {
	public final static String TAG = "ActivityManager";

	public final static int STATUS_NEW = 0;
	public final static int STATUS_CREATED = 1;
	public final static int STATUS_RESUMED = 2;
	public final static int STATUS_PAUSED = 3;
	public final static int STATUS_DESTROYED = 4;

	public static Stack<Activity> activityStack = new Stack<Activity>();
	static Button backButton, menuButton;

	// static {
	// History.addValueChangeHandler(new ValueChangeHandler<String>() {
	// @Override
	// public void onValueChange(ValueChangeEvent<String> event) {
	// // TODO We manage only back press
	// if (activityStack.size() > 1) {
	// // If is back, must match the previous activity in the stack
	// if (event.getValue().equals(activityStack.get(activityStack.size() -
	// 2).getClass().getName())) {
	// finish(activityStack.peek());
	// }
	// }
	// }
	// });
	// }

	public static void setup() {
		if (DOM.getElementById("BackButton") != null) {
			backButton = Button.wrap(DOM.getElementById("BackButton"));
			backButton.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					ActivityManager.back();
				}
			});
		}
		if (DOM.getElementById("MenuButton") != null) {
			menuButton = Button.wrap(DOM.getElementById("MenuButton"));
			menuButton.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					ActivityManager.openOptionsMenu();
				}
			});
		}
	}

	public static void startActivity(Intent intent, Integer requestCode) {
		Log.d(TAG, "Start activity " + intent.activity.getClass().getName());
		activityStack.push(intent.activity);
		intent.activity.requestCode = requestCode;
		checkActivityStackDeferred();
	}

	public static void finish(final Activity activity) {
		Log.d(TAG, "Finish activity " + activity.getClass().getName());
		activity.targetStatus = STATUS_DESTROYED;
		checkActivityStackDeferred();
	}

	public static void back() {
		activityStack.peek().onBackPressed();
		if (activityStack.size() > 1) {
			finish(activityStack.peek());
		}
	}
{'fraction_non_alphanumeric': 0.13157894736842105, 'fraction_numerical': 0.003142183817753339, 'mean_word_length': 4.3162839248434235, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1997000', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1539, 'n_words': 343}