Skip to content

Instantly share code, notes, and snippets.

@minibugdev
minibugdev / WrapGridLayoutManager.java
Created November 11, 2015 05:57 — forked from ArthurSav/WrapGridLayoutManager.java
GridLayoutManager with working wrap_content.
package com.inperson.android.utils.leastview;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public class WrappableGridLayoutManager extends GridLayoutManager {
package com.example.hellorx;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
abstract class Validator() {
var errorListener: OnErrorListener? = null
var validateValue: Any? = null
protected abstract fun hasError(): Boolean
fun validate(): Boolean {
if (hasError()) {
errorListener?.onError()
return false
// 1st by "const"
@file:JvmName("Url")
const val URL_BASE: String = "http://github.com"
const val URL_USER: String = "$URL_BASE/user"
// 2nd by "companion"
class Url {
companion object {
@JvmField val URL_BASE: String = "http://github.com"
@JvmField val URL_USER: String = "$URL_BASE/user"
@minibugdev
minibugdev / gist:fad4ba5ea93d2fb0530e054359a198ef
Created August 22, 2016 09:45 — forked from dodyg/gist:5823184
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.

public class CookieApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
CookieHandler defaultHandler = CookieHandler.getDefault();
if (defaultHandler == null) {
CookieHandler.setDefault(new CookieManager(new PersistentCookieStore(this), CookiePolicy.ACCEPT_ALL));
}
// สร้าง Observable ของ API
var observable = service.getWeather(CITY_NAME, getString(R.string.api_key))
// Delay 1 วินาทีเพื่อให้ API ทำงานช้ากว่า Cache เพื่อให้เห็นภาพการทำงานง่ายขึ้น
.delay(1L, java.util.concurrent.TimeUnit.SECONDS)
// เขียนข้อมูลลง Realm
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.map { this.writeToRealm(it) }
private fun findInRealm(realm: Realm, name: String): WeatherRealm? {
return realm.where(WeatherRealm::class.java)
.equalTo(FIELD_CITY_NAME, name)
.findFirst()
}
open class WeatherRealm : RealmObject() {
@PrimaryKey
var name: String? = null
var temp: Double? = null
}
interface WeatherService {
@GET("weather?units=metric")
fun getWeather(@Query("q") city: String, @Query("appid") apiKey: String): Observable<WeatherResponse>
}