Skip to content

Instantly share code, notes, and snippets.

@vorobeij
vorobeij / sss.kt
Created April 24, 2018 15:00
long to date
/**
* * <ul>
* <li>FORMAT_SHOW_TIME</li>
* <li>FORMAT_SHOW_WEEKDAY</li>
* <li>FORMAT_SHOW_YEAR</li>
* <li>FORMAT_SHOW_DATE</li>
* <li>FORMAT_NO_MONTH_DAY</li>
* <li>FORMAT_12HOUR</li>
* <li>FORMAT_24HOUR</li>
* <li>FORMAT_CAP_AMPM</li>
@vorobeij
vorobeij / MyActivity.kt
Created April 24, 2018 14:14
collapsing toolbar
import kotlinx.android.synthetic.main.activity_details.toolbar
....
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_details)
setSupportActionBar(toolbar) // at xml
supportActionBar?.setDisplayHomeAsUpEnabled(true)
....
<?xml version="1.0" encoding="utf-8"?>
<!--
Duration = 1 means that one rotation will be done in 1 second. leave it.
If you want to speed up the rotation, increase duration value.
in example 1080 shows three times faster revolution.
make the value multiply of 360, or the ring animates clunky
-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="720"
@vorobeij
vorobeij / DetailsActivity.kt
Last active April 24, 2018 13:05
transitions
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detailed)
var url = intent.getStringExtra("link")
// set same transition name
detailImg.transitionName = url
detailImg.setOnClickListener {
finishAfterTransition()
}
@vorobeij
vorobeij / MaterialRangeBar.kt
Last active April 20, 2018 13:46
setListener for custom view lambda
fun setRangeChangeListener(listener: (Int, Int) -> Unit) {
rangeChangedListener = object : RangeChangedListener {
override fun onRangeChanged(left: Int,
right: Int) = listener(left, right)
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- other shapes are oval, line ,ring -->
<corners
android:radius="100dp"
android:bottomRightRadius="20dp" />
<!-- Use these attributes for the rest of the corners
android:topLeftRadius="integer"
@vorobeij
vorobeij / SearchView.kt
Created April 17, 2018 11:52
search view
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import au.sj.owl.uimock.R
import com.jakewharton.rxbinding2.InitialValueObservable
import com.jakewharton.rxbinding2.view.RxView
import com.jakewharton.rxbinding2.widget.RxTextView
import io.reactivex.Observable
import kotlinx.android.synthetic.main.w_serchview.view.sv_filters
import kotlinx.android.synthetic.main.w_serchview.view.sv_search
@vorobeij
vorobeij / CompoundView.kt
Created April 17, 2018 11:36
compound view parent
import android.annotation.TargetApi
import android.content.Context
import android.graphics.Outline
import android.os.Build
import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
import android.view.View
import android.view.ViewOutlineProvider
@vorobeij
vorobeij / HomeActivity.kt
Last active April 24, 2018 09:58
custom tablayout
private var mSectionsPagerAdapter: SectionsPagerAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
mSectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager)
container.adapter = mSectionsPagerAdapter
tl_9.setViewPager(container)
nav_view.setNavigationItemSelectedListener(this)
@vorobeij
vorobeij / HomeActivity.kt
Created April 17, 2018 09:47
setup menu icons at toolbar
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.home, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.