Skip to content

Instantly share code, notes, and snippets.

View kyze8439690's full-sized avatar
📱
Working

Yang Hui kyze8439690

📱
Working
View GitHub Profile
@kyze8439690
kyze8439690 / ActivityLifecycleLogger.java
Last active January 12, 2016 03:57
Activity Lifecycle Logger, not support onActivityResult()
//call if(BuildConfig.DEBUG) registerActivityLifecycleCallbacks(new ActivityLifecycleLogger()) in your own Application class.
public class ActivityLifecycleLogger implements Application.ActivityLifecycleCallbacks {
private static final String TAG = "LifeCycleLogger";
private static final Class[] LOG_CYCLE_ACTIVITIES = new Class[] {
//add activities you want to log here
MainActivity.class
};
@kyze8439690
kyze8439690 / PermissionUtils
Created February 3, 2016 09:03
android 6.0 request permission callback pattern
import android.app.Activity;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.ActivityCompat;
import java.util.Map;
GetObjectClass -> DeleteLocalRef
FindClass -> DeleteLocalRef
NewString -> DeleteLocalRef
NewStringUTF -> DeleteLocalRef
NewObject -> DeleteLocalRef
NewBooleanArray -> DeleteLocalRef
NewByteArray -> DeleteLocalRef
NewCharArray -> DeleteLocalRef
NewShortArray -> DeleteLocalRef
NewIntArray -> DeleteLocalRef
@kyze8439690
kyze8439690 / watch-fds.sh
Created April 16, 2021 09:32 — forked from jhansche/watch-fds.sh
Simple script to monitor the number open file descriptors for an Android application.
#!/bin/sh
# Usage: ./watch-fds.sh <application_id> [delay_secs = 5]
APP_ID=${1:?missing application id}
DELAY=$(( ${2:-5} ))
DEVICE_LIMIT=$(( $(adb shell ulimit -n) ))
WARN_THRESHOLD=$(( ${DEVICE_LIMIT} / 3 ))
echo "Will warn at ${WARN_THRESHOLD}"
@kyze8439690
kyze8439690 / build.gradle.kts
Created December 21, 2021 16:08
Protobuf gradle plugin with gradle kotlin dsl
import com.google.protobuf.gradle.*
plugins {
id("com.google.protobuf") version "0.8.18"
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.19.1"
}
@kyze8439690
kyze8439690 / SettingFragment.kt
Created February 9, 2022 16:50
Get itemView in androidx.preference.PreferenceFragmentCompat
findPreference<Preference>(getString(R.string.setting_settings_key))
?.setOnPreferenceClickListener { pref ->
@SuppressLint("RestrictedApi")
if (listView.adapter is PreferenceGroupAdapter) {
val adapter = listView.adapter as PreferenceGroupAdapter
val position = adapter.getPreferenceAdapterPosition(pref)
if (position != RecyclerView.NO_POSITION) {
val itemView = listView.findViewHolderForAdapterPosition(position)?.itemView
if (itemView != null) {
// do something