Skip to content

Instantly share code, notes, and snippets.

View vbuberen's full-sized avatar
🛠️

Volodymyr Buberenko vbuberen

🛠️
View GitHub Profile
@vbuberen
vbuberen / conditional_parent_widget.dart
Last active December 24, 2021 21:31 — forked from ltOgt/conditional_parent_widget.dart
Flutter Widget to conditionally wrap a subtree with some parent widget
import 'package:flutter/widgets.dart';
/// Conditionally wrap a subtree with a parent widget.
///
/// [isParentWidgetNeeded]: the condition depending on which the subtree [child] is wrapped with the parent.
/// [child]: The subtree that should always be build.
/// [conditionalBuilder]: builds the parent wrapping the subtree [child].
///
/// ___________
/// Usage:
@vbuberen
vbuberen / dependabot.yml
Last active July 20, 2020 09:46
Basic Dependabot config
version: 2
updates:
- package-ecosystem: gradle
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
@vbuberen
vbuberen / dependabot.yml
Created July 19, 2020 16:46
Dependabot config in Chucker library
version: 2
updates:
# Updates for Github Actions used in the repo
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
# Updates for Gradle dependencies used in the app
- package-ecosystem: gradle
directory: "/"
@vbuberen
vbuberen / Compass.kt
Last active February 10, 2020 11:57
Compass rotation animation for Android View
private var currentAzimuth = TRUE_NORTH
private fun animateArrow(newDegreesValue: Float) {
var from = currentAzimuth
var to = newDegreesValue
val min = from.coerceAtMost(to)
if (abs(to - from) > HALF_CIRCLE) {
if (min == from) {
@vbuberen
vbuberen / Extentsions.kt
Created November 3, 2019 12:10
Extension function, which helps to forget about `ActivityNotFoundException` in your Android apps.
// It is better to use dialogs with detailed description of error, but for clarity of this gist I decided to use Toasts here
fun Context.startIntentOrShowError(intent: Intent,
errorDialogDescription: String,
errorDialogTitle: String = "No app found!") {
if (intent.resolveActivity(this.packageManager) != null) {
when (intent.resolveActivityInfo(this.packageManager, intent.flags).exported) {
true -> startActivity(intent)
else -> Toast.makeText(this, errorDialogTitle, Toast.LENGHT_SHORT).show()
}
} else {
@vbuberen
vbuberen / ImageRotationRestore.kt
Last active September 4, 2018 12:35
Image rotation restore for devices with physically rotated camera
@Throws(IOException::class)
private fun restoreBitmapRotation(bitmapFile: File): Bitmap {
val exif = ExifInterface(Uri.fromFile(bitmapFile).path)
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
val rotationAngle = when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> 90f
ExifInterface.ORIENTATION_ROTATE_180 -> 180f
ExifInterface.ORIENTATION_ROTATE_270 -> 270f
else -> 0f
@vbuberen
vbuberen / MaskImageTransformation.kt
Created December 18, 2017 23:36
Glide v4 mask transformation. Supports vector drawables as mask drawable for transformation.
import android.graphics.*
import android.graphics.drawable.Drawable
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import java.io.UnsupportedEncodingException
import java.security.MessageDigest
class MaskImageTransformation(private val mask: Drawable) : BitmapTransformation() {
override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
@vbuberen
vbuberen / CircleTransformation.java
Created October 12, 2016 09:55
ImageCircleTransformation
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
public class CircleTransform extends BitmapTransformation {
@vbuberen
vbuberen / ImageRotationRestore.java
Last active September 4, 2018 12:34
Image rotating method for restoring correct image rotations on devices with physically rotated camera
private Bitmap restoreRotation(File originalFile) throws IOException {
int rotationAngle;
ExifInterface ei = new ExifInterface(Uri.fromFile(originalFile).getPath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotationAngle = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180: