Skip to content

Instantly share code, notes, and snippets.

View Bramengton's full-sized avatar

Konstantin Bramengton

  • Ukraine, Mykolaiv city
View GitHub Profile
@Bramengton
Bramengton / HashUtils.kt
Created December 25, 2023 11:58 — forked from LongClipeus/HashUtils.kt
How to generate checksum hash for a file in Kotlin
import StringUtils.encodeHex
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.security.MessageDigest
object HashUtils {
const val STREAM_BUFFER_LENGTH = 1024
@Bramengton
Bramengton / Ticker
Created November 3, 2021 20:30
CountDownTimer - a different look at the obvious!
package eld.trackensure.utilities;
import android.os.SystemClock;
import java.util.concurrent.TimeUnit;
import eld.trackensure.BuildConfig;
import timber.log.Timber;
public abstract class Ticker implements Runnable, AutoCloseable {
private static final String TAG = Ticker.class.getSimpleName();
package com.tom.utils;
import android.os.Environment;
import android.os.StatFs;
/**
* Created by Tom on 7/15/13.
* Some helper methods for FS queries.
*/
public class DiskUtils {
@Bramengton
Bramengton / android-7-localization.org
Created September 29, 2020 20:57 — forked from amake/android-7-localization.org
Correct localization on Android 7

Correct localization on Android 7

Prior to Android 7, the system had a single preferred locale, and fallback behavior was quite rudimentary. Starting with Android 7, the user can now specify a priority list of locales, and fallback behavior is improved.

However, in many cases it is still surprisingly difficult to make full use of locale fallback, and there are some hidden gotchas when trying to fully support both Android 7 and earlier versions.

@Bramengton
Bramengton / BluetoothCallback.java
Created January 14, 2020 13:24 — forked from joinAero/BluetoothCallback.java
Android - The bluetooth listener and profile proxy.
package cc.cubone.turbo.core.bluetooth;
/**
* Interface definition for a callback to be invoked when bluetooth state changed.
*/
public interface BluetoothCallback {
/**
* Called when the bluetooth is off.
*/
@Bramengton
Bramengton / ToastHelper.java
Last active May 20, 2019 08:46
Custom Android Toast, not system.
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import androidx.core.view.GravityCompat;
@Bramengton
Bramengton / websocketserver.py
Created May 13, 2019 15:17 — forked from mwielondek/websocketserver.py
Simple WebSocket server. Can be run independently or as a module import.
import struct
import SocketServer
import sys
from base64 import b64encode
from hashlib import sha1
from mimetools import Message
from StringIO import StringIO
DEFAULT_PORT = 9999
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.text.Editable;
import android.util.AttributeSet;
import android.util.TypedValue;
@Bramengton
Bramengton / SpannableUrl.java
Created March 1, 2019 12:51
SpannableUrl - A simple way to show/select/click url links from HTML text on TextView #TextView #URL
/**
* @author Bramengton on 01.03.19.
* HTML text: <string name="text_html"><![CDATA[This is link <a href=http://google.com>Google</a>]]></string>
* HOW TO USE: setTextViewHTML((TextView) findViewById(R.id.link), getString(R.string.text_html));
*/
public class SpannableUrl extends SpannableStringBuilder {
public OnLinkClickListener mListener;
public interface OnLinkClickListener{
void onClick(URLSpan span);
}
@Bramengton
Bramengton / matrixScaling.md
Created February 5, 2019 09:53 — forked from vxhviet/matrixScaling.md
Android scale bitmap with the highest quality

Source: StackOverflow

Question: How to scale Bitmap without losing much quality

Answer: Use Matrix instead of Bitmap.createScaledBitmap()

    /**
     * @param bitmap the Bitmap to be scaled
     * @param threshold the maxium dimension (either width or height) of the scaled bitmap