Skip to content

Instantly share code, notes, and snippets.

View chkwok's full-sized avatar

Chi Ho Kwok chkwok

  • Digibites Technology
View GitHub Profile
@chkwok
chkwok / MyActivity.java
Created November 5, 2018 20:11
AdMob banner example without MobileAds.initialize
/*
* Copyright (C) 2013 Google, Inc.
*
* 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
@chkwok
chkwok / admob-choreographer-hack.java
Created November 5, 2018 14:24
Quick hack to pause and unpause animation callbacks
// You need to call pause/resume in a ActivityLifecycleCallbacks, pause after all activities are stopped, resume if any is started.
// Just removing the callback will bork WebView rendering (animation, selection, etc).
private Object choreographerAnimationCallback = null;
@SuppressWarnings({ "JavaReflectionMemberAccess", "SynchronizationOnLocalVariableOrMethodParameter" })
private void pauseAnimationCallbacks() {
try {
Class<?> choreographerType = Class.forName("android.view.Choreographer");
final int CALLBACK_ANIMATION = 1;
public static TypedArray obtainStyledAttributes(@NonNull Context context, int[] attrs) {
int[] tmp = new int[attrs.length];
long[] sorted = AttrSorter.sorted(attrs);
@SuppressLint("Recycle")
android.content.res.TypedArray a = context.obtainStyledAttributes(
AttrSorter.sortedAttrs(sorted, tmp));
return new TypedArray(a, AttrSorter.sortedIndices(sorted, tmp));
}
@chkwok
chkwok / Arm64Bug.java
Created April 19, 2016 12:32
Demo of an array index, long to int cast type confusion error in Android/ART @ 5.0/5.1.
package com.digibites.arm64bugtest;
import java.util.Arrays;
import android.util.Log;
public class Arm64Bug {
private static final String TAG = "Arm64Bug";
/**
@chkwok
chkwok / app.wsgi
Last active December 19, 2015 03:29
UWSGI touch-reload issue minimal test case
def application(env, start_response):
import time
time.sleep(5)
start_response('200 OK', [('Content-Type', 'text/html')])
return "Hello World\n"