Skip to content

Commit

Permalink
updated the project files and updated compatibility settings
Browse files Browse the repository at this point in the history
The new compileSDK is 33 and the minSDK version is 26
  • Loading branch information
jackeri committed Jan 24, 2024
1 parent cc83428 commit d3eb9a8
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 156 deletions.
57 changes: 24 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,46 @@
# 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
3. Button Radius = 25%
4. StayPut = false
5. Directional-Axis = 8

<H2>Setup:</H2>
## Setup:

```xml
<com.erz.joysticklibrary.JoyStick
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -127,7 +118,7 @@ To set Axis Type:
joyStick.setType(JoyStick.TYPE_4_AXIS);
```

<H2>Getters/Setters</H2>
## Getters/Setters

```java
//Set GamePad Color
Expand Down Expand Up @@ -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");
Expand Down
22 changes: 12 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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'
}
13 changes: 0 additions & 13 deletions app/src/androidTest/java/com/erz/joystick/ApplicationTest.java

This file was deleted.

9 changes: 4 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/erz/joystick/GameLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
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) {
Expand All @@ -26,7 +24,7 @@ public void setRunning(boolean run) {
@Override
public void run() {
while (running) {
startTime = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
try {
canvas = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
Expand All @@ -37,12 +35,14 @@ public void run() {
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) {}
}
}
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/java/com/erz/joystick/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;
Expand All @@ -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);
Expand All @@ -57,6 +57,7 @@ public GameView(Context context, AttributeSet attrs) {

@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if (canvas == null) return;
canvas.drawColor(Color.BLACK);

Expand Down Expand Up @@ -94,8 +95,8 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig
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;
Expand Down
26 changes: 14 additions & 12 deletions app/src/main/java/com/erz/joystick/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
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;

@Override
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);
Expand All @@ -29,13 +30,14 @@ protected void onCreate(Bundle savedInstanceState) {

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

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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>
7 changes: 7 additions & 0 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -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>
Loading

0 comments on commit d3eb9a8

Please sign in to comment.