Release Boxcars v1.2.7 for Android
This commit is contained in:
parent
fda9b09bcf
commit
4eea632c5f
2 changed files with 70 additions and 22 deletions
|
@ -3,7 +3,7 @@ plugins {
|
|||
}
|
||||
|
||||
project.ext {
|
||||
boxcarsVersion = "v1.2.6" // https://code.rocket9labs.com/tslocum/boxcars/tags
|
||||
boxcarsVersion = "v1.2.7" // https://code.rocket9labs.com/tslocum/boxcars/tags
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -17,8 +17,8 @@ android {
|
|||
applicationId "com.rocket9labs.boxcars"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 34
|
||||
versionCode 102060
|
||||
versionName "1.2.6"
|
||||
versionCode 102070
|
||||
versionName "1.2.7"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
|
|
@ -3,40 +3,42 @@ package com.rocket9labs.boxcars;
|
|||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.widget.Toast;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.BaseInputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.rocket9labs.boxcars.mobile.EbitenView;
|
||||
|
||||
import go.Seq;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
private static final int backButtonDoubleTapTime = 1000; // Milliseconds.
|
||||
private long backButtonLastTapped;
|
||||
|
||||
Runnable exitRunnable = new Runnable() {
|
||||
private static final int backButtonLongPress = 2000; // Milliseconds.
|
||||
private long backButtonPressed;
|
||||
private long keyPressed;
|
||||
private final Handler handler = new Handler();
|
||||
private final Runnable exitRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
Handler handler = new Handler();
|
||||
private EbitenView getEbitenView() {
|
||||
return this.findViewById(R.id.ebitenView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Seq.setContext(getApplicationContext());
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
private EbitenView getEbitenView() {
|
||||
return (EbitenView) this.findViewById(R.id.ebitenView);
|
||||
getEbitenView().requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
handler.postDelayed(exitRunnable, 10 * 60 * 1000);
|
||||
this.getEbitenView().suspendGame();
|
||||
getEbitenView().suspendGame();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -44,18 +46,64 @@ public class MainActivity extends Activity {
|
|||
protected void onResume() {
|
||||
handler.removeCallbacks(exitRunnable);
|
||||
super.onResume();
|
||||
this.getEbitenView().resumeGame();
|
||||
getEbitenView().resumeGame();
|
||||
getEbitenView().requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (backButtonLastTapped >= System.currentTimeMillis() - backButtonDoubleTapTime) {
|
||||
finishAndRemoveTask();
|
||||
System.exit(0);
|
||||
return;
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
backButtonPressed = System.currentTimeMillis();
|
||||
event.startTracking();
|
||||
return true;
|
||||
}
|
||||
boolean handled = super.onKeyDown(keyCode, event);
|
||||
getEbitenView().requestFocus();
|
||||
return handled;
|
||||
}
|
||||
|
||||
Toast.makeText(getBaseContext(), "Double tap the back button to exit", Toast.LENGTH_SHORT).show();
|
||||
backButtonLastTapped = System.currentTimeMillis();
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (System.currentTimeMillis() - backButtonPressed >= backButtonLongPress) {
|
||||
finishAndRemoveTask();
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInputFromWindow(getEbitenView().getWindowToken(), 0, 0);
|
||||
getEbitenView().requestFocus();
|
||||
return true;
|
||||
}
|
||||
boolean handled = super.onKeyDown(keyCode, event);
|
||||
getEbitenView().requestFocus();
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
int keycode = event.getKeyCode();
|
||||
if (keycode == 66 || keycode == 67 || (keycode >= 7 && keycode <= 16 && !event.isShiftPressed())) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - keyPressed >= 100) {
|
||||
super.dispatchKeyEvent(event);
|
||||
BaseInputConnection mInputConnection = new BaseInputConnection((EbitenView) findViewById(R.id.ebitenView), false);
|
||||
if (keycode == 66) {
|
||||
mInputConnection.commitText(Character.toString((char) 199), 1);
|
||||
} else if (keycode == 67) {
|
||||
mInputConnection.commitText(Character.toString((char) 231), 1);
|
||||
} else {
|
||||
mInputConnection.commitText(Character.toString((char) (48 + (keycode - 7))), 1);
|
||||
}
|
||||
keyPressed = now;
|
||||
getEbitenView().requestFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean handled = super.dispatchKeyEvent(event);
|
||||
getEbitenView().requestFocus();
|
||||
return handled;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue