forked from eothein/Presentation-Android-Introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkshopAndroid.tex
550 lines (445 loc) · 15.8 KB
/
workshopAndroid.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
%%----------------------------------------------------------------------------
%% Presentatie HoGent Bedrijf en Organisatie
%%----------------------------------------------------------------------------
%% Auteur: Bert Van Vreckem [[email protected]]
\documentclass{beamer}
%==============================================================================
% Aanloop
%==============================================================================
%---------- Packages ----------------------------------------------------------
\usepackage{graphicx,multicol}
\usepackage{comment,enumerate,hyperref}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{eurosym}
\usepackage{listings}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{framed}
\usepackage{wrapfig}
\usepackage{lstautogobble}
%---------- Configuratie ------------------------------------------------------
\usetikzlibrary{arrows,shapes,backgrounds,positioning,shadows}
\usetheme{hogent}
%---------- Commando-definities -----------------------------------------------
\definecolor{forestgreen}{RGB}{34,139,34}
\definecolor{orangered}{RGB}{239,134,64}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\lstdefinestyle{java}{language=Java,
backgroundcolor=\color{white},
frame=single,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\footnotesize\color{blue}\ttfamily,
commentstyle=\color{forestgreen},
breaklines=true,
breakatwhitespace=true,
tabsize=2,
columns=fullflexible,
autogobble=true,
showstringspaces=false,
showtabs=true,
}
\lstdefinestyle{XML}
{ basicstyle=\tiny\ttfamily,
columns=fullflexible,
frame=single,
showstringspaces=false,
commentstyle=\color{forestgreen}\upshape
morestring=[b]",
morestring=[s]{>}{<},
morecomment=[s]{<?}{?>},
stringstyle=\color{black},
identifierstyle=\color{darkblue},
keywordstyle=\color{forestgreen},
morekeywords={xml,xmlns,version,type,android}% list your attributes here
}
%---------- Info over de presentatie ------------------------------------------
\title[Intro]{Quick Workshop Android}
\author{Dr. Jens Buysse }
\date{2014-2015}
%==============================================================================
% Inhoud presentatie
%==============================================================================
\begin{document}
%---------- Front matter ------------------------------------------------------
% Dia met het HoGent logo
\HoGentLogo
% Titeldia met faculteitslogo
\titleframe
%---------- Inhoud ------------------------------------------------------------
\section{Welcome to Mobile: Android}
\sectionframe
\begin{frame}
\frametitle{Hello Android}
I've come up with a set of rules that describe our reactions to
technologies:
\begin{enumerate}
\item Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works.
\item Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
\item Anything invented after you're thirty-five is against the natural order of things.
\end{enumerate}
\begin{flushright}
\end{flushright}
-- Douglas Adams, author of \textsl{Hithhiker's Guide to the Galaxy}
\end{frame}
\begin{frame}
\frametitle{Mobile Development}
\begin{columns}
\begin{column}{0.3 \textwidth}
\pause
\begin{figure}
\centering
\includegraphics[width=1.00\textwidth]{img/iphone.jpg}
\label{fig:iphone}
\end{figure}
\end{column}
\begin{column}{0.3 \textwidth}
\pause
\begin{figure}
\centering
\includegraphics[width=1.00\textwidth]{img/nexus.png}
\label{fig:iphone}
\end{figure}
\end{column}
\begin{column}{0.3 \textwidth}
\pause
\begin{figure}
\centering
\includegraphics[width=1.00\textwidth]{img/windowsPhone.jpg}
\label{fig:iphone}
\end{figure}
\end{column}
\end{columns}
\end{frame}
{
\usebackgroundtemplate{\includegraphics[height=\paperheight,width=\paperwidth]{img/timeLineMobile.jpg}}
\setbeamertemplate{navigation symbols}{}
\begin{frame}[plain]
\end{frame}
}
\begin{frame}
\frametitle{What is Android}
\begin{figure}
\centering
\includegraphics[width=0.3 \textwidth]{img/androidlogo.png}
\label{fig:androidlogo}
\end{figure}
Android is a ecosystem consisting of the following components:
\begin{enumerate}
\item A free, open source, operating system for embedded devices \pause
\item An open source development platform to create mobile applications \pause
\item Devices, specifically mobile devices, which run the mobile Android OS and the applications made for it
\end{enumerate}
See \url{http://developer.android.com/training}
\end{frame}
{
\usebackgroundtemplate{\includegraphics[height=\paperheight,width=\paperwidth]{img/androidstack.pdf}}
\setbeamertemplate{navigation symbols}{}
\begin{frame}[plain]
\end{frame}
}
\begin{frame}
\frametitle{Linux Kernel}
Core services:
\begin{itemize}
\item Hardware drivers
\item Process and Memory management
\item Security and Power Management
\end{itemize}
De Kernel is a layer of abstraction between hardware and rest of Software Stack
\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{img/kernel.pdf}
\label{fig:kernel}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Libraries}
\begin{itemize}
\item Media Library
\item Graphical libraries
\item SQLLite for database support
\item \dots
\end{itemize}
\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{img/runtimeLibraries.pdf}
\label{fig:kernel}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Run time}
\begin{itemize}
\item Core Libraries: proper implementations for the Dalvik Virtual Machine $\neq$ Java VM
\item Dalvik VM: virtual machine for Android, optimized for mobile devices (battery, processor \& memory management)
\end{itemize}
\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{img/runtimeLibraries.pdf}
\label{fig:kernel}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Dalvik Virtual Machine}
\begin{itemize}
\item Typical Java VMs $\Rightarrow$ stack machines
\item Dalvik VM $\Rightarrow$ a register-based architecture: cooler and thus uses less battery energy
\item Each app uses its own process: sandboxing $\Rightarrow$ cornerstond of security in Android
\end{itemize}
\pause
But \dots
\begin{itemize}
\item Android 5.0 \textit{Lollipop}: Dalvik was entirely replaced by \textsl{ART} (Android RunTime)
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{A typical work flow}
\begin{enumerate}
\item App written in java
\item Compiled to Java bytecode files
\item dx converts java bytecode files to a single dex bytecodefile (classes.dex)
\item Dalvik executes dex bytecode file
\end{enumerate}
\end{frame}
\begin{frame}
\frametitle{Application Framework}
The application framework provides the classes which can be used to create Android applications: an interface for access to the hardware
\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{img/appFramework.pdf}
\label{fig:kernel}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Application Layer}
All applications are build in the application layer, using the different API libraries, and executed in the Dalvik VM.
\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{img/apllicationLayer.pdf}
\label{fig:kernel}
\end{figure}
\end{frame}
{
\usebackgroundtemplate{\includegraphics[height=\paperheight,width=\paperwidth]{img/androidstack.pdf}}
\setbeamertemplate{navigation symbols}{}
\begin{frame}[plain]
\end{frame}
}
\section{Basic Programming in Android}
\sectionframe
\begin{frame}
\frametitle{Google is your friend!}
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{img/google.jpg}
\label{fig:google}
\end{figure}
\begin{itemize}
\item \url{http://developer.android.com/index.html}
\item \url{http://android-developers.blogspot.be/}
\item \dots
\end{itemize}
\end{frame}
\subsection{Activities \& Activity Lifecycle}
\begin{frame}
\frametitle{Activities \& Activity Lifecycle}
\brightbox{An \textcolor{HoGentAccent6}{Activity} is a single screen the user sees on the device at one time}
\begin{figure}
\centering
\includegraphics[width=0.6\textwidth]{img/activitySketch.jpg}
\label{fig:activitySketch}
\end{figure}
\pause
\begin{center}
Comparable: www
\end{center}
\end{frame}
\begin{frame}
\frametitle{Activity Life Cycle}
The \textcolor{HoGentAccent6}{activity manager} is responsible for creating, destroying and managing activities.
\begin{columns}
\begin{column}{0.4 \textwidth}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{img/actState.jpg}
\end{figure}
\end{column}
\begin{column}{0.6 \textwidth}
\begin{itemize}
\item \textbf{Active process}: have components which interact with the user
\item \textbf{Visible process}: visisble but inactive process (e.g. non-full screen or transparant)
\item \textbf{Started service process}: Process hosting and services
\item \textbf{Background process}: process with non-visible activities and without started services
\item \textbf{Empty process}: to improve memory management, apps are stored in memory
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}
\frametitle{De Activity Lifecylce}
An acitivity has 4 states:
\begin{description}
\item [Running] is on top of the activity stack, is able to be manipulated and Android will do everything to keep this alive
\item [Paused] activity still visible, but interaction is not possible (e.g. when transparant)
\item [Stopped] activity is invisible, but still in memory
\item [Destroyed] activity is not on the stack any more and needs to be restarted
\end{description}
\end{frame}
{
\usebackgroundtemplate{\includegraphics[height=\paperheight,width=\paperwidth]{img/activityLifeCycle.pdf}}
\setbeamertemplate{navigation symbols}{}
\begin{frame}[plain]
\end{frame}
}
\subsection{Project layout}
\begin{frame}
\frametitle{Anatomy Android Project }
\begin{description}
\item [Manifest File] Glues the project together (building blocks, permissions \dots)
\item [String resources] \texttt{res/values/strings.xml} $\Rightarrow$ all the strings for the app
\item [Layout XML colde] \texttt{res/layout/} declares the layouts of the activities
\item [Drawable Resources] all images used in the app
\item [R file] The connections between java and the external resources: automatically generated
\item [Source Code] the java source code for the app
\end{description}
\end{frame}
\begin{frame}
\frametitle{Emulator}
\begin{itemize}
\item The SDK comes with an emulator (lacks in performance though \dots )
\item Genymotion is an emulator which is better
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Demonstration}
See \url{https://github.com/eothein/Presentation-Android-Introduction}
\end{frame}
\section{Tutorial: lets go for it!}
\begin{frame}
\frametitle{Goal of application}
We will build an application which downloads a random Chuck Norris Joke and add this to a list
\end{frame}
\begin{frame}[fragile]
\frametitle{Step 1: create the activity}
\begin{itemize}
\item Start a new project
\item Choose to create a new Activity, lets call this MainActivity
\item Create the layout (use LinearLayout and add a ListView and a Button)
\item Do not forget to create the string constant for the button text
\item You Should be able to start the application!
\end{itemize}
\pause
Don't forget \dots
\begin{lstlisting}[style=XML]
<uses-permission android:name="android.permission.INTERNET" />
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Asynctask}
\brightbox{An \textcolor{HoGentAccent6}{Asynctask} allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.}
\begin{lstlisting}[style=java]
public void onClick(View v) {
new DownloadImageTask().execute("http://example.com/image.png");
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
/** Excutes in worker thread */
protected Bitmap doInBackground(String... urls) {
return loadImageFromNetwork(urls[0]);
}
/** Returns results */
protected void onPostExecute(Bitmap result) {
mImageView.setImageBitmap(result);
}
}
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Asynctask}
\begin{description}
\item [onPreExecute()] used to setup the task
\item [doInBackground(Params\dots)] invoked on the background thread immediately after onPreExecute() finishes executing. This step is used to perform background computation that can take a long time.
\item [onProgressUpdate(Progress \dots)], invoked on the UI thread after a call to publishProgress(Progress...) and used to display any form of progress in the user interface
\item [onPostExecute(Result)] invoked on the UI thread after the background computation finishes
\end{description}
\end{frame}
\begin{frame}
\frametitle{Step 2: create an AsyncTask}
Create the AsyncTask
The three types used by an asynchronous task are the following:
\begin{description}
\item [Params] the type of the parameters sent to the task upon execution.
\item [Progress] the type of the progress units published during the background computation.
\item [Result] the type of the result of the background computation.
\end{description}
\end{frame}
\begin{frame}
\frametitle{Step 3: use GSON}
In File $\rightarrow$ Project Structure $\rightarrow$ app $\rightarrow$ Dependencies add GSON
\end{frame}
\begin{frame}[fragile]
\brightbox{\textcolor{HoGentAccent6}{Gson} is a Java library that can be used to convert Java Objects into their JSON representation and vice versa}
\begin{lstlisting}[style=java]
class BagOfPrimitives {
private int value1 = 1;
private String value2 = "abc";
private transient int value3 = 3;
BagOfPrimitives() {
// no-args constructor
}
}
BagOfPrimitives obj = gson.fromJson(json, BagOfPrimitives.class);
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Step 3: use GSON}
\begin{itemize}
\item Make a connection to \url{http://api.icndb.com/jokes/random?}
\item Download the JSON response
\item Use GSON to parse into a joke object
\item In Mainactivty add a listener to the button and start the asynctask
\item Test by logging to the logcat
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{BroadcastReceivers and Intents}
\brightbox{A \textcolor{HoGentAccent6}{broadcast receiver} is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens. }
\end{frame}
{
\usebackgroundtemplate{\includegraphics[height=\paperheight,width=\paperwidth]{img/broadcastReceiver.png}}
\setbeamertemplate{navigation symbols}{}
\begin{frame}[plain]
\end{frame}
}
\begin{frame}
\frametitle{Create a broadcastreceiver}
\begin{itemize}
\item Create the JokeReceiver
\item Implements the onReceive methode
\item Make an interface which the activity must implements (to add the joke)
\item Create the intent and send it to the broadcastreceiver
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{ListView and Adapter}
\begin{figure}
\centering
\includegraphics[width=1.00\textwidth]{img/adapter.jpg}
\label{fig:adapter}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Create the adapter}
\begin{itemize}
\item Add an arraylist with strings in the activity
\item Couple this with the arrayAdapter
\item Allow to add strings to the list (implement the interface)
\end{itemize}
\end{frame}
%---------- Back matter -------------------------------------------------------
\end{document}