This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
var x = 10 | |
var y = 3 | |
println("Before Swapping x = ${x}, y = ${y}") | |
x += y | |
y = x - y | |
x -= y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
println("IPHONE AND ANDROID".reverseSentence()) | |
} | |
private fun String.reverseSentence(): String { | |
val words = this.split(" ") | |
return words.map { it.reversed() }.joinToString { it }.replace(",", "") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
println(13.isPrimeNumber()) | |
} | |
private fun Int.isPrimeNumber(): Boolean { | |
if (this < 1) return false | |
var count = 0 | |
(1..this).forEach { | |
if (this%it == 0) count++ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ViewExtension | |
fun View.setOnAnimateClickListener(onClick: (View) -> Unit) { | |
this.setOnAnimateClickListener(null, onClick) | |
} | |
// MainActivity | |
val applyButton = findViewById(R.id.applyButton) | |
applyButton.setOnAnimateClickListener({view -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initCardViewWithKotlinExtensionWay() { | |
val cardView2 = findViewById(R.id.card_view2) as CardView | |
cardView2.setOnAnimateClickListener(R.id.imageBackground2, { view -> | |
Toast.makeText(this, "Clicked " + view.id , Toast.LENGTH_SHORT).show() | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun View.setOnAnimateClickListener(resId: Int?, onClick: (View) -> Unit) { | |
var secondaryView: View? = null | |
if (resId != null) { | |
secondaryView = this.findViewById(resId) | |
} | |
this.setOnClickListener({ view -> | |
Handler().postDelayed({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initCardViewWithNormalWay() { | |
val cardView = findViewById(R.id.card_view) as CardView | |
cardView.setOnTouchListener { v, event -> | |
Log.d("ANIMATE", event.toString()) | |
when (event.action) { | |
MotionEvent.ACTION_DOWN -> { | |
v.animate().cancel() | |
v.animate().scaleY(0.96f).scaleX(0.96f).setDuration(200).start() | |
val img = v.findViewById(R.id.imageBackground) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.v4.widget.NestedScrollView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ta.com.workshop2.ImageRatioView | |
android:id="@+id/banner" | |
android:src="@drawable/meet" | |
android:background="@color/colorAccent" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:scaleType="fitXY" | |
app:imageOrientation="landscape" | |
app:imageRatio="W2L1" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageRatioView : AppCompatImageView { | |
var imageOrientation: Int? = 0 | |
var imageRatio: Int? = 0 | |
val LANDSCAPE = 0 | |
val PORTRAIT = 1 | |
val SQUARE = 0 | |
val RATIO_2_1 = 1 | |
val RATIO_2_1_DIVISION = 0.5 | |
val PIXEL_PERFECT = 1 |
NewerOlder