updated the project files and updated compatibility settings

The new compileSDK is 33 and the minSDK version is 26
This commit is contained in:
Jacker 2024-01-24 17:39:09 +02:00
parent cc83428c82
commit d3eb9a8df9
No known key found for this signature in database
GPG key ID: 1ACCC1587C75F319
19 changed files with 251 additions and 157 deletions

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,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
}

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'