Compare commits

..

6 commits

Author SHA1 Message Date
Jacker
ef6e142d1c
gradle: version parsing fix 2024-01-24 19:01:11 +02:00
Jacker
2541d84169
github-action: fetch depth fix 2024-01-24 18:56:44 +02:00
Jacker
b517866731
gradle: have sensible defaults for the version information 2024-01-24 18:43:31 +02:00
Jacker
66f28f9188
github-action: fetch the repo fully to get version info 2024-01-24 18:32:57 +02:00
Jacker
87b680c9c4
added github workflow and the gradle wrapper into the repo 2024-01-24 18:24:42 +02:00
Jacker
d3eb9a8df9
updated the project files and updated compatibility settings
The new compileSDK is 33 and the minSDK version is 26
2024-01-24 17:39:09 +02:00
25 changed files with 637 additions and 163 deletions

38
.github/workflows/build.yaml vendored Normal file
View file

@ -0,0 +1,38 @@
name: Publish package to GitHub Packages
on:
push:
tags:
- 'v*'
workflow_dispatch:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
name: Checkout sources
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-java@v4
name: Setup Java 17
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Build and publish
run: ./gradlew publish --no-daemon --info
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

6
.gitignore vendored
View file

@ -32,9 +32,5 @@ proguard-project.txt
local.properties
#gradle
build
.gradle
gradle
gradlew
gradlew.bat
signing.properties
signing.properties

View file

@ -1,48 +1,38 @@
# JoyStick
Android Library for JoyStick View.<br>
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")
<H2>Sample App</H2>
<img height="70px" src="https://github.com/erz05/JoyStick/blob/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png" />
<a href="https://play.google.com/store/apps/details?id=com.erz.joystick&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-AC-global-none-all-co-pr-py-PartBadges-Oct1515-1"><img height="70px" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /></a>
![Sample app image 1](/images/Screenshot_2015-10-30-21-43-47.png "Sample app image 1")
<img width="300px" src="https://github.com/erz05/JoyStick/blob/master/images/Screenshot_2015-10-30-21-38-13.png" />
<br><br>
<img width="300px" src="https://github.com/erz05/JoyStick/blob/master/images/Screenshot_2015-10-30-21-43-47.png" />
<br><br>
JoyStick with Image for button<br>
<img width="300px" src="https://github.com/erz05/JoyStick/blob/master/images/Screenshot_2015-11-02-18-05-49.png" />
<br>
![Sample app image 2](/images/Screenshot_2015-11-02-18-05-49.png "Sample app image 2")
<H2>Usage</H2>
Gradle Import: jcenter <br>
## 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'
}
```
<H2>v1.1.0 BREAKING CHANGE!</H2>
## v1.1.0 BREAKING CHANGE!
1. Made changes to JoyStickListener<br>
a. Added Direction to onMove<br>
b. Added Event calls for onTap and onDoubleTap<br>
* Made changes to JoyStickListener
* Added Direction to onMove
* Added Event calls for onTap and onDoubleTap
<H2>Defaults:</H2>
## Defaults:
1. Background = White
2. Button = Red
@ -50,7 +40,7 @@ b. Added Event calls for onTap and onDoubleTap<br>
4. StayPut = false
5. Directional-Axis = 8
<H2>Setup:</H2>
## Setup:
```xml
<com.erz.joysticklibrary.JoyStick
@ -59,6 +49,7 @@ b. Added Event calls for onTap and onDoubleTap<br>
android:layout_height="200dp"
android:layout_gravity="bottom"/>
<!-- default 25: radius percentage of full size of the view between 25% and 50% -->
<com.erz.joysticklibrary.JoyStick
android:id="@+id/joy2"
android:layout_width="200dp"
@ -67,20 +58,20 @@ b. Added Event calls for onTap and onDoubleTap<br>
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);
```
<H2>JoyStickListener:</H2>
## JoyStickListener:
```java
//JoyStickListener Interface
@ -97,7 +88,7 @@ joyStick.setListener(this);
2. onTap: gets called onSingleTapConfirmed
3. onDoubleTap: gets called onDoubleTap
<H2>Directions:</H2>
## 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
<H2>Axis Types:</H2>
## 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);
```
<H2>Getters/Setters</H2>
## Getters/Setters
```java
//Set GamePad Color
@ -158,7 +149,7 @@ joyStick.getAngle();
joyStick.getAngleDegrees();
```
<H2>License</H2>
## License
Copyright 2015 erz05
Licensed under the Apache License, Version 2.0 (the "License");

View file

@ -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'
}

View file

@ -1,13 +0,0 @@
package com.erz.joystick;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View file

@ -3,19 +3,18 @@
package="com.erz.joystick">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize">
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true"
android:label="@string/title_activity_fullscreen"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

View file

@ -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) {}
}
}

View file

@ -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<Star> stars = new Vector<>();
private final Paint paint;
private final Vector<Star> 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;

View file

@ -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");
}
}

View file

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:background="?attr/fullscreenBackgroundColor"
android:theme="@style/ThemeOverlay.Etlegacyjoystick.FullscreenContainer"
tools:context=".MainActivity">
<com.erz.joystick.GameView
android:id="@+id/game"
@ -19,6 +23,6 @@
android:id="@+id/joy2"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="bottom|right"/>
android:layout_gravity="bottom|end"/>
</FrameLayout>

View file

@ -0,0 +1,7 @@
<resources>
<style name="ThemeOverlay.Etlegacyjoystick.FullscreenContainer" parent="">
<item name="fullscreenBackgroundColor">@color/light_blue_900</item>
<item name="fullscreenTextColor">@color/light_blue_A400</item>
</style>
</resources>

View file

@ -0,0 +1,6 @@
<resources>
<declare-styleable name="FullscreenAttrs">
<attr name="fullscreenBackgroundColor" format="color" />
<attr name="fullscreenTextColor" format="color" />
</declare-styleable>
</resources>

View file

@ -3,4 +3,9 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="light_blue_600">#FF039BE5</color>
<color name="light_blue_900">#FF01579B</color>
<color name="light_blue_A200">#FF40C4FF</color>
<color name="light_blue_A400">#FF00B0FF</color>
<color name="black_overlay">#66000000</color>
</resources>

View file

@ -1,3 +1,6 @@
<resources>
<string name="app_name">JoyStick</string>
<string name="title_activity_fullscreen">FullscreenActivity</string>
<string name="dummy_button">Dummy Button</string>
<string name="dummy_content">DUMMY\nCONTENT</string>
</resources>

View file

@ -21,4 +21,13 @@
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="Widget.AppTheme.ActionBar.Fullscreen" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
<style name="Widget.AppTheme.ButtonBar.Fullscreen" parent="">
<item name="android:background">@color/black_overlay</item>
<item name="android:buttonBarStyle">?android:attr/buttonBarStyle</item>
</style>
</resources>

View file

@ -0,0 +1,13 @@
<resources>
<style name="AppTheme.Fullscreen" parent="AppTheme">
<item name="android:actionBarStyle">@style/Widget.AppTheme.ActionBar.Fullscreen</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
</style>
<style name="ThemeOverlay.Etlegacyjoystick.FullscreenContainer" parent="">
<item name="fullscreenBackgroundColor">@color/light_blue_600</item>
<item name="fullscreenTextColor">@color/light_blue_A200</item>
</style>
</resources>

View file

@ -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);
}
}

View file

@ -3,23 +3,58 @@
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 = 1
def minor = 2
def patch = 0
def postfix = '-UNKNOWN'
def hash = ''
def output = 'git describe --long --tags --dirty --always'.execute().text.trim()
project.logger.info("Ran git describe with the output: {}", output)
(output =~ /^v(\d+)\.(\d+)\.(\d+)-(\d+)-(\w+)/).each { match, majorVal, minorVal, patchVal, commitVal, hashVal ->
if (output.toLowerCase().endsWith('-dirty')) {
patchVal = (patchVal as int + 1) as String
postfix = '-DIRTY'
} else if(commitVal 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
}
def outputHash = [version: "${major}.${minor}.${patch}${postfix}", hash: hash]
project.logger.info("Parsed version: {}", outputHash.version)
return outputHash
}
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
}
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

244
gradlew vendored Executable file
View file

@ -0,0 +1,244 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

92
gradlew.bat vendored Normal file
View file

@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View file

@ -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'
}
assemble {
doFirst {
println("Assembling version: ${project.version}")
}
}

View file

@ -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);

View file

@ -1 +1,2 @@
rootProject.name = 'JoyStick'
include ':app', ':joysticklibrary'