Skip to content

Instantly share code, notes, and snippets.

View nosix's full-sized avatar

nosix nosix

View GitHub Profile
@nosix
nosix / MainActivity.kt
Created July 9, 2016 12:22
UpdateReceiver for Android (SDK 22) in Kotlin 1.0.2
class MainActivity : AppCompatActivity() {
private val updateReceiver = UpdateReceiver(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
registerReceiver(updateReceiver, IntentFilter(SampleService.ACTION_SAMPLE))
}
@nosix
nosix / CircleMeter.kt
Created July 17, 2016 05:51
Custom View for Android (SDK 22) in Kotlin 1.0.2
package xxx.view
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import xxx.R
class CircleMeter(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
View(context, attrs, defStyleAttr) {
@nosix
nosix / XXXFragment.kt
Created July 17, 2016 14:44
RecylerView for Android (SDK 22) in Kotlin 1.0.2
package xxx.view
import android.app.Activity
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.helper.ItemTouchHelper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@nosix
nosix / XXXDialogFragment
Created July 17, 2016 15:26
dismiss DialogFragment for Android (SDK 22) in Kotlin 1.0.2
package xxx.view
import android.app.Activity
import android.app.AlertDialog
import android.app.Dialog
import android.app.DialogFragment
import android.os.Bundle
import android.support.v7.widget.RecyclerView
import xxx.R
@nosix
nosix / AndroidManifest.xml
Last active July 24, 2016 09:29
Dialog Activity for Android (SDK 22) in Kotlin 1.0.2
...
<activity
android:name=".NewItemActivity"
android:label="@string/new_item"
android:theme="@style/DialogTheme" />
...
@nosix
nosix / CustomViewPager.kt
Last active July 26, 2016 14:07
ViewPager for Android (SDK 22) in Kotlin 1.0.2. It can be scrolled in one direction. (Left only, Right only or Both)
package xxx.view
import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
class CustomViewPager(context: Context, attrs: AttributeSet?) : ViewPager(context, attrs) {
constructor(context: Context) : this(context, null)
@nosix
nosix / MainActivity.kt
Created July 26, 2016 14:25
ViewPager for Android (SDK 22) in Kotlin 1.0.2. It can be scrolled in one direction. (Left only, Right only or Both)
class MainActivity : AppCompatActivity() {
private fun updateViewPager() {
findViewById(R.id.main_container).let {
it as ViewPager
(it.adapter as MainPagerAdapter).last = it.currentItem
}
}
}
@nosix
nosix / AndroidManifest.xml
Created July 28, 2016 02:40
Using the LeakCanary that is a memory leak detection library for Android and Java.
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="xxx">
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
@nosix
nosix / text-to-speech.html
Created September 7, 2016 10:06
Text to Speech using Watson
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text to Speech</title>
</head>
<body>
<div id="text-to-speech">
<input type="text" name="speech-text" placeholder="Sentence">
@nosix
nosix / AndroidManifest.xml
Last active September 14, 2016 14:18
How to use Android Service API
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="xxx">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />