the whole game
This commit is contained in:
58
project/android/src/com/mojang/android/EditTextAscii.java
Executable file
58
project/android/src/com/mojang/android/EditTextAscii.java
Executable file
@@ -0,0 +1,58 @@
|
||||
package com.mojang.android;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class EditTextAscii extends EditText
|
||||
implements TextWatcher {
|
||||
|
||||
public EditTextAscii(Context context) {
|
||||
super(context);
|
||||
_init();
|
||||
}
|
||||
|
||||
public EditTextAscii(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
_init();
|
||||
}
|
||||
|
||||
public EditTextAscii(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
_init();
|
||||
}
|
||||
|
||||
private void _init() {
|
||||
this.addTextChangedListener(this);
|
||||
}
|
||||
|
||||
//
|
||||
// TextWatcher
|
||||
//
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
//@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
||||
//@Override
|
||||
public void afterTextChanged(Editable e) {
|
||||
String s = e.toString();
|
||||
String sanitized = sanitize(s);
|
||||
|
||||
if (!s.equals(sanitized)) {
|
||||
e.replace(0, e.length(), sanitized);
|
||||
}
|
||||
}
|
||||
|
||||
static public String sanitize(String s) {
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
char ch = s.charAt(i);
|
||||
if (ch < 128)
|
||||
sb.append(ch);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
5
project/android/src/com/mojang/android/StringValue.java
Executable file
5
project/android/src/com/mojang/android/StringValue.java
Executable file
@@ -0,0 +1,5 @@
|
||||
package com.mojang.android;
|
||||
|
||||
public interface StringValue {
|
||||
public String getStringValue();
|
||||
}
|
||||
29
project/android/src/com/mojang/android/licensing/LicenseCodes.java
Executable file
29
project/android/src/com/mojang/android/licensing/LicenseCodes.java
Executable file
@@ -0,0 +1,29 @@
|
||||
package com.mojang.android.licensing;
|
||||
|
||||
///see LicenseResult.h in C++ project
|
||||
public class LicenseCodes {
|
||||
|
||||
// Something's not ready, call again later
|
||||
public static final int WAIT_PLATFORM_NOT_READY = -2; // Note used from java
|
||||
public static final int WAIT_SERVER_NOT_READY = -1;
|
||||
|
||||
// License is ok
|
||||
public static final int LICENSE_OK = 0;
|
||||
public static final int LICENSE_TRIAL_OK = 1;
|
||||
|
||||
// License is not working in one way or another
|
||||
public static final int LICENSE_VALIDATION_FAILED = 50;
|
||||
public static final int ITEM_NOT_FOUND = 51;
|
||||
public static final int LICENSE_NOT_FOUND = 52;
|
||||
public static final int ERROR_CONTENT_HANDLER = 100;
|
||||
public static final int ERROR_ILLEGAL_ARGUMENT = 101;
|
||||
public static final int ERROR_SECURITY = 102;
|
||||
public static final int ERROR_INPUT_OUTPUT = 103;
|
||||
public static final int ERROR_ILLEGAL_STATE = 104;
|
||||
public static final int ERROR_NULL_POINTER = 105;
|
||||
public static final int ERROR_GENERAL = 106;
|
||||
public static final int ERROR_UNABLE_TO_CONNECT_TO_CDS = 107;
|
||||
|
||||
// The call went wrong so we didn't get a license value at all
|
||||
public static final int LICENSE_CHECK_EXCEPTION = 200;
|
||||
}
|
||||
233
project/android/src/com/mojang/android/preferences/SliderPreference.java
Executable file
233
project/android/src/com/mojang/android/preferences/SliderPreference.java
Executable file
@@ -0,0 +1,233 @@
|
||||
package com.mojang.android.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SliderPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
private static final String androidns = "http://schemas.android.com/apk/res/android";
|
||||
|
||||
private Context _context;
|
||||
|
||||
//private TextView _minValueTextView;
|
||||
private TextView _valueTextView;
|
||||
//private TextView _maxValueTextView;
|
||||
private SeekBar _seekBar;
|
||||
|
||||
private String _valueSuffix;
|
||||
|
||||
private int _defaultValue; // Stores the default preference value when none has been set
|
||||
private int _maxValue; // Stores the upper preference value bound
|
||||
private int _value; // Stores the value of the preference
|
||||
private int _minValue; // Stores the minimum preference value bound
|
||||
|
||||
public SliderPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
_context = context;
|
||||
|
||||
_valueSuffix = getResourceValueFromAttribute(attrs, androidns, "text", "");
|
||||
|
||||
_defaultValue = getResourceValueFromAttribute(attrs, androidns, "defaultValue", 0);
|
||||
_maxValue = getResourceValueFromAttribute(attrs, androidns, "max", 100);
|
||||
_minValue = getResourceValueFromAttribute(attrs, null, "min", 0);
|
||||
|
||||
// Set the default value of the preference to the default value found in attribute
|
||||
setDefaultValue((Integer) _defaultValue);
|
||||
}
|
||||
//public SliderPreference(Context context, AttributeSet attrs, int)
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
LinearLayout.LayoutParams params;
|
||||
LinearLayout layout = new LinearLayout(getContext());
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.setPadding(6,6,6,6);
|
||||
|
||||
// mSplashText = new TextView(_context);
|
||||
// if (mDialogMessage != null)
|
||||
// mSplashText.setText(mDialogMessage);
|
||||
// layout.addView(mSplashText);
|
||||
|
||||
_valueTextView = new TextView(_context);
|
||||
_valueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
_valueTextView.setTextSize(32);
|
||||
params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.FILL_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
layout.addView(_valueTextView, params);
|
||||
|
||||
_seekBar = new SeekBar(_context);
|
||||
_seekBar.setOnSeekBarChangeListener(this);
|
||||
layout.addView(_seekBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
if (shouldPersist())
|
||||
_value = getPersistedInt(_defaultValue);
|
||||
|
||||
_seekBar.setMax(_maxValue);
|
||||
_seekBar.setProgress(_value);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restore, Object defaultValue) {
|
||||
super.onSetInitialValue(restore, defaultValue);
|
||||
if (restore)
|
||||
_value = shouldPersist() ? getPersistedInt(_defaultValue) : 0;
|
||||
else
|
||||
_value = (Integer) defaultValue;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
// Bind _seekBar to the layout's internal view
|
||||
_seekBar = (SeekBar) view.findViewById(R.id.slider_preference_seekbar);
|
||||
|
||||
// Setup it's listeners and parameters
|
||||
_seekBar.setMax(translateValueToSeekBar(_maxValue));
|
||||
_seekBar.setProgress(translateValueToSeekBar(_value));
|
||||
_seekBar.setOnSeekBarChangeListener(this);
|
||||
|
||||
// Bind mTextView to the layout's internal view
|
||||
_valueTextView = (TextView) view.findViewById(R.id.slider_preference_value);
|
||||
|
||||
// Setup it's parameters
|
||||
_valueTextView.setText(getValueText(_value));
|
||||
|
||||
// Setup min and max value text views
|
||||
_minValueTextView = (TextView) view.findViewById(R.id.slider_preference_min_value);
|
||||
_minValueTextView.setText(getValueText(_minValue));
|
||||
_maxValueTextView = (TextView) view.findViewById(R.id.slider_preference_max_value);
|
||||
_maxValueTextView.setText(getValueText(_maxValue));
|
||||
}
|
||||
*/
|
||||
|
||||
//@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int value, boolean fromUser) {
|
||||
// Change mTextView and _value to the current seekbar value
|
||||
_value = translateValueFro_seekBar(value);
|
||||
_valueTextView.setText(getValueText(_value));
|
||||
if (shouldPersist())
|
||||
persistInt(translateValueFro_seekBar(value));
|
||||
callChangeListener(new Integer(_value));
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// Not used
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// Not used
|
||||
}
|
||||
|
||||
private String getValueText(int value) {
|
||||
String t = String.valueOf(value);
|
||||
return t.concat(_valueSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value from the resources of this slider preference's context
|
||||
* based on an attribute pointing to that resource.
|
||||
*
|
||||
* @param attrs
|
||||
* The attribute set to search
|
||||
*
|
||||
* @param namespace
|
||||
* The namespace of the attribute
|
||||
*
|
||||
* @param name
|
||||
* The name of the attribute
|
||||
*
|
||||
* @param defaultValue
|
||||
* The default value returned if no resource is found
|
||||
*
|
||||
* @return
|
||||
* The resource value
|
||||
*/
|
||||
private int getResourceValueFromAttribute(AttributeSet attrs, String namespace, String name, int defaultValue) {
|
||||
Resources res = getContext().getResources();
|
||||
int valueID = attrs.getAttributeResourceValue(namespace, name, 0);
|
||||
if (valueID != 0) {
|
||||
return res.getInteger(valueID);
|
||||
}
|
||||
else {
|
||||
return attrs.getAttributeIntValue(namespace, name, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value from the resources of this slider preference's context
|
||||
* based on an attribute pointing to that resource.
|
||||
*
|
||||
* @param attrs
|
||||
* The attribute set to search
|
||||
*
|
||||
* @param namespace
|
||||
* The namespace of the attribute
|
||||
*
|
||||
* @param name
|
||||
* The name of the attribute
|
||||
*
|
||||
* @param defaultValue
|
||||
* The default value returned if no resource is found
|
||||
*
|
||||
* @return
|
||||
* The resource value
|
||||
*/
|
||||
private String getResourceValueFromAttribute(AttributeSet attrs, String namespace, String name, String defaultValue) {
|
||||
Resources res = getContext().getResources();
|
||||
int valueID = attrs.getAttributeResourceValue(namespace, name, 0);
|
||||
if (valueID != 0) {
|
||||
return res.getString(valueID);
|
||||
}
|
||||
else {
|
||||
String value = attrs.getAttributeValue(namespace, name);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a value from this slider preference's seekbar by
|
||||
* adjusting it for a set perceived minimum value.
|
||||
*
|
||||
* @param value
|
||||
* The value to be translated from the seekbar
|
||||
*
|
||||
* @return
|
||||
* A value equal to the value passed plus the currently set minimum value.
|
||||
*/
|
||||
private int translateValueFro_seekBar(int value) {
|
||||
return value + _minValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a value for when setting this slider preference's seekbar by
|
||||
* adjusting it for a set perceived minimum value.
|
||||
*
|
||||
* @param value
|
||||
* The value to be translated for use
|
||||
*
|
||||
* @return
|
||||
* A value equal to the value passed minus the currently set minimum value.
|
||||
*/
|
||||
private int translateValueToSeekBar(int value) {
|
||||
return value - _minValue;
|
||||
}
|
||||
}
|
||||
77
project/android/src/com/mojang/minecraftpe/GameModeButton.java
Executable file
77
project/android/src/com/mojang/minecraftpe/GameModeButton.java
Executable file
@@ -0,0 +1,77 @@
|
||||
package com.mojang.minecraftpe;
|
||||
|
||||
import com.mojang.android.StringValue;
|
||||
import com.mojang.minecraftpe.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
public class GameModeButton extends ToggleButton implements OnClickListener, StringValue {
|
||||
public GameModeButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
_init();
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void onClick(View v) {
|
||||
_update();
|
||||
}
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
_update();
|
||||
}
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
if (!_attached) {
|
||||
_update();
|
||||
_attached = true;
|
||||
}
|
||||
}
|
||||
private boolean _attached = false;
|
||||
|
||||
private void _init() {
|
||||
setOnClickListener(this);
|
||||
}
|
||||
private void _update() {
|
||||
_setGameType(isChecked()?Survival:Creative);
|
||||
}
|
||||
private void _setGameType(int i) {
|
||||
_type = _clamp(i);
|
||||
|
||||
int id = R.string.gamemode_creative_summary;
|
||||
if (_type == Survival)
|
||||
id = R.string.gamemode_survival_summary;
|
||||
String desc = getContext().getString(id);
|
||||
|
||||
View v = getRootView().findViewById(R.id.labelGameModeDesc);
|
||||
System.out.println("Mode: " + _type + ", view? " + (v!=null));
|
||||
if (desc != null && v != null && v instanceof TextView) {
|
||||
((TextView)v).setText(desc);
|
||||
}
|
||||
}
|
||||
|
||||
static private int _clamp(int i) {
|
||||
if (i > Survival) return Survival;
|
||||
if (i < Creative) return Creative;
|
||||
return i;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return getStringForType(_type);
|
||||
}
|
||||
static public String getStringForType(int i) {
|
||||
return new String[] {
|
||||
"creative",
|
||||
"survival"
|
||||
} [_clamp(i)];
|
||||
}
|
||||
|
||||
private int _type = 0;
|
||||
static final int Creative = 0;
|
||||
static final int Survival = 1;
|
||||
}
|
||||
531
project/android/src/com/mojang/minecraftpe/MainActivity.java
Executable file
531
project/android/src/com/mojang/minecraftpe/MainActivity.java
Executable file
@@ -0,0 +1,531 @@
|
||||
package com.mojang.minecraftpe;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mojang.android.StringValue;
|
||||
import com.mojang.android.licensing.LicenseCodes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.NativeActivity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.view.inputmethod.*;
|
||||
import com.mojang.minecraftpe.R;
|
||||
|
||||
public class MainActivity extends NativeActivity {
|
||||
private boolean _isTouchscreen = true;
|
||||
private int _viewDistance = 2;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
getOptionStrings(); // Updates settings
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
super.onCreate(savedInstanceState);
|
||||
nativeRegisterThis();
|
||||
}
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
Log.w("MCPE", event.toString());
|
||||
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
return false;
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Log.w("MCPE", "Java - onBackPressed");
|
||||
return;
|
||||
}
|
||||
|
||||
private void createAlertDialog(boolean hasOkButton, boolean hasCancelButton, boolean preventBackKey) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
|
||||
builder.setTitle("");
|
||||
if (preventBackKey)
|
||||
builder.setCancelable(false);
|
||||
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
//@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
onDialogCanceled();
|
||||
}
|
||||
});
|
||||
|
||||
if (hasOkButton)
|
||||
builder.setPositiveButton("Ok", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) { onDialogCompleted(); }});
|
||||
|
||||
if (hasCancelButton)
|
||||
builder.setNegativeButton("Cancel", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) { onDialogCanceled(); }});
|
||||
|
||||
mDialog = builder.create();
|
||||
mDialog.setOwnerActivity(this);
|
||||
}
|
||||
|
||||
static private boolean _isPowerVr = false;
|
||||
public void setIsPowerVR(boolean status) { MainActivity._isPowerVr = status; }
|
||||
static public boolean isPowerVR() { return _isPowerVr; }
|
||||
|
||||
public boolean supportsTouchscreen() {
|
||||
return isXperiaPlay();
|
||||
//if (isXperiaPlay()) return false;
|
||||
//return true;
|
||||
}
|
||||
|
||||
static public boolean isXperiaPlay() {
|
||||
final String[] tags = { android.os.Build.MODEL,
|
||||
android.os.Build.DEVICE,
|
||||
android.os.Build.PRODUCT};
|
||||
for (String tag : tags) {
|
||||
tag = tag.toLowerCase();
|
||||
if (tag.indexOf("r800") >= 0) return true;
|
||||
if (tag.indexOf("so-01d") >= 0) return true;
|
||||
if (tag.indexOf("xperia") >= 0 && tag.indexOf("play") >= 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
// TODO Auto-generated method stub
|
||||
//System.out.println("Focus has changed. Has Focus? " + hasFocus);
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
//System.out.println("KeyDown: " + keyCode);
|
||||
Log.w("MCPE", "onKeyDown: " + keyCode);
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
public int getKeyFromKeyCode(int keyCode, int metaState, int deviceId) {
|
||||
return InputDevice.getDevice(deviceId).getKeyCharacterMap().get(keyCode, metaState);
|
||||
}
|
||||
static public void saveScreenshot(String filename, int w, int h, int[] pixels) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(pixels, w, h, Bitmap.Config.ARGB_8888);
|
||||
|
||||
//System.out.println("Save screenshot: " + filename);
|
||||
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filename);
|
||||
bitmap.compress(CompressFormat.JPEG, 85, fos);
|
||||
//System.out.println("Compression completed!");
|
||||
|
||||
try {
|
||||
fos.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
System.err.println("Couldn't create file: " + filename);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getFileDataBytes(String filename) {
|
||||
AssetManager assets = getAssets();
|
||||
|
||||
BufferedInputStream bis;
|
||||
try {
|
||||
InputStream is = assets.open(filename);
|
||||
bis = new BufferedInputStream(is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream(4096);
|
||||
byte[] tmp = new byte[1024];
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
int count = bis.read(tmp);
|
||||
if (count <= 0) break;
|
||||
s.write(tmp, 0, count);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
try { bis.close(); }
|
||||
catch (IOException e) {}
|
||||
}
|
||||
|
||||
return s.toByteArray();
|
||||
}
|
||||
|
||||
public int[] getImageData(String filename) {
|
||||
AssetManager assets = getAssets();
|
||||
|
||||
try {
|
||||
/*String[] filenames = */assets.list("images");
|
||||
} catch (IOException e) {
|
||||
System.err.println("getImageData: Could not list directory");
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = assets.open(filename);
|
||||
} catch (IOException e) {
|
||||
System.err.println("getImageData: Could not open image " + filename);
|
||||
return null;
|
||||
}
|
||||
|
||||
Bitmap bm = BitmapFactory.decodeStream(inputStream);
|
||||
int w = bm.getWidth();
|
||||
int h = bm.getHeight();
|
||||
|
||||
int[] pixels = new int[w * h + 2];
|
||||
pixels[0] = w;
|
||||
pixels[1] = h;
|
||||
bm.getPixels(pixels, 2, w, 0, 0, w, h);
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
Display display = ((WindowManager)this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
int out = Math.max(display.getWidth(), display.getHeight());
|
||||
System.out.println("getwidth: " + out);
|
||||
return out;
|
||||
}
|
||||
public int getScreenHeight() {
|
||||
Display display = ((WindowManager)this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
int out = Math.min(display.getWidth(), display.getHeight());
|
||||
System.out.println("getheight: " + out);
|
||||
return out;
|
||||
}
|
||||
public float getPixelsPerMillimeter() {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
//System.err.println("metrics: " + metrics.xdpi + ", " + metrics.ydpi);
|
||||
return (metrics.xdpi + metrics.ydpi) * 0.5f / 25.4f;
|
||||
}
|
||||
|
||||
public int checkLicense() { return LicenseCodes.LICENSE_OK; }
|
||||
|
||||
public String getDateString(int s) {
|
||||
return DateFormat.format(new Date(s * 1000L));
|
||||
}
|
||||
|
||||
public boolean hasBuyButtonWhenInvalidLicense() { return true; }
|
||||
|
||||
public void postScreenshotToFacebook(String filename, int w, int h, int[] pixels) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode,
|
||||
Intent data) {
|
||||
|
||||
if (requestCode == DialogDefinitions.DIALOG_MAINMENU_OPTIONS) {
|
||||
_userInputStatus = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void quit() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() { finish(); } });
|
||||
}
|
||||
|
||||
public void displayDialog(int dialogId) {
|
||||
|
||||
if (dialogId == DialogDefinitions.DIALOG_CREATE_NEW_WORLD) {
|
||||
chooseDialog(R.layout.create_new_world,
|
||||
new int[] { R.id.editText_worldName,
|
||||
R.id.editText_worldSeed,
|
||||
R.id.button_gameMode},
|
||||
false, // Don't prevent back key
|
||||
R.id.button_createworld_create,
|
||||
R.id.button_createworld_cancel
|
||||
);
|
||||
} else if (dialogId == DialogDefinitions.DIALOG_MAINMENU_OPTIONS) {
|
||||
Intent intent = new Intent(this, MainMenuOptionsActivity.class);
|
||||
intent.putExtra("preferenceId", R.xml.preferences);
|
||||
startActivityForResult(intent, dialogId);
|
||||
} else if (dialogId == DialogDefinitions.DIALOG_RENAME_MP_WORLD) {
|
||||
chooseDialog(R.layout.rename_mp_world,
|
||||
new int[] { R.id.editText_worldNameRename },
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void chooseDialog(final int layoutId, final int[] viewIds) {
|
||||
chooseDialog(layoutId, viewIds, true);
|
||||
}
|
||||
void chooseDialog(final int layoutId, final int[] viewIds, final boolean hasCancelButton) {
|
||||
chooseDialog(layoutId, viewIds, hasCancelButton, true);
|
||||
}
|
||||
void chooseDialog(final int layoutId, final int[] viewIds, final boolean hasCancelButton, final boolean preventBackKey) {
|
||||
chooseDialog(layoutId, viewIds, preventBackKey, 0, hasCancelButton? 0 : -1);
|
||||
}
|
||||
void chooseDialog(final int layoutId, final int[] viewIds, final boolean preventBackKey, final int okButtonId, final int cancelButtonId) {
|
||||
_userInputValues.clear();
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
createAlertDialog(okButtonId==0, cancelButtonId==0, preventBackKey);
|
||||
LayoutInflater li = LayoutInflater.from(MainActivity.this);
|
||||
|
||||
try {
|
||||
View view = li.inflate(layoutId, null);
|
||||
if (okButtonId != 0 && okButtonId != -1) {
|
||||
View b = view.findViewById(okButtonId);
|
||||
if (b != null)
|
||||
b.setOnClickListener(new View.OnClickListener()
|
||||
{ public void onClick(View v) { if (mDialog != null) mDialog.dismiss(); onDialogCompleted(); }});
|
||||
}
|
||||
if (cancelButtonId != 0 && cancelButtonId != -1) {
|
||||
View b = view.findViewById(cancelButtonId);
|
||||
if (b != null)
|
||||
b.setOnClickListener(new View.OnClickListener()
|
||||
{ public void onClick(View v) { if (mDialog != null) mDialog.cancel(); onDialogCanceled(); }});
|
||||
}
|
||||
|
||||
//mDialog.setO
|
||||
MainActivity.this.mDialog.setView(view);
|
||||
|
||||
if (viewIds != null)
|
||||
for (int viewId : viewIds) {
|
||||
View v = view.findViewById(viewId);
|
||||
if (v instanceof StringValue)
|
||||
_userInputValues.add( (StringValue) v );
|
||||
else if (v instanceof TextView)
|
||||
_userInputValues.add(new TextViewReader((TextView)v));
|
||||
}
|
||||
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MainActivity.this.mDialog.show();
|
||||
MainActivity.this.mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
MainActivity.this.mDialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT);
|
||||
//MainActivity.this.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void tick() {}
|
||||
|
||||
public String[] getOptionStrings() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
Map<String, ?> m = prefs.getAll();
|
||||
|
||||
String[] tmpOut = new String[m.size() * 2];
|
||||
|
||||
int n = 0;
|
||||
for (Map.Entry<String, ?> e : m.entrySet()) {
|
||||
// @todo: Would be nice if the disabled settings could be stripped out here
|
||||
|
||||
String key = e.getKey();
|
||||
String value = e.getValue().toString();
|
||||
|
||||
//
|
||||
// Feel free to modify key or value!
|
||||
//
|
||||
// This can be used to correct differences between the different
|
||||
// platforms, such as Android not supporting floating point
|
||||
// ranges for Sliders/SeekBars: {0..100} - TRANSFORM -> {0..1}
|
||||
//
|
||||
if (key.equals(MainMenuOptionsActivity.Controls_UseTouchscreen))
|
||||
_isTouchscreen = !isXperiaPlay() || (Boolean) e.getValue();
|
||||
|
||||
if (key.equals(MainMenuOptionsActivity.Graphics_LowQuality))
|
||||
_viewDistance = ((Boolean) e.getValue()) ? 3 : 2;
|
||||
|
||||
if (key.equals(MainMenuOptionsActivity.Internal_Game_DifficultyPeaceful)) {
|
||||
key = MainMenuOptionsActivity.Game_DifficultyLevel;
|
||||
value = ((Boolean) e.getValue()) ? "0" : "2";
|
||||
}
|
||||
|
||||
try {
|
||||
if (key.equals(MainMenuOptionsActivity.Controls_Sensitivity))
|
||||
value = new Double( 0.01 * Integer.parseInt(value) ).toString();
|
||||
} catch (Exception exc) {}
|
||||
|
||||
tmpOut[n++] = key;
|
||||
tmpOut[n++] = value;
|
||||
|
||||
//System.out.println("Key: " + e.getKey());
|
||||
//System.out.println("Val: " + e.getValue().toString() + " (" + e.getValue().getClass().getName() + ")\n");
|
||||
}
|
||||
|
||||
// Copy over the enabled preferences
|
||||
String[] out = new String[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
out[i] = tmpOut[i];
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public void buyGame() {}
|
||||
|
||||
public String getPlatformStringVar(int id) {
|
||||
if (id == 0) return android.os.Build.MODEL;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isNetworkEnabled(boolean onlyWifiAllowed) {
|
||||
return true;
|
||||
/*
|
||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo info = onlyWifiAllowed? cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
|
||||
: cm.getActiveNetworkInfo();
|
||||
//(info.getState() == NetworkInfo.State.CONNECTED || info.getState() == NetworkInfo.State.CONNECTING));
|
||||
return (info != null && info.isConnectedOrConnecting());
|
||||
*/
|
||||
}
|
||||
|
||||
private Bundle data;
|
||||
private int _userInputStatus = -1;
|
||||
private String[] _userInputText = null;
|
||||
private ArrayList<StringValue> _userInputValues = new ArrayList<StringValue>();
|
||||
public void initiateUserInput(int id) {
|
||||
_userInputText = null;
|
||||
_userInputStatus = -1;
|
||||
}
|
||||
public int getUserInputStatus() { return _userInputStatus; }
|
||||
public String[] getUserInputString() { return _userInputText; }
|
||||
|
||||
private AlertDialog mDialog;
|
||||
private final DateFormat DateFormat = new SimpleDateFormat();
|
||||
// public EditText mTextInputWidget;
|
||||
|
||||
public void vibrate(int milliSeconds) {
|
||||
Vibrator v = (Vibrator)this.getSystemService(VIBRATOR_SERVICE);
|
||||
v.vibrate(milliSeconds);
|
||||
}
|
||||
|
||||
private void onDialogCanceled() {
|
||||
_userInputStatus = 0;
|
||||
}
|
||||
|
||||
private void onDialogCompleted() {
|
||||
int size = _userInputValues.size();
|
||||
_userInputText = new String[size];
|
||||
for (int i = 0; i < size; ++i) {
|
||||
_userInputText[i] = _userInputValues.get(i).getStringValue();
|
||||
}
|
||||
for (String s : _userInputText) System.out.println("js: " + s);
|
||||
|
||||
_userInputStatus = 1;
|
||||
InputMethodManager inputManager = (InputMethodManager)getSystemService("input_method");
|
||||
boolean result = inputManager.showSoftInput(this.getCurrentFocus(), InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
|
||||
protected void onStart() {
|
||||
//System.out.println("onStart");
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
protected void onResume() {
|
||||
//System.out.println("onResume");
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
protected void onPause() {
|
||||
//System.out.println("onPause");
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
protected void onStop() {
|
||||
//System.out.println("onStop");
|
||||
nativeStopThis();
|
||||
super.onStop();
|
||||
}
|
||||
protected void onDestroy() {
|
||||
System.out.println("onDestroy");
|
||||
|
||||
nativeUnregisterThis();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected boolean isDemo() { return false; }
|
||||
|
||||
//
|
||||
// Native interface
|
||||
//
|
||||
native void nativeRegisterThis();
|
||||
native void nativeUnregisterThis();
|
||||
native void nativeStopThis();
|
||||
|
||||
static {
|
||||
System.loadLibrary("minecraftpe");
|
||||
}
|
||||
}
|
||||
|
||||
// see client/gui/screens/DialogDefinitions.h
|
||||
class DialogDefinitions {
|
||||
static final int DIALOG_CREATE_NEW_WORLD = 1;
|
||||
static final int DIALOG_NEW_CHAT_MESSAGE = 2;
|
||||
static final int DIALOG_MAINMENU_OPTIONS = 3;
|
||||
static final int DIALOG_RENAME_MP_WORLD = 4;
|
||||
}
|
||||
|
||||
class TextViewReader implements StringValue {
|
||||
public TextViewReader(TextView view) {
|
||||
_view = view;
|
||||
}
|
||||
public String getStringValue() {
|
||||
return _view.getText().toString();
|
||||
}
|
||||
private TextView _view;
|
||||
}
|
||||
197
project/android/src/com/mojang/minecraftpe/MainMenuOptionsActivity.java
Executable file
197
project/android/src/com/mojang/minecraftpe/MainMenuOptionsActivity.java
Executable file
@@ -0,0 +1,197 @@
|
||||
package com.mojang.minecraftpe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.mojang.android.EditTextAscii;
|
||||
//import com.mojang.minecraftpe.R;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
public class MainMenuOptionsActivity extends PreferenceActivity implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener
|
||||
{
|
||||
static public final String Multiplayer_Username = "mp_username";
|
||||
static public final String Multiplayer_ServerVisible = "mp_server_visible_default";
|
||||
static public final String Graphics_Fancy = "gfx_fancygraphics";
|
||||
static public final String Graphics_LowQuality = "gfx_lowquality";
|
||||
static public final String Controls_InvertMouse = "ctrl_invertmouse";
|
||||
static public final String Controls_Sensitivity = "ctrl_sensitivity";
|
||||
static public final String Controls_UseTouchscreen = "ctrl_usetouchscreen";
|
||||
static public final String Controls_UseTouchJoypad = "ctrl_usetouchjoypad";
|
||||
static public final String Controls_FeedbackVibration = "feedback_vibration";
|
||||
static public final String Game_DifficultyLevel = "game_difficulty";
|
||||
static public final String Internal_Game_DifficultyPeaceful = "game_difficultypeaceful";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
addPreferencesFromResource(extras.getInt("preferenceId"));//R.xml.preferences);
|
||||
|
||||
//getPreferenceManager().setSharedPreferencesMode(MODE_PRIVATE);
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
PreferenceScreen s = getPreferenceScreen();
|
||||
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).contains(Multiplayer_Username)) {
|
||||
previousName = PreferenceManager.getDefaultSharedPreferences(this).getString(Multiplayer_Username, null);
|
||||
}
|
||||
|
||||
_validator = new PreferenceValidator(this);
|
||||
readBackAll(s);
|
||||
_validator.commit();
|
||||
}
|
||||
|
||||
private void readBackAll(PreferenceGroup g) {
|
||||
traversePreferences(g, new PreferenceTraverser() {
|
||||
void onPreference(Preference p) { readBack(p); _validator.validate(p); }
|
||||
});
|
||||
}
|
||||
private void traversePreferences(PreferenceGroup g, PreferenceTraverser pt) {
|
||||
int size = g.getPreferenceCount();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
Preference p = g.getPreference(i);
|
||||
if (p instanceof PreferenceGroup) {
|
||||
PreferenceGroup pg = (PreferenceGroup)p;
|
||||
pt.onPreferenceGroup(pg);
|
||||
traversePreferences(pg, pt);
|
||||
}
|
||||
else
|
||||
pt.onPreference(p);
|
||||
}
|
||||
}
|
||||
private void readBack(Preference p) {
|
||||
if (p == null)
|
||||
return;
|
||||
|
||||
//System.out.println("pref: " + p.toString());
|
||||
|
||||
if (p instanceof EditTextPreference) {
|
||||
EditTextPreference e = (EditTextPreference) p;
|
||||
p.setSummary("'" + e.getText() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Preference p = findPreference(key);
|
||||
_validator.validate(sharedPreferences, key);
|
||||
|
||||
if (p instanceof EditTextPreference) {
|
||||
EditTextPreference e = (EditTextPreference) p;
|
||||
Editor editor = sharedPreferences.edit();
|
||||
|
||||
String s = e.getText();
|
||||
String sanitized = EditTextAscii.sanitize(s).trim();
|
||||
|
||||
if (key.equals(Multiplayer_Username) && sanitized == null || sanitized.length() == 0) {
|
||||
sanitized = previousName;
|
||||
if (sanitized == null || sanitized.equals("")) {
|
||||
sanitized = "Steve";
|
||||
previousName = sanitized;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s.equals(sanitized)) {
|
||||
editor.putString(key, sanitized);
|
||||
editor.commit();
|
||||
e.setText(sanitized);
|
||||
}
|
||||
}
|
||||
|
||||
readBack(p);
|
||||
}
|
||||
|
||||
String previousName;
|
||||
PreferenceValidator _validator;
|
||||
}
|
||||
|
||||
class PreferenceValidator {
|
||||
static private class Pref {
|
||||
Pref(PreferenceGroup g, Preference p) {
|
||||
this.g = g;
|
||||
this.p = p;
|
||||
}
|
||||
PreferenceGroup g;
|
||||
Preference p;
|
||||
}
|
||||
private PreferenceActivity _prefs;
|
||||
private ArrayList<Pref> _arrayList = new ArrayList<Pref>();
|
||||
|
||||
public PreferenceValidator(PreferenceActivity prefs) {
|
||||
_prefs = prefs;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
//System.err.println("ERR: " + _arrayList.size());
|
||||
for (int i = 0; i < _arrayList.size(); ++i) {
|
||||
PreferenceGroup g = _arrayList.get(i).g;
|
||||
Preference p = _arrayList.get(i).p;
|
||||
g.removePreference(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void validate(Preference p) {
|
||||
validate(PreferenceManager.getDefaultSharedPreferences(_prefs), p.getKey());
|
||||
}
|
||||
public void validate(SharedPreferences preferences, String key) {
|
||||
Preference p = findPreference(key);
|
||||
|
||||
if (p instanceof CheckBoxPreference) {
|
||||
//CheckBoxPreference e = (CheckBoxPreference) p;
|
||||
if (key.equals(MainMenuOptionsActivity.Graphics_LowQuality)) {
|
||||
boolean isShort = preferences.getBoolean(MainMenuOptionsActivity.Graphics_LowQuality, false);
|
||||
CheckBoxPreference fancyPref = (CheckBoxPreference)findPreference(MainMenuOptionsActivity.Graphics_Fancy);
|
||||
if (fancyPref != null) {
|
||||
fancyPref.setEnabled(isShort == false);
|
||||
if (isShort)
|
||||
fancyPref.setChecked(false);
|
||||
}
|
||||
}
|
||||
if (key.equals(MainMenuOptionsActivity.Graphics_Fancy)) {
|
||||
CheckBoxPreference fancyPref = (CheckBoxPreference) p;
|
||||
//System.err.println("Is PowerVR? : " + MainActivity.isPowerVR());
|
||||
if (MainActivity.isPowerVR()) {
|
||||
fancyPref.setSummary("Experimental on this device!");
|
||||
}
|
||||
}
|
||||
|
||||
if (p.getKey().equals(MainMenuOptionsActivity.Controls_UseTouchscreen)) {
|
||||
boolean hasOtherPrimaryControls = MainActivity.isXperiaPlay();
|
||||
if (!hasOtherPrimaryControls) {
|
||||
PreferenceCategory mCategory = (PreferenceCategory) findPreference("category_graphics");
|
||||
_arrayList.add(new Pref(mCategory, p));
|
||||
}
|
||||
p.setEnabled(hasOtherPrimaryControls);
|
||||
p.setDefaultValue( !hasOtherPrimaryControls );
|
||||
|
||||
if (hasOtherPrimaryControls) {
|
||||
CheckBoxPreference pp = (CheckBoxPreference) p;
|
||||
CheckBoxPreference j = (CheckBoxPreference)findPreference(MainMenuOptionsActivity.Controls_UseTouchJoypad);
|
||||
j.setEnabled(pp.isChecked());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Preference findPreference(String key) {
|
||||
return _prefs.findPreference(key);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class PreferenceTraverser {
|
||||
void onPreference(Preference p) {}
|
||||
void onPreferenceGroup(PreferenceGroup p) {}
|
||||
}
|
||||
|
||||
14
project/android/src/com/mojang/minecraftpe/Minecraft_Market.java
Executable file
14
project/android/src/com/mojang/minecraftpe/Minecraft_Market.java
Executable file
@@ -0,0 +1,14 @@
|
||||
package com.mojang.minecraftpe;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import com.mojang.minecraftpe.MainActivity;
|
||||
|
||||
public class Minecraft_Market extends MainActivity {
|
||||
@Override
|
||||
public void buyGame() {
|
||||
final Uri buyLink = Uri.parse("market://details?id=com.mojang.minecraftpe");
|
||||
Intent marketIntent = new Intent( Intent.ACTION_VIEW, buyLink );
|
||||
startActivity(marketIntent);
|
||||
}
|
||||
}
|
||||
17
project/android/src/com/mojang/minecraftpe/Minecraft_Market_Demo.java
Executable file
17
project/android/src/com/mojang/minecraftpe/Minecraft_Market_Demo.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package com.mojang.minecraftpe;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import com.mojang.android.licensing.LicenseCodes;
|
||||
|
||||
public class Minecraft_Market_Demo extends MainActivity {
|
||||
@Override
|
||||
public void buyGame() {
|
||||
final Uri buyLink = Uri.parse("market://details?id=com.mojang.minecraftpe");
|
||||
Intent marketIntent = new Intent( Intent.ACTION_VIEW, buyLink );
|
||||
startActivity(marketIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDemo() { return true; }
|
||||
}
|
||||
89
project/android/src/com/mojang/minecraftpe/Minecraft_Verizon.java
Executable file
89
project/android/src/com/mojang/minecraftpe/Minecraft_Verizon.java
Executable file
@@ -0,0 +1,89 @@
|
||||
package com.mojang.minecraftpe;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.mojang.android.licensing.LicenseCodes;
|
||||
import com.verizon.vcast.apps.LicenseAuthenticator;
|
||||
|
||||
|
||||
public class Minecraft_Verizon extends MainActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
_licenseLib = new LicenseAuthenticator(this);
|
||||
_verizonThread = new VerizonLicenseThread(_licenseLib, VCastMarketKeyword, false);
|
||||
_verizonThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkLicense() {
|
||||
if (_verizonThread == null)
|
||||
return _licenseCode;
|
||||
|
||||
if (!_verizonThread.hasCode)
|
||||
return -1;
|
||||
|
||||
_licenseCode = _verizonThread.returnCode;
|
||||
_verizonThread = null;
|
||||
return _licenseCode;
|
||||
}
|
||||
@Override
|
||||
public boolean hasBuyButtonWhenInvalidLicense() { return false; }
|
||||
|
||||
private LicenseAuthenticator _licenseLib;
|
||||
private VerizonLicenseThread _verizonThread;
|
||||
private int _licenseCode;
|
||||
static private final String VCastMarketKeyword = "Minecraft";
|
||||
}
|
||||
|
||||
//
|
||||
// Requests license code from the Verizon VCAST application on the phone
|
||||
//
|
||||
class VerizonLicenseThread extends Thread
|
||||
{
|
||||
public VerizonLicenseThread(LicenseAuthenticator licenseLib, String keyword, boolean isTest) {
|
||||
_keyword = keyword;
|
||||
_isTest = isTest;
|
||||
_licenseLib = licenseLib;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (_isTest)
|
||||
validateTestLicense();
|
||||
else
|
||||
validateLicense();
|
||||
}
|
||||
|
||||
void validateTestLicense() {
|
||||
try {
|
||||
//final int status = LicenseAuthenticator.LICENSE_NOT_FOUND;
|
||||
final int status = LicenseAuthenticator.LICENSE_OK;
|
||||
returnCode = _licenseLib.checkTestLicense( _keyword, status );
|
||||
}
|
||||
catch (Throwable e) {
|
||||
returnCode = LicenseCodes.LICENSE_CHECK_EXCEPTION;
|
||||
}
|
||||
hasCode = true;
|
||||
}
|
||||
|
||||
void validateLicense() {
|
||||
try {
|
||||
returnCode = _licenseLib.checkLicense( _keyword );
|
||||
}
|
||||
catch (Throwable e) {
|
||||
returnCode = LicenseCodes.LICENSE_CHECK_EXCEPTION;
|
||||
//e.printStackTrace();
|
||||
}
|
||||
hasCode = true;
|
||||
}
|
||||
|
||||
public volatile boolean hasCode = false;
|
||||
public volatile int returnCode = -1;
|
||||
|
||||
private String _keyword;
|
||||
private boolean _isTest;
|
||||
private LicenseAuthenticator _licenseLib;
|
||||
}
|
||||
Reference in New Issue
Block a user