Skip to content

Instantly share code, notes, and snippets.

View agap's full-sized avatar
🏠
Working from home

Artem Gapchenko agap

🏠
Working from home
View GitHub Profile
fun startScans() {
BluetoothAdapter
.getDefaultAdapter()
.bluetoothLeScanner
.startScan(
object : ScanCallback() {
override fun onScanFailed(errorCode: Int) {
// todo handle scan failure
}
2019-10-25 18:46:08.398 3037-18057/? D/HostEmulationManager: notifyHostEmulationActivated
2019-10-25 18:46:08.401 3037-18057/? D/HostEmulationManager: notifyHostEmulationData
2019-10-25 18:46:08.402 3037-18057/? D/HostEmulationManager: Service already bound as regular service.
2019-10-25 18:46:08.402 3037-18057/? D/HostEmulationManager: Waiting for new service.
2019-10-25 18:46:09.184 3037-18057/? D/HostEmulationManager: notifyHostEmulationDeactivated
2019-10-25 19:19:31.587 3046-3506/? D/HostEmulationManager: notifyHostEmulationActivated
2019-10-25 19:19:31.588 3046-3506/? D/HostEmulationManager: notifyHostEmulationData
2019-10-25 19:19:31.588 3046-3506/? D/HostEmulationManager: Binding to service ComponentInfo{service name omitted}
2019-10-25 19:19:31.592 3046-3506/? D/HostEmulationManager: Waiting for new service.
2019-10-25 19:19:31.605 3046-3046/? D/HostEmulationManager: Service bound
2019-10-25 19:19:31.610 3046-3046/? D/HostEmulationManager: Sending data
2019-10-25 19:19:31.654 3046-3506/? D/HostEmulationManager: notifyHostEmulationData
2019-10-25 19:19:31.658 3046-3046/? D/HostEmulationManager: Sending data
2019-10-25 19:19:31.685 3046-3506/? D/HostEmulationManager: notifyHostEmulationData
2019-10-25 19:19:31.697 3046-3046/? D/HostEmulationManager: Sending data
@Nullable
protected String createStackElementTag(@NotNull StackTraceElement element) {
String tag = element.getClassName();
Matcher m = ANONYMOUS_CLASS.matcher(tag);
if (m.find()) {
tag = m.replaceAll("");
}
tag = tag.substring(tag.lastIndexOf('.') + 1);
// Tag length limit was removed in API 24.
if (tag.length() <= MAX_TAG_LENGTH || Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@Override final String getTag() {
String tag = super.getTag();
if (tag != null) {
return tag;
}
// DO NOT switch this to Thread.getCurrentThread().getStackTrace(). The test will pass
// because Robolectric runs them on the JVM but on Android the elements are different.
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
if (stackTrace.length <= CALL_STACK_INDEX) {
/** Set a one-time tag for use on the next logging call. */
@NotNull
public static Tree tag(String tag) {
Tree[] forest = forestAsArray;
//noinspection ForLoopReplaceableByForEach
for (int i = 0, count = forest.length; i < count; i++) {
forest[i].explicitTag.set(tag);
}
return TREE_OF_SOULS;
}
@Nullable
String getTag() {
String tag = explicitTag.get();
if (tag != null) {
explicitTag.remove();
}
return tag;
}
private void prepareLog(int priority, Throwable t, String message, Object... args) {
// Consume tag even when message is not loggable so that next message is correctly tagged.
String tag = getTag();
if (!isLoggable(tag, priority)) {
return;
}
// some code omitted for brevity
/** Log a debug message with optional format args. */
public void d(String message, Object... args) {
prepareLog(Log.DEBUG, null, message, args);
}
@agap
agap / MainActivity.kt
Created October 5, 2019 09:50
Sample Activity for View Binding Test
package aga.android.viewbindingtest
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import butterknife.BindView
import butterknife.ButterKnife