Skip to content

Instantly share code, notes, and snippets.

@dodyg
dodyg / gist:5823184
Last active July 26, 2024 14:33
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@staltz
staltz / introrx.md
Last active August 1, 2024 08:51
The introduction to Reactive Programming you've been missing
@daniellevass
daniellevass / android_material_design_colours.xml
Last active June 5, 2024 13:54
Android Material Design Colours
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>
@vedant1811
vedant1811 / Spinner.java
Created January 6, 2015 19:16
Custom Spinner to differentiate between user selected and prorammatically selected item. Make sure to call correct method to use this feature
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
/**
* Used this to differentiate between user selected and prorammatically selected
* Call {@link Spinner#programmaticallySetPosition} to use this feature.
* Created by vedant on 6/1/15.
@lopspower
lopspower / KeyboardUtils.java
Last active July 6, 2023 13:35
Force Hide Keyboard Android
import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
public class KeyboardUtils {
public static void hideKeyboard(Activity activity) {
View view = activity.findViewById(android.R.id.content);
@hackjutsu
hackjutsu / ObjectWaitNotifyExample.java
Last active February 28, 2018 10:17
[wait/notify/notifyAll] Example for Java Object's wait/notify/notifyAll #concurrency mechanism.
public class ObjectWaitNotifyExample {
private static final long SLEEP_INTERVAL_MS = 1000;
private boolean running = true;
private Thread thread;
public void start() {
print("Inside start()...");
thread = new Thread(new Runnable() {
@Override
public void run() {
@jaisonfdo
jaisonfdo / SocialConnection.java
Last active September 4, 2021 16:24
Connect social media account in a single line of code in Android.For more information, check out my detailed guide here : http://droidmentor.com/connect-social-media-account/
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.Toast;
/**
@jemshit
jemshit / proguard-rules.pro
Last active July 28, 2024 11:15
Proguard Rules for Android libraries
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
### RxJava, RxAndroid (https://gist.github.com/kosiara/487868792fbd3214f9c9)
-keep class rx.schedulers.Schedulers {
public static <methods>;
@adavis
adavis / CommonExtensions.kt
Last active April 2, 2024 20:51
Common Android Extensions in Kotlin
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.gone() {
visibility = View.GONE
@AgiMaulana
AgiMaulana / Adding Badge to BottomNavigationView
Created August 16, 2017 18:00
Adding badge (such as notification count) in bottom nav menu item on android
navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(this);
navigation.setSelectedItemId(R.id.navigation_store);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) navigation.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(2); // number of menu from left
new QBadgeView(this).bindTarget(v).setBadgeNumber(5);
/**
* compile 'q.rorbin:badgeview:1.1.2'
* https://github.com/qstumn/BadgeView