Skip to content

Instantly share code, notes, and snippets.

@pfn
pfn / 00-gradle-generated.sbt
Created Aug 28, 2015
generated sbt build definition from gradle
View 00-gradle-generated.sbt
val viewserver = Project(id = raw"""viewserver""", base = file(raw"""C:\Users\pfnguyen\src\vs2\viewserver""")).settings(
android.Plugin.androidBuildAar:_*).settings(
SettingKey[android.Keys.PackagingOptions]("packagingOptions") in config("android") := android.Keys.PackagingOptions(Nil, Nil, Nil),
SettingKey[scala.collection.Seq[sbt.Resolver]]("resolvers") ++= List(raw"""https://jcenter.bintray.com/""" at raw"""https://jcenter.bintray.com/""",
raw"""https://jcenter.bintray.com/""" at raw"""https://jcenter.bintray.com/""",
raw"""file:/C:/Users/pfnguyen/android-sdk-windows/extras/android/m2repository/""" at raw"""file:/C:/Users/pfnguyen/android-sdk-windows/extras/android/m2repository/""",
raw"""file:/C:/Users/pfnguyen/android-sdk-windows/extras/google/m2repository/""" at raw"""file:/C:/Users/pfnguyen/android-sdk-windows/extras/google/m2repository/"""),
SettingKey[java.lang.String]("platformTarget") in config("android") := raw"""android-21""",
SettingKey[java.lang.String]("nam
@pfn
pfn / workaround.scala
Last active Aug 29, 2015
Workaround for AOSP #63777
View workaround.scala
// workaround for https://code.google.com/p/android/issues/detail?id=63777
class KitKatDrawerLayout(c: Context) extends DrawerLayout(c) {
var baseline = Integer.MAX_VALUE
var change = 0
override def fitSystemWindows(insets: Rect) = {
val adj = insets.top + insets.bottom
baseline = math.min(adj, baseline)
if (baseline != Integer.MAX_VALUE && adj > baseline) {
@pfn
pfn / email-5.0.0_r6.diff
Created Nov 24, 2014
email & exchange hack for android 5.0
View email-5.0.0_r6.diff
diff --git a/Android.mk b/Android.mk
index a7dbba5..209e8b8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -44,6 +44,7 @@ LOCAL_ASSET_DIR := $(LOCAL_PATH)/$(unified_email_dir)/assets
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips:com.android.mail:com.android.email:com.android.emailcommon:com.android.ex.photo:android.support.v7.appcompat:android.support.v7.gridlayout:com.android.bitmap:com.android.datetimepicker
+LOCAL_AAPT_FLAGS += --rename-manifest-package com.android.emailhack
@pfn
pfn / build.sbt
Last active Aug 29, 2015
alternative to externalPom()
View build.sbt
def loadFromPom(pom: File): Seq[ModuleID] = {
import scala.xml._
val root = XML.loadFile(pom)
val parent = root \\ "parent" // TODO look up variables in parents
(root \\ "dependency") map { n =>
for {
o <- n.child.find(_.label == "groupId")
a <- n.child.find(_.label == "artifactId")
v <- n.child.find(_.label == "version")
} yield ModuleID(o.text, a.text, v.text,
@pfn
pfn / 1-conversions.scala
Last active Aug 29, 2015
android function generators
View 1-conversions.scala
package com.hanhuy.android
import language.implicitConversions
package object conversions {
implicit def `fn1 to android.nfc.NfcAdapter$CreateNdefMessageCallback`(fn: (android.nfc.NfcEvent) => android.nfc.NdefMessage): android.nfc.NfcAdapter.CreateNdefMessageCallback = new android.nfc.NfcAdapter.CreateNdefMessageCallback {
override def createNdefMessage(a: android.nfc.NfcEvent) = fn(a)
}
implicit def `fn0 to android.nfc.NfcAdapter$CreateNdefMessageCallback`(fn: () => android.nfc.NdefMessage): android.nfc.NfcAdapter.CreateNdefMessageCallback = new android.nfc.NfcAdapter.CreateNdefMessageCallback {
@pfn
pfn / 1-usage.scala
Last active Aug 29, 2015
extension class that returns 'this'
View 1-usage.scala
textfield.asScala.onEditorAction((_,id,event) => true)
@pfn
pfn / output.txt
Created Sep 23, 2015
key-path plugin output
View output.txt
pfnguyen@galactica1:~/src/sbt-key-path-test$ sbt "keypath package test:compile" [info] Loading global plugins from /home/pfnguyen/.sbt/0.13/plugins
[info] Loading project definition from /cifs/pfnguyen/src/sbt-key-path-test/project
[info] Set current project to sbt-key-path-test (in build file:/cifs/pfnguyen/src/sbt-key-path-test/)
[info] Path: compile:package
[info] Looking for: compile:package <- test:compile
[error] No paths found
pfnguyen@galactica1:~/src/sbt-key-path-test$ sbt "keypath package update"
[info] Loading global plugins from /home/pfnguyen/.sbt/0.13/plugins
[info] Loading project definition from /cifs/pfnguyen/src/sbt-key-path-test/project
[info] Set current project to sbt-key-path-test (in build file:/cifs/pfnguyen/src/sbt-key-path-test/)
@pfn
pfn / gist:1690765
Created Jan 27, 2012
listener queue with weak reference to anonymous functions
View gist:1690765
object E {
class O {
val listeners = new ArrayBuffer[E.H]
}
trait RO {
implicit val __ERO__ = new O
}
type H = PartialFunction[Any,Any]
}
abstract class E {
View gist:1762813
def using[A <: { def close() }](closeable: => A)(f: A => Unit) {
var c: Option[A] = None
try {
c = Option(closeable)
c foreach f
} finally {
c foreach(_.close)
}
}
@pfn
pfn / AndroidConversions.scala
Created Feb 7, 2012
AndroidConversions.scala
View AndroidConversions.scala
package com.hanhuy.android.irc
import android.app.Activity
import android.app.ActionBar
import android.content.Intent
import android.content.Context
import android.content.BroadcastReceiver
import android.content.res.Configuration
import android.os.AsyncTask
import android.os.Build