Skip to content

Instantly share code, notes, and snippets.

View Zaherkorechi's full-sized avatar

Zaher Abd Ulmoula Zaherkorechi

View GitHub Profile
@fingerboxes
fingerboxes / IPAddressText.java
Last active April 8, 2024 12:56
Android widget for inputting numeric IP addresses
/**
* EditText that only allows input of IP Addresses, using the Phone
* input type, and automatically inserts periods at the earliest appropriate
* interval.
*/
// Note; this probably isn't the best pattern for this - a Factory of Decorator
// pattern would have made more sense, rather than inheritance. However, this
// pattern is consistent with how other android Widgets are invoked, so I went
// with this to prevent confusion
@vs-krasnov
vs-krasnov / geo.kt
Created November 25, 2018 17:14
Simple function to calculate a new point's latitude and longitude based on provided start point, bearing and distance.
fun getPointByDistanceAndBearing(lat: Double, lon: Double, bearing: Double, distanceKm: Double): Pair<Double, Double> {
val earthRadius = 6378.1
val bearingR = Math.toRadians(bearing)
val latR = Math.toRadians(lat)
val lonR = Math.toRadians(lon)
val distanceToRadius = distanceKm / earthRadius
@dnanib
dnanib / ViewScreenshot.java
Created August 19, 2020 06:45
A small Java class to take a screenshot of a View in Android
package com.example.lib.screenshots;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Handler;
import android.view.PixelCopy;
import android.view.View;