Skip to content

Instantly share code, notes, and snippets.

View ekosp's full-sized avatar

Eko Setyo Purnomo ekosp

View GitHub Profile
@ekosp
ekosp / gist:c1bc60f71be24c8e0d9b9c532e5c5d3c
Created July 23, 2021 02:22 — forked from liminal/gist:8801401
Using adb over wifi with Android Tether device
# Set up adb to use tcpip port
adb tcpip 5555
# Default device ip when it's used as a portable hotspot
adb connect 192.168.43.1
# List connected devices
adb devices
@ekosp
ekosp / CutCopyPaste.java
Created May 25, 2021 05:44 — forked from guillermomuntaner/CutCopyPaste.java
EditText which notifies of Cut, Copy and Paste events via an attachable listener
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
/**
* Original:
* An EditText, which notifies when something was cut/copied/pasted inside it.
* @author Lukas Knuth
* @version 1.0
*
@ekosp
ekosp / haversine.kt
Created March 7, 2021 09:18 — forked from jferrao/haversine.kt
Kotlin implementation of the Haversine formula
class Geo(private val lat: Double, private val lon: Double) {
companion object {
const val earthRadiusKm: Double = 6372.8
}
/**
* Haversine formula. Giving great-circle distances between two points on a sphere from their longitudes and latitudes.
* It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the
* sides and angles of spherical "triangles".
@ekosp
ekosp / fragment.java
Created November 29, 2019 15:41 — forked from atoennis/fragment.java
WebViews automatically persist cookies into a android.webkit.CookieManager. Need to store cookies from a WebView into a java.net.CookieManager? Here's one way to do so.
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String cookieStr = CookieManager.getInstance().getCookie(url); // android.webkit.CookieManager
storeCookies(url, cookieStr);
return super.shouldOverrideUrlLoading(view, url);
}
// Convert cookie string into a list of cookies. Persist cookies in a java.net.CookieStore
@ekosp
ekosp / bottom_stroke.xml
Created November 23, 2019 03:18 — forked from CiTuX/bottom_stroke.xml
Android xml drawable with a bottom stroke
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="-6dp"
android:left="-6dp"
android:right="-6dp"
android:bottom="0dp">
<shape android:shape="rectangle">
<solid android:color="#88FFFF00"/>
@ekosp
ekosp / README.md
Created July 4, 2019 13:35 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

All hex value from 100% to 0% alpha:

@ekosp
ekosp / ImageCompression
Created February 15, 2019 07:14 — forked from vipulasri/ImageCompression
Whatsapp Like Image Compression
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.media.ExifInterface;
import android.os.AsyncTask;
import android.os.Environment;
@ekosp
ekosp / Connectivity.java
Created February 4, 2019 03:53 — forked from emil2k/Connectivity.java
Android utility class for checking device's network connectivity and speed.
/*
* Copyright (c) 2017 Emil Davtyan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@ekosp
ekosp / expand-collapse.java
Created January 17, 2019 13:47 — forked from ZkHaider/expand-collapse.java
Simple Expand / Collapse RecyclerView Item
public static class ExampleViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private int originalHeight = 0;
private boolean isViewExpanded = false;
private YourCustomView yourCustomView
public ExampleViewHolder(View v) {
super(v);
v.setOnClickListener(this);
@ekosp
ekosp / shadow.xml
Created January 17, 2019 06:40 — forked from lecho/shadow.xml
Android shadow drawable xml.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"