-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathmaptour.html
More file actions
967 lines (966 loc) · 26.4 KB
/
Copy pathmaptour.html
File metadata and controls
967 lines (966 loc) · 26.4 KB
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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="App Inventor for Android" name="description" />
<meta content="Android, Blocks App Inventor, Mobile, Phone, IDE" name="keywords" />
<title>
Map Tour - App Inventor for Android
</title>
<link href="/static/images/appinventor-16.png" rel="SHORTCUT ICON" type="image/ico" />
<link href="/static/images/appinventor-16.png" rel="icon" type="image/png" />
<link href="/static/css/appinventor.css" rel="stylesheet" />
<script src="http://www.google.com/js/gweb/analytics/autotrack.js">
</script>
<script>
var tracker = new gweb.analytics.AutoTrack({
profile: 'UA-5856106-2'
});
</script>
<script language = "JavaScript" src="/static/scripts/HeaderAndFooter.js"></script>
<style>
img.c2 {border-width:0}
div.c1 {clear:both;}
</style>
</head>
<body>
<script language = "JavaScript">createHeader('<div id="navigation-breadcrumb"> <a href="/learn/">Learn</a> > <a href="/learn/tutorials">Tutorials</a> > Map Tour ');</script><br>
<div id="aiac">
<div class="main-container">
<div class="customhr customhr-gray">
</div>
<div class="content">
<div class="content-body">
<div class="learn-page">
<h1>
Map Tour
</h1>
<h2>
What You're Building
</h2>
<div class="imagecontainer">
<img align="right" alt="" border="0" src="MapTourAssets/listPicker.png" />
</div>
<span align="RIGHT"><a href = "http://cs.usfca.edu/~wolber/appinventor/bookSplits/ch6Map.pdf" title="Get the updated, refined version of this tutorial from the book, App Inventor: Create your own Android Apps">Download Book Chapter</a><img src="/static/images/pdficon_small.png" /></span>
<p>
This is a two-part tutorial introduces the
<span class="ButtonText">
ActivityStarter
</span>
component for launching arbitrary Android Apps
and the
<span class="ButtonText">
ListPicker
</span>
component for allowing a user to
choose from a list of items. You'll build MapTour, an app for visiting French
vacation destinations with a single click. Users of your app will be able to visit
the Eiffel Tower, the Louvre, and Notre Dame in quick succession.
<br />
</p>
<p>
This tutorial assumes you are familiar with the basics of App Inventor-- using the
Component Designer to build a user interface, and using the Blocks Editor to
specify event-handlers. If you are not familiar with the basics, try stepping
through some of the
<a href="/learn/tutorials/index.html">
basic tutorials
</a>
before continuing.
</p>
<p>
Once you complete the first part of this tutorial, try
<a href="/learn/tutorials/maptour/maptour2.html">
part 2
</a>
.
</p>
<h2>
Getting Started
</h2>
<p>
Connect to the App Inventor web site and start a new project. Name it MapTour, and
also set the screen's
<span class="ButtonText">
Title
</span>
to MapTour. Open the
Blocks Editor and connect to the phone.
</p>
<h2>
Introduction
</h2>
<p>
You'll design the app so that a list of destinations appears. When the user chooses
one, the Google Maps app is launched to display a map of the destination.
</p>
<p>
The tutorial introduces the following App Inventor concepts:
<br />
</p>
<ul>
<li>
The Activity Starter component for launching Android apps from your app.
</li>
<li>
The ListPicker component for allowing the user to choose from a list of
choices.
<br />
</li>
</ul>
<h2>
Set up the Components
<br />
</h2>
<p>
The user interface for MapTour is simple: you'll have a single ListPicker component
and an ActivityStarter (non-visible) component. The design view should look like
this when you're done:
</p>
<div class="imagecontainer">
<img alt="" src="MapTourAssets/designer.png" width="961" />
</div>
<p>
The components listed below were used to create this designer window. Drag each
component from the
<span class="ButtonText">
Palette
</span>
into the
<span class="ButtonText">
Viewer
</span>
and name it as specified:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Component Type
</td>
<td class="tbl-header">
Palette Group
</td>
<td class="tbl-header">
What you'll name it
</td>
<td class="tbl-header">
Purpose of Component
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Image
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
Image1
</span>
</td>
<td>
Show a static image of Paris map on screen
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ListPicker
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
ListPicker1
</span>
</td>
<td>
Display the list of destinations
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ActivityStarter
</span>
</td>
<td>
other stuff
</td>
<td>
<span class="ButtonText">
ActivityStarter1
</span>
</td>
<td>
Launches the maps app when a destination is chosen
<br />
</td>
</tr>
</tbody>
</table>
</div>
<p>
Download the file
<a href="MapTourAssets/parismap.png">
parismap.png
</a>
onto your
computer, then choose
<span class="ButtonText">
Add
</span>
in the
<span class="ButtonText">
Media
</span>
section to load it into your project. For it to appear,
you'll also need to set this as the Picture property of Image1.
</p>
<p>
The
<span class="ButtonText">
ListPicker
</span>
component has an associated button--
when the user clicks it, the choices are listed. Set the text of that button by
setting the
<span class="ButtonText">
Text
</span>
property of
<span class="ButtonText">
ListPicker1
</span>
to "Choose Destination".
</p>
<h2>
Setting the properties of ActivityStarter
</h2>
<p>
<span class="ButtonText">
ActivityStarter
</span>
is a component that lets you launch
any Android app-- the browser, Maps, even another one of your own apps. When
another app is launched from your app, the user can click the back button to get
back to your app. You'll build MapTour so that the Maps application is launched to
show particular maps based on the user's choice. The user can then hit the back
button to return to your app and choose a different destination.
</p>
<p>
<span class="ButtonText">
ActivityStarter
</span>
is a relatively low-level component
in that you'll need to set some properties of the component with information
familiar to a Java Android SDK programmer, but foreign to the rest of the 99.999%
people in the world. Not to worry, however. By copying the sample protocol
information provided here, you can easily learn how to launch apps like Maps from
the apps you are creating.
</p>
<p>
So, to set-up the
<span class="ButtonText">
ActivityStarter
</span>
to launch the
Maps application, set the following ActivityStarter properties in the Component
Designer:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Property
</td>
<td class="tbl-header">
Value
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Action
</span>
</td>
<td>
android.intent.action.VIEW
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ActivityPackage
</span>
</td>
<td>
com.google.android.apps.maps
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ActivityClass
</span>
</td>
<td>
com.google.android.maps.MapsActivity
</td>
</tr>
</tbody>
</table>
</div>
<p>
With these values set, you'll be able to launch the Maps application. In the Blocks
Editor, you'll set one more property,
<span class="ButtonText">
DataUri
</span>
,
which will allow you to launch Maps with a particular map being displayed. This
property must be set in the Blocks Editor because it will change based on whether
the user chooses to visit the Louvre, the Eiffel Tower, or the Notre Dame.
</p>
<h2>
Create a list of destinations
</h2>
<p>
Open the blocks editor and create a variable with the list of destinations for the
MapTour. You'll need the following blocks:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Block Type
</td>
<td class="tbl-header">
Drawer
</td>
<td class="tbl-header">
Purpose
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
def variable
</span>
("Destinations")
</td>
<td>
Definitions
</td>
<td>
create a list of the destinations
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
make a list
</span>
</td>
<td>
Lists
<br />
</td>
<td>
use to add the items to the list
<br />
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("Tour Eiffel")
</td>
<td>
Text
</td>
<td>
the first destination
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("Musee du Louvre")
</td>
<td>
Text
</td>
<td>
the second destination
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("Cathedrale Notre Dame")
<br />
</td>
<td>
Text
</td>
<td>
set the
<span class="ButtonText">
Message
</span>
property before sending
<br />
</td>
</tr>
</tbody>
</table>
</div>
<p>
The blocks will look like this:
</p>
<div class="imagecontainer">
<img alt="" height="141" src="MapTourAssets/destinationList.png" width="489" />
</div>
<h2>
Add behaviors to the components
</h2>
<p>
MapTour has two behaviors:
</p>
<p>
1. When the app begins, the app loads the destinations into the
<span class="ButtonText">
ListPicker
</span>
component so the user can choose.
</p>
<p>
2. When the user chooses a destination from the
<span class="ButtonText">
ListPicker
</span>
, the Maps application is launched to show a map of
that destination. For Part I, you'll just open Maps and tell it to invoke a search
for the chosen destination
</p>
<p>
The
<span class="ButtonText">
ListPicker
</span>
component displays a list of items
when the user clicks a button.
<span class="ButtonText">
ListPicker
</span>
has a
property
<span class="ButtonText">
Elements
</span>
. If you set
<span class="ButtonText">
Elements
</span>
to a list, the items in the list will appear in the
<span class="ButtonText">
ListPicker
</span>
. For this app, you want to set the
<span class="ButtonText">
ListPicker'
</span>
s
<span class="ButtonText">
Elements
</span>
property to the destinations list you just created.
Because you want this to happen when the app begins, you'll define this behavior in
the
<span class="ButtonText">
Screen1.Initialize
</span>
event. You'll need the
following blocks:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Block Type
</td>
<td class="tbl-header">
Drawer
</td>
<td class="tbl-header">
Purpose
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Screen1.Initialize
</span>
</td>
<td>
Screen1
</td>
<td>
this event is triggered when the app starts
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
set ListPicker1.Elements to
</span>
</td>
<td>
ListPicker1
</td>
<td>
set this property to the list you want to appear
<br />
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
global destinations
</span>
</td>
<td>
My Definitions
</td>
<td>
the list of destinations
</td>
</tr>
</tbody>
</table>
</div>
<p>
The blocks should look like this:
</p>
<div class="imagecontainer">
<img alt="" height="110" src="MapTourAssets/screenInit.png" width="369" />
</div>
<h2>
How the Blocks Work
</h2>
<p>
<span class="ButtonText">
Screen1.Initialize
</span>
is triggered when the app
begins. The event-handler just sets the
<span class="ButtonText">
Elements
</span>
property of
<span class="ButtonText">
ListPicker
</span>
so that the three
destinations will appear.
</p>
<blockquote class="testing">
<strong>
Test this behavior.
</strong>
On the phone, click the button labeled "Choose
Destination". The list picker should appear with the three items.
</blockquote>
<h2>
Launching Maps with a search for the destination
</h2>
<p>
Next, you'll program the behavior that should occur when the user chooses one of
the destinations-- the
<span class="ButtonText">
ActivityStarter
</span>
should
launch Maps and search for the selected destination.
</p>
<p>
When the user chooses from the
<span class="ButtonText">
ListPicker
</span>
component, the
<span class="ButtonText">
ListPicker.AfterPicking
</span>
event is
triggered. In the event-handler for
<span class="ButtonText">
AfterPicking
</span>
you need to set the
<span class="ButtonText">
DataUri
</span>
of the ActivityStarter
component so it knows which map to open, then you need to launch the app using
StartActivity.
</p>
<p>
You'll need the following blocks:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Block Type
</td>
<td class="tbl-header">
Drawer
</td>
<td class="tbl-header">
Purpose
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ListPicker1.AfterPicking
</span>
</td>
<td>
ListPicker1
</td>
<td>
this event is triggered when the user chooses from
<span class="ButtonText">
ListPicker
</span>
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
set ActivityStarter1.DataUri to
</span>
</td>
<td>
ActivityStarter1
<br />
</td>
<td>
the
<span class="ButtonText">
DataUri
</span>
tells Maps which map to open on
launch
<br />
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
make text
</span>
</td>
<td>
Text
</td>
<td>
build the
<span class="ButtonText">
DataUri
</span>
from two pieces of text
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("geo:0,0?q=")
</td>
<td>
Text
</td>
<td>
the first part of the
<span class="ButtonText">
DataUri
</span>
expected by
Maps
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ListPicker1.Selection
</span>
</td>
<td>
ListPicker1
</td>
<td>
the item the user chose
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ActivityStarter1.StartActivity
</span>
</td>
<td>
ActivityStarter1
</td>
<td>
launch Maps
</td>
</tr>
</tbody>
</table>
</div>
<p>
The blocks should look like this:
</p>
<div class="imagecontainer">
<img alt="" height="199" src="MapTourAssets/afterPicking.png" width="541" />
</div>
<h2>
How the Blocks Work
</h2>
<p>
When the user chooses from the
<span class="ButtonText">
ListPicker
</span>
, the
<span class="ButtonText">
AfterPicking
</span>
event is triggered. Whatever item was
chosen is in the
<span class="ButtonText">
ListPicker1.Selection
</span>
property. So
if the user chose "Musee du Louvre", that value is in
<span class="ButtonText">
ListPicker1
</span>
's
<span class="ButtonText">
Selection
</span>
property.
</p>
<p>
In the Component Designer, you already setup the
<span class="ButtonText">
ActivityStarter
</span>
componenent with properties so that it will
launch the Maps application. Here, you just need to tell it which map to show. The
<span class="ButtonText">
DataUri
</span>
property of ActivityStarter allows you to
specify this using a special protocol.
</p>
<p>
In this case, you want to show the map that would appear if you typed in "Musee du
Louvre" in the search box of the Maps application. To do this, the
<span class="ButtonText">
DataUri
</span>
should be set to:
</p>
<blockquote>
geo:0,0?q='Musee du Louvre'
</blockquote>
<p>
The
<span class="ButtonText">
make a text
</span>
block creates a text exactly like
this, only the text after "q=" will be the choice made by the user.
</p>
<p>
Once the
<span class="ButtonText">
DataUri
</span>
is set,
<span class="ButtonText">
ActivityStarter1.StartActivity
</span>
launches the Maps app.
</p>
<blockquote class="notice">
For help with the Maps application parameters, see this
<a href="http://mapki.com/wiki/Google_Map_Parameters">
document
</a>
from mapki.com
</blockquote>
<blockquote class="testing">
<strong>
Test this behavior.
</strong>
Restart the app and click the "Choose
Destinations" button again. When you choose one of the destinations, does a map of
that destination appear? Can you click the back button to return to your app to
choose again (you may have to click a couple of times to leave the Maps app).
</blockquote>
<h2>
Map Tour, Final Program
</h2>
<div class="imagecontainer">
<img alt="" height="451" src="MapTourAssets/mapTourFinal.png" width="541" />
</div>
<h2>
Review
</h2>
<p>
Here are some of the ideas covered in this tutorial:
</p>
<ul>
<li>
The
<span class="ButtonText">
ListPicker
</span>
component lets the user choose
from a list of items.
<span class="ButtonText">
ListPicker'
</span>
s
<span class="ButtonText">
Elements
</span>
property holds the list, the
<span class="ButtonText">
Selection
</span>
property holds the selected item, and the
<span class="ButtonText">
AfterPicking
</span>
event is triggered when the user chooses.
<br />
</li>
<li>
The
<span class="ButtonText">
ActivityStarter
</span>
component allows your app
to launch other apps. This tutorial demonstrated its use with the Maps application,
but you can launch a browser or any other Android app as well-- even another one of
your own.
</li>
<li>
See the
<a href="/learn/reference/other/activitystarter.html">
reference page on
Activity Starter
</a>
for more details.
</li>
<li>
Learn more sophisticated uses of the
<span class="ButtonText">
ActivityStarter
</span>
and the
<span class="ButtonText">
ListPicker
</span>
componants in
<a href="/learn/tutorials/maptour/maptour2.html">
MapTour Part 2
</a>
.
<br />
</li>
</ul>
<h2>
Scan the Sample App to your Phone
</h2>
<p>
Scan the following barcode onto your phone to install and run the sample app.
</p>
<div class="imagecontainer">
<img alt="" src="MapTourAssets/barcode.png" />
</div>
<h2>
Download Source Code
</h2>
If you'd like to work with this sample in App Inventor, download the
<a href="MapTourAssets/MapTour.zip">
source code
</a>
to your computer, then open App Inventor,
go to the
<span class="ButtonText">
My Projects
</span>
page, and choose
<span class="ButtonText">
More Actions | Upload Source
</span>
.
</div>
<div>
<blockquote class="notice">
Google is grateful to
<a href="http://www.appinventor.org/">
Professor David
Wolber
</a>
, CS Professor at The University of San Francisco, for developing this
tutorial.
</blockquote>
</div>
</div>
</div>
<div class="footer">
<script language = "JavaScript">createFooter();</script><br>
<div class="footer-lastupdate">
<script>
if (document.lastModified != '') {
var m = "Page last updated: " + document.lastModified;
var p = m.length-8;
document.writeln("<center>");
document.write(m.substring(p, 0));
document.writeln("<\/center>");
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>