Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RelativeLayout layout = (RelativeLayout) findViewById(R.id.rel); | |
GradientDrawable drawable = new GradientDrawable(); | |
drawable.setColors(new int[] { | |
Color.parseColor("#FFF6B7"), | |
Color.parseColor("#F6416C") | |
}); | |
drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); | |
drawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has | |
* already been handled. | |
* | |
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled. | |
*/ | |
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> { | |
override fun onChanged(event: Event<T>?) { | |
event?.getContentIfNotHandled()?.let { value -> | |
onEventUnhandledContent(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import okhttp3.OkHttpClient | |
import java.security.cert.CertificateException | |
import javax.net.ssl.SSLContext | |
import javax.net.ssl.TrustManager | |
import javax.net.ssl.X509TrustManager | |
class UnsafeOkHttpClient { | |
companion object { | |
fun getUnsafeOkHttpClient(): OkHttpClient.Builder { | |
try { |