Double tap back button to exit
This commit is contained in:
parent
a41870c2c5
commit
88c2a394ef
3 changed files with 33 additions and 9 deletions
20
app/bind.sh
20
app/bind.sh
|
@ -5,7 +5,7 @@ export GOPATH="$PROJECTPATH/go"
|
|||
export GO111MODULE=on
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: ./bind.sh <boxcars commit hash or tag>"
|
||||
echo "Usage: ./bind.sh <boxcars tag, commit hash or local path>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -20,17 +20,23 @@ go get github.com/hajimehoshi/ebiten/v2@latest
|
|||
echo "Installing ebitenmobile..."
|
||||
go install github.com/hajimehoshi/ebiten/v2/cmd/ebitenmobile@latest
|
||||
|
||||
echo "Downloading boxcars $1..."
|
||||
mkdir -p $GOPATH/src/code.rocket9labs.com/tslocum
|
||||
if [ ! -d "$GOPATH/src/code.rocket9labs.com/tslocum/boxcars" ]; then
|
||||
git clone https://code.rocket9labs.com/tslocum/boxcars $GOPATH/src/code.rocket9labs.com/tslocum/boxcars
|
||||
BOXCARSPATH=""
|
||||
if [[ "$1" == *\/* ]]; then
|
||||
BOXCARSPATH=$1/game/mobile
|
||||
else
|
||||
echo "Downloading boxcars $1..."
|
||||
mkdir -p $GOPATH/src/code.rocket9labs.com/tslocum
|
||||
if [ ! -d "$GOPATH/src/code.rocket9labs.com/tslocum/boxcars" ]; then
|
||||
git clone https://code.rocket9labs.com/tslocum/boxcars $GOPATH/src/code.rocket9labs.com/tslocum/boxcars
|
||||
fi
|
||||
cd $GOPATH/src/code.rocket9labs.com/tslocum/boxcars && git fetch origin && git reset --hard `printf %q "$1"` && cd $PROJECTPATH
|
||||
BOXCARSPATH=$GOPATH/src/code.rocket9labs.com/tslocum/boxcars/game/mobile
|
||||
fi
|
||||
cd $GOPATH/src/code.rocket9labs.com/tslocum/boxcars && git fetch origin && git reset --hard `printf %q "$1"` && cd $PROJECTPATH
|
||||
|
||||
echo "Binding boxcars..."
|
||||
mkdir -p libs
|
||||
PATH="$PROJECTPATH/go/bin:$PATH"
|
||||
cd $GOPATH/src/code.rocket9labs.com/tslocum/boxcars/game/mobile
|
||||
cd $BOXCARSPATH
|
||||
ebitenmobile bind -target android -androidapi 21 -javapkg com.rocket9labs.boxcars -o $PROJECTPATH/libs/boxcars.aar .
|
||||
|
||||
echo "Finished."
|
||||
|
|
|
@ -40,6 +40,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||
|
||||
}
|
||||
|
||||
task bindLibrary(type: Exec) {
|
||||
|
|
|
@ -2,11 +2,16 @@ package com.rocket9labs.boxcars;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import go.Seq;
|
||||
import com.rocket9labs.boxcars.mobile.EbitenView;
|
||||
|
||||
import go.Seq;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
private static final int backButtonDoubleTapTime = 1000; // Milliseconds.
|
||||
private long backButtonLastTapped;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -16,7 +21,7 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
|
||||
private EbitenView getEbitenView() {
|
||||
return (EbitenView)this.findViewById(R.id.ebitenView);
|
||||
return (EbitenView) this.findViewById(R.id.ebitenView);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,4 +35,16 @@ public class MainActivity extends Activity {
|
|||
super.onResume();
|
||||
this.getEbitenView().resumeGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (backButtonLastTapped >= System.currentTimeMillis() - backButtonDoubleTapTime) {
|
||||
finishAndRemoveTask();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(getBaseContext(), "Double tap the back button to exit", Toast.LENGTH_SHORT).show();
|
||||
backButtonLastTapped = System.currentTimeMillis();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue