Skip to content

Instantly share code, notes, and snippets.

@vorobeij
vorobeij / HomeActivity.kt
Created April 17, 2018 09:18
set logo at toolbar
private fun setLogoInsteadOfText(){
// setSupportActionBar(toolbar) // use it if not set yet
supportActionBar?.setDisplayShowTitleEnabled(false)
toolbar.setLogo(R.drawable.ic_launcher_foreground)
}
@vorobeij
vorobeij / gradle.properties
Created April 17, 2018 09:02
gradle config
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
@vorobeij
vorobeij / MainActtivity.kt
Created March 17, 2018 09:07
TapTargetView usage
class MainActivity : AppCompatActivity() {
val tapTargets: MutableList<TapAct> = mutableListOf()
/**
* @param listener - what will be done onTargetClick
*/
fun getTapTarget(listener: () -> Unit): TapTargetView.Listener {
return object : TapTargetView.Listener() { // The listener can listen for regular clicks, long clicks or cancels
override fun onTargetClick(view: TapTargetView) {
@vorobeij
vorobeij / XXXActivity.kt
Created March 10, 2018 11:59
activity with arrow back
// take auto generated xml
class XXXActivity : BaseRxActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_upgrade_to_premium)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
@vorobeij
vorobeij / xxx.kt
Last active February 28, 2018 11:14
genson
// interface: need to use constructor
interface Launchable {
fun idString(): String
fun description(): String
fun execute(manager: LaunchManager)
fun getIcon(model: Model,
color: Int): Single<Drawable>
}
class LaunchAppAction(var pac: Pac) : Launchable {
@vorobeij
vorobeij / Main.kt
Last active February 21, 2018 16:57
start activity
// by application package name
val packName = "com.google.chrome"
val intent = packageManager.getLaunchIntentForPackage(packName)
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
startActivity(intent)
//launch shortcut (package name+ activity name)
@vorobeij
vorobeij / ShakeService.kt
Created February 21, 2018 14:10
Shake sensor
// sensor
private lateinit var mSensorManager: SensorManager
private var mAccel: Float = 0.toFloat() // acceleration apart from gravity
private var mAccelCurrent: Float = 0.toFloat() // current acceleration including gravity
private var mAccelLast: Float = 0.toFloat() // last acceleration including gravity
override onCreate(){
...
@vorobeij
vorobeij / HeadsetPlugReciever.kt
Created February 21, 2018 13:33
HeadsetDetection
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import timber.log.Timber
class HeadsetPlugReciever : BroadcastReceiver() {
override fun onReceive(context: Context?,
intent: Intent) {
if (intent.action != Intent.ACTION_HEADSET_PLUG) {
Timber.e("jsp HeadsetPlugReciever recieved ${intent.action} event")
// set on long click listener
launcherGrid.setOnItemLongClickListener { parent, view, position, id ->
Timber.d("jsp grid item id=$id pos=$position long clicked")
launcherAdapter().startDrag(view, position)
false
}
data class DragData(val view: View,
val position: Int)
@vorobeij
vorobeij / MainActivity.kt
Last active February 15, 2018 17:02
Swipe to delete callback
private fun initRvActions() {
rvCommands.layoutManager = LinearLayoutManager(this)
rvCommands.adapter = AdapterCommands(model)
rvCommands.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
val swipeHandler = object : SwipeToDeleteCallback(this) {
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val adapter = rvCommands.adapter as AdapterCommands
adapter.removeAt(viewHolder.adapterPosition)
}