Skip to content

Instantly share code, notes, and snippets.

View nekocode's full-sized avatar

nekocode nekocode

View GitHub Profile
/**
* 裁剪文本
*/
private static String cutText(float textSize, String title, float maxWidth) {
final TextPaint textPaint = new TextPaint();
textPaint.setTextSize(textSize);
if (textPaint.measureText(title) < maxWidth)
return title;
@nekocode
nekocode / LoadingView.java
Created November 23, 2017 05:36
Draw animatable drawable to view.
public class LoadingView extends View {
private CircularProgressDrawable mDrawable;
public LoadingView(Context pContext) {
super(pContext);
init();
}
public LoadingView(Context pContext, AttributeSet pAttributeSet) {
import groovy.json.JsonOutput
import com.google.common.io.Files
android.applicationVariants.all { variant ->
variant.assemble.doLast {
variant.outputs.each { output ->
def apkInfo = [
apk: output.outputFile.absolutePath,
versionCode: variant.versionCode,
versionName: variant.versionName
project.afterEvaluate {
android.productFlavors.all { flavor ->
dependencies {
if (flavor.applicationIdSuffix) {
it."${flavor.name}Implementation" "cn.nekocode.lib:keys-alpha:${versions.keys}"
} else {
it."${flavor.name}Implementation" "cn.nekocode.lib:keys:${versions.keys}"
}
}
}
# Referenced from https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000094584/comments/115000405564
# Get the certification of the google.com
echo -n | openssl s_client -connect google.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/google.cer
# Navigate to the jre security directory insides the Android Studio
cd "/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre/lib/security"
# Move the certification to current directory
mv ~/google.cer .
import org.gradle.util.NameMatcher
def isTaskSelected(String... taskNames) {
def matcher = new NameMatcher()
def nameList = Arrays.asList(taskNames)
def requestedTaskNames = gradle.startParameter.taskNames
for (def requestedTaskName : requestedTaskNames) {
if (matcher.find(requestedTaskName, nameList) != null) {
return true
}
project.afterEvaluate {
project.tasks["transformClassesWithDepanForDebug"]
.outputs.upToDateWhen { false }
}
def classpathConfig = project.configurations.maybeCreate("gradleClasspath")
project.dependencies {
gradleClasspath "org.xerial:sqlite-jdbc:3.25.2"
}
def classloader = Thread.currentThread().contextClassLoader as URLClassLoader
classpathConfig.each {
classloader.addURL(it.toURI().toURL())
}
project.configurations.remove(classpathConfig)
import org.gradle.api.Project
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.component.ComponentSelector
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentSelector
import org.gradle.api.artifacts.result.DependencyResult
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.artifacts.result.UnresolvedDependencyResult
import com.google.common.io.Files
import groovy.json.JsonOutput
@nekocode
nekocode / ResponseWrapper.kt
Created June 3, 2019 16:29
The json(/gson) deserializer for mix-structure response
import android.os.Parcelable
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
sealed class ResponseWrapper<out T> {
class Anomaly(val value: com.xxx.model.wrapper.Anomaly) : ResponseWrapper<Nothing>()
class Single<T : Parcelable>(val value: T) : ResponseWrapper<T>()