Skip to content

Commit

Permalink
Modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
Jawnnypoo committed Jan 17, 2024
1 parent 3a82ecd commit 4471566
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 169 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
fail-fast: false
matrix:
java-version:
- 11
- 17

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Configure JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.java-version }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v1
- name: Install JDK
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 17

- name: Set version
run: sed -i "s/VERSION_NAME=0.0.1/VERSION_NAME=$GITHUB_REF_NAME/" gradle.properties
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Each view contained within the layout has a physics configuration that it uses t
app:layout_density="0.5" />
```
or alternatively, the Physics definition can be made programmatically:
```java
```
val circleView = findViewById<View>(R.id.circle)
val config = PhysicsConfig(
shape = Shape.CIRCLE,
Expand All @@ -96,7 +96,7 @@ This library was designed with the intention of allowing for playful animations
License
--------

Copyright 2022 John Carlson
Copyright 2024 John Carlson

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
31 changes: 11 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ apply plugin: "com.android.application"
apply plugin: "kotlin-android"

android {
compileSdkVersion 32
namespace = "com.jawnnypoo.physicslayout.sample"
compileSdk 34

defaultConfig {
applicationId "com.jawnnypoo.physicslayout.sample"
minSdkVersion 21
targetSdkVersion 32
minSdk 21
targetSdk 34
versionCode 101
versionName "1.0.1"
}
Expand All @@ -23,33 +24,23 @@ android {
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
abortOnError false
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
kotlin {
jvmToolchain 17
}

def coroutinesVersion = "1.6.0"
def coroutinesVersion = "1.7.1"
def retrofitVersion = "2.9.0"
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")

implementation("androidx.activity:activity-ktx:1.4.0")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1")
implementation("androidx.activity:activity-ktx:1.8.2")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")

implementation("com.google.android.material:material:1.5.0")
implementation("com.google.android.material:material:1.11.0")

implementation("de.hdodenhof:circleimageview:3.1.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AboutActivity : AppCompatActivity() {

private lateinit var binding: ActivityAboutBinding
private lateinit var sensorManager: SensorManager
private lateinit var gravitySensor: Sensor
private var gravitySensor: Sensor? = null
private lateinit var gimbal: Gimbal

private val sensorEventListener = object : SensorEventListener {
Expand All @@ -61,18 +61,22 @@ class AboutActivity : AppCompatActivity() {
val drawerArrowDrawable = DrawerArrowDrawable(this)
drawerArrowDrawable.progress = 1.0f
binding.toolbar.navigationIcon = drawerArrowDrawable
binding.toolbar.setNavigationOnClickListener { onBackPressed() }
binding.toolbar.setNavigationOnClickListener { finish() }
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY)
val model: ContributorsViewModel by viewModels()
model.getContributors().observe(this, { contributors ->
model.getContributors().observe(this) { contributors ->
addContributors(contributors)
})
}
}

override fun onResume() {
super.onResume()
sensorManager.registerListener(sensorEventListener, gravitySensor, SensorManager.SENSOR_DELAY_GAME)
sensorManager.registerListener(
sensorEventListener,
gravitySensor,
SensorManager.SENSOR_DELAY_GAME
)
}

override fun onPause() {
Expand All @@ -88,8 +92,9 @@ class AboutActivity : AppCompatActivity() {
val contributor = contributors[i]
val imageView = CircleImageView(this)
val llp = FlowLayout.LayoutParams(
imageSize,
imageSize)
imageSize,
imageSize
)
imageView.layoutParams = llp
imageView.borderWidth = borderSize
imageView.borderColor = Color.BLACK
Expand All @@ -108,8 +113,11 @@ class AboutActivity : AppCompatActivity() {
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, "You don't have a browser... What are you doing?", Toast.LENGTH_LONG)
.show()
Toast.makeText(
this,
"You don't have a browser... What are you doing?",
Toast.LENGTH_LONG
).show()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainActivity : AppCompatActivity() {
if (!isChecked) {
for (i in 0 until binding.physicsLayout.childCount) {
binding.physicsLayout.getChildAt(i)
.animate().translationY(0f).translationX(0f).rotation(0f)
.animate().translationY(0f).translationX(0f).rotation(0f)
}
}
}
Expand All @@ -54,14 +54,14 @@ class MainActivity : AppCompatActivity() {
}
binding.impulseButton.setOnClickListener { binding.physicsLayout.physics.giveRandomImpulse() }
val circlePhysicsConfig = PhysicsConfig(
shape = Shape.CIRCLE
shape = Shape.CIRCLE
)
binding.addViewButton.setOnClickListener {
val imageView = ImageView(this)
imageView.setImageResource(R.drawable.ic_logo)
val layoutParams = LinearLayout.LayoutParams(
resources.getDimensionPixelSize(R.dimen.square_size),
resources.getDimensionPixelSize(R.dimen.square_size)
resources.getDimensionPixelSize(R.dimen.square_size),
resources.getDimensionPixelSize(R.dimen.square_size)
)
imageView.layoutParams = layoutParams
imageView.id = index
Expand All @@ -87,13 +87,15 @@ class MainActivity : AppCompatActivity() {
override fun onCollisionExited(viewIdA: Int, viewIdB: Int) {}
})

binding.physicsLayout.physics.addOnPhysicsProcessedListener(object : Physics.OnPhysicsProcessedListener {
binding.physicsLayout.physics.addOnPhysicsProcessedListener(object :
Physics.OnPhysicsProcessedListener {
override fun onPhysicsProcessed(physics: Physics, world: World) {
Log.d(TAG, "onPhysicsProcessed")
}
})

binding.physicsLayout.physics.setOnBodyCreatedListener(object : Physics.OnBodyCreatedListener {
binding.physicsLayout.physics.setOnBodyCreatedListener(object :
Physics.OnBodyCreatedListener {
override fun onBodyCreated(view: View, body: Body) {
Log.d(TAG, "Body created for view ${view.id}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class PhysicsFlowLayout : FlowLayout {
init(attrs)
}

constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init(attrs)
}

Expand Down Expand Up @@ -63,7 +67,8 @@ class PhysicsFlowLayout : FlowLayout {
return LayoutParams(context, attrs)
}

class LayoutParams(c: Context, attrs: AttributeSet) : FlowLayout.LayoutParams(c, attrs), PhysicsLayoutParams {
class LayoutParams(c: Context, attrs: AttributeSet) : FlowLayout.LayoutParams(c, attrs),
PhysicsLayoutParams {
override var config: PhysicsConfig = PhysicsLayoutParamsProcessor.process(c, attrs)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jawnnypoo.physicslayout.sample.github

import com.squareup.moshi.Json

data class Contributor (
data class Contributor(
@Json(name = "avatar_url")
var avatarUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ object GitHubClient {

private val github: GitHub by lazy {
val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
.add(KotlinJsonAdapterFactory())
.build()
val retrofit = Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create(moshi))
.baseUrl("https://api.github.com/")
.build()
.addConverterFactory(MoshiConverterFactory.create(moshi))
.baseUrl("https://api.github.com/")
.build()
retrofit.create(GitHub::class.java)
}

Expand All @@ -27,8 +27,8 @@ object GitHubClient {
interface GitHub {
@GET("/repos/{owner}/{repo}/contributors")
suspend fun contributors(
@Path("owner") owner: String,
@Path("repo") repo: String
@Path("owner") owner: String,
@Path("repo") repo: String
): List<Contributor>
}
}
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
buildscript {
ext.kotlin_version = "1.6.10"
ext.kotlin_version = "1.9.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.1.1"
classpath 'com.android.tools.build:gradle:8.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.vanniktech:gradle-maven-publish-plugin:0.18.0"
}
}

plugins {
id "com.github.ben-manes.versions" version "0.42.0"
}

allprojects {
repositories {
google()
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ POM_DEVELOPER_ID=Jawnnypoo
POM_DEVELOPER_NAME=John Carlson
POM_DEVELOPER_URL=https://github.com/Jawnnypoo/

# This gets updated by CI
VERSION_NAME=0.0.1
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
17 changes: 8 additions & 9 deletions physicslayout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ apply plugin: "com.vanniktech.maven.publish"
apply from: "../publish.gradle"

android {
compileSdkVersion 32
namespace = "com.jawnnypoo.physicslayout"
compileSdk 34

defaultConfig {
minSdkVersion 15
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
minSdk 15
targetSdk 34
}
}

kotlin {
jvmToolchain 17
}

dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
api("org.jbox2d:jbox2d-library:2.2.1.1")
api("com.commit451:translationviewdraghelper:2.0.3")
}
Loading

0 comments on commit 4471566

Please sign in to comment.