Skip to content

Instantly share code, notes, and snippets.

View pcqpcq's full-sized avatar

Joker pcqpcq

View GitHub Profile
#!/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
##
##
##
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);
}
{
"alignment_chars" : ["=", ":"]
}
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;
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 {
@pcqpcq
pcqpcq / PossibleAndroidId.java
Last active May 25, 2017 08:14
any possible ways to get an android id outside the world.
// #region from [here](https://github.com/nisrulz/easydeviceinfo/blob/develop/easydeviceinfo-base/src/main/java/github/nisrulz/easydeviceinfo/base/EasyIdMod.java)
/**
* Gets android id.
*
* @return the android id
*/
@SuppressLint("HardwareIds")
public final String getAndroidID() {
return CheckValidityUtil.checkValidData(
Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
sundayFirstCalendar = 'cal && date'
mondayFirstCalendar = 'cal | awk \'{ print " "$0; getline; print "Mo Tu We Th Fr Sa Su"; \
getline; if (substr($0,1,2) == " 1") print " 1 "; \
do { prevline=$0; if (getline == 0) exit; print " " \
substr(prevline,4,17) " " substr($0,1,2) " "; } while (1) }\' && date'
command: sundayFirstCalendar
refreshFrequency: 3600000