Skip to content

Instantly share code, notes, and snippets.

@tobrun
tobrun / generate_snapshot_version.py
Last active February 14, 2023 18:35
Script to automatically generate SNAPSHOT version if repository tags start with `v` naming
import subprocess
from datetime import datetime
# Get the ISO 8601 UTC datetime
now = datetime.utcnow()
iso_time = now.strftime('%Y%m%dT%H%M%SZ')
# Get the SHA of the latest commit
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip()[:7]
@tobrun
tobrun / Filter.kt
Last active June 14, 2021 11:13
Filter a layer
mapView.getMapboxMap().addOnMapClickListener { point ->
val queryRenderOptions = RenderedQueryOptions(arrayListOf("country-label"), null)
mapView.getMapboxMap().queryRenderedFeatures(
mapView.getMapboxMap().pixelForCoordinate(point),
queryRenderOptions
) {
val feature: Feature = it.getValueOrElse {
throw IllegalStateException()
}[0].feature
./gradlew -Pmapbox.abis=none :MapboxGLAndroidSDKTestApp:assembleAndroidTest
@tobrun
tobrun / adb_pull.sh
Last active September 25, 2017 19:04
A common issue that Android developers face with copying files between device and development machine is that the structure of the external storage folders can differ. A robust way of getting files through adb is using the EXTERNAL_STORAGE environment variable of the device as a base.
# below matches files saved to Environment.getExternalStorageDirectory() + "/from/path"
adb pull "`adb shell 'printenv EXTERNAL_STORAGE' | tr -d '\r'`/from/path
@tobrun
tobrun / SymbolGenerator.java
Last active February 7, 2021 14:46
SymbolGenerator allows to convert a Android SDK View to a Bitmap. Use SymbolGenerator in combination with SymbolLayer. Add the result from SymbolGenerator#generate(View) with MapboxMap#addImage(String, Bitmap) and link the id of the image with PropertyFactory#iconImage(String) when setting properties to a SymbolLayer with SymbolLayer#setProperti…
/**
* Utility class to generate Bitmaps for Symbol.
* <p>
* Bitmaps can be added to the map with {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}
* </p>
*/
public final class SymbolGenerator {
/**
* Generate a Bitmap from an Android SDK View.
/*
* Copyright (C) 2014 The Android Open Source Project
*
* 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
/*
* Copyright (C) 2014 Chris Banes
*
* 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
@tobrun
tobrun / gist:40b833e7879478190c0b
Created October 3, 2014 14:18
Tracking memory from command line
adb shell dumpsys meminfo <process name>
@tobrun
tobrun / gist:3043b8dc9e5cb01af37d
Created October 2, 2014 09:06
Disable screenshot
// DISABLE SCREENSHOT
getWindow().setFlags(LayoutParams.FLAG_SECURE,LayoutParams.FLAG_SECURE);
@tobrun
tobrun / gist:5ab43beee185ab792462
Last active August 29, 2015 14:06
Generic findViewById
public class ViewFinder {
@SuppressWarnings("unchecked")
public static <T extends View> T find(Activity activity, int id) {
return (T) activity.findViewById(id);
}
@SuppressWarnings("unchecked")
public static <T extends View> T find(Fragment fragment, int id) {
return (T) fragment.getView().findViewById(id);