Skip to content

Instantly share code, notes, and snippets.

View LiewJunTung's full-sized avatar

Liew Jun Tung LiewJunTung

View GitHub Profile
@LiewJunTung
LiewJunTung / RenderScriptRgbToYuvConversion.kt
Created December 21, 2018 07:24
Convert YUV to RGB via RenderScript. Set the surface to the captureRequest
import android.graphics.ImageFormat
import android.renderscript.Allocation
import android.renderscript.Element
import android.renderscript.RenderScript
import android.renderscript.ScriptIntrinsicYuvToRGB
import android.renderscript.Type
import android.util.Log
import android.util.Size
import android.view.Surface
@LiewJunTung
LiewJunTung / local.properties
Created March 21, 2019 16:53
kotlin multiplatform init
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=PleaseSpecifyAndroidSdkPathHere
@LiewJunTung
LiewJunTung / login_interfaces.kt
Created March 22, 2019 17:02
interfaces for LoginView and LoginPresenter
package com.netvirta.common.login
interface LoginView {
fun loginResult(result: Boolean)
}
interface LoginPresenter {
fun processLogin(password: String)
}
package com.netvirta.common.login
class LoginPresenterImpl(private val loginView: LoginView): LoginPresenter {
val user = User("John", 1234)
override fun processLogin(password: String) {
if (password.toInt() == user.password){
loginView.loginResult("Login Successful! Welcome ${user.username}.")
} else {
package com.netvirta.common.login
interface LoginView {
fun loginResult(result: String)
}
interface LoginPresenter {
fun processLogin(password: String)
}
@LiewJunTung
LiewJunTung / LoginActivity.kt
Created March 28, 2019 16:01
Remember to update your AndroidManifest.xml
package com.netvirta.android.login
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.netvirta.common.login.LoginView
import sample.R
class LoginActivity : AppCompatActivity(), LoginView {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
task replaceTest {
doLast {
replaceText("$projectDir/tools/app_history_a", "history.txt", "OK Google", "OK Dara")
}
}
void replaceText(String folderPath, String match, String oldText, String newText) {
fileTree(folderPath).matching {
include match
}.each {
package com.netvirta.android.login
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.netvirta.android.R
import com.netvirta.common.login.LoginPresenter
import com.netvirta.common.login.LoginPresenterImpl
import com.netvirta.common.login.LoginView
import kotlinx.android.synthetic.main.activity_login.*
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netvirta.android">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.netvirta.android.login.LoginActivity">
<intent-filter>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.netvirta.android.login.LoginActivity">
<EditText
android:layout_width="wrap_content"