Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Android with Kotlin
Search
Ahmed Tarek
October 12, 2017
Programming
0
130
Android with Kotlin
Slides from my talk Android with Kotlin at Oct 2017 GDG 6 October City, Egypt.
Ahmed Tarek
October 12, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
CSC509 Lecture 01
javiergs
PRO
0
180
Pythonによるイベントソーシングへの挑戦と現状に対する考察 / Challenging Event Sourcing with Python and Reflections on the Current State
nrslib
3
680
So you want to write a User-Defined Function for Flink? @ Current 2024 - Austin, TX
hpgrahsl
0
110
ECS向けのドリフト検知機構を実装してみた
tkikuc
0
150
宿泊予約サイトにおける検索と料金計算の両立
skaji
1
200
ビット演算の話 / Let's play with bit operations
kaityo256
PRO
3
130
AWS CDKを用いたセキュアなCI/CDパイプラインの構築 / Build a secure CI/CD pipeline using AWS CDK
seike460
PRO
3
460
Micro Frontends Unmasked: Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
220
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
4
92k
Perl 5 OOP機構30年史 - Perl 5's OOP Mechanism over the past 30 years
moznion
1
730
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
650
サークルポータルを支えるフロントエンドアーキテクチャの選定
toranoana
1
210
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
WebSockets: Embracing the real-time Web
robhawkes
59
7.3k
How GitHub Uses GitHub to Build GitHub
holman
472
290k
Fireside Chat
paigeccino
31
2.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
41
6.5k
GraphQLとの向き合い方2022年版
quramy
43
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
327
21k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
26
4k
Fashionably flexible responsive web design (full day workshop)
malarkey
401
65k
What's new in Ruby 2.0
geeforr
340
31k
Transcript
Android with Kotlin a_tarek360 Oct, 2017
What is kotlin?
Kotlin is a Russian island
Kotlin • By JetBrains in 2011 • Open sourced in
2012 • The first officially stable release in 2016
At Google I/O 2017, Google announced..
Kotlin • Official Programming Language for Android Development
Kotlin • Statically typed programming language • 100% interoperable with
Java and Android • Avoid entire classes of errors such as null pointer exceptions.
var / val var name = "Ahmed" val id =
1 Val cannot be reassigned id = 3
Null Safety Safe var name: String name = null //
Compilation error Nullable val name: String? = null // Nullable type println(name.length()) // Compilation error println(name?.length())
Classes/Interfaces class SimpleClass class SimpleClass(value: String) interface SimpleInterface class SimpleClass
: BaseClass(), SimpleInterface
Data Class data class Car( var name: String, var color:
Int, var speed: Float) • No need to implement: toString, equals
Functions fun isMoving(speed: Int): Boolean { return speed > 0
} fun isMoving(speed: Int) = speed > 0
Companion Object class Car { companion object { fun drive()
{ } } } // Like calling a static method Car.drive()
Simple Android Activity class MainActivity : Activity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val name = savedInstanceState?.getString("name") } }
Extending Language isLollipop { view.elevation = 3.0f } . .
. . inline fun isLollipop(code: () -> Unit) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { code.invoke() } }
Smart Cast fun setData(view: View) { if (view is ImageView)
{ view.setImageDrawable(drawable) } if (view is TextView) { view.setText("hello") } }
Callback/Lambda • view.setOnClickListener(object : View.OnClickListener { override fun onClick(view: View?)
{ doSomething() } }) • view.setOnClickListener { view -> doSomething(view) } • view.setOnClickListener { doSomething() }
Function Parameter Default Value fun toast(message: String) { Toast.toast(this, message,
Toast.LENGTH_LONG).show() } fun toast(message: String, duration: Int) { Toast.makeText(this, message, duration).show() } fun toast(message: String, duration: Int = Toast.LENGTH_LONG) { Toast.makeText(this, message, duration).show() }
Extension Functions fun Activity.toast(message: String, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, message, duration).show() } // Call it from any activity instance toast("Hello World!") toast("Hello World!", Toast.LENGTH_SHORT)
Kotlin Android Extensions <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/photo" … />
<TextView android:id="@+id/name" … /> </RelativeLayout>
Kotlin Android Extensions import kotlinx.android.synthetic.main.activity_main.* override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) photo.setImageBitmap(bitmap) name.setText("Hello World!") }
Thank You!