diff --git a/README.md b/README.md
index edeb46a..a7b187c 100644
--- a/README.md
+++ b/README.md
@@ -1,48 +1,38 @@
# JoyStick
-Android Library for JoyStick View.
+Android Library for JoyStick View.
+
Customizable, small and lightweight.
-[![Download](https://api.bintray.com/packages/erz05/maven/JoyStick/images/download.svg)](https://bintray.com/erz05/maven/JoyStick/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-JoyStick-blue.svg?style=flat)](http://android-arsenal.com/details/1/2712)
+## Sample App
+![Sample app](/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png "Sample App image")
-
Sample App
-
-
+![Sample app image 1](/images/Screenshot_2015-10-30-21-43-47.png "Sample app image 1")
-
-
-
-
-JoyStick with Image for button
-
-
+![Sample app image 2](/images/Screenshot_2015-11-02-18-05-49.png "Sample app image 2")
-Usage
-Gradle Import: jcenter
+## Usage
+Gradle Import: This github repository
```groovy
repositories {
maven {
- url "http://dl.bintray.com/erz05/maven"
+ url uri("https://maven.pkg.github.com/etlegacy/JoyStick")
}
-
- //Or
-
- jcenter()
}
dependencies {
- compile 'com.github.erz05:JoyStick:1.1.0'
+ compile 'com.etlegacy.android:JoyStick:1.2.0'
}
```
-v1.1.0 BREAKING CHANGE!
+## v1.1.0 BREAKING CHANGE!
-1. Made changes to JoyStickListener
-a. Added Direction to onMove
-b. Added Event calls for onTap and onDoubleTap
+* Made changes to JoyStickListener
+ * Added Direction to onMove
+ * Added Event calls for onTap and onDoubleTap
-Defaults:
+## Defaults:
1. Background = White
2. Button = Red
@@ -50,7 +40,7 @@ b. Added Event calls for onTap and onDoubleTap
4. StayPut = false
5. Directional-Axis = 8
-Setup:
+## Setup:
```xml
android:layout_height="200dp"
android:layout_gravity="bottom"/>
+
app:padColor="#55ffffff"
app:buttonColor="#55ff0000"
app:stayPut="true"
- app:percentage="25" //default 25: radius percentage of full size of the view between 25% and 50%
+ app:percentage="25"
app:backgroundDrawable="R.drawable.background"
app:buttonDrawable="R.drawable.button"/>
```
```java
-JoyStick joyStick = (JoyStick) findViewById(R.id.joyStick);
+JoyStick joyStick = findViewById(R.id.joyStick);
//or
JoyStick joyStick = new JoyStick(context);
```
-JoyStickListener:
+## JoyStickListener:
```java
//JoyStickListener Interface
@@ -97,7 +88,7 @@ joyStick.setListener(this);
2. onTap: gets called onSingleTapConfirmed
3. onDoubleTap: gets called onDoubleTap
-Directions:
+## Directions:
1. DIRECTION_CENTER = -1
2. DIRECTION_LEFT = 0
3. DIRECTION_LEFT_UP = 1
@@ -115,7 +106,7 @@ joyStick.getDirection();
```
or get it from the JoyStickListener
-Axis Types:
+## Axis Types:
1. TYPE_8_AXIS
2. TYPE_4_AXIS
3. TYPE_2_AXIS_LEFT_RIGHT
@@ -127,7 +118,7 @@ To set Axis Type:
joyStick.setType(JoyStick.TYPE_4_AXIS);
```
-Getters/Setters
+## Getters/Setters
```java
//Set GamePad Color
@@ -158,7 +149,7 @@ joyStick.getAngle();
joyStick.getAngleDegrees();
```
-License
+## License
Copyright 2015 erz05
Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/app/build.gradle b/app/build.gradle
index d70fca0..54ded6a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,15 @@
-apply plugin: 'com.android.application'
+plugins {
+ id 'com.android.application'
+}
android {
- compileSdkVersion 26
- buildToolsVersion "26.0.2"
+ namespace "com.erz.joystick"
+ compileSdk 33
defaultConfig {
applicationId "com.erz.joystick"
- minSdkVersion 14
- targetSdkVersion 26
+ minSdkVersion 31
+ targetSdk 33
versionCode 1
versionName "1.0"
}
@@ -17,13 +19,13 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
+ buildFeatures {
+ viewBinding true
+ }
}
dependencies {
implementation project(path: ':joysticklibrary')
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:26.1.0'
- compile 'com.android.support:design:26.1.0'
-// compile 'com.github.erz05:JoyStick:1.1.0'
+ implementation 'com.android.support:appcompat-v7:28.0.0'
+ testImplementation 'junit:junit:4.13.2'
}
\ No newline at end of file
diff --git a/app/src/androidTest/java/com/erz/joystick/ApplicationTest.java b/app/src/androidTest/java/com/erz/joystick/ApplicationTest.java
deleted file mode 100644
index 521f396..0000000
--- a/app/src/androidTest/java/com/erz/joystick/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.erz.joystick;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7266936..6d51c24 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,19 +3,18 @@
package="com.erz.joystick">
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:exported="true"
+ android:label="@string/title_activity_fullscreen"
+ android:theme="@style/AppTheme.NoActionBar">
-
diff --git a/app/src/main/java/com/erz/joystick/GameLoop.java b/app/src/main/java/com/erz/joystick/GameLoop.java
index f3e737d..31c6f1e 100644
--- a/app/src/main/java/com/erz/joystick/GameLoop.java
+++ b/app/src/main/java/com/erz/joystick/GameLoop.java
@@ -9,10 +9,8 @@ import android.view.SurfaceView;
public class GameLoop extends Thread {
private static final long FPS = 24;
private static final long ticksPS = 1000 / FPS;
- private SurfaceView view;
+ private final SurfaceView view;
private boolean running = false;
- private long startTime;
- private long sleepTime;
private Canvas canvas;
public GameLoop(SurfaceView view) {
@@ -26,7 +24,7 @@ public class GameLoop extends Thread {
@Override
public void run() {
while (running) {
- startTime = System.currentTimeMillis();
+ long startTime = System.currentTimeMillis();
try {
canvas = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
@@ -37,12 +35,14 @@ public class GameLoop extends Thread {
view.getHolder().unlockCanvasAndPost(canvas);
}
}
- sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
+ long sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
+ if (sleepTime <= 0) {
+ sleepTime = 20;
+ }
+
try {
- if (sleepTime > 0)
- sleep(sleepTime);
- else
- sleep(10);
+ //noinspection BusyWait
+ sleep(sleepTime);
} catch (Exception ignore) {}
}
}
diff --git a/app/src/main/java/com/erz/joystick/GameView.java b/app/src/main/java/com/erz/joystick/GameView.java
index c563793..95b8a54 100644
--- a/app/src/main/java/com/erz/joystick/GameView.java
+++ b/app/src/main/java/com/erz/joystick/GameView.java
@@ -20,7 +20,7 @@ import java.util.Vector;
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
private int i;
- private int size = 20;
+ private final int size = 20;
private int minSpeed;
private int maxSpeed;
private int minRadius;
@@ -33,12 +33,12 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
private double angle;
private double power;
private double angle2;
- private Bitmap droid;
+ private final Bitmap droid;
private GameLoop gameLoop;
- private Paint paint;
- private Vector stars = new Vector<>();
+ private final Paint paint;
+ private final Vector stars = new Vector<>();
private RectF rectF = new RectF();
- private Random random = new Random();
+ private final Random random = new Random();
public GameView(Context context) {
this(context, null);
@@ -57,6 +57,7 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
@Override
public void draw(Canvas canvas) {
+ super.draw(canvas);
if (canvas == null) return;
canvas.drawColor(Color.BLACK);
@@ -94,8 +95,8 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
this.height = height;
float min = Math.min(width, height);
- float centerX = width / 2;
- float centerY = height / 2;
+ float centerX = (float) width / 2;
+ float centerY = (float) height / 2;
posX = centerX;
posY = centerY;
radius = min / 12;
diff --git a/app/src/main/java/com/erz/joystick/MainActivity.java b/app/src/main/java/com/erz/joystick/MainActivity.java
index 6a7648a..baf8711 100644
--- a/app/src/main/java/com/erz/joystick/MainActivity.java
+++ b/app/src/main/java/com/erz/joystick/MainActivity.java
@@ -1,12 +1,13 @@
package com.erz.joystick;
+import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
import com.erz.joysticklibrary.JoyStick;
-public class MainActivity extends AppCompatActivity implements JoyStick.JoyStickListener {
+public class MainActivity extends Activity implements JoyStick.JoyStickListener {
private GameView gameView;
@@ -14,13 +15,13 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- gameView = (GameView) findViewById(R.id.game);
- JoyStick joy1 = (JoyStick) findViewById(R.id.joy1);
+ gameView = findViewById(R.id.game);
+ JoyStick joy1 = findViewById(R.id.joy1);
joy1.setListener(this);
joy1.setPadColor(Color.parseColor("#55ffffff"));
joy1.setButtonColor(Color.parseColor("#55ff0000"));
- JoyStick joy2 = (JoyStick) findViewById(R.id.joy2);
+ JoyStick joy2 = findViewById(R.id.joy2);
joy2.setListener(this);
joy2.enableStayPut(true);
joy2.setPadBackground(R.drawable.pad);
@@ -29,13 +30,14 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick
@Override
public void onMove(JoyStick joyStick, double angle, double power, int direction) {
- switch (joyStick.getId()) {
- case R.id.joy1:
- gameView.move(angle, power);
- break;
- case R.id.joy2:
- gameView.rotate(angle);
- break;
+ int id = joyStick.getId();
+
+ if (id == R.id.joy1) {
+ gameView.move(angle, power);
+ } else if(id == R.id.joy2) {
+ gameView.rotate(angle);
+ } else {
+ Log.w("onMove", "Wrong id detected on the move");
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index e1d1986..b3c95f6 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,8 +1,12 @@
+ android:orientation="vertical"
+ android:background="?attr/fullscreenBackgroundColor"
+ android:theme="@style/ThemeOverlay.Etlegacyjoystick.FullscreenContainer"
+ tools:context=".MainActivity">
+ android:layout_gravity="bottom|end"/>
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
new file mode 100644
index 0000000..e10a356
--- /dev/null
+++ b/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..e52391d
--- /dev/null
+++ b/app/src/main/res/values/attrs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 3ab3e9c..e28683a 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -3,4 +3,9 @@
#3F51B5
#303F9F
#FF4081
+ #FF039BE5
+ #FF01579B
+ #FF40C4FF
+ #FF00B0FF
+ #66000000
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a73e10f..f494eb2 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,6 @@
JoyStick
+ FullscreenActivity
+ Dummy Button
+ DUMMY\nCONTENT
\ No newline at end of file
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 0a1cd50..46522cf 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -21,4 +21,13 @@
+
+
+
+
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
new file mode 100644
index 0000000..4bc95fa
--- /dev/null
+++ b/app/src/main/res/values/themes.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/test/java/com/erz/joystick/ExampleUnitTest.java b/app/src/test/java/com/erz/joystick/ExampleUnitTest.java
deleted file mode 100644
index 33442db..0000000
--- a/app/src/test/java/com/erz/joystick/ExampleUnitTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.erz.joystick;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * To work on unit tests, switch the Test Artifact in the Build Variants view.
- */
-public class ExampleUnitTest {
- @Test
- public void addition_isCorrect() throws Exception {
- assertEquals(4, 2 + 2);
- }
-}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index cbb218d..2ded6fd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,23 +3,54 @@
buildscript {
repositories {
google()
- jcenter()
+ mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.1'
+ classpath 'com.android.tools.build:gradle:8.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
-allprojects {
- repositories {
+def parseGitVersion() {
+ def major = 0
+ def minor = 0
+ def patch = 0
+ def postfix = 'UNKNOWN'
+ def hash = ''
+ def output = 'git describe --long --tags --dirty --always'.execute().text.trim()
+ (output =~ /^v(\d+)\.(\d+)\.(\d+)-(\d+)-(\w+)/).each { match, majorVal, minorVal, patchVal, commitVal, hashVal ->
+ if (output.toLowerCase().endsWith('-dirty')) {
+ postfix = '-DIRTY'
+ } else if(commit as int > 0) {
+ patchVal = (patchVal as int + 1) as String
+ postfix = '-SNAPSHOT'
+ } else {
+ postfix = ''
+ }
+
+ major = majorVal as int
+ minor = minorVal as int
+ patch = patchVal as int
+ hash = hashVal
+ }
+ return [version: "${major}.${minor}.${patch}${postfix}", hash: hash]
+}
+
+def versionInfo = parseGitVersion()
+
+version = versionInfo.version
+def root = project
+
+subprojects { Project ch ->
+ ch.version = root.version
+ ch.repositories {
google()
- jcenter()
+ mavenCentral()
}
}
-task clean(type: Delete) {
+tasks.register('clean', Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
diff --git a/joysticklibrary/build.gradle b/joysticklibrary/build.gradle
index 110d28f..f47260a 100644
--- a/joysticklibrary/build.gradle
+++ b/joysticklibrary/build.gradle
@@ -1,13 +1,15 @@
-apply plugin: 'com.android.library'
-apply plugin: 'com.novoda.bintray-release'
+plugins {
+ id 'com.android.library'
+ id 'maven-publish'
+}
android {
- compileSdkVersion 27
- buildToolsVersion "27.0.3"
+ namespace "com.erz.joysticklibrary"
+ compileSdk 33
defaultConfig {
- minSdkVersion 14
- targetSdkVersion 27
+ minSdkVersion 26
+ targetSdk 33
versionCode 2
versionName "1.1"
}
@@ -17,23 +19,67 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
+ publishing {
+ singleVariant("release") {
+ withSourcesJar()
+ }
+ }
}
-buildscript {
+publishing {
+ publications {
+ maven(MavenPublication) {
+ groupId = 'com.etlegacy.android'
+ artifactId = 'JoyStick'
+ version = project.version
+
+ pom {
+ name = 'Android JoyStick library'
+ description = 'Android Library for JoyStick View'
+ url = 'https://github.com/etlegacy/JoyStick'
+ /*
+ developers {
+ developer {
+ id = 'johnd'
+ name = 'John Doe'
+ email = 'john.doe@etlegacy.com'
+ }
+ }
+ */
+ scm {
+ connection = 'scm:git:git@github.com:etlegacy/JoyStick.git'
+ url = 'https://github.com/etlegacy/JoyStick.git'
+ }
+ }
+
+ afterEvaluate {
+ from components.release
+ }
+ }
+ }
+
repositories {
- google()
- jcenter()
- }
- dependencies {
- classpath 'com.novoda:bintray-release:0.7.0'
+ if (System.getenv("GITHUB_ACTOR") != null) {
+ maven {
+ name = "GitHubPackages"
+ url = "https://maven.pkg.github.com/etlegacy/JoyStick"
+ credentials {
+ username = System.getenv("GITHUB_ACTOR")
+ password = System.getenv("GITHUB_TOKEN")
+ }
+ }
+ } else {
+ maven {
+ def releasesRepoUrl = layout.buildDirectory.dir('repos/releases')
+ def snapshotsRepoUrl = layout.buildDirectory.dir('repos/snapshots')
+ url = (project.version as String).endsWith("-SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
+ }
+ }
}
}
-publish {
- userOrg = 'erz05'
- groupId = 'com.github.erz05'
- artifactId = 'JoyStick'
- version = '1.1.0'
- description = 'Android Library for JoyStick View'
- website = 'https://github.com/erz05/JoyStick'
-}
\ No newline at end of file
+assemble {
+ doFirst {
+ println("Assembling version: ${project.version}")
+ }
+}
diff --git a/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java b/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java
index d4f9f26..8a99da2 100644
--- a/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java
+++ b/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java
@@ -16,6 +16,7 @@
package com.erz.joysticklibrary;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
@@ -32,6 +33,7 @@ import android.view.View;
/**
* Created by edgarramirez on 10/30/15.
* JoyStick view with lots of customizable options
+ * @noinspection unused
*/
public class JoyStick extends View implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
@@ -51,9 +53,9 @@ public class JoyStick extends View implements GestureDetector.OnGestureListener,
public static final int TYPE_2_AXIS_UP_DOWN = 44;
private JoyStickListener listener;
- private Paint paint;
- private RectF temp;
- private GestureDetector gestureDetector;
+ private final Paint paint;
+ private final RectF temp;
+ private final GestureDetector gestureDetector;
private int direction = DIRECTION_CENTER;
private int type = TYPE_8_AXIS;
private float centerX;
@@ -111,29 +113,28 @@ public class JoyStick extends View implements GestureDetector.OnGestureListener,
padColor = Color.WHITE;
buttonColor = Color.RED;
- if (attrs != null) {
- TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.JoyStick);
- if (typedArray != null) {
- padColor = typedArray.getColor(R.styleable.JoyStick_padColor, Color.WHITE);
- buttonColor = typedArray.getColor(R.styleable.JoyStick_buttonColor, Color.RED);
- stayPut = typedArray.getBoolean(R.styleable.JoyStick_stayPut, false);
- percentage = typedArray.getInt(R.styleable.JoyStick_percentage, 25);
- if (percentage > 50) percentage = 50;
- if (percentage < 25) percentage = 25;
-
- int padResId = typedArray.getResourceId(R.styleable.JoyStick_backgroundDrawable, -1);
- int buttonResId = typedArray.getResourceId(R.styleable.JoyStick_buttonDrawable, -1);
-
- if (padResId > 0) {
- padBGBitmap = BitmapFactory.decodeResource(getResources(), padResId);
- }
- if (buttonResId > 0) {
- buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId);
- }
-
- typedArray.recycle();
- }
+ if (attrs == null) {
+ return;
}
+
+ TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.JoyStick);
+ padColor = typedArray.getColor(R.styleable.JoyStick_padColor, Color.WHITE);
+ buttonColor = typedArray.getColor(R.styleable.JoyStick_buttonColor, Color.RED);
+ stayPut = typedArray.getBoolean(R.styleable.JoyStick_stayPut, false);
+ percentage = typedArray.getInt(R.styleable.JoyStick_percentage, 25);
+ if (percentage > 50) percentage = 50;
+ if (percentage < 25) percentage = 25;
+
+ int padResId = typedArray.getResourceId(R.styleable.JoyStick_backgroundDrawable, -1);
+ int buttonResId = typedArray.getResourceId(R.styleable.JoyStick_buttonDrawable, -1);
+
+ if (padResId > 0) {
+ padBGBitmap = BitmapFactory.decodeResource(getResources(), padResId);
+ }
+ if (buttonResId > 0) {
+ buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId);
+ }
+ typedArray.recycle();
}
@Override
@@ -169,6 +170,7 @@ public class JoyStick extends View implements GestureDetector.OnGestureListener,
}
}
+ @SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
gestureDetector.onTouchEvent(event);
diff --git a/settings.gradle b/settings.gradle
index 6b5d4c4..c931508 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1,2 @@
+rootProject.name = 'JoyStick'
include ':app', ':joysticklibrary'