sudo kill -9 `ps ax|grep 'coreaudio[a-z]' | awk '{print $1}'`
经常遇到 macOS 在 Zoom 或者飞书语音时连着的 AirPods 怎么都没办法用,重启下音频服务就行了。
垃圾苹果
| /** | |
| * 直接接收 ByteArray 作为数据来源的 okio Source 实现 | |
| */ | |
| class ByteBufferSource : Source { | |
| private val buffer = Buffer() | |
| private val queue: BlockingQueue<ByteArray> = ArrayBlockingQueue(1024) | |
| private val isClosed = AtomicBoolean(false) | |
| fun onDataReceived(data: ByteArray) { | |
| queue.put(data) |
| fun RepositoryHandler.enableMirror() { | |
| all { | |
| if (this is MavenArtifactRepository) { | |
| val originalUrl = this.url.toString().removeSuffix("/") | |
| urlMappings[originalUrl]?.let { | |
| logger.lifecycle("Repository[$url] is mirrored to $it") | |
| this.setUrl(it) | |
| } | |
| } | |
| } |
| # Library 定义 | |
| [libraries] | |
| # AndroidX 系列 | |
| androidx-core = "androidx.core:core:1.13.1" | |
| androidx-legacy = "androidx.legacy:legacy-support-v4:1.0.0" | |
| androidx-fragment = "androidx.fragment:fragment-ktx:1.8.3" | |
| androidx-appcompat = "androidx.appcompat:appcompat:1.7.0" | |
| androidx-recyclerview = "androidx.recyclerview:recyclerview:1.3.2" | |
| androidx-transition = "androidx.transition:transition:1.5.1" |
sudo kill -9 `ps ax|grep 'coreaudio[a-z]' | awk '{print $1}'`
经常遇到 macOS 在 Zoom 或者飞书语音时连着的 AirPods 怎么都没办法用,重启下音频服务就行了。
垃圾苹果
| class SingleLiveEvent<T> : MutableLiveData<T>() { | |
| private val observers = CopyOnWriteArraySet<ObserverWrapper<T>>() | |
| @MainThread | |
| override fun observe(owner: LifecycleOwner, observer: Observer<T>) { | |
| val wrapper = ObserverWrapper(observer) | |
| observers.add(wrapper) | |
| super.observe(owner, wrapper) | |
| } |
| class KeyboardVisibilityListener( | |
| private val activity: Activity, | |
| private val rootLayout: ViewGroup, | |
| private val listener: (isShow: Boolean) -> Unit | |
| ) { | |
| private val keyboardLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { | |
| val heightDiff = rootLayout.rootView.height - rootLayout.height | |
| val contentViewTop = activity.window.findViewById<View>(ID_ANDROID_CONTENT).top | |
| listener(heightDiff > contentViewTop) | |
| } |
defaultConfig 下添加:
consumerProguardFiles 'proguard-rules.pro'
或者也可以在特定的配置下
| fun generateNonce(size: Int): String { | |
| val nonceScope = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| val scopeSize = nonceScope.length | |
| val nonceItem: (Int) -> Char = { nonceScope[(scopeSize * Math.random()).toInt()] } | |
| return Array(size, nonceItem).joinToString("") | |
| } |
在 Java 中经常会用到 public/protected/private 来修饰一个成员变量或者方法。public、private 的含义相当明确,前者代表无论何时都可以在任何地方引用这个变量或方法,而后者代表只要在类之外,一概不允许引用这个变量或方法。而 protected 我们一开始被告知它是让成员在包内可见的,然而另外一个特性经常被选择性忽略,就是它能让这个成员可在包外的子类访问。例如我们定义下面这个类:
package com.example.package1;
public class A {
void defaultMethod() {
//...
}
很多上传操作需要文件对象或者 byte 数组,但是 Uri 获取文件对象是不方便的(content 类型的 Uri),但是相对于获取 InputStream 是方便的:
InputStream iStream = getContentResolver().openInputStream(uri);
byte[] inputData = getBytes(iStream);然后 InputStream 获取目标文件的 bytes