Formatting
This commit is contained in:
@@ -49,237 +49,237 @@ import java.util.Locale;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class AndroidLauncher extends AndroidApplication{
|
||||
public static final int PERMISSION_REQUEST_CODE = 1;
|
||||
public static final int PERMISSION_REQUEST_CODE = 1;
|
||||
|
||||
boolean doubleScaleTablets = true;
|
||||
FileChooser chooser;
|
||||
boolean doubleScaleTablets = true;
|
||||
FileChooser chooser;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||
config.useImmersiveMode = true;
|
||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||
config.useImmersiveMode = true;
|
||||
|
||||
Platform.instance = new Platform(){
|
||||
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
||||
Platform.instance = new Platform(){
|
||||
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
||||
|
||||
@Override
|
||||
public boolean hasDiscord() {
|
||||
return isPackageInstalled("com.discord");
|
||||
}
|
||||
@Override
|
||||
public boolean hasDiscord(){
|
||||
return isPackageInstalled("com.discord");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(Date date){
|
||||
return format.format(date);
|
||||
}
|
||||
@Override
|
||||
public String format(Date date){
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(int number){
|
||||
return NumberFormat.getIntegerInstance().format(number);
|
||||
}
|
||||
@Override
|
||||
public String format(int number){
|
||||
return NumberFormat.getIntegerInstance().format(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field, int length){
|
||||
TextFieldDialogListener.add(field, 0, length);
|
||||
}
|
||||
@Override
|
||||
public void addDialog(TextField field, int length){
|
||||
TextFieldDialogListener.add(field, 0, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocaleName(Locale locale){
|
||||
return locale.getDisplayName(locale);
|
||||
}
|
||||
@Override
|
||||
public String getLocaleName(Locale locale){
|
||||
return locale.getDisplayName(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openDonations() {
|
||||
showDonations();
|
||||
}
|
||||
@Override
|
||||
public void openDonations(){
|
||||
showDonations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadProvider getThreadProvider() {
|
||||
return new DefaultThreadImpl();
|
||||
}
|
||||
@Override
|
||||
public ThreadProvider getThreadProvider(){
|
||||
return new DefaultThreadImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isDebug(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUUID() {
|
||||
try {
|
||||
String s = Secure.getString(getContext().getContentResolver(),
|
||||
Secure.ANDROID_ID);
|
||||
@Override
|
||||
public String getUUID(){
|
||||
try{
|
||||
String s = Secure.getString(getContext().getContentResolver(),
|
||||
Secure.ANDROID_ID);
|
||||
|
||||
int len = s.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
||||
+ Character.digit(s.charAt(i + 1), 16));
|
||||
}
|
||||
int len = s.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for(int i = 0; i < len; i += 2){
|
||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
||||
+ Character.digit(s.charAt(i + 1), 16));
|
||||
}
|
||||
|
||||
String result = new String(Base64Coder.encode(data));
|
||||
String result = new String(Base64Coder.encode(data));
|
||||
|
||||
if(result.equals("AAAAAAAAAOA=")) throw new RuntimeException("Bad UUID.");
|
||||
if(result.equals("AAAAAAAAAOA=")) throw new RuntimeException("Bad UUID.");
|
||||
|
||||
return result;
|
||||
}catch (Exception e){
|
||||
return super.getUUID();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e){
|
||||
return super.getUUID();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shareFile(FileHandle file){
|
||||
@Override
|
||||
public void shareFile(FileHandle file){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, String filetype) {
|
||||
chooser = new FileChooser(text, file -> file.extension().equalsIgnoreCase(filetype), open, cons);
|
||||
@Override
|
||||
public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, String filetype){
|
||||
chooser = new FileChooser(text, file -> file.extension().equalsIgnoreCase(filetype), open, cons);
|
||||
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
||||
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)){
|
||||
chooser.show();
|
||||
chooser = null;
|
||||
}else {
|
||||
ArrayList<String> perms = new ArrayList<>();
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
||||
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)){
|
||||
chooser.show();
|
||||
chooser = null;
|
||||
}else{
|
||||
ArrayList<String> perms = new ArrayList<>();
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
perms.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
|
||||
perms.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
perms.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
if(checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
|
||||
perms.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
requestPermissions(perms.toArray(new String[perms.size()]), PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
requestPermissions(perms.toArray(new String[perms.size()]), PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginForceLandscape() {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
@Override
|
||||
public void beginForceLandscape(){
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endForceLandscape() {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||
}
|
||||
@Override
|
||||
public void endForceLandscape(){
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDonate(){
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public boolean canDonate(){
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
ProviderInstaller.installIfNeeded(this);
|
||||
} catch (GooglePlayServicesRepairableException e) {
|
||||
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
|
||||
apiAvailability.getErrorDialog(this, e.getConnectionStatusCode(), 0).show();
|
||||
} catch (GooglePlayServicesNotAvailableException e) {
|
||||
Log.e("SecurityException", "Google Play Services not available.");
|
||||
}
|
||||
try{
|
||||
ProviderInstaller.installIfNeeded(this);
|
||||
}catch(GooglePlayServicesRepairableException e){
|
||||
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
|
||||
apiAvailability.getErrorDialog(this, e.getConnectionStatusCode(), 0).show();
|
||||
}catch(GooglePlayServicesNotAvailableException e){
|
||||
Log.e("SecurityException", "Google Play Services not available.");
|
||||
}
|
||||
|
||||
if(doubleScaleTablets && isTablet(this.getContext())){
|
||||
Unit.dp.addition = 0.5f;
|
||||
}
|
||||
|
||||
config.hideStatusBar = true;
|
||||
if(doubleScaleTablets && isTablet(this.getContext())){
|
||||
Unit.dp.addition = 0.5f;
|
||||
}
|
||||
|
||||
config.hideStatusBar = true;
|
||||
|
||||
Net.setClientProvider(new KryoClient());
|
||||
Net.setServerProvider(new KryoServer());
|
||||
|
||||
initialize(new Mindustry(), config);
|
||||
|
||||
checkFiles(getIntent());
|
||||
}
|
||||
checkFiles(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
if(requestCode == PERMISSION_REQUEST_CODE){
|
||||
for(int i : grantResults){
|
||||
if(i != PackageManager.PERMISSION_GRANTED) return;
|
||||
}
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults){
|
||||
if(requestCode == PERMISSION_REQUEST_CODE){
|
||||
for(int i : grantResults){
|
||||
if(i != PackageManager.PERMISSION_GRANTED) return;
|
||||
}
|
||||
|
||||
if(chooser != null){
|
||||
chooser.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(chooser != null){
|
||||
chooser.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFiles(Intent intent){
|
||||
try {
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null) {
|
||||
File myFile = null;
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme.equals("file")) {
|
||||
String fileName = uri.getEncodedPath();
|
||||
myFile = new File(fileName);
|
||||
} else if (!scheme.equals("content")) {
|
||||
//error
|
||||
return;
|
||||
}
|
||||
private void checkFiles(Intent intent){
|
||||
try{
|
||||
Uri uri = intent.getData();
|
||||
if(uri != null){
|
||||
File myFile = null;
|
||||
String scheme = uri.getScheme();
|
||||
if(scheme.equals("file")){
|
||||
String fileName = uri.getEncodedPath();
|
||||
myFile = new File(fileName);
|
||||
}else if(!scheme.equals("content")){
|
||||
//error
|
||||
return;
|
||||
}
|
||||
|
||||
boolean save = uri.getPath().endsWith(saveExtension);
|
||||
boolean map = uri.getPath().endsWith(mapExtension);
|
||||
boolean save = uri.getPath().endsWith(saveExtension);
|
||||
boolean map = uri.getPath().endsWith(mapExtension);
|
||||
|
||||
InputStream inStream;
|
||||
if (myFile != null) inStream = new FileInputStream(myFile);
|
||||
else inStream = getContentResolver().openInputStream(uri);
|
||||
InputStream inStream;
|
||||
if(myFile != null) inStream = new FileInputStream(myFile);
|
||||
else inStream = getContentResolver().openInputStream(uri);
|
||||
|
||||
Gdx.app.postRunnable(() -> {
|
||||
Gdx.app.postRunnable(() -> {
|
||||
|
||||
if(save){ //open save
|
||||
System.out.println("Opening save.");
|
||||
FileHandle file = Gdx.files.local("temp-save." + saveExtension);
|
||||
file.write(inStream, false);
|
||||
if(save){ //open save
|
||||
System.out.println("Opening save.");
|
||||
FileHandle file = Gdx.files.local("temp-save." + saveExtension);
|
||||
file.write(inStream, false);
|
||||
|
||||
if(SaveIO.isSaveValid(file)){
|
||||
try{
|
||||
SaveSlot slot = control.getSaves().importSave(file);
|
||||
ui.load.runLoadSave(slot);
|
||||
}catch (IOException e){
|
||||
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}else{
|
||||
ui.showError("$text.save.import.invalid");
|
||||
}
|
||||
if(SaveIO.isSaveValid(file)){
|
||||
try{
|
||||
SaveSlot slot = control.getSaves().importSave(file);
|
||||
ui.load.runLoadSave(slot);
|
||||
}catch(IOException e){
|
||||
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}else{
|
||||
ui.showError("$text.save.import.invalid");
|
||||
}
|
||||
|
||||
}else if(map){ //open map
|
||||
Gdx.app.postRunnable(() -> {
|
||||
System.out.println("Opening map.");
|
||||
if (!ui.editor.isShown()) {
|
||||
ui.editor.show();
|
||||
}
|
||||
}else if(map){ //open map
|
||||
Gdx.app.postRunnable(() -> {
|
||||
System.out.println("Opening map.");
|
||||
if(!ui.editor.isShown()){
|
||||
ui.editor.show();
|
||||
}
|
||||
|
||||
ui.editor.beginEditMap(inStream);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.editor.beginEditMap(inStream);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPackageInstalled(String packagename) {
|
||||
try {
|
||||
getPackageManager().getPackageInfo(packagename, 0);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTablet(Context context) {
|
||||
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE;
|
||||
}
|
||||
|
||||
private void showDonations(){
|
||||
Intent intent = new Intent(this, DonationsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPackageInstalled(String packagename){
|
||||
try{
|
||||
getPackageManager().getPackageInfo(packagename, 0);
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTablet(Context context){
|
||||
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE;
|
||||
}
|
||||
|
||||
private void showDonations(){
|
||||
Intent intent = new Intent(this, DonationsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,20 +11,20 @@ import android.widget.EditText;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
public class AndroidTextFieldDialog{
|
||||
private Activity activity;
|
||||
private EditText userInput;
|
||||
private AlertDialog.Builder builder;
|
||||
private TextPromptListener listener;
|
||||
private boolean isBuild;
|
||||
private Activity activity;
|
||||
private EditText userInput;
|
||||
private AlertDialog.Builder builder;
|
||||
private TextPromptListener listener;
|
||||
private boolean isBuild;
|
||||
|
||||
public AndroidTextFieldDialog() {
|
||||
this.activity = (Activity)Gdx.app;
|
||||
load();
|
||||
}
|
||||
public AndroidTextFieldDialog(){
|
||||
this.activity = (Activity) Gdx.app;
|
||||
load();
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog show() {
|
||||
public AndroidTextFieldDialog show(){
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
activity.runOnUiThread(() -> {
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
@@ -33,12 +33,12 @@ public class AndroidTextFieldDialog{
|
||||
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private AndroidTextFieldDialog load() {
|
||||
private AndroidTextFieldDialog load(){
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
activity.runOnUiThread(() -> {
|
||||
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
|
||||
LayoutInflater li = LayoutInflater.from(activity);
|
||||
@@ -55,64 +55,65 @@ public class AndroidTextFieldDialog{
|
||||
isBuild = true;
|
||||
});
|
||||
|
||||
// Wait till TextPrompt is built.
|
||||
while (!isBuild) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) { }
|
||||
}
|
||||
// Wait till TextPrompt is built.
|
||||
while(!isBuild){
|
||||
try{
|
||||
Thread.sleep(10);
|
||||
}catch(InterruptedException e){
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getResourceId(String pVariableName, String pVariableType) {
|
||||
try {
|
||||
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
|
||||
} catch (Exception e) {
|
||||
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
|
||||
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
public int getResourceId(String pVariableName, String pVariableType){
|
||||
try{
|
||||
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
|
||||
}catch(Exception e){
|
||||
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
|
||||
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setText(CharSequence value) {
|
||||
userInput.append(value);
|
||||
return this;
|
||||
}
|
||||
public AndroidTextFieldDialog setText(CharSequence value){
|
||||
userInput.append(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label) {
|
||||
builder.setNegativeButton(label, (dialog, id) -> dialog.cancel());
|
||||
return this;
|
||||
}
|
||||
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label){
|
||||
builder.setNegativeButton(label, (dialog, id) -> dialog.cancel());
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label) {
|
||||
builder.setPositiveButton(label, (dialog, id) -> {
|
||||
if (listener != null && !userInput.getText().toString().isEmpty()) {
|
||||
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label){
|
||||
builder.setPositiveButton(label, (dialog, id) -> {
|
||||
if(listener != null && !userInput.getText().toString().isEmpty()){
|
||||
listener.confirm(userInput.getText().toString());
|
||||
}
|
||||
|
||||
});
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener){
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setInputType(int type) {
|
||||
userInput.setInputType(type);
|
||||
return this;
|
||||
}
|
||||
public AndroidTextFieldDialog setInputType(int type){
|
||||
userInput.setInputType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setMaxLength(int length) {
|
||||
userInput.setFilters(new InputFilter[] { new InputFilter.LengthFilter(length) });
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface TextPromptListener{
|
||||
void confirm(String text);
|
||||
}
|
||||
public AndroidTextFieldDialog setMaxLength(int length){
|
||||
userInput.setFilters(new InputFilter[]{new InputFilter.LengthFilter(length)});
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface TextPromptListener{
|
||||
void confirm(String text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,9 @@ import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.sufficientlysecure.donations.DonationsFragment;
|
||||
|
||||
public class DonationsActivity extends FragmentActivity {
|
||||
DonationsFragment donationsFragment;
|
||||
|
||||
public class DonationsActivity extends FragmentActivity{
|
||||
/**
|
||||
* Google
|
||||
*/
|
||||
@@ -21,13 +18,14 @@ public class DonationsActivity extends FragmentActivity {
|
||||
private static final String[] GOOGLE_CATALOG = new String[]{
|
||||
"mindustry.donation.1", "mindustry.donation.2", "mindustry.donation.5",
|
||||
"mindustry.donation.10", "mindustry.donation.15",
|
||||
"mindustry.donation.25", "mindustry.donation.50" };
|
||||
"mindustry.donation.25", "mindustry.donation.50"};
|
||||
DonationsFragment donationsFragment;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTheme(R.style.GdxTheme);
|
||||
@@ -35,7 +33,7 @@ public class DonationsActivity extends FragmentActivity {
|
||||
setContentView(R.layout.donations_activity);
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
if (BuildConfig.DONATIONS_GOOGLE) {
|
||||
if(BuildConfig.DONATIONS_GOOGLE){
|
||||
donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY, GOOGLE_CATALOG,
|
||||
getResources().getStringArray(R.array.donation_google_catalog_values), false, null, null,
|
||||
null, false, null, null, false, null);
|
||||
@@ -48,9 +46,10 @@ public class DonationsActivity extends FragmentActivity {
|
||||
|
||||
public void onStart(){
|
||||
super.onStart();
|
||||
Button b = ((Button)findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View view) {
|
||||
Button b = ((Button) findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
||||
b.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view){
|
||||
donationsFragment.donateGoogleOnClick(donationsFragment.getView());
|
||||
b.setEnabled(false);
|
||||
}
|
||||
@@ -58,20 +57,19 @@ public class DonationsActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Needed for Google Play In-app Billing. It uses startIntentSenderForResult(). The result is not propagated to
|
||||
* the Fragment like in startActivityForResult(). Thus we need to propagate manually to our Fragment.
|
||||
*/
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
Button b = ((Button)findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
||||
Button b = ((Button) findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
||||
b.setEnabled(true);
|
||||
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
Fragment fragment = fragmentManager.findFragmentByTag("donationsFragment");
|
||||
if (fragment != null) {
|
||||
if(fragment != null){
|
||||
fragment.onActivityResult(requestCode, resultCode, data);
|
||||
//TODO donation event, set settings?
|
||||
}
|
||||
|
||||
@@ -11,57 +11,57 @@ import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
|
||||
public class TextFieldDialogListener extends ClickListener{
|
||||
private TextField field;
|
||||
private int type;
|
||||
private int max;
|
||||
private TextField field;
|
||||
private int type;
|
||||
private int max;
|
||||
|
||||
public static void add(TextField field, int type, int max){
|
||||
field.addListener(new TextFieldDialogListener(field, type, max));
|
||||
field.addListener(new InputListener(){
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
//type - 0 is text, 1 is numbers, 2 is decimals
|
||||
public TextFieldDialogListener(TextField field, int type, int max){
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public static void add(TextField field){
|
||||
add(field, 0, 16);
|
||||
}
|
||||
public static void add(TextField field, int type, int max){
|
||||
field.addListener(new TextFieldDialogListener(field, type, max));
|
||||
field.addListener(new InputListener(){
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//type - 0 is text, 1 is numbers, 2 is decimals
|
||||
public TextFieldDialogListener(TextField field, int type, int max){
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
this.max = max;
|
||||
}
|
||||
public static void add(TextField field){
|
||||
add(field, 0, 16);
|
||||
}
|
||||
|
||||
public void clicked(final InputEvent event, float x, float y){
|
||||
|
||||
if(Gdx.app.getType() == ApplicationType.Desktop) return;
|
||||
|
||||
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
|
||||
public void clicked(final InputEvent event, float x, float y){
|
||||
|
||||
dialog.setTextPromptListener(text -> {
|
||||
if(Gdx.app.getType() == ApplicationType.Desktop) return;
|
||||
|
||||
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
|
||||
|
||||
dialog.setTextPromptListener(text -> {
|
||||
field.clearText();
|
||||
field.appendText(text);
|
||||
field.fire(new ChangeListener.ChangeEvent());
|
||||
Gdx.graphics.requestRendering();
|
||||
});
|
||||
|
||||
if(type == 0){
|
||||
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}else if(type == 1){
|
||||
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
}else if(type == 2){
|
||||
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
}
|
||||
if(type == 0){
|
||||
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}else if(type == 1){
|
||||
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
}else if(type == 2){
|
||||
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
}
|
||||
|
||||
dialog.setConfirmButtonLabel("OK").setText(field.getText());
|
||||
dialog.setCancelButtonLabel("Cancel");
|
||||
dialog.setMaxLength(max);
|
||||
dialog.show();
|
||||
event.cancel();
|
||||
dialog.setConfirmButtonLabel("OK").setText(field.getText());
|
||||
dialog.setCancelButtonLabel("Cancel");
|
||||
dialog.setMaxLength(max);
|
||||
dialog.show();
|
||||
event.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user