Skip to content

Instantly share code, notes, and snippets.

@zhanghai
zhanghai / svg-to-drawable.sh
Created December 9, 2016 04:59
Convert SVG files from Material Design Icons to XML drawables for Android
#!/bin/bash
if [[ -z "$1" ]]; then
echo "Usage: $0 ICON_SVG_FILE" >&2
exit 1
fi
path_data="$(grep -oP '(?<=<path d=").*z(?="/>)' "$1")"
if [[ -z "${path_data}" ]]; then
echo "$1: Cannot recognize path data" >&2
exit 1
fi
@zhanghai
zhanghai / fix-material-design-icons.sh
Created December 9, 2016 04:57
Fix XML format of Material Design icon generation in Android Studio
#!/bin/bash
set -e
ANDROID_LIB_PATH='/opt/android-studio/plugins/android/lib/'
TEMP_DIR='sdk-tools/'
TEMP_FILE='sdk-tools.jar'
if [[ -f "${ANDROID_LIB_PATH}/sdk-tools.jar.orig" ]]; then
echo "${ANDROID_LIB_PATH}/sdk-tools.jar.orig already exists, exiting..." >&2
exit 1
@zhanghai
zhanghai / douya.md
Last active January 4, 2016 03:04
关于豆芽

豆芽

Douban, Yet Another.

另一个叫豆芽的应用。

关于名字

豆芽的名字取自“Douban, Yet Another”的缩写和中文词语“豆芽”的拼音正好相同的巧合。

@zhanghai
zhanghai / ForegroundRelativeLayout.java
Last active December 1, 2015 09:25
RelativeLayout with backward-compatible foreground support.
/*
* Copyright (c) 2015 Zhang Hai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@zhanghai
zhanghai / OnVerticalScrollListener.java
Last active May 8, 2019 07:17
RecyclerView.OnScrollListener that reports scrolled up/down or reached top/bottom.
/*
* Copyright (c) 2015 Zhang Hai <[email protected]>
* All Rights Reserved.
*/
package com.example.android;
import android.support.v7.widget.RecyclerView;
public abstract class OnVerticalScrollListener extends RecyclerView.OnScrollListener {
@zhanghai
zhanghai / DragUtils.java
Last active October 23, 2017 03:21
Drag and drop for sort and delete implementation.
/*
* Copyright (c) 2014-2015 Zhang Hai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@zhanghai
zhanghai / SimpleDialogFragment.java
Created December 24, 2014 07:09
Simple DialogFragment for showing dialogs that saves/restores its instance state.
/*
* Copyright (c) 2014 Zhang Hai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@zhanghai
zhanghai / dpigen.sh
Created December 11, 2014 06:27
Script for generating image assets of different DPIs for Android from SVG source file, using Inkscape.
#!/bin/bash
#
# dpigen.sh: Script for generating image assets of different DPIs for Android from SVG source file, using Inkscape.
#
# Copyright (c) 2014 Zhang Hai <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@zhanghai
zhanghai / MergeListAdapter.java
Last active August 29, 2015 14:09
A ListAdapter (and a StickyListHeaders version) that merges multiple ListAdapters.
/*
* Copyright (c) 2014 Zhang Hai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@zhanghai
zhanghai / unzip-gbk.py
Created July 5, 2014 11:12
Python script that can unzip filename with gbk encoding correctly.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# unzip-gbk.py
import os
import sys
import zipfile
print u"正在处理压缩文件 %s" % sys.argv[1].decode('utf-8')
print