Skip to content

Instantly share code, notes, and snippets.

View pcqpcq's full-sized avatar

Joker pcqpcq

View GitHub Profile
{
"alignment_chars" : ["=", ":"]
}
#!/bin/bash
f=$(pwd)
mkdir drawable-mdpi drawable-hdpi drawable-xhdpi drawable-xxhdpi
# fake argv and argc in bash
argc=$#; argv[0]=$0 # argv[0] is a prog name
for foo in $( seq $argc )
do
@pcqpcq
pcqpcq / AndroidBeanGen.rb
Last active August 29, 2015 14:02
Android JavaBean Generator for android. Java Bean with Parcelable. Version 1.0.1
## 使命行参数格式:
## ARGV[0] ==> config文件路径[必须有]
## ARGV[1] ==> 保存文件路径[必须有]
## ARGV[2] ==> 包名[必须有]
##
## 示例:
## ruby ./AndroidBeanGen.rb ./config.txt ./resp com.a.b
##
##
##
package me.pcqpcq.android.widget;
import android.view.View;
/**
* Adapter interface. The list adapter must implement this interface.
*
* @see <a href="http://stackoverflow.com/questions/10613552/pinned-groups-in-expandablelistview">source</a>
*/
public interface PinnedHeaderAdapter {
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
return; // Skip debug builds.
}
def task = project.tasks.create "jar${name.capitalize()}", Jar
task.dependsOn variant.javaCompile
//Include Java classes
task.from variant.javaCompile.destinationDir
//Include dependent jars with some exceptions

HOWTO Cross compiling on Android

5W1H

What is NDK

NDK (Native Develop Toolkit) is a toolchain from Android official, originally for users who writes native C/C++ code as JNI library. It's not designed for compiling standalone programs (./a.out) and not compatible with automake/cmake etc.

What is Standalone Toolchain

"Standalone" refers to two meanings:

  1. The program is standalone (has nothing connect to NDK, and don't need helper scripts to run it)
  2. The toolchain is made for building standalone programs and libs, and which can used by automake etc.

(Optional) Why NDK is hard to use

By default, NDK uses android flavor directory structure when it's finding headers and libs, which is different from GNU flavor, so the compiler cannot find them. For Example:

@pcqpcq
pcqpcq / findView
Created April 2, 2015 10:33
Reduce findViewById
/**
* @param resId resource Id
*/
public <T extends View> T findView(int resId) {
return (T) findViewById(resId);
}
package com.oasisfeng.greenify.utils;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
@pcqpcq
pcqpcq / default.custom.yaml
Created May 5, 2016 09:35 — forked from lotem/default.custom.yaml
在Rime輸入方案選單中添加五筆、雙拼、粵拼、注音,保留你需要的
# default.custom.yaml
# save it to:
# ~/.config/ibus/rime (linux)
# ~/Library/Rime (macos)
# %APPDATA%\Rime (windows)
patch:
schema_list:
- schema: luna_pinyin # 朙月拼音
- schema: luna_pinyin_simp # 朙月拼音 简化字模式
@pcqpcq
pcqpcq / shadow.xml
Created August 23, 2016 07:12 — forked from lecho/shadow.xml
Android shadow drawable xml.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"