Skip to content

Instantly share code, notes, and snippets.

View suzp1984's full-sized avatar
🏢
Office time

Jacob Su suzp1984

🏢
Office time
View GitHub Profile
@suzp1984
suzp1984 / main.java
Created May 19, 2016 12:54
java multi-threading synchronization
public class Main {
public static void main(String[] args) {
Printer p = new Printer();
Thread t1 = new NumberPrinter(p);
Thread t2 = new LetterPrinter(p);
t1.start();
t2.start();
}
@suzp1984
suzp1984 / FlipAnimation.kt
Last active March 5, 2017 14:41
FlipAnimation
package suzp1984.github.io.exapidemo.animation
import android.graphics.Camera
import android.view.animation.Animation
import android.view.animation.Transformation
class FlipAnimation(fromDegre: Float, toDegre: Float, centerX : Float, centerY : Float) : Animation() {
var fromDegree : Float = 0.0f
var toDegree : Float = 0.0f
val animation = FlipAnimation(startAngor, endAngor, 0.0f, flipCardView.height / 2.0f)
animation.duration = 1000
animation.interpolator = AccelerateInterpolator()
animation.fillAfter = true
animation.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationRepeat(animation: Animation?) {
}
override fun onAnimationEnd(animation: Animation?) {
// flipCardView.rotationY = endAngor
@suzp1984
suzp1984 / flipcard_animator.kt
Created March 5, 2017 14:23
object animator flip card effect
flipCardView.pivotX = 0.0f
flipCardView.pivotY = flipCardView.height / 2.0f
val animator = ObjectAnimator.ofFloat(flipCardView, "rotationY", startDeg, endDeg)
animator.setDuration(1000);
animator.interpolator = AccelerateInterpolator()
animator.start()
@suzp1984
suzp1984 / checkbox_layout.xml
Created May 10, 2017 15:05
checkbox layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.suzp1984.delegatetouchdemo.MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/box_container"
@suzp1984
suzp1984 / touch_delegate.kt
Created May 10, 2017 15:09
Touch Delegate sample
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val box1 = findViewById(R.id.checkbox1)
val box1Parent = findViewById(R.id.checkbox1_container)
val box2 = findViewById(R.id.checkbox2)
val box2Parent = findViewById(R.id.checkbox2_container)
@suzp1984
suzp1984 / fast_build.groovy
Last active September 15, 2017 09:44
android fast build 10 tips
# Tip 1: Use the lastes Android Gradle plugin
buildscript {
repositories {
jcenter()
maven { url 'http://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
}
@suzp1984
suzp1984 / gist:04e9c25990b3265eb1203ee7938c5e3b
Created November 23, 2017 02:26
add google's maven repo after android gradle plugin 3.0.1
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@suzp1984
suzp1984 / audio.swift
Last active November 24, 2019 23:06
os x: get default audio input device
func getDefaultAudioInputDevice() -> AudioDeviceID? {
var audioInputDevice: AudioDeviceID = 0
var audioInputAddress = AudioObjectPropertyAddress(
mSelector: kAudioHardwarePropertyDefaultInputDevice,
mScope: kAudioObjectPropertyScopeGlobal,
mElement: kAudioObjectPropertyElementMaster)
var propertySize = UInt32(MemoryLayout.size(ofValue: audioInputDevice))
if AudioObjectGetPropertyData(AudioObjectID(kAudioObjectSystemObject),
@suzp1984
suzp1984 / listenAudioInput.swift
Created November 24, 2019 23:17
os x: listen default audio device changed
func listenDefaultAudioInputDeviceChanged() {
var audioInputAddress = AudioObjectPropertyAddress(
mSelector: kAudioHardwarePropertyDefaultInputDevice,
mScope: kAudioObjectPropertyScopeGlobal,
mElement: kAudioObjectPropertyElementMaster)
let status = AudioObjectAddPropertyListenerBlock(AudioObjectID(kAudioObjectSystemObject),
&audioInputAddress, DispatchQueue.main) {
inNumberAddress, inAddress in