Skip to content

Instantly share code, notes, and snippets.

View androidovshchik's full-sized avatar
😺

Vlad androidovshchik

😺
View GitHub Profile
@geekykant
geekykant / hotspot_ip
Created July 17, 2019 13:37
Get Hotspot IP Address
private String getHotspotIpAddress() {
String ip = "";
try {
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (enumNetworkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = enumNetworkInterfaces
.nextElement();
Enumeration<InetAddress> enumInetAddress = networkInterface
.getInetAddresses();
@naddeoa
naddeoa / InputStreamUtil.kt
Created November 26, 2018 00:50
Copy input stream in Kotlin with progress
import java.io.InputStream
import java.io.OutputStream
fun InputStream.copyTo(out: OutputStream, onCopy: (totalBytesCopied: Long, bytesJustCopied: Int) -> Any): Long {
var bytesCopied: Long = 0
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
var bytes = read(buffer)
while (bytes >= 0) {
out.write(buffer, 0, bytes)
bytesCopied += bytes
/*
* Copyright (C) 2018 Square, Inc.
*
* 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
@addeeandra
addeeandra / AnyAdapter.kt
Last active November 12, 2022 16:37
Android - Kotlin Easy Adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
abstract class AnyAdapter<T>(val items: MutableList<T>) : RecyclerView.Adapter<AnyViewHolder<T>>() {
abstract fun getLayoutId(): Int
abstract fun onCreateViewHolder(view: View): AnyViewHolder<T>
@micer
micer / RealPathUtil.kt
Last active April 18, 2021 01:21
Utility class to get real path from URI object - all API versions
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.support.v4.content.CursorLoader
import android.text.TextUtils
@gvr23
gvr23 / fragmentDialogFullScreen.java
Last active July 31, 2018 07:17
Create a Dialog Fragment Full Screen
ANDROID
THIS IS THE ACTIVITY CLASS
=============================================================================================================================
public class AyudaEntelDialog extends android.support.v4.app.DialogFragment{
private ImageView ivExit;
private VideoView vvTutorial;
private View rootView;
@thackerronak
thackerronak / AESHelper.java
Last active September 5, 2024 16:35 — forked from armanso/AES.java
AES encryption/decryption in crypto-js way, use KDF for generating IV and Key, use CBC with PKCS7Padding for Cipher
import com.sun.jersey.core.util.Base64;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;
import javax.crypto.BadPaddingException;
@vestrel00
vestrel00 / Dagger2SimpleExample.java
Last active October 7, 2021 19:59
A: Dagger.android 2.11 simple example with support for Singleton, PerActivity, PerFragment, and PerChildFragment scopes
// This is a super simplified example of how to use the new dagger.android framework
// introduced in Dagger 2.10. For a more complete, in-depth guide to dagger.android
// read https://proandroiddev.com/how-to-android-dagger-2-10-2-11-butterknife-mvp-part-1-eb0f6b970fd
// For a complete codebase using dagger.android 2.11-2.17, butterknife 8.7-8.8, and MVP,
// see https://github.com/vestrel00/android-dagger-butterknife-mvp
// This example works with Dagger 2.11-2.17. Starting with Dagger 2.11,
// @ContributesAndroidInjector was introduced removing the need to define @Subcomponent classes.
@tinmegali
tinmegali / AppDatabse.kt
Last active January 12, 2023 13:44
Android Room @TypeConverter using Kotlin
@Database(entities = arrayOf(Note::class, User::class), version = 1)
@TypeConverters(Converters::class)
abstract class AppDatabse : RoomDatabase() {
abstract fun userDAO(): UserDAO
abstract fun noteDAO(): NoteDAO
}
@dlimpid
dlimpid / string-md5.kt
Created July 7, 2017 09:34
Get MD5 hash of the string (of length 32, with leading zeros) in Kotlin
import java.math.BigInteger
import java.security.MessageDigest
fun String.md5(): String {
val md = MessageDigest.getInstance("MD5")
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
}