Convert AnimationUtils, ConcurrentPool, IntIdGenerator and SimpleAnimatorListener to kotlin
This commit is contained in:
1 parent
c61afc7a04
commit
4f47febc06
4 files changed
+54
-80
No files matched your search
@@ -13,20 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.yorozuya
|
||||
|
||||
package com.hippo.ehviewer.yorozuya;
|
||||
import android.view.animation.Interpolator
|
||||
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
||||
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import androidx.interpolator.view.animation.FastOutLinearInInterpolator;
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
||||
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator;
|
||||
|
||||
public final class AnimationUtils {
|
||||
public static final Interpolator FAST_SLOW_INTERPOLATOR = new LinearOutSlowInInterpolator();
|
||||
public static final Interpolator SLOW_FAST_INTERPOLATOR = new FastOutLinearInInterpolator();
|
||||
public static final Interpolator SLOW_FAST_SLOW_INTERPOLATOR = new FastOutSlowInInterpolator();
|
||||
|
||||
private AnimationUtils() {
|
||||
}
|
||||
object AnimationUtils {
|
||||
val FAST_SLOW_INTERPOLATOR: Interpolator = LinearOutSlowInInterpolator()
|
||||
val SLOW_FAST_INTERPOLATOR: Interpolator = FastOutLinearInInterpolator()
|
||||
val SLOW_FAST_SLOW_INTERPOLATOR: Interpolator = FastOutSlowInInterpolator()
|
||||
}
|
||||
@@ -13,38 +13,35 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.yorozuya
|
||||
|
||||
package com.hippo.ehviewer.yorozuya;
|
||||
class ConcurrentPool<T>(size: Int) {
|
||||
private val mArray: Array<T?>
|
||||
private val mMaxSize: Int
|
||||
private var mSize: Int
|
||||
|
||||
public class ConcurrentPool<T> {
|
||||
|
||||
private final T[] mArray;
|
||||
private final int mMaxSize;
|
||||
private int mSize;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConcurrentPool(int size) {
|
||||
if (size <= 0) {
|
||||
throw new IllegalStateException("Pool size must > 0, it is " + size);
|
||||
}
|
||||
mArray = (T[]) new Object[size];
|
||||
mMaxSize = size;
|
||||
mSize = 0;
|
||||
init {
|
||||
check(size > 0) { "Pool size must > 0, it is $size" }
|
||||
mArray = arrayOfNulls<Any>(size) as Array<T?>
|
||||
mMaxSize = size
|
||||
mSize = 0
|
||||
}
|
||||
|
||||
public synchronized void push(T t) {
|
||||
@Synchronized
|
||||
fun push(t: T?) {
|
||||
if (t != null && mSize < mMaxSize) {
|
||||
mArray[mSize++] = t;
|
||||
mArray[mSize++] = t
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized T pop() {
|
||||
if (mSize > 0) {
|
||||
T t = mArray[--mSize];
|
||||
mArray[mSize] = null;
|
||||
return t;
|
||||
@Synchronized
|
||||
fun pop(): T? {
|
||||
return if (mSize > 0) {
|
||||
val t = mArray[--mSize]
|
||||
mArray[mSize] = null
|
||||
t
|
||||
} else {
|
||||
return null;
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,39 +13,34 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.yorozuya
|
||||
|
||||
package com.hippo.ehviewer.yorozuya;
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
class IntIdGenerator {
|
||||
private val mId = AtomicInteger()
|
||||
|
||||
public final class IntIdGenerator {
|
||||
|
||||
public static final int INVALID_ID = -1;
|
||||
|
||||
private final AtomicInteger mId = new AtomicInteger();
|
||||
|
||||
public IntIdGenerator() {
|
||||
constructor()
|
||||
constructor(init: Int) {
|
||||
setNextId(init)
|
||||
}
|
||||
|
||||
public IntIdGenerator(int init) {
|
||||
setNextId(init);
|
||||
fun nextId(): Int {
|
||||
var id: Int
|
||||
while (mId.getAndIncrement().also { id = it } == INVALID_ID);
|
||||
return id
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
public int nextId() {
|
||||
int id;
|
||||
while ((id = mId.getAndIncrement()) == INVALID_ID) ;
|
||||
return id;
|
||||
fun setNextId(id: Int) {
|
||||
checkInValidId(id)
|
||||
mId.set(id)
|
||||
}
|
||||
|
||||
public void setNextId(int id) {
|
||||
checkInValidId(id);
|
||||
mId.set(id);
|
||||
private fun checkInValidId(id: Int) {
|
||||
check(INVALID_ID != id) { "Can't set INVALID_ID" }
|
||||
}
|
||||
|
||||
private void checkInValidId(int id) {
|
||||
if (INVALID_ID == id) {
|
||||
throw new IllegalStateException("Can't set INVALID_ID");
|
||||
}
|
||||
companion object {
|
||||
const val INVALID_ID = -1
|
||||
}
|
||||
}
|
||||
@@ -13,26 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.yorozuya
|
||||
|
||||
package com.hippo.ehviewer.yorozuya;
|
||||
import android.animation.Animator
|
||||
|
||||
import android.animation.Animator;
|
||||
|
||||
public abstract class SimpleAnimatorListener implements Animator.AnimatorListener {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
}
|
||||
abstract class SimpleAnimatorListener : Animator.AnimatorListener {
|
||||
override fun onAnimationStart(animation: Animator) {}
|
||||
override fun onAnimationEnd(animation: Animator) {}
|
||||
override fun onAnimationCancel(animation: Animator) {}
|
||||
override fun onAnimationRepeat(animation: Animator) {}
|
||||
}
|
||||
Reference in new issue
Block a user