You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: android/1introduction/tutorial.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,14 @@ title: Introduction to Android Development
5
5
6
6
## 1. Intro
7
7
8
-
The aim of this worksheet is to create a cookie clicker game (http://orteil.dashnet.org/cookieclicker/), with a cookie image that can be tapped to increase the score.
8
+
The aim of this worksheet is to create a cookie clicker game (http://orteil.dashnet.org/cookieclicker), with a cookie image that can be tapped to increase the score.
9
9
10
10
To follow this tutorial, you will need to [install Android
note: this is a large file, so our advice is to download and install it before
13
13
arriving at the workshop!)
14
14
15
-
Feel free to chose a different topic other than cookies, we really like the popular pokémon Goomy Clicker - http://joezeng.github.io/goomyclicker what things do you like?
15
+
Feel free to chose a different topic other than cookies, we really like the popular pokémon [Goomy Clicker](http://joezeng.github.io/goomyclicker) - what things do you like?
16
16
17
17

18
18
@@ -24,15 +24,15 @@ Feel free to chose a different topic other than cookies, we really like the popu
24
24
25
25
Next, we set the SDK level to `14` - It'll give you a helpful guide for how many people this supports. Speak to your coach about what minimum sdk level they usually have to use.
26
26
27
-
Finally, we want to create an `Empty Activity`
27
+
Finally, we want to create an `Empty Activity`
28
28
29
29

30
30
31
31
> We are going to keep the default of MainActivity.java and activity_main.xml :smile:
32
32
33
33
click FINISH (this might take some time)
34
34
35
-
Take some time to look at the different buttons with your coach - where are the different files located in the project? How do you run your app in an emulator or on a device?
35
+
Take some time to look at the different buttons with your coach - where are the different files located in the project? How do you run your app in an emulator or on a device?
36
36
37
37
## 3. Layouts
38
38
@@ -44,7 +44,7 @@ We're going to be dealing with the XML directly in this tutorial, so find the 't
44
44
45
45
Now you should see some code that looks familiar-ish! Android layouts using XML, which is very very similar to HTML. You should see already we have a `<RelativeLayout>` and a `<TextView>` tag, with some attributes already there. The thing that looks weird is that all the attributes currently are prefixed with the word `android`.
46
46
47
-
One of the most important features of our cookie clicker will be our cookie - we can create an `<ImageView>`, you will need to provide a `height` and a `width`. We also need to provide it an id so we can connect to it later.
47
+
One of the most important features of our cookie clicker will be our cookie - we can create an `<ImageView>`, you will need to provide a `height` and a `width`. We also need to provide it an id so we can connect to it later.
48
48
49
49
```xml
50
50
<ImageView
@@ -55,17 +55,17 @@ One of the most important features of our cookie clicker will be our cookie - we
55
55
56
56
> id’s need to start with @+id/ - the plus symbol means it assigns the variable name to the current ImageView
57
57
58
-
In Android we don't use pixels, but instead use `dp` which is a device point. 1 point might be 1 pixel on a really low resolution device, but might be 4 pixels, or even 8 pixels on a newer device. Take a look at this handy guide Android wrote for more information https://developer.android.com/guide/practices/screens_support.html.
58
+
In Android we don't use pixels, but instead use `dp` which is a device point. 1 point might be 1 pixel on a really low resolution device, but might be 4 pixels, or even 8 pixels on a newer device. Take a look at [this handy official guide](https://developer.android.com/guide/practices/screens_support.html) for more information.
59
59
60
-
Next, we want to save the following cookie image into our project. You can either google for a cookie image that's free to use, or use ours that we found earlier = http://imgur.com/a/9BXV4. You need to save it inside your project folder using Windows Explorer or Mac OSX Finder and navigate to the following -> app -> src -> main -> res . You need to create a folder called `drawable-xhdpi` and place your cookie image in here!
60
+
Next, we want to save the following cookie image into our project. You can either google for a cookie image that's free to use, or use [our example image](http://imgur.com/a/9BXV4). You need to save it inside your project folder using Windows Explorer or Mac OSX Finder and navigate to the following -> app -> src -> main -> res . You need to create a folder called `drawable-xhdpi` and place your cookie image in here!
61
61
62
62
Because android has different density devices, we usually need to provide different resolution images for all those different devices. If we only provide it in one folder, Android will scale the image for other devices, but this might cause make the image look bad!
63
63
64
64

65
65
66
66
If we want to then use that image in our Android app we can use an attribute `android:src="@drawable/cookie"` - autocomplete will be your friend here!
67
67
68
-
Because we have a RelativeLayout parent this means we can do some special things to position our cookie on our screen. We can provide an attribute like `android:layout_centerInParent="true"`.
68
+
Because we have a RelativeLayout parent this means we can do some special things to position our cookie on our screen. We can provide an attribute like `android:layout_centerInParent="true"`.
69
69
70
70
Next, we want to look at having a TextView for to keep track of how many cookies we've clicked. Again you need to provide it a height, width, and id. But we can also provide it some special label things, such as `text`, `textColor`, or `textSize`
71
71
@@ -75,13 +75,13 @@ Another neat feature of using a RelativeLayout is how we can position things **i
75
75
76
76
> this is how our layout code finally looked :smile:
77
77
78
-
Ask your coach what other special things RelativeLayout can do? Do you know any other alternative parent layouts? Take a look at https://developer.android.com/guide/topics/ui/layout/relative.html for more information.
78
+
Ask your coach what other special things RelativeLayout can do? Do you know any other alternative parent layouts? Take a look at the [official guide](https://developer.android.com/guide/topics/ui/layout/relative.html) for more information.
79
79
80
80
## 4. Clicking
81
81
82
82
Next, we want to make it so our cookie actually does something when it's been clicked on!
83
83
84
-
We want to open our MainActivity.java file and take a look at what's there already. What do you think the `onCreate` method might do? Speak to your coach about what other methods get called in the activity lifecycle. For more information look at https://developer.android.com/training/basics/activity-lifecycle/index.html.
84
+
We want to open our MainActivity.java file and take a look at what's there already. What do you think the `onCreate` method might do? Speak to your coach about what other methods get called in the activity lifecycle. For more information look at the [official training guide](https://developer.android.com/training/basics/activity-lifecycle/index.html).
85
85
86
86
Inside the `onCreate` method, below where it sets the layout to the xml file we just finished designing. We want to create a variable called imgCookie and findViewById to hook them up. This is similar to how we use jQuery in JavaScript to hook up with a HTML element
87
87
@@ -99,11 +99,11 @@ After, we can set an onClickListener, which is again similar to the JavaScript e
99
99
100
100

101
101
102
-
Inside our method we're going to put a Toast. These are those little messages at the bottom of the phone that show for a short period of time. They're really good
102
+
Inside our method we're going to put a Toast. These are those little messages at the bottom of the phone that show for a short period of time. They're really good
103
103
104
104

105
105
106
-
Run your app now, and see what happens when you tap on the cookie!
106
+
Run your app now, and see what happens when you tap on the cookie!
107
107
108
108
## 5. Game Logic
109
109
@@ -155,8 +155,8 @@ If you want to take your cookie game clicker onwards, maybe consider:
155
155
156
156
## 8. More Information
157
157
158
-
Amal has written a more advanced android tutorial located at https://github.com/K4KYA/MakersHelloAndroid/tree/codebar if you want to take Android even further :)
158
+
Amal has written a more [advanced android tutorial](https://github.com/K4KYA/MakersHelloAndroid/tree/codebar) if you want to take Android even further :)
159
159
160
-
If you’d like to go even further, the Big Nerd Ranch have a really very good book to pick up Android (they have an iOS book too) - https://www.bignerdranch.com/we-write/
160
+
If you’d like to go even further, the Big Nerd Ranch have a [really very good book](https://www.bignerdranch.com/we-write) to pick up Android (they have an iOS book too).
161
161
162
-
Google also has their own tutorial series at https://developer.android.com/training/basics/firstapp/index.html, which touches on some of the details and complexities of Android app development - saving data, sharing things with other apps, getting location data and other things you may want a more complex app to be able to do.
162
+
Google also has their own [tutorial series](https://developer.android.com/training/basics/firstapp/index.html), which touches on some of the details and complexities of Android app development - saving data, sharing things with other apps, getting location data and other things you may want a more complex app to be able to do.
0 commit comments