View CutText.java
/** | |
* 裁剪文本 | |
*/ | |
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; |
View DiffUtils.java
import java.lang.reflect.Method; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
/** | |
* Modified from {@link <a href="http://stackoverflow.com/a/32817115/5729581"/>} | |
* | |
* @author nekocode (nekocode.cn@gmail.com) | |
*/ | |
public class DiffUtils { |
View LoadingView.java
public class LoadingView extends View { | |
private CircularProgressDrawable mDrawable; | |
public LoadingView(Context pContext) { | |
super(pContext); | |
init(); | |
} | |
public LoadingView(Context pContext, AttributeSet pAttributeSet) { |
View dependencies2json.gradle
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 |
View get_apk_info.gradle
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 |
View conditional_dependence.gradle
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}" | |
} | |
} | |
} |
View androidstudio_trust_ certification.sh
# 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 . |
View check_if_task_is_selected.gradle
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 | |
} |
View import_external_classes.gradle
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) |
View always_run_a_transform_task.gradle
project.afterEvaluate { | |
project.tasks["transformClassesWithDepanForDebug"] | |
.outputs.upToDateWhen { false } | |
} |
OlderNewer