Skip to content

Instantly share code, notes, and snippets.

@pfn
pfn / jhat.js
Last active December 16, 2015 03:49
oql query
select { ary: s, sz: s.length, ref: forEachReferrer(
function refs(r) {
function cid(o) {
var cn = classof(o).name;
cn = cn.substring(cn.lastIndexOf(".") + 1);
return cn + "@" + objectid(o);
}
println(cid(s) + "=" + s.length + " <= " + cid(r) + " <= " +
toArray(map(sort(
referrers(r), "classof(rhs).name.length() - classof(lhs).name.length()"),
@pfn
pfn / aosp odex hack.txt
Last active December 16, 2015 09:39
modify built-in app
Add LOCAL_DEX_PREOPT := false to Android.mk for App being built
make -j4 AppName
push resulting App.apk to device /sdcard/somewhere-temp
adb shell; cd to /sdcard/somewhere-temp
dexopt --zip 3 5 App.apk "v=a o=f" 5<>App.odex 3<App.apk
@pfn
pfn / plugin.scala
Created June 26, 2013 22:06
sbt plugin dependency wiring
def androidBuild(projects: Project*): Project.SettingsDefinition = {
androidBuild ++
(projects map { p =>
Seq(
collectResources in Android <<=
collectResources in Android dependsOn (compile in Compile in p),
compile in Compile <<= compile in Compile dependsOn(
packageT in Compile in p)
)
}).flatten
@pfn
pfn / build.scala
Last active December 19, 2015 00:59
multi-project build example: 2 common libraries, and 3 application projects. All projects are java.
import sbt._
import sbt.Keys._
import android.Keys._
object ExampleMultiBuild extends Build {
// define a new task
val release = TaskKey[Unit]("release", "build & release all release builds")
// setup an aggregate for 'install' and 'release'
// calling either will perform the install or release operation against
@pfn
pfn / build.scala
Last active December 19, 2015 00:59
Another java-based multi-project build example. 1 java library project, 2 android library projects, 1 test project, 1 use of the actionbarsherlock apklib and 1 android project.
import sbt._
import sbt.Keys._
import android.Keys._
import android.Dependencies.apklib
object ExampleMultiBuild extends Build {
// add 'run' alias to the root project
lazy val root = Project(id = "root-prj", base = file(".")) settings(
android.Plugin.androidCommands ++ Seq(
run <<= (run in (mainprj, Android)) map { _ => Unit }): _*
@pfn
pfn / build.sbt
Last active December 19, 2015 00:59
Simple scala android project build example. It only takes one line in build.sbt to do what's necessary. Everything else is optional.
// so we can use keywords from Android, such as 'Android' and 'proguardOptions'
import android.Keys._
// load the android plugin into the build
android.Plugin.androidBuild
// project name, completely optional
name := "time-widgets"
// pick the version of scala you want to use
@pfn
pfn / build.scala
Last active December 19, 2015 00:59
A scala-based multi-project build. 1 android library and one android project, both using scala (in this case, only the common project has any sources). Also includes usage of an aar, apklib and support-v4 all in libraryDependencies; additionally there is a java-project automatically fetched and built from github.
import sbt._
import sbt.Keys._
import android.Keys._
object QicrBuild extends Build {
lazy val root = Project(id = "qicr", base = file(".")) settings(Seq(
packageT in Compile <<= packageT in Android in lite,
packageRelease <<= packageRelease in Android in lite,
packageDebug <<= packageDebug in Android in lite,
object SpannedGenerator {
private def span(style: Object, text: CharSequence) = {
val s = new SpannableString(text)
s.setSpan(style, 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
s
}
def textColor(color: Int, text: CharSequence) =
span(new ForegroundColorSpan(color) , text)
def bold(text: CharSequence) = span(new StyleSpan(Typeface.BOLD) , text)
@pfn
pfn / build.scala
Last active December 21, 2015 02:49
Load an arbitrary project from git, include it as an Android Library Project in our main application build.
import sbt._
import android.ArbitraryProject
object SampleBuild extends Build {
import android.Keys._
import android.Dependencies.LibraryProject
// we're gonna pull tag android-sdk-support_r11 from the support repo
val supportGit = uri("https://android.googlesource.com/" +
@pfn
pfn / widgets.scala
Last active December 21, 2015 05:39
qicr's multi-widget goodness
package com.hanhuy.android.irc
import AndroidConversions._
import android.appwidget.{AppWidgetManager, AppWidgetProvider}
import android.widget.{Toast, RemoteViews, RemoteViewsService}
import android.content.{DialogInterface, Context, BroadcastReceiver, Intent}
import android.app.{AlertDialog, Activity, PendingIntent}
import android.view.View
import com.hanhuy.android.irc.model._