mirror of
https://github.com/etlegacy/JoyStick.git
synced 2024-11-14 00:20:51 +00:00
updated the project files and updated compatibility settings
The new compileSDK is 33 and the minSDK version is 26
This commit is contained in:
parent
cc83428c82
commit
d3eb9a8df9
19 changed files with 251 additions and 157 deletions
57
README.md
57
README.md
|
@ -1,48 +1,38 @@
|
||||||
# JoyStick
|
# JoyStick
|
||||||
Android Library for JoyStick View.<br>
|
Android Library for JoyStick View.
|
||||||
|
|
||||||
Customizable, small and lightweight.
|
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>
|
![Sample app image 1](/images/Screenshot_2015-10-30-21-43-47.png "Sample app image 1")
|
||||||
<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>
|
|
||||||
|
|
||||||
<img width="300px" src="https://github.com/erz05/JoyStick/blob/master/images/Screenshot_2015-10-30-21-38-13.png" />
|
![Sample app image 2](/images/Screenshot_2015-11-02-18-05-49.png "Sample app image 2")
|
||||||
<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>
|
|
||||||
|
|
||||||
<H2>Usage</H2>
|
## Usage
|
||||||
Gradle Import: jcenter <br>
|
Gradle Import: This github repository
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url "http://dl.bintray.com/erz05/maven"
|
url uri("https://maven.pkg.github.com/etlegacy/JoyStick")
|
||||||
}
|
}
|
||||||
|
|
||||||
//Or
|
|
||||||
|
|
||||||
jcenter()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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>
|
* Made changes to JoyStickListener
|
||||||
a. Added Direction to onMove<br>
|
* Added Direction to onMove
|
||||||
b. Added Event calls for onTap and onDoubleTap<br>
|
* Added Event calls for onTap and onDoubleTap
|
||||||
|
|
||||||
<H2>Defaults:</H2>
|
## Defaults:
|
||||||
|
|
||||||
1. Background = White
|
1. Background = White
|
||||||
2. Button = Red
|
2. Button = Red
|
||||||
|
@ -50,7 +40,7 @@ b. Added Event calls for onTap and onDoubleTap<br>
|
||||||
4. StayPut = false
|
4. StayPut = false
|
||||||
5. Directional-Axis = 8
|
5. Directional-Axis = 8
|
||||||
|
|
||||||
<H2>Setup:</H2>
|
## Setup:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<com.erz.joysticklibrary.JoyStick
|
<com.erz.joysticklibrary.JoyStick
|
||||||
|
@ -59,6 +49,7 @@ b. Added Event calls for onTap and onDoubleTap<br>
|
||||||
android:layout_height="200dp"
|
android:layout_height="200dp"
|
||||||
android:layout_gravity="bottom"/>
|
android:layout_gravity="bottom"/>
|
||||||
|
|
||||||
|
<!-- default 25: radius percentage of full size of the view between 25% and 50% -->
|
||||||
<com.erz.joysticklibrary.JoyStick
|
<com.erz.joysticklibrary.JoyStick
|
||||||
android:id="@+id/joy2"
|
android:id="@+id/joy2"
|
||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
|
@ -67,20 +58,20 @@ b. Added Event calls for onTap and onDoubleTap<br>
|
||||||
app:padColor="#55ffffff"
|
app:padColor="#55ffffff"
|
||||||
app:buttonColor="#55ff0000"
|
app:buttonColor="#55ff0000"
|
||||||
app:stayPut="true"
|
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:backgroundDrawable="R.drawable.background"
|
||||||
app:buttonDrawable="R.drawable.button"/>
|
app:buttonDrawable="R.drawable.button"/>
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
JoyStick joyStick = (JoyStick) findViewById(R.id.joyStick);
|
JoyStick joyStick = findViewById(R.id.joyStick);
|
||||||
|
|
||||||
//or
|
//or
|
||||||
|
|
||||||
JoyStick joyStick = new JoyStick(context);
|
JoyStick joyStick = new JoyStick(context);
|
||||||
```
|
```
|
||||||
|
|
||||||
<H2>JoyStickListener:</H2>
|
## JoyStickListener:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
//JoyStickListener Interface
|
//JoyStickListener Interface
|
||||||
|
@ -97,7 +88,7 @@ joyStick.setListener(this);
|
||||||
2. onTap: gets called onSingleTapConfirmed
|
2. onTap: gets called onSingleTapConfirmed
|
||||||
3. onDoubleTap: gets called onDoubleTap
|
3. onDoubleTap: gets called onDoubleTap
|
||||||
|
|
||||||
<H2>Directions:</H2>
|
## Directions:
|
||||||
1. DIRECTION_CENTER = -1
|
1. DIRECTION_CENTER = -1
|
||||||
2. DIRECTION_LEFT = 0
|
2. DIRECTION_LEFT = 0
|
||||||
3. DIRECTION_LEFT_UP = 1
|
3. DIRECTION_LEFT_UP = 1
|
||||||
|
@ -115,7 +106,7 @@ joyStick.getDirection();
|
||||||
```
|
```
|
||||||
or get it from the JoyStickListener
|
or get it from the JoyStickListener
|
||||||
|
|
||||||
<H2>Axis Types:</H2>
|
## Axis Types:
|
||||||
1. TYPE_8_AXIS
|
1. TYPE_8_AXIS
|
||||||
2. TYPE_4_AXIS
|
2. TYPE_4_AXIS
|
||||||
3. TYPE_2_AXIS_LEFT_RIGHT
|
3. TYPE_2_AXIS_LEFT_RIGHT
|
||||||
|
@ -127,7 +118,7 @@ To set Axis Type:
|
||||||
joyStick.setType(JoyStick.TYPE_4_AXIS);
|
joyStick.setType(JoyStick.TYPE_4_AXIS);
|
||||||
```
|
```
|
||||||
|
|
||||||
<H2>Getters/Setters</H2>
|
## Getters/Setters
|
||||||
|
|
||||||
```java
|
```java
|
||||||
//Set GamePad Color
|
//Set GamePad Color
|
||||||
|
@ -158,7 +149,7 @@ joyStick.getAngle();
|
||||||
joyStick.getAngleDegrees();
|
joyStick.getAngleDegrees();
|
||||||
```
|
```
|
||||||
|
|
||||||
<H2>License</H2>
|
## License
|
||||||
Copyright 2015 erz05
|
Copyright 2015 erz05
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
apply plugin: 'com.android.application'
|
plugins {
|
||||||
|
id 'com.android.application'
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 26
|
namespace "com.erz.joystick"
|
||||||
buildToolsVersion "26.0.2"
|
compileSdk 33
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.erz.joystick"
|
applicationId "com.erz.joystick"
|
||||||
minSdkVersion 14
|
minSdkVersion 31
|
||||||
targetSdkVersion 26
|
targetSdk 33
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
}
|
}
|
||||||
|
@ -17,13 +19,13 @@ android {
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
buildFeatures {
|
||||||
|
viewBinding true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(path: ':joysticklibrary')
|
implementation project(path: ':joysticklibrary')
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
testCompile 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
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'
|
|
||||||
}
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,19 +3,18 @@
|
||||||
package="com.erz.joystick">
|
package="com.erz.joystick">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
android:theme="@style/AppTheme.NoActionBar"
|
android:exported="true"
|
||||||
android:configChanges="orientation|screenSize">
|
android:label="@string/title_activity_fullscreen"
|
||||||
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
|
@ -9,10 +9,8 @@ import android.view.SurfaceView;
|
||||||
public class GameLoop extends Thread {
|
public class GameLoop extends Thread {
|
||||||
private static final long FPS = 24;
|
private static final long FPS = 24;
|
||||||
private static final long ticksPS = 1000 / FPS;
|
private static final long ticksPS = 1000 / FPS;
|
||||||
private SurfaceView view;
|
private final SurfaceView view;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
private long startTime;
|
|
||||||
private long sleepTime;
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
|
|
||||||
public GameLoop(SurfaceView view) {
|
public GameLoop(SurfaceView view) {
|
||||||
|
@ -26,7 +24,7 @@ public class GameLoop extends Thread {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (running) {
|
while (running) {
|
||||||
startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
canvas = view.getHolder().lockCanvas();
|
canvas = view.getHolder().lockCanvas();
|
||||||
synchronized (view.getHolder()) {
|
synchronized (view.getHolder()) {
|
||||||
|
@ -37,12 +35,14 @@ public class GameLoop extends Thread {
|
||||||
view.getHolder().unlockCanvasAndPost(canvas);
|
view.getHolder().unlockCanvasAndPost(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
|
long sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
|
||||||
|
if (sleepTime <= 0) {
|
||||||
|
sleepTime = 20;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (sleepTime > 0)
|
//noinspection BusyWait
|
||||||
sleep(sleepTime);
|
sleep(sleepTime);
|
||||||
else
|
|
||||||
sleep(10);
|
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Vector;
|
||||||
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
|
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
private int i;
|
private int i;
|
||||||
private int size = 20;
|
private final int size = 20;
|
||||||
private int minSpeed;
|
private int minSpeed;
|
||||||
private int maxSpeed;
|
private int maxSpeed;
|
||||||
private int minRadius;
|
private int minRadius;
|
||||||
|
@ -33,12 +33,12 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
private double angle;
|
private double angle;
|
||||||
private double power;
|
private double power;
|
||||||
private double angle2;
|
private double angle2;
|
||||||
private Bitmap droid;
|
private final Bitmap droid;
|
||||||
private GameLoop gameLoop;
|
private GameLoop gameLoop;
|
||||||
private Paint paint;
|
private final Paint paint;
|
||||||
private Vector<Star> stars = new Vector<>();
|
private final Vector<Star> stars = new Vector<>();
|
||||||
private RectF rectF = new RectF();
|
private RectF rectF = new RectF();
|
||||||
private Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
public GameView(Context context) {
|
public GameView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
|
@ -57,6 +57,7 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
|
super.draw(canvas);
|
||||||
if (canvas == null) return;
|
if (canvas == null) return;
|
||||||
canvas.drawColor(Color.BLACK);
|
canvas.drawColor(Color.BLACK);
|
||||||
|
|
||||||
|
@ -94,8 +95,8 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
this.height = height;
|
this.height = height;
|
||||||
float min = Math.min(width, height);
|
float min = Math.min(width, height);
|
||||||
|
|
||||||
float centerX = width / 2;
|
float centerX = (float) width / 2;
|
||||||
float centerY = height / 2;
|
float centerY = (float) height / 2;
|
||||||
posX = centerX;
|
posX = centerX;
|
||||||
posY = centerY;
|
posY = centerY;
|
||||||
radius = min / 12;
|
radius = min / 12;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package com.erz.joystick;
|
package com.erz.joystick;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.erz.joysticklibrary.JoyStick;
|
import com.erz.joysticklibrary.JoyStick;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements JoyStick.JoyStickListener {
|
public class MainActivity extends Activity implements JoyStick.JoyStickListener {
|
||||||
|
|
||||||
private GameView gameView;
|
private GameView gameView;
|
||||||
|
|
||||||
|
@ -14,13 +15,13 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
gameView = (GameView) findViewById(R.id.game);
|
gameView = findViewById(R.id.game);
|
||||||
JoyStick joy1 = (JoyStick) findViewById(R.id.joy1);
|
JoyStick joy1 = findViewById(R.id.joy1);
|
||||||
joy1.setListener(this);
|
joy1.setListener(this);
|
||||||
joy1.setPadColor(Color.parseColor("#55ffffff"));
|
joy1.setPadColor(Color.parseColor("#55ffffff"));
|
||||||
joy1.setButtonColor(Color.parseColor("#55ff0000"));
|
joy1.setButtonColor(Color.parseColor("#55ff0000"));
|
||||||
|
|
||||||
JoyStick joy2 = (JoyStick) findViewById(R.id.joy2);
|
JoyStick joy2 = findViewById(R.id.joy2);
|
||||||
joy2.setListener(this);
|
joy2.setListener(this);
|
||||||
joy2.enableStayPut(true);
|
joy2.enableStayPut(true);
|
||||||
joy2.setPadBackground(R.drawable.pad);
|
joy2.setPadBackground(R.drawable.pad);
|
||||||
|
@ -29,13 +30,14 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMove(JoyStick joyStick, double angle, double power, int direction) {
|
public void onMove(JoyStick joyStick, double angle, double power, int direction) {
|
||||||
switch (joyStick.getId()) {
|
int id = joyStick.getId();
|
||||||
case R.id.joy1:
|
|
||||||
|
if (id == R.id.joy1) {
|
||||||
gameView.move(angle, power);
|
gameView.move(angle, power);
|
||||||
break;
|
} else if(id == R.id.joy2) {
|
||||||
case R.id.joy2:
|
|
||||||
gameView.rotate(angle);
|
gameView.rotate(angle);
|
||||||
break;
|
} else {
|
||||||
|
Log.w("onMove", "Wrong id detected on the move");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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
|
<com.erz.joystick.GameView
|
||||||
android:id="@+id/game"
|
android:id="@+id/game"
|
||||||
|
@ -19,6 +23,6 @@
|
||||||
android:id="@+id/joy2"
|
android:id="@+id/joy2"
|
||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
android:layout_height="200dp"
|
android:layout_height="200dp"
|
||||||
android:layout_gravity="bottom|right"/>
|
android:layout_gravity="bottom|end"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
7
app/src/main/res/values-night/themes.xml
Normal file
7
app/src/main/res/values-night/themes.xml
Normal 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>
|
6
app/src/main/res/values/attrs.xml
Normal file
6
app/src/main/res/values/attrs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<resources>
|
||||||
|
<declare-styleable name="FullscreenAttrs">
|
||||||
|
<attr name="fullscreenBackgroundColor" format="color" />
|
||||||
|
<attr name="fullscreenTextColor" format="color" />
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
|
@ -3,4 +3,9 @@
|
||||||
<color name="colorPrimary">#3F51B5</color>
|
<color name="colorPrimary">#3F51B5</color>
|
||||||
<color name="colorPrimaryDark">#303F9F</color>
|
<color name="colorPrimaryDark">#303F9F</color>
|
||||||
<color name="colorAccent">#FF4081</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>
|
</resources>
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">JoyStick</string>
|
<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>
|
</resources>
|
|
@ -21,4 +21,13 @@
|
||||||
|
|
||||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
<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>
|
</resources>
|
||||||
|
|
13
app/src/main/res/values/themes.xml
Normal file
13
app/src/main/res/values/themes.xml
Normal 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>
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
43
build.gradle
43
build.gradle
|
@ -3,23 +3,54 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
def parseGitVersion() {
|
||||||
repositories {
|
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()
|
google()
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
tasks.register('clean', Delete) {
|
||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
|
@ -1,13 +1,15 @@
|
||||||
apply plugin: 'com.android.library'
|
plugins {
|
||||||
apply plugin: 'com.novoda.bintray-release'
|
id 'com.android.library'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 27
|
namespace "com.erz.joysticklibrary"
|
||||||
buildToolsVersion "27.0.3"
|
compileSdk 33
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 14
|
minSdkVersion 26
|
||||||
targetSdkVersion 27
|
targetSdk 33
|
||||||
versionCode 2
|
versionCode 2
|
||||||
versionName "1.1"
|
versionName "1.1"
|
||||||
}
|
}
|
||||||
|
@ -17,23 +19,67 @@ android {
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
publishing {
|
||||||
|
singleVariant("release") {
|
||||||
buildscript {
|
withSourcesJar()
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
jcenter()
|
|
||||||
}
|
}
|
||||||
dependencies {
|
|
||||||
classpath 'com.novoda:bintray-release:0.7.0'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publish {
|
publishing {
|
||||||
userOrg = 'erz05'
|
publications {
|
||||||
groupId = 'com.github.erz05'
|
maven(MavenPublication) {
|
||||||
|
groupId = 'com.etlegacy.android'
|
||||||
artifactId = 'JoyStick'
|
artifactId = 'JoyStick'
|
||||||
version = '1.1.0'
|
version = project.version
|
||||||
|
|
||||||
|
pom {
|
||||||
|
name = 'Android JoyStick library'
|
||||||
description = 'Android Library for JoyStick View'
|
description = 'Android Library for JoyStick View'
|
||||||
website = 'https://github.com/erz05/JoyStick'
|
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 {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assemble {
|
||||||
|
doFirst {
|
||||||
|
println("Assembling version: ${project.version}")
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.erz.joysticklibrary;
|
package com.erz.joysticklibrary;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
@ -32,6 +33,7 @@ import android.view.View;
|
||||||
/**
|
/**
|
||||||
* Created by edgarramirez on 10/30/15.
|
* Created by edgarramirez on 10/30/15.
|
||||||
* JoyStick view with lots of customizable options
|
* JoyStick view with lots of customizable options
|
||||||
|
* @noinspection unused
|
||||||
*/
|
*/
|
||||||
public class JoyStick extends View implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
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;
|
public static final int TYPE_2_AXIS_UP_DOWN = 44;
|
||||||
|
|
||||||
private JoyStickListener listener;
|
private JoyStickListener listener;
|
||||||
private Paint paint;
|
private final Paint paint;
|
||||||
private RectF temp;
|
private final RectF temp;
|
||||||
private GestureDetector gestureDetector;
|
private final GestureDetector gestureDetector;
|
||||||
private int direction = DIRECTION_CENTER;
|
private int direction = DIRECTION_CENTER;
|
||||||
private int type = TYPE_8_AXIS;
|
private int type = TYPE_8_AXIS;
|
||||||
private float centerX;
|
private float centerX;
|
||||||
|
@ -111,9 +113,11 @@ public class JoyStick extends View implements GestureDetector.OnGestureListener,
|
||||||
padColor = Color.WHITE;
|
padColor = Color.WHITE;
|
||||||
buttonColor = Color.RED;
|
buttonColor = Color.RED;
|
||||||
|
|
||||||
if (attrs != null) {
|
if (attrs == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.JoyStick);
|
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.JoyStick);
|
||||||
if (typedArray != null) {
|
|
||||||
padColor = typedArray.getColor(R.styleable.JoyStick_padColor, Color.WHITE);
|
padColor = typedArray.getColor(R.styleable.JoyStick_padColor, Color.WHITE);
|
||||||
buttonColor = typedArray.getColor(R.styleable.JoyStick_buttonColor, Color.RED);
|
buttonColor = typedArray.getColor(R.styleable.JoyStick_buttonColor, Color.RED);
|
||||||
stayPut = typedArray.getBoolean(R.styleable.JoyStick_stayPut, false);
|
stayPut = typedArray.getBoolean(R.styleable.JoyStick_stayPut, false);
|
||||||
|
@ -130,11 +134,8 @@ public class JoyStick extends View implements GestureDetector.OnGestureListener,
|
||||||
if (buttonResId > 0) {
|
if (buttonResId > 0) {
|
||||||
buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId);
|
buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
@ -169,6 +170,7 @@ public class JoyStick extends View implements GestureDetector.OnGestureListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
gestureDetector.onTouchEvent(event);
|
gestureDetector.onTouchEvent(event);
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
|
rootProject.name = 'JoyStick'
|
||||||
include ':app', ':joysticklibrary'
|
include ':app', ':joysticklibrary'
|
||||||
|
|
Loading…
Reference in a new issue