Skip to content

Instantly share code, notes, and snippets.

View darwind's full-sized avatar

Kasper Rugård Thomsen darwind

  • rugaard.it
  • Copenhagen
View GitHub Profile
@darwind
darwind / gist:4bd71c410a593a6eb136bf5b83c07a80
Created September 30, 2019 13:54
Custom tooltip (PopupWindow)
Create and show tooltip right above BottomNavigationBar:
val popup = PopupWindow(this@MainActivity).apply {
ItemPopupBinding.inflate(LayoutInflater.from(this@MainActivity)).apply {
contentView = this.root
root.setOnClickListener {
dismiss()
}
}
#1. Create a file: adb_restart.sh and put these lines in:
#!/bin/sh
adb kill-server
adb start-server
adb devices
#2. Make the bashscript executable:
chmod a+x adb_restart.sh
@darwind
darwind / AndroidManifest.xml
Created March 20, 2017 22:30
ViewPager with WebViews that shows individual ProgressBars for each WebView when it's loading
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loadingview">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
@darwind
darwind / gist:8bba058aa495c178a66fd744ad7b39b2
Last active June 1, 2016 23:42
Circular reveal splashscreen
**MainActivity**
package it.rugaard.circularreveal;
public class MainActivity extends AppCompatActivity {
private boolean isRevealed;
@Override
protected void onCreate(Bundle savedInstanceState) {
@darwind
darwind / gist:0faf46c4bf0394a6dd10
Last active February 23, 2016 10:19
RGBA - Opacities
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
@darwind
darwind / FizzBuzz
Created November 4, 2015 23:36
I read about this test on Quora and just wanted to see if I was actually a real programmer... ;-)
public class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if ((i % 5 == 0) && (i % 3 == 0)) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
System.out.println("Buzz");
} else {
@darwind
darwind / gist:32458409aeac7c945784
Created May 3, 2015 19:23
Android screenresolutions
List of good posts about Android screenresolutions:
http://stackoverflow.com/questions/6272384/most-popular-screen-sizes-resolutions-on-android-phones
http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/
More to come...
@darwind
darwind / gist:02f5bea23338af53ab42
Created March 16, 2015 19:42
Android: load bitmap from Drawable
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource);
@darwind
darwind / gist:773f6abf703b5ec18583
Created March 14, 2015 20:16
Android: sharing photos to Facebook
Uri myImageContentUri; // A content Uri to the image you would like to share.
String myAppId = "<Your_Facebook_App_Id>";
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, myImageContentUri);
// Include your Facebook App Id for attribution
shareIntent.putExtra("com.facebook.platform.extra.APPLICATION_ID", myAppId);
@darwind
darwind / gist:5a6101667b5304d79b9a
Last active July 27, 2016 10:43
Get Android keyhash programatically...
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo("my.app.packagename",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {