restore include paths for cross-platform builds because i messed absolutely every #include up. dont worry that everything is modified, all i did was normalize line endings because CLRF snuck into the repo and this prevents fake diffs

This commit is contained in:
2026-03-24 19:07:55 -04:00
parent 7d485fdcd7
commit bfecad40be
1340 changed files with 264990 additions and 264996 deletions

View File

@@ -1,58 +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();
}
}
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();
}
}

View File

@@ -1,5 +1,5 @@
package com.mojang.android;
public interface StringValue {
public String getStringValue();
}
package com.mojang.android;
public interface StringValue {
public String getStringValue();
}

View File

@@ -1,29 +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;
}
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;
}

View File

@@ -1,233 +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;
}
}
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;
}
}

View File

@@ -1,77 +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;
}
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;
}

View File

@@ -1,197 +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) {}
}
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) {}
}

View File

@@ -1,14 +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);
}
}
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);
}
}

View File

@@ -1,17 +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; }
}
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; }
}

View File

@@ -1,89 +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;
}
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;
}