Mobile App Midterm - 2020

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Name__________________________________________________________ID___________________

Asian Institute of Technology


School of Engineering and Technology
Graduate Program

January 2020 Semester Midterm Examination

Course Code: AT80.9009 Course Title: Selected Topic: Mobile Application

Instructor: Chantri Polprasert

Exam Date (dd/mm/yyyy): 6/3/2020 Room : TC101 Time: 9:00-12:00

No. of Students: 8 Instructor is proctoring the exam? • Yes x ​No

Instructions:

·​ Books • open x close


· ​Calculators x allowed • not allowed
· ​Notes • open x close
· ​Computers • allowed x not allowed

Additional Instructions:

Only 1 A4 sheet (2-sided) is allowed in the exam

➢ This examination paper has 16 pages (including this cover page).

➢ This exam consists of 5 parts (44 points).

➢ This examination is worth 25% of the final grade.

➢ Show your implementation/calculation in an ordered and proper step.


Justify your answer.
Name______________________
Student ID__________________

Part 1 [Short answers] (11 points) 


Q1.1 What's the benefit of putting all resources such as images, strings into a 
resource folder? (2 points) 
 
 
 
 
Q1.2 What type of resources do we put into the Drawable folder? (0.5 point) 
 
 
 
 
Q1.3 How to refer to the string “Hello AIT” as “h1_AIT” in strings.xml? (0.5 point) 
 
 
 
Q1.4 From Q1.3, how to refer to the string “Hello AIT” in XML file? (0.5 point) 
 
 
 
 
Q1.5 From Q1.3, how to refer to the string “Hello AIT” in Kotlin file? (0.5 point) 
 
 
 
Q1.6 What does AVD stand for? (0.5 point) 
 
 
 
Page ​2
Name______________________
Student ID__________________

Q1.7 What's the purpose of AndroidManifest.xml? (1.5 points) 


 
 
 
 
Q1.8 Why do we need different resolutions of an icon picture in the mipmap folder? 
(2 points) 
 
 
 
 
 
 
Q1.9 Fig 1.1 shows the manifest file of the application. From the figure, answer the 
following questions. 

 
Fig. 1.1 Android manifest file of the application 
Q1.9.1 How many activities does this application have? (0.5 point) 
 
 
 
Page ​3
Name______________________
Student ID__________________

 
Q1.9.2 From Fig. 1.1, what will happen on the launcher if you run this application? 
Justify your answer. (1.5 points). 
 
 
 
 
 
Q1.10 Explain the difference between margin and padding. (1 point) 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Page ​4
Name______________________
Student ID__________________

Part 2 [Views and Layout] (9 points) 

 
Fig. 2.1 Layout of the application 
Fig 2.1 shows the layout of the application. From the figure, answer the following 
question. 
Q2.1. Design the application with LinearLayout. ​Hint​: Use 
@android:color/holo_red_dark as background color for View 1 and 
@android:color/holo_blue_dark for View 2. (3 points) 
<​LinearLayout android:orientation=“vertical”> 
<View     
(0.5 point)​______________________________________  

Page ​5
Name______________________
Student ID__________________

(0.5 point)​______________________________________  
(0.5 point)​______________________________________ /> 

<View     
(0.5 point)​______________________________________  
(0.5 point)​______________________________________  
(0.5 point)​______________________________________ /> 
</LinearLayout> 
Q2.2. Explain how to make view1 span 40% of the screen height. Note that the 
height of view1 must scale up or down according to device’s height (i.e. if you run 
the application on a device with the total screen height of 100dp, height of view1 
should be equal to 40dp. However, if the device has a screen height of 200dp, view2 
should have a height of 80dp). (1 point) 
 
   
 
   
Q2.3. Explain how to make view2 span 60% of the screen height. Note that the 
height of view2 must scale up or down according to device’s height similar to (1.2). (1 
point) 
 

Page ​6
Name______________________
Student ID__________________

   
 
   
Q2.4. From Q2.2 and Q2.3, explain how Android maintains a 40-60 height ratio 
between view1 and view2 across different devices (i.e. you will find that view1/view2 
ratio remains constant even if you run the application on two devices with different 
heights). (2 points) 
 
   
 
   
 
   
 
Q2.5. What can you do if you want to have a single view in LinearLayout that 
occupies only 40% of the screen height, assuming that LinearLayout is already in a 
vertical orientation. (2 points) 
 
 
 

Page ​7
Name______________________
Student ID__________________

Part 3 [Activities] (9.5 points) 


Fig. 3.1 shows an application with two activities; FirstActivity and SecondActivity. 
FirstActivity is associated with activity_first.xml, containing one text field and one 
button. When the button in FirstActivity is clicked, it should launch SecondActivity. 
SecondActivity should show activity_second.xml, which displays the value you 
entered in FirstActivity and presents that value on the Toast message. Answer the 
following questions. 

 
Fig 3.1 (left) FirstActivity and (right) SecondActivity 
Q3.1. Add one EditText (use ed1 as its ID), and one Button (use btn1 as its ID) to 
activity_first.xml. (3 points) 
 

Page ​8
Name______________________
Student ID__________________

 
<LinearLayout android:orientation=“vertical” …> 
<EditText (0.5 point)​_____________________________________ 
(0.5 point)​_____________________________________ 
(0.5 point)​_____________________________________/> 
<Button (0.5 point)​_____________________________________ 
(0.5 point)​_____________________________________ 
(0.5 point) ​_____________________________________/> 
</LinearLayout> 
Q3.2 Complete Kotlin codes for FirstActivity. (2.5 points) 
import kotlinx.android.synthetic.main.activity_first.* 
class FirstActivity : AppCompatActivity, View.OnClickListener {  
override fun onCreate(savedInstanceState: Bundle) { 
super.onCreate(savedInstanceState) 
setContentView((0.5 point) ​_____________________​)   
btn1.setOnClickListener( (0.5 point)​___________​) 

 

Page ​9
Name______________________
Student ID__________________

override fun onClick(view : View) { 


(0.5 point) ​_____________________________________   
(0.5 point) ​_____________________________________ 
(0.5 point) ​_____________________________________ 


Q3.3. Add one TextView (use tv1 as its ID) to activity_second.xml. (1.5 point) 
<LinearLayout android:orientation:”vertical”> 
<TextView (0.5 point) ​______________________________ 
(0.5 point) ​______________________________   
(0.5 point) ​______________________________/> 
</LinearLayout> 
Q3.4. Complete Kotlin codes for SecondActivity. (2.5 point) 
import kotlinx.android.synthetic.main.activity_second.* 
class SecondActivity : AppCompatActivity ( ) { 
override fun onCreate(savedInstanceState: Bundle?) { 
super.onCreate(savedInstanceState); 
setContentView((0.5 point) ​_________________________)   

Page ​10
Name______________________
Student ID__________________

val ________(0.5 point) : String?​ =​ intent.​________________​(0.5 point)   


(0.5 point) ​_________________________​ //display the String on the TextView 
(0.5 point) ​_________________________ ​//Show the String on the Toast message 


 
 
 
   
 
   
 
   
 
   
 
 
 

Page ​11
Name______________________
Student ID__________________

Question 4 [Menus and Dimension] (10.5 points) 


Q4.1 Fig. 4.1 shows steps to implement context menu. 

 
Fig. 4.1 Steps to implement floating context menu 
From Fig. 4.1, identify 5 steps to implement context menu and explain the reason 
behind each step (0.5 point for Step and 1 point for reason) 
Step 1:_________________________________ 
Reason:________________________________ 
 
 
Step 2:_________________________________ 
Reason:________________________________ 
 
 

Page ​12
Name______________________
Student ID__________________

Step 3:_________________________________ 
Reason:________________________________ 
 
 
Step 4:_________________________________ 
Reason:________________________________ 
 
 
Step 5:_________________________________ 
Reason:________________________________ 
 
Q4.2 Explain the the concept of scaling factor. (1 point) 
 
 
 
 
 
 

Page ​13
Name______________________
Student ID__________________

 
Table 4.1: Density bucket and scaling factor corresponding to device density 
Device Density  Density Bucket  Scaling factor 
232 dpi  hdpi - 240 dpi  1.5 px/dp 
240 dpi  hdpi - 240 dpi  1.5 px/dp 
 
Q4.3 From Table 4.1, determine the size of a 100 dp view on 232 dpi and on 240 dpi 
device. Does it exhibit the same physical size on both devices? Justify your results. 
Size on 232 dpi (0.5 point)________________________ (inch) 
Size on 240 dpi (0.5 point)________________________ (inch) 
Justify results (1 point)________________________________________ 
 
 
 
 
 
 
 
 

Page ​14
Name______________________
Student ID__________________

Question 5 [Views] (4 points) 


Q5.1 How to refer to the RadioGroup from Fig. 5.1 (page 16) in Kotlin file? (1 point) 
 
 
 
 
Q5.2 Draw the UI corresponding to the code in Fig. 5.1 (page 16). (3 points) 

Page ​15
Name______________________
Student ID__________________

<​RadioGroup

​android​:layout_width=​"wrap_content"

​android​:layout_height=​"wrap_content"

​android​:orientation=​"vertical"

​android​:id=​"@+id/rgOperator"

​android​:checkedButton=​"@+id/rdDivide"​>

<​RadioButton

​android​:text=​"X"

​android​:id=​"@+id/rdMult"

​android​:layout_width=​"wrap_content"

​android​:layout_height=​"wrap_content" ​/>

<​RadioButton

​android​:layout_width=​"wrap_content"

​android​:layout_height=​"wrap_content"

​android​:text=​"/"

​android​:id=​"@+id/rdDivide"

​android​:layout_marginLeft=​"16dp"​/>

</​RadioGroup​>

Fig. 5.1 XML code of the radio group 

Page ​16

You might also like