<commit_before>//activity and other Android variables
var currentActivity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();

var displayingPopup1 = false;

function modTick()
{
	//player carrying an iron sword
	if(Player.getCarriedItem() == 267)
	{
		if(!displayingPopup1)
		{
			displayingPopup1 = true;

			currentActivity.runOnUiThread(new java.lang.Runnable(
			{
				run: function()
				{
					try
					{
						// FIRST BUTTON
						var button1 = MinecraftButton(); // set to true or leave blank for click sound
						button1.setOnClickListener(new android.view.View.OnClickListener()
						{
							onClick: function(v)
							{
								clientMessage("I'm a button, with click sound!");

								return false;
							}
						});
						button1.setText("I'm a button!");
						button1.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

						// POPUP FOR THE FIRST BUTTON
						popup1 = new android.widget.PopupWindow(button1, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
						popup1.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
						popup1.showAtLocation(currentActivity.getWindow().getDecorView(), android.view.Gravity.RIGHT | android.view.Gravity.CENTER, 0, 0);



						// SECOND BUTTON
						var squareButtonWidth = 48; // in dp
						var squareButton = MinecraftButton(false); // set to false for no click sound
						squareButton.setOnClickListener(new android.view.View.OnClickListener()
						{
							onClick: function(v)
							{
								clientMessage("No click sound");

								return false;
							}
						});
						squareButton.setText("B");
						squareButton.setLayoutParams(new android.view.ViewGroup.LayoutParams(convertDpToPixel(squareButtonWidth), convertDpToPixel(squareButtonWidth)));

						// POPUP FOR THE SECOND BUTTON
						popup2 = new android.widget.PopupWindow(squareButton, convertDpToPixel(squareButtonWidth), convertDpToPixel(squareButtonWidth));
						popup2.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
						popup2.showAtLocation(currentActivity.getWindow().getDecorView(), android.view.Gravity.LEFT | android.view.Gravity.BOTTOM, 0, 0);
					} catch(err)
					{
						clientMessage("Error: " + err);
					}
				}
			}));
		}
	} else
	{
		if(displayingPopup1)
		{
			currentActivity.runOnUiThread(new java.lang.Runnable(
			{
				run: function()
				{
					popup1.dismiss();
					popup2.dismiss();
				}
			}));

			displayingPopup1 = false;
		}
	}
}

function leaveGame()
{
	try
	{
		currentActivity.runOnUiThread(new java.lang.Runnable(
		{
			run: function()
			{
				popup1.dismiss();
				popup2.dismiss();
			}
		}));
		displayingPopup1 = false;
	} catch(e){ /*popup already dismissed*/ }
}

function convertDpToPixel(dp)
{
	var metrics = new android.util.DisplayMetrics();<commit_msg>Fix crash that may happen sometimes when the user exits the world<commit_after>//activity and other Android variables
var currentActivity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();

var displayingPopup1 = false;

function modTick()
{
	//player carrying an iron sword
	if(Player.getCarriedItem() == 267)
	{
		if(!displayingPopup1)
		{
			displayingPopup1 = true;

			currentActivity.runOnUiThread(new java.lang.Runnable(
			{
				run: function()
				{
					try
					{
						// FIRST BUTTON
						var button1 = MinecraftButton(); // set to true or leave blank for click sound
						button1.setOnClickListener(new android.view.View.OnClickListener()
						{
							onClick: function(v)
							{
								clientMessage("I'm a button, with click sound!");

								return false;
							}
						});
						button1.setText("I'm a button!");
						button1.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

						// POPUP FOR THE FIRST BUTTON
						popup1 = new android.widget.PopupWindow(button1, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
						popup1.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
						popup1.showAtLocation(currentActivity.getWindow().getDecorView(), android.view.Gravity.RIGHT | android.view.Gravity.CENTER, 0, 0);



						// SECOND BUTTON
						var squareButtonWidth = 48; // in dp
						var squareButton = MinecraftButton(false); // set to false for no click sound
						squareButton.setOnClickListener(new android.view.View.OnClickListener()
						{
							onClick: function(v)
							{
								clientMessage("No click sound");

								return false;
							}
						});
						squareButton.setText("B");
						squareButton.setLayoutParams(new android.view.ViewGroup.LayoutParams(convertDpToPixel(squareButtonWidth), convertDpToPixel(squareButtonWidth)));

						// POPUP FOR THE SECOND BUTTON
						popup2 = new android.widget.PopupWindow(squareButton, convertDpToPixel(squareButtonWidth), convertDpToPixel(squareButtonWidth));
						popup2.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
						popup2.showAtLocation(currentActivity.getWindow().getDecorView(), android.view.Gravity.LEFT | android.view.Gravity.BOTTOM, 0, 0);
					} catch(err)
					{
						clientMessage("Error: " + err);
					}
				}
			}));
		}
	} else
	{
		if(displayingPopup1)
		{
			currentActivity.runOnUiThread(new java.lang.Runnable(
			{
				run: function()
				{
					try
					{
						popup1.dismiss();
						popup2.dismiss();
					} catch(e){ /*popup already dismissed*/ }
				}
			}));

			displayingPopup1 = false;
		}
	}
}

function leaveGame()
{
	currentActivity.runOnUiThread(new java.lang.Runnable(
	{
		run: function()
		{
			try
			{
				popup1.dismiss();
				popup2.dismiss();
			} catch(e){ /*popup already dismissed*/ }
		}
	}));
	displayingPopup1 = false;
}

function convertDpToPixel(dp)
{
	var metrics = new android.util.DisplayMetrics();
{'fraction_non_alphanumeric': 0.11625647668393782, 'fraction_numerical': 0.009715025906735751, 'mean_word_length': 3.3438818565400843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2036217', 'n_tokens_mistral': 2483, 'n_tokens_neox': 1888, 'n_words': 331}