Skip to content

Commit

Permalink
Add spine-android to formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Jul 24, 2024
1 parent 5de003c commit 12f11cb
Show file tree
Hide file tree
Showing 27 changed files with 853 additions and 1,030 deletions.
3 changes: 2 additions & 1 deletion formatters/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ spotless {
lineEndings 'UNIX'

java {
target 'spine-libgdx/**/*.java'
target 'spine-libgdx/**/*.java',
'spine-android/**/*.java'
eclipse().configFile('formatters/eclipse-formatter.xml')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,38 @@
import com.esotericsoftware.spine.android.SpineView;

public class SimpleAnimationActivity extends AppCompatActivity {
/** @noinspection FieldCanBeLocal*/
private SpineView spineView;
/** @noinspection FieldCanBeLocal*/
private SpineController spineController;
/** @noinspection FieldCanBeLocal */
private SpineView spineView;
/** @noinspection FieldCanBeLocal */
private SpineController spineController;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_animation);
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_animation);

// Set up the toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("Simple Animation");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Set up the toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("Simple Animation");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}

spineView = findViewById(R.id.spineView);
spineController = new SpineController( controller ->
controller.getAnimationState().setAnimation(0, "walk", true)
);
spineView = findViewById(R.id.spineView);
spineController = new SpineController(controller -> controller.getAnimationState().setAnimation(0, "walk", true));

spineView.setController(spineController);
spineView.loadFromAsset("spineboy.atlas","spineboy-pro.json");
}
spineView.setController(spineController);
spineView.loadFromAsset("spineboy.atlas", "spineboy-pro.json");
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected (MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
14 changes: 14 additions & 0 deletions spine-android/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

#
# 1. Set up PGP key for signing
# 2. Create ~/.gradle/gradle.properties
# 3. Add
# ossrhUsername=<sonatype-token-user-name>
# ossrhPassword=<sonatype-token>
# signing.gnupg.passphrase=<pgp-key-passphrase>
#
# After publishing via this script, log into https://oss.sonatype.org and release it manually after
# checks pass ("Release & Drop").
set -e
./gradlew publishReleasePublicationToSonaTypeRepository --info
3 changes: 2 additions & 1 deletion spine-android/spine-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
}

val libraryVersion = "4.2.2-SNAPSHOT" // Update this as needed
val libraryVersion = "4.2.3-SNAPSHOT" // Update this as needed

tasks.register<Jar>("sourceJar") {
archiveClassifier.set("sources")
Expand Down Expand Up @@ -125,5 +125,6 @@ afterEvaluate {
signing {
useGpgCmd()
sign(publishing.publications["release"])
sign(tasks.getByName("sourceJar"))
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.esotericsoftware.android;

import android.content.Context;
Expand All @@ -10,17 +11,15 @@

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
/** Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.esotericsoftware.spine.test", appContext.getPackageName());
}
}
@Test
public void useAppContext () {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.esotericsoftware.spine.test", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,129 +48,111 @@
import java.io.File;
import java.net.URL;

/**
* A {@link AndroidSkeletonDrawable} bundles loading updating updating an {@link AndroidTextureAtlas}, {@link Skeleton}, and {@link AnimationState}
* into a single easy-to-use class.
/** A {@link AndroidSkeletonDrawable} bundles loading updating updating an {@link AndroidTextureAtlas}, {@link Skeleton}, and
* {@link AnimationState} into a single easy-to-use class.
*
* Use the {@link AndroidSkeletonDrawable#fromAsset(String, String, Context)}, {@link AndroidSkeletonDrawable#fromFile(File, File)},
* or {@link AndroidSkeletonDrawable#fromHttp(URL, URL, File)} methods to construct a {@link AndroidSkeletonDrawable}. To have
* multiple skeleton drawable instances share the same {@link AndroidTextureAtlas} and {@link SkeletonData}, use the constructor.
* Use the {@link AndroidSkeletonDrawable#fromAsset(String, String, Context)},
* {@link AndroidSkeletonDrawable#fromFile(File, File)}, or {@link AndroidSkeletonDrawable#fromHttp(URL, URL, File)} methods to
* construct a {@link AndroidSkeletonDrawable}. To have multiple skeleton drawable instances share the same
* {@link AndroidTextureAtlas} and {@link SkeletonData}, use the constructor.
*
* You can then directly access the {@link AndroidSkeletonDrawable#getAtlas()}, {@link AndroidSkeletonDrawable#getSkeletonData()},
* {@link AndroidSkeletonDrawable#getSkeleton()}, {@link AndroidSkeletonDrawable#getAnimationStateData()}, and {@link AndroidSkeletonDrawable#getAnimationState()}
* to query and animate the skeleton. Use the {@link AnimationState} to queue animations on one or more tracks
* via {@link AnimationState#setAnimation(int, Animation, boolean)} or {@link AnimationState#addAnimation(int, Animation, boolean, float)}.
* {@link AndroidSkeletonDrawable#getSkeleton()}, {@link AndroidSkeletonDrawable#getAnimationStateData()}, and
* {@link AndroidSkeletonDrawable#getAnimationState()} to query and animate the skeleton. Use the {@link AnimationState} to queue
* animations on one or more tracks via {@link AnimationState#setAnimation(int, Animation, boolean)} or
* {@link AnimationState#addAnimation(int, Animation, boolean, float)}.
*
* To update the {@link AnimationState} and apply it to the {@link Skeleton}, call the {@link AndroidSkeletonDrawable#update(float)} function, providing it
* a delta time in seconds to advance the animations.
* To update the {@link AnimationState} and apply it to the {@link Skeleton}, call the
* {@link AndroidSkeletonDrawable#update(float)} function, providing it a delta time in seconds to advance the animations.
*
* To render the current pose of the {@link Skeleton}, use {@link SkeletonRenderer#render(Skeleton)}, {@link SkeletonRenderer#renderToCanvas(Canvas, Array)},
* {@link SkeletonRenderer#renderToBitmap(float, float, int, Skeleton)}, depending on your needs.
*/
* To render the current pose of the {@link Skeleton}, use {@link SkeletonRenderer#render(Skeleton)},
* {@link SkeletonRenderer#renderToCanvas(Canvas, Array)}, {@link SkeletonRenderer#renderToBitmap(float, float, int, Skeleton)},
* depending on your needs. */
public class AndroidSkeletonDrawable {

private final AndroidTextureAtlas atlas;

private final SkeletonData skeletonData;

private final Skeleton skeleton;

private final AnimationStateData animationStateData;

private final AnimationState animationState;

/**
* Constructs a new skeleton drawable from the given (possibly shared) {@link AndroidTextureAtlas} and {@link SkeletonData}.
*/
public AndroidSkeletonDrawable(AndroidTextureAtlas atlas, SkeletonData skeletonData) {
this.atlas = atlas;
this.skeletonData = skeletonData;

skeleton = new Skeleton(skeletonData);
animationStateData = new AnimationStateData(skeletonData);
animationState = new AnimationState(animationStateData);

skeleton.updateWorldTransform(Skeleton.Physics.none);
}

/**
* Updates the {@link AnimationState} using the {@code delta} time given in seconds, applies the
* animation state to the {@link Skeleton} and updates the world transforms of the skeleton
* to calculate its current pose.
*/
public void update(float delta) {
animationState.update(delta);
animationState.apply(skeleton);

skeleton.update(delta);
skeleton.updateWorldTransform(Skeleton.Physics.update);
}

/**
* Get the {@link AndroidTextureAtlas}
*/
public AndroidTextureAtlas getAtlas() {
return atlas;
}

/**
* Get the {@link Skeleton}
*/
public Skeleton getSkeleton() {
return skeleton;
}

/**
* Get the {@link SkeletonData}
*/
public SkeletonData getSkeletonData() {
return skeletonData;
}

/**
* Get the {@link AnimationStateData}
*/
public AnimationStateData getAnimationStateData() {
return animationStateData;
}

/**
* Get the {@link AnimationState}
*/
public AnimationState getAnimationState() {
return animationState;
}

/**
* Constructs a new skeleton drawable from the {@code atlasFileName} and {@code skeletonFileName} from the the apps resources using {@link Context}.
*
* Throws an exception in case the data could not be loaded.
*/
public static AndroidSkeletonDrawable fromAsset (String atlasFileName, String skeletonFileName, Context context) {
AndroidTextureAtlas atlas = AndroidTextureAtlas.fromAsset(atlasFileName, context);
SkeletonData skeletonData = SkeletonDataUtils.fromAsset(atlas, skeletonFileName, context);
return new AndroidSkeletonDrawable(atlas, skeletonData);
}

/**
* Constructs a new skeleton drawable from the {@code atlasFile} and {@code skeletonFile}.
*
* Throws an exception in case the data could not be loaded.
*/
public static AndroidSkeletonDrawable fromFile (File atlasFile, File skeletonFile) {
AndroidTextureAtlas atlas = AndroidTextureAtlas.fromFile(atlasFile);
SkeletonData skeletonData = SkeletonDataUtils.fromFile(atlas, skeletonFile);
return new AndroidSkeletonDrawable(atlas, skeletonData);
}

/**
* Constructs a new skeleton drawable from the {@code atlasUrl} and {@code skeletonUrl}.
*
* Throws an exception in case the data could not be loaded.
*/
public static AndroidSkeletonDrawable fromHttp (URL atlasUrl, URL skeletonUrl, File targetDirectory) {
AndroidTextureAtlas atlas = AndroidTextureAtlas.fromHttp(atlasUrl, targetDirectory);
SkeletonData skeletonData = SkeletonDataUtils.fromHttp(atlas, skeletonUrl, targetDirectory);
return new AndroidSkeletonDrawable(atlas, skeletonData);
}
private final AndroidTextureAtlas atlas;

private final SkeletonData skeletonData;

private final Skeleton skeleton;

private final AnimationStateData animationStateData;

private final AnimationState animationState;

/** Constructs a new skeleton drawable from the given (possibly shared) {@link AndroidTextureAtlas} and
* {@link SkeletonData}. */
public AndroidSkeletonDrawable (AndroidTextureAtlas atlas, SkeletonData skeletonData) {
this.atlas = atlas;
this.skeletonData = skeletonData;

skeleton = new Skeleton(skeletonData);
animationStateData = new AnimationStateData(skeletonData);
animationState = new AnimationState(animationStateData);

skeleton.updateWorldTransform(Skeleton.Physics.none);
}

/** Updates the {@link AnimationState} using the {@code delta} time given in seconds, applies the animation state to the
* {@link Skeleton} and updates the world transforms of the skeleton to calculate its current pose. */
public void update (float delta) {
animationState.update(delta);
animationState.apply(skeleton);

skeleton.update(delta);
skeleton.updateWorldTransform(Skeleton.Physics.update);
}

/** Get the {@link AndroidTextureAtlas} */
public AndroidTextureAtlas getAtlas () {
return atlas;
}

/** Get the {@link Skeleton} */
public Skeleton getSkeleton () {
return skeleton;
}

/** Get the {@link SkeletonData} */
public SkeletonData getSkeletonData () {
return skeletonData;
}

/** Get the {@link AnimationStateData} */
public AnimationStateData getAnimationStateData () {
return animationStateData;
}

/** Get the {@link AnimationState} */
public AnimationState getAnimationState () {
return animationState;
}

/** Constructs a new skeleton drawable from the {@code atlasFileName} and {@code skeletonFileName} from the the apps resources
* using {@link Context}.
*
* Throws an exception in case the data could not be loaded. */
public static AndroidSkeletonDrawable fromAsset (String atlasFileName, String skeletonFileName, Context context) {
AndroidTextureAtlas atlas = AndroidTextureAtlas.fromAsset(atlasFileName, context);
SkeletonData skeletonData = SkeletonDataUtils.fromAsset(atlas, skeletonFileName, context);
return new AndroidSkeletonDrawable(atlas, skeletonData);
}

/** Constructs a new skeleton drawable from the {@code atlasFile} and {@code skeletonFile}.
*
* Throws an exception in case the data could not be loaded. */
public static AndroidSkeletonDrawable fromFile (File atlasFile, File skeletonFile) {
AndroidTextureAtlas atlas = AndroidTextureAtlas.fromFile(atlasFile);
SkeletonData skeletonData = SkeletonDataUtils.fromFile(atlas, skeletonFile);
return new AndroidSkeletonDrawable(atlas, skeletonData);
}

/** Constructs a new skeleton drawable from the {@code atlasUrl} and {@code skeletonUrl}.
*
* Throws an exception in case the data could not be loaded. */
public static AndroidSkeletonDrawable fromHttp (URL atlasUrl, URL skeletonUrl, File targetDirectory) {
AndroidTextureAtlas atlas = AndroidTextureAtlas.fromHttp(atlasUrl, targetDirectory);
SkeletonData skeletonData = SkeletonDataUtils.fromHttp(atlas, skeletonUrl, targetDirectory);
return new AndroidSkeletonDrawable(atlas, skeletonData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader;

/**
* A class holding an {@link Bitmap} of an {@link AndroidTextureAtlas} page image with it's associated
* blend modes and paints.
*/
/** A class holding an {@link Bitmap} of an {@link AndroidTextureAtlas} page image with it's associated blend modes and paints. */
public class AndroidTexture extends Texture {
private Bitmap bitmap;
private ObjectMap<BlendMode, Paint> paints = new ObjectMap<>();
Expand Down
Loading

0 comments on commit 12f11cb

Please sign in to comment.