Skip to content

Instantly share code, notes, and snippets.

@kohendrix
kohendrix / index.js
Created February 5, 2019 08:51
Babel + es6 + Nodemon sample
'use strict';
var p = console.log;
import obj from './test_module';
(function() {
p('obj', obj);
try {
p('circleArea', obj.circleArea(5));
@kohendrix
kohendrix / MyAlertDialog.kt
Created February 2, 2019 04:32
DialogFragment sample
class MyAlertDialog: DialogFragment(){
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(activity)
.setMessage("Hello")
.setPositiveButton("OK") { _,_ -> dismiss() }
.create()
}
}
@kohendrix
kohendrix / MainActivity.kt
Created February 2, 2019 04:25
ReproSample ReproTrigger version
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onResume() {
super.onResume()
Handler().postDelayed({
@kohendrix
kohendrix / MainActivity.kt
Created February 2, 2019 04:23
ReproSample
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onResume() {
super.onResume()
Repro.track("main_open") // send tracking
class DeepLinkTargetTWOActivity : AppCompatActivity() {
companion object {
const val EXTRA_TEXT = "text"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_deeplink_two)
findViewById<TextView>(R.id.tv_to_replace).text = intent.getStringExtra(EXTRA_TEXT) ?: "text not passed"
}
class DeepLinkTargetONEActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_deeplink_one)
}
}
@kohendrix
kohendrix / AndroidManifest.xml
Created February 2, 2019 04:15
ReproSample
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.koheiando.reprosample">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".ReproApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@kohendrix
kohendrix / VolleyTestClasses.kt
Created February 2, 2019 04:08
Volley Coroutines Sample
class TestRequest : HttpRequest() {
companion object {
private const val HEADER_AUTHORIZATION_KEY = "Authorization"
private const val QUERY_KEY = "q"
}
override val method: Int = Request.Method.GET
override val url: String = "https://www.testrequestforfun.com"
override val queryParams: Map<String, String> = mapOf(QUERY_KEY to "paramTest")
@kohendrix
kohendrix / VolleyRequest.kt
Created February 2, 2019 04:06
Volley Coroutines Sample request() coroutines
suspend fun request(method: Int, url: String, headers: Map<String, String>, jsonRequest: JSONObject?): JSONObject {
return suspendCancellableCoroutine { continuation ->
val success = Response.Listener<JSONObject> { response -> continuation.resume(response) }
val error = Response.ErrorListener { error -> continuation.resumeWithException(error) }
val request = object : JsonObjectRequest(method, url, jsonRequest, success, error) {
override fun getHeaders(): Map<String, String> = headers
override fun parseNetworkError(volleyError: VolleyError): VolleyError {
return volleyError.networkResponse?.let {
@kohendrix
kohendrix / VolleyRequest.kt
Created February 2, 2019 04:05
Volley Coroutines Sample request() no coroutines
fun request(method: Int, url: String, headers: Map<String, String>, jsonRequest: JSONObject?,
successListener: (json: JSONObject) -> Unit, errorListener: (error: Exception) -> Unit) {
val request = object : JsonObjectRequest(method, url, jsonRequest,
Response.Listener<JSONObject> { json -> successListener(json) },
Response.ErrorListener { e -> errorListener(e) }) {
override fun getHeaders(): Map<String, String> = headers
override fun parseNetworkError(volleyError: VolleyError): VolleyError {
return volleyError.networkResponse?.let {
Log.e("VolleyRequest", volleyError.networkResponse.headers.toString())