Skip to content

Instantly share code, notes, and snippets.

@gitzxon
gitzxon / build.gradle
Created May 7, 2019 11:59
copy dependencies to build/dependencies
// ./gradlew copyDependenciesDebug
android.applicationVariants.all { variant ->
task "copyDependencies${variant.name.capitalize()}"() {
outputs.upToDateWhen { false }
doLast {
println "Executing copyDependencies${variant.name.capitalize()}"
variant.getCompileClasspath().each { fileDependency ->
def sourcePath = fileDependency.absolutePath
def destinationPath = project.projectDir.path + "/build/dependencies/${variant.name}/"
@gitzxon
gitzxon / java
Last active February 18, 2019 10:05
find the soft keyboard height, and scroll the target view when it is hidden by the soft keyboard.
public class KeyboardUtil {
public static void hide(View v) {
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isActive()) {
imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
}
}
public interface SoftKeyboardCallback {
@gitzxon
gitzxon / weekly_summary.py
Last active July 30, 2018 07:16
周报.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import datetime
date1 = datetime.datetime.now()
this_week_monday = date1 - datetime.timedelta(days=date1.weekday())
this_week_friday = date1 + datetime.timedelta(days=6-date1.weekday())
# print this_week_monday, this_week_friday
this_week_monday_str = str(this_week_monday).split()[0]
@gitzxon
gitzxon / snippet_in_app.gradle
Last active March 21, 2017 07:56
printing executed time of a task
// (1) put this snippet to the tail of app.gradle
// (2) ./gradlew assembleDebug
public class BuildTimeListener implements TaskExecutionListener, BuildListener {
private org.gradle.internal.time.Clock clock
private times = []
@Override
void beforeExecute(Task task) {
clock = new org.gradle.internal.time.Clock()
@gitzxon
gitzxon / gist:efa3a0ff627cf412ed793f8b037b5b40
Created August 19, 2016 03:30
api23 android permission
/**
* Checks whether it is necessary to ask for permission to read storage. If necessary, it also
* requests permission.
*
* @return true if a permission request is made. False if it is not necessary.
*/
@TargetApi(23)
private boolean maybeRequestPermission() {
if (requiresPermission(contentUri)) {
requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0);