Skip to content

Instantly share code, notes, and snippets.

View dokinkon's full-sized avatar

chaochih.lin dokinkon

  • freelance
  • Taiwan
View GitHub Profile
@dokinkon
dokinkon / activity.kt
Last active December 4, 2020 02:10
suspend activityForResult
/**
* Wraps the parameters of onActivityResult
*
* @property resultCode the result code returned from the activity.
* @property data the optional intent returned from the activity.
* @since 0.0.3
*/
data class ActivityResult(
val requestCode: Int,
val resultCode: Int,
fun exampleOfAudioFocus() {
// AUDIOFOCUS_GAIN : 嘗試取得非特定時間長度的Audio focus
// AUDIOFOCUS_GAIN_TRANSIENT, 取得一個短時間的focus,例如導航的提示音
// AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, 取得一個短時間的focus,但是可以跟其他App播放的聲音一起播放,例如導航的提示音,蓋在背景音樂上
// AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE, 預期取得一個獨佔的focus,佔有這個focus的期間,其他App應該安靜,例如語音筆記或是語音辨識
// 要播放聲音前,先取得Audio focus
// Audio focus改變時,會透過Listener通知
val gain = AudioManager.AUDIOFOCUS_GAIN
val request = AudioFocusRequest.Builder(gain)
@dokinkon
dokinkon / build.gradle
Created November 13, 2018 06:42
* Kotlin: Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
android {
compileSdkVersion 28
...
/**
* 解決:
* Kotlin: Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
* 參考:
* https://stackoverflow.com/a/52561908/307442
@dokinkon
dokinkon / createApiService.kt
Created November 11, 2018 00:50
Retrofit如何避免multipart-form-data中的參數被雙引號夾起來
inline fun <reified T> createWebService(okHttpClient: OkHttpClient, url: String): T {
val retrofit = Retrofit.Builder()
.baseUrl(url)
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create()) // <--- 避免產生雙引號在multipart-formdata的參數中
.addConverterFactory(GsonConverterFactory.create()) // <-- ScalarsConverterFactory要放在GsonConverterFactory之前
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build()
return retrofit.create(T::class.java)
}
@dokinkon
dokinkon / Example.java
Last active February 4, 2017 05:32
搭配Dagger2的做法
public class RxBusExample {
RxBus bus = RxBus.getInstance();
bus.post();
}
@dokinkon
dokinkon / PlayServicesUtils.java
Last active February 4, 2017 05:20
檢查Play Service在裝置上的可用性 (Deprecated)
public class PlayServicesUtils {
public static boolean checkGooglePlayServices(final Activity activity) {
final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
switch (googlePlayServicesCheck) {
case ConnectionResult.SUCCESS:
return true;
case ConnectionResult.SERVICE_DISABLED:
case ConnectionResult.SERVICE_INVALID:
case ConnectionResult.SERVICE_MISSING:
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
public class RxMediaRecorder {
public enum State {
INITIAL("initial"),
INITIALIZED("initialized"),
DATASOURCE_CONFIGURED("data_source_configured"),
PREPARED("prepared"),
RECORDING("recording"),
STOPPED("stopped"),
PAUSED("paused"),
PLAYBACK_COMPLETED("completed"),
public class RxKeyboardVisibilityDetector {
public final static class Change {
public final boolean visible;
public final int height;
Change(boolean visible, int height) {
this.visible = visible;
this.height = height;
}
@Override
public String toString() {
public class RxMediaPlayer {
public static final int DEFAULT_SAMPLING_MILLIS = 33;
public enum State {
IDLE("idle"),
INITIALIZED("initialize"),
PREPARING("preparing"),
PREPARED("prepared"),
STARTED("started"),
STOPPED("stopped"),
PAUSED("paused"),
<?xml version="1.0" encoding="utf-8"?>
<com.siegfried.myapplication.CustomKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:keyBackground="@drawable/keyboard_background"
android:background="@drawable/keyboard_background">
</com.siegfried.myapplication.CustomKeyboardView>