Skip to content

Instantly share code, notes, and snippets.

buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta5'
@Nathaniel100
Nathaniel100 / Installation.java
Created April 27, 2016 07:12
Android installation
public class Installation {
private static String sID = null;
private static final String INSTALLATION = "INSTALLATION";
public synchronized static String id(Context context) {
if (sID == null) {
File installation = new File(context.getFilesDir(), INSTALLATION);
try {
if (!installation.exists()) writeInstallationFile(installation);
sID = readInstallationFile(installation);
@Nathaniel100
Nathaniel100 / MeasureSpec.md
Last active May 14, 2016 03:20
MeasureSpec

MeasureSpec

A MeasureSpec encapsulates the layout requirements passed from parent to child. Each MeasureSpec represents a requirement for either the width or the height. A MeasureSpec is comprised of a size and a mode. There are three possible modes: UNSPECIFIED The parent has not imposed any constraint on the child. It can be whatever size it wants. EXACTLY The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be. AT_MOST The child can be as large as it wants up to the specified size. MeasureSpecs are implemented as ints to reduce object allocation. This class is provided to pack and unpack the <size, mode> tuple into the int.

/**
 * Version of {@link #resolveSizeAndState(int, int, int)}
 * returning only the {@link #MEASURED_SIZE_MASK} bits of the result.
 */
public static int resolveSize(int size, int measureSpec) {
    return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK;
}

/**
@Nathaniel100
Nathaniel100 / SoLibrary.md
Last active August 16, 2017 02:48
Android.mk中使用预编译的动态库

自定义一个MODULE,名为libFoo,对应的so为libFoo.so, 头文件.h文件与.so文件放在当前目录的Foo目录中

# Android.mk增加LOCAL_MODULE libFoo
FOO_LIBRARY_PATH = $(LOCAL_PATH)/Foo
include $(CLEAR_VARS)
LOCAL_MODULE := libFoo
LOCAL_SRC_FILES := $(FOO_LIBRARY_PATH)/libFoo.so
LOCAL_EXPORT_C_INCLUDES := $(FOO_LIBRARY_PATH)
# 预编译的共享库
include $(PREBUILT_SHARED_LIBRARY)
@Nathaniel100
Nathaniel100 / file.cpp
Created May 16, 2016 05:53
Awesome file operation
inline bool LoadBinaryFile(const char *name, std::vector<uint8_t> *v) {
std::ifstream ifs(name, std::ifstream::binary);
if(!ifs.is_open()) return false;
ifs.seekg(0, std::ios::end);
(*v).resize(static_cast<size_t>(ifs.tellg()));
ifs.seekg(0, std::ios::beg);
ifs.read(reinterpret_cast<char *>(&(*v)[0]), (*v).size());
return !ifs.bad();
}
public class Hex {
private static final char[] HEX_DIGITS = new char[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
private static final char[] FIRST_CHAR = new char[256];
private static final char[] SECOND_CHAR = new char[256];
static {
@Nathaniel100
Nathaniel100 / crossover.md
Created May 24, 2016 13:43
crossover在mac系统字体模糊解决方法

先从windows系统复制文件simsun.ttf到你的虚拟机下(c:\windows\fonts\),在CrossOver下打开regedit(命令行方式) 找到HKEY_CURRENT_USER\Software\Wine\Fonts\Replacements,删除下面的项目simsun 宋体 新宋体

@Nathaniel100
Nathaniel100 / ByteArrayPool.java
Last active May 27, 2016 03:31
ByteArrayPool, implement in Volley library
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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
@Nathaniel100
Nathaniel100 / cache.md
Created May 27, 2016 10:21
Based on Volley Cache

Cache

Based on Volley Cache

Cache interface

/**
 * An interface for a cache keyed by a String with a byte array as data
 */
interface Cache {