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
150
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
Discover Metal 4
rei315
2
130
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
720
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
800
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
180
PicoRuby on Rails
makicamel
2
130
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
440
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
670
Goで作る、開発・CI環境
sin392
0
230
10 Costly Database Performance Mistakes (And How To Fix Them)
andyatkinson
0
250
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
130
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
5
1.1k
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
640
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Become a Pro
speakerdeck
PRO
28
5.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
820
Site-Speed That Sticks
csswizardry
10
680
Measuring & Analyzing Core Web Vitals
bluesmoon
7
510
Documentation Writing (for coders)
carmenintech
72
4.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
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!