Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9ba0d89
Added possibility to center one of the axis only
Mathias-Boulay Feb 3, 2022
7bcf724
Update gradle-wrapper.properties, gradlew, and 2 more files...
Mathias-Boulay Feb 20, 2022
27c2ed7
Optimize cpu performance using a Handler instead of a dedicated Thread;
Mathias-Boulay Feb 20, 2022
754b93f
Width cannot be larger than height
Mathias-Boulay Feb 20, 2022
c6d2c2d
Add deadzone attribute;
Mathias-Boulay Feb 20, 2022
79c80a2
Hey we can make it support android 2.3.6
Mathias-Boulay Feb 20, 2022
970cf78
Update README.md
Mathias-Boulay Feb 20, 2022
c2e5653
Bump up version before release
Mathias-Boulay Feb 20, 2022
b8dc231
Add implementation in the readme
Mathias-Boulay Feb 20, 2022
08cb7d3
Update build.gradle
Mathias-Boulay Sep 11, 2022
2a17177
Update README.md
Mathias-Boulay Sep 11, 2022
2a75bb3
Add the ability to change the deadzone
Mathias-Boulay Sep 11, 2022
888c876
Add ability to enable forward lock
Mathias-Boulay Sep 13, 2022
c43281e
Add ability to set forward lock distance
Mathias-Boulay Sep 13, 2022
83b49a7
Update JoystickView.java
Mathias-Boulay Sep 13, 2022
bf41dda
Build: update to recent gradle version
Mathias-Boulay May 14, 2023
9bd9a27
Feat[misc]: Add a demo app
Mathias-Boulay May 14, 2023
d43dd10
Fix[joystick]: better pointer id storage
Mathias-Boulay May 14, 2023
bb32c59
Feat: auto forward lock when y crosses past the threshold
Mathias-Boulay May 14, 2023
f8c9dff
Feat: instant events
Mathias-Boulay May 14, 2023
3929ad3
Fix: forward distance not being offset
Mathias-Boulay May 14, 2023
3832b4f
Misc: update demo app
Mathias-Boulay May 14, 2023
4fee901
Fix: size change doesn't change forward lock distance
Mathias-Boulay May 15, 2023
44c2a67
Fix: remove reliance on OOB canvas drawing
Mathias-Boulay Aug 2, 2023
e4e91fa
Fix[lifecycle]: handle forward lock view already being removed
Mathias-Boulay Aug 2, 2023
2a607db
Fix[lifecycle]:detach state listener
Mathias-Boulay Aug 2, 2023
ac02e46
Fix[lifecycle]: detach the view only when necessary
Mathias-Boulay Aug 2, 2023
06e19f1
Fix[lifecycle]: wait out the activity shenanigans
Mathias-Boulay Aug 3, 2023
a4ab959
Fix[UI]: hide the forward lock
Mathias-Boulay Aug 3, 2023
3ab5276
Fix[ui]: handle resize
Mathias-Boulay Aug 3, 2023
231334e
Fix: handle non existant layout params
Mathias-Boulay Aug 3, 2023
cb7bf45
Feat: display a lock when forward lockis enabled
Mathias-Boulay Aug 4, 2023
dac9ab5
Feat: sync alpha between joystick and forward lock view
Mathias-Boulay Oct 13, 2023
2e7aa25
Build: update min API
Mathias-Boulay Oct 13, 2023
07513da
Fix: make the mesured size square
Mathias-Boulay Dec 1, 2024
1923b95
Chore: bump release version
Mathias-Boulay Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# virtual-joystick-android

**v1.10.1** _(New version - [support custom images](#image), button & background size, limited direction, normalized coordinate, alpha border)_
[![](https://jitpack.io/v/Mathias-Boulay/virtual-joystick-android.svg)](https://jitpack.io/#Mathias-Boulay/virtual-joystick-android)

**v1.10.1** _(New version - button & background size, limited direction, normalized coordinate, alpha border)_

_I created this very simple library as a learning process and I have been inspired by this project [JoystickView](https://github.com/zerokol/JoystickView) (the author is a genius!)_

Expand All @@ -25,6 +27,11 @@ protected void onCreate(Bundle savedInstanceState) {
public void onMove(int angle, int strength) {
// do whatever you want
}

@Override
public void onForwardLock(boolean forwardLock){
// do whatever you want, overriding this function is optionnal
}
});
}
```
Expand All @@ -39,9 +46,7 @@ joystick.setOnMoveListener(new JoystickView.OnMoveListener() { ... }, 17); // ar

### Attributes

You can customize the joystick according to these attributes `JV_buttonImage`, `JV_buttonColor`, `JV_buttonSizeRatio`, `JV_borderColor`, `JV_borderAlpha`, `JV_borderWidth`, `JV_backgroundColor`, `JV_backgroundSizeRatio`, `JV_fixedCenter`, `JV_autoReCenterButton`, `JV_buttonStickToBorder`, `JV_enabled` and `JV_buttonDirection`

If you specified `JV_buttonImage` you don't need `JV_buttonColor`
You can customize the joystick according to these attributes `JV_buttonColor`, `JV_buttonSizeRatio`, `JV_borderColor`, `JV_borderAlpha`, `JV_borderWidth`, `JV_backgroundColor`, `JV_backgroundSizeRatio`, `JV_fixedCenter`, `JV_autoReCenterButton`, `JV_buttonStickToBorder`, `JV_enabled`, `JV_buttonDirection`, `JV_deadzone` and `JV_forwardLockDistance`

Here is an example for your layout resources:
```xml
Expand All @@ -56,19 +61,6 @@ Here is an example for your layout resources:
custom:JV_borderWidth="4dp"
custom:JV_fixedCenter="false"/>
```
#### Image
If you want a more customized joystick, you can use `JV_buttonImage` and the regular `background` attributes to specify drawables. The images will be automatically resized.

```xml
<io.github.controlwear.virtual.joystick.android.JoystickView
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/joystick_base_blue"
custom:JV_buttonImage="@drawable/ball_pink"/>
```

![Alt text](/misc/android-virtual-joystick-custom-image.png?raw=true "Left joystick with custom image")

#### SizeRatio
We can change the default size of the button and background.
Expand All @@ -90,8 +82,6 @@ joystick.setBackgroundSizeRatio(0.5);
joystick.setButtonSizeRatio(0.1);
```

_The background size is not working for a custom picture._

#### FixedCenter or Not? (and auto re-center)
If you don’t set up this parameter, it will be FixedCenter by default, which is the regular behavior.

Expand Down Expand Up @@ -133,31 +123,37 @@ We can also set this option in the Java file by setting an integer value:
joystick.setButtonDirection(1); // vertical
```

### Wearable
If you use this library in Wearable app, you will probably disable the Swipe-To-Dismiss Gesture and implement the Long Press to Dismiss Pattern, which could be a problem for a Joystick Pattern (because we usually let the user touch the joystick as long as she/he wants), in that case you can set another convenient listener: `OnMultipleLongPressListener` which will be invoked only with multiple pointers (at least two fingers) instead of one.
```java
joystick.setOnMultiLongPressListener(new JoystickView.OnMultipleLongPressListener() {
@Override
public void onMultipleLongPress() {
... // eg. mDismissOverlay.show();
}
});
#### Deadzone
Most joysticks have an inner deadzone, else games would feel hypersensitive in their inputs.
By default, the deadzone is at 10% strength.
To change the deadzone, you can specify the following in xml.
```xml
<...
custom:JV_deadzone="integer"/>
```
Or better, if you just want a simple Joystick (and few other cool stuff) as a controller for your mobile app you can use the following related project ;)

## Demo
For those who want more than just a snippet, here is the demo :
- [Basic two joysticks ](https://github.com/controlwear/virtual-joystick-demo) (similar to screenshot)
#### ForwardLockDistance
By default, the button doesn't have any forward locking, as it may not be desirable in all situations
To enable forward locking, you need to specify a distance != 0 in xml.

```xml
<...
custom:JV_forwardLockDistance="dimension"/>
```

_For those who don't know, forward locking is this thing in CODM and PUBG where the stick can stay forward so you can keep moving without wasting fingers_


If you want to add your project here, go ahead :)

## Required
Minimum API level is 16 (Android 4.1.x - Jelly Bean) which cover 99.5% of the Android platforms as of October 2018 according to the <a href="https://developer.android.com/about/dashboards" class="user-mention">distribution dashboard</a>.
Minimum API level is 10 (Android 2.3.6 - Gingerbread) which cover **100%** of the Android platforms as of February 2022 according to the <a href="https://developer.android.com/about/dashboards" class="user-mention">distribution dashboard</a>.

## Download
### Gradle
```java
compile 'io.github.controlwear:virtualjoystick:1.10.1'
dependencies {
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:1.12.3'
}
```

## Contributing
Expand All @@ -181,6 +177,8 @@ limitations under the License.

## Authors

This repository is maintained by <a href="https://github.com/Mathias-Boulay" class="user-mention">@Mathias-Boulay</a>

**virtual-joystick-android** is an open source project created by <a href="https://github.com/makowildcat" class="user-mention">@makowildcat</a> (mostly spare time) and partially funded by [Black Artick](http://blackartick.com/) and [NSERC](http://www.nserc-crsng.gc.ca/index_eng.asp).

Also, thanks to <a href="https://github.com/Bernix01" class="user-mention">Bernix01</a>, <a href="https://github.com/teancake" class="user-mention">teancake</a>, <a href="https://github.com/Spettacolo83" class="user-mention">Spettacolo83</a>, <a href="https://github.com/djjaysmith" class="user-mention">djjaysmith</a>, <a href="https://github.com/jaybkim1" class="user-mention">jaybkim1</a>, <a href="https://github.com/sikrinick" class="user-mention">sikrinick</a>, <a href="https://github.com/AlexandrDavydov" class="user-mention">AlexandrDavydov</a>, <a href="https://github.com/indrek-koue" class="user-mention">indrek-koue</a>, <a href="https://github.com/QitmentX7" class="user-mention">QitmentX7</a>, <a href="https://github.com/esplemea" class="user-mention">esplemea</a>, <a href="https://github.com/FenixGit" class="user-mention">FenixGit</a>, <a href="https://github.com/AlexanderShniperson" class="user-mention">AlexanderShniperson</a>
Expand Down
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.android.tools.build:gradle:7.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,7 +15,7 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 20 17:17:49 EST 2018
#Sun May 14 19:31:20 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
72 changes: 42 additions & 30 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions joystickdemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions joystickdemo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
id 'com.android.application'
}

android {
namespace 'fr.spse.joystickdemo'
compileSdk 33

defaultConfig {
applicationId "fr.spse.joystickdemo"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation project(':virtualjoystick')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions joystickdemo/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading