Skip to content

Instantly share code, notes, and snippets.

View ntlv's full-sized avatar

Love Lindström ntlv

  • Stockholm, Sweden
View GitHub Profile
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ntlv
ntlv / debugview.kt
Created March 20, 2021 16:41
debug view that draws a cross hair in its middle and draws another cross hair at a designated location
class DebugView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
var debugPoint = PointF(0f, 0f)
set(value) {
field = value
invalidate()
@ntlv
ntlv / bfs_view_tree_to_json.java
Created August 30, 2016 11:51
Transform a Android view tree into a json tree.
//Breadth first view tree -> json transformation
private static final String CHILDREN = "children";
@SuppressWarnings("unchecked")
private Object extract(ViewGroup container) throws JSONException {
final Map<String, Object> result = new HashMap<>(); //create root node
List<Object> currentNodeList = new LinkedList<>();

Keybase proof

I hereby claim:

  • I am ntlv on github.
  • I am ntlv (https://keybase.io/ntlv) on keybase.
  • I have a public key whose fingerprint is 3FFB 6691 6CAB FA1B E10D 3853 7909 D311 2298 F4A3

To claim this, I am signing this object:

@ntlv
ntlv / MainActivity.java
Last active January 1, 2016 13:29
show a fragment
private void showFragmentRoutine(Class<?> fragment, String tag) {
try {
FragmentManager fm = getFragmentManager();
if (fm.findFragmentByTag(tag) != null) {
fm.popBackStack(tag, 0);
} else {
fm.beginTransaction()
.replace(R.id.container, (Fragment) Class.forName(fragment.getName()).newInstance(), tag)
.addToBackStack(tag)
.commit();