aboutsummaryrefslogtreecommitdiff
path: root/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java
blob: cb7ba8d3befa8c771c2438ddc28738600f45b621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package net.minetest.minetest;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;

public class MinetestTextEntry extends Activity {
	private final int MultiLineTextInput = 1;
	private final int SingleLineTextInput = 2;
	private final int SingleLinePasswordInput = 3;
	private AlertDialog mTextInputDialog;
	private EditText mTextInputWidget;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle b = getIntent().getExtras();
		String acceptButton = b.getString("EnterButton");
		String hint = b.getString("hint");
		String current = b.getString("current");
		int editType = b.getInt("editType");

		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		mTextInputWidget = new EditText(this);
		mTextInputWidget.setHint(hint);
		mTextInputWidget.setText(current);
		mTextInputWidget.setMinWidth(300);
		if (editType == SingleLinePasswordInput) {
			mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT |
					InputType.TYPE_TEXT_VARIATION_PASSWORD);
		} else {
			mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT);
		}

		builder.setView(mTextInputWidget);

		if (editType == MultiLineTextInput) {
			builder.setPositiveButton(acceptButton, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					pushResult(mTextInputWidget.getText().toString());
				}
			});
		}

		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
			public void onCancel(DialogInterface dialog) {
				cancelDialog();
			}
		});

		mTextInputWidget.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(View view, int KeyCode, KeyEvent event) {
				if (KeyCode == KeyEvent.KEYCODE_ENTER) {

					pushResult(mTextInputWidget.getText().toString());
					return true;
				}
				return false;
			}
		});

		mTextInputDialog = builder.create();
		mTextInputDialog.show();
	}

	private void pushResult(String text) {
		Intent resultData = new Intent();
		resultData.putExtra("text", text);
		setResult(Activity.RESULT_OK, resultData);
		mTextInputDialog.dismiss();
		finish();
	}

	private void cancelDialog() {
		setResult(Activity.RESULT_CANCELED);
		mTextInputDialog.dismiss();
		finish();
	}
}
y_raw = y_raw * (1 / x_abs) z_raw = z_raw * (1 / x_abs) x_raw = x_raw / x_abs end if y_abs >= x_abs and y_abs >= z_abs then x_raw = x_raw * (1 / y_abs) z_raw = z_raw * (1 / y_abs) y_raw = y_raw / y_abs end if z_abs >= y_abs and z_abs >= x_abs then x_raw = x_raw * (1 / z_abs) y_raw = y_raw * (1 / z_abs) z_raw = z_raw / z_abs end return {x=x_raw, y=y_raw, z=z_raw} end function vector.add(a, b) if type(b) == "table" then return {x = a.x + b.x, y = a.y + b.y, z = a.z + b.z} else return {x = a.x + b, y = a.y + b, z = a.z + b} end end function vector.subtract(a, b) if type(b) == "table" then return {x = a.x - b.x, y = a.y - b.y, z = a.z - b.z} else return {x = a.x - b, y = a.y - b, z = a.z - b} end end function vector.multiply(a, b) if type(b) == "table" then return {x = a.x * b.x, y = a.y * b.y, z = a.z * b.z} else return {x = a.x * b, y = a.y * b, z = a.z * b} end end function vector.divide(a, b) if type(b) == "table" then return {x = a.x / b.x, y = a.y / b.y, z = a.z / b.z} else return {x = a.x / b, y = a.y / b, z = a.z / b} end end function vector.sort(a, b) return {x = math.min(a.x, b.x), y = math.min(a.y, b.y), z = math.min(a.z, b.z)}, {x = math.max(a.x, b.x), y = math.max(a.y, b.y), z = math.max(a.z, b.z)} end