Android Google Maps v2 Tutorial
Android Google Maps v2 Tutorial
02 xmlns:tools="[Link]
03 android:id="@+id/container"
04 android:layout_width="match_parent"
05 android:layout_height="match_parent"
06 android:layout_gravity="center"
07 android:background="#333333"
08 android:orientation="vertical"
09 android:paddingBottom="@dimen/activity_vertical_margin"
10 android:paddingLeft="@dimen/activity_horizontal_margin"
11 android:paddingRight="@dimen/activity_horizontal_margin"
12 android:paddingTop="@dimen/activity_vertical_margin" >
13
14 <TextView
15 android:id="@+id/songName"
16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content"
18 android:layout_gravity="center"
19 android:text="songName" />
20
21 <ImageView
22 android:id="@+id/mp3Image"
23 android:layout_width="match_parent"
24 android:layout_height="200dp"
25 android:padding="30dp"
26 android:src="@drawable/music"
27 android:background="#ffffff"
28 android:layout_margin="30dp" />
29
30 <TextView
31 android:id="@+id/songDuration"
32 android:layout_width="wrap_content"
33 android:layout_height="wrap_content"
34 android:layout_gravity="center"
35 android:text="songDuration" />
36
37 <SeekBar
38 android:id="@+id/seekBar"
39 android:layout_width="match_parent"
40 android:layout_height="wrap_content" />
41
42 <LinearLayout
43 android:layout_width="match_parent"
44 android:layout_height="match_parent"
45 android:layout_marginTop="30dp"
46 android:gravity="center_horizontal"
47 android:orientation="horizontal" >
48
49 <ImageButton
50 android:id="@+id/media_rew"
51 android:layout_width="wrap_content"
52 android:layout_height="wrap_content"
53 android:layout_marginLeft="14dp"
54 android:onClick="rewind"
55 android:src="@android:drawable/ic_media_rew" />
56
57 <ImageButton
58 android:id="@+id/media_pause"
59 android:layout_width="wrap_content"
60 android:layout_height="wrap_content"
61 android:layout_marginLeft="14dp"
62 android:onClick="pause"
63 android:src="@android:drawable/ic_media_pause" />
64
65 <ImageButton
66 android:id="@+id/media_play"
67 android:layout_width="wrap_content"
68 android:layout_height="wrap_content"
69 android:layout_marginLeft="14dp"
70 android:onClick="play"
71 android:src="@android:drawable/ic_media_play" />
72
73 <ImageButton
74 android:id="@+id/media_ff"
75 android:layout_width="wrap_content"
76 android:layout_height="wrap_content"
77 android:layout_marginLeft="14dp"
78 android:onClick="forward"
79 android:src="@android:drawable/ic_media_ff" />
80 </LinearLayout>
81
82 </LinearLayout>
You can notice that we will use the smart android:onClick attribute from the xml, in order to
avoid setting onTouch listeners in the main Android Java Code. The onClick attribute describes
which method is going to “catch” this event.
Also, do not forget to insert a sound clip in the res/raw folder of the project. We have dragged
and dropped the sample_song.mp3 file.
Figure 8: Inserted an mp3 file inside raw folder
We have also added an image jpg file, in res/drawable folders of the project. This image is
used as a background source of an ImageView in our layout xml file.
02
03 import [Link];
04
05 import [Link];
06 import [Link];
07 import [Link];
08 import [Link];
09 import [Link];
10 import [Link];
11 import [Link];
12
14
21
22 @Override
24 [Link](savedInstanceState);
25
27 setContentView([Link].activity_main);
28
29 //initialize views
30 initializeViews();
31 }
32
36 finalTime = [Link]();
39 [Link]("Sample_Song.mp3");
40
41 [Link]((int) finalTime);
42 [Link](false);
43 }
44
47 [Link]();
48 timeElapsed = [Link]();
49 [Link]((int) timeElapsed);
50 [Link](updateSeekBarTime, 100);
51 }
52
57 timeElapsed = [Link]();
59 [Link]((int) timeElapsed);
63
65 [Link](this, 100);
66 }
67 };
68
71 [Link]();
72 }
73
77 if ((timeElapsed + forwardTime) 0) {
78 timeElapsed = timeElapsed - backwardTime;
79
81 [Link]((int) timeElapsed);
82 }
83 }
84
85 }
2 initializeViews();
With [Link](); we can start the audio playback, and with timeElapsed =
[Link](); we can take the exact milliseconds in order to set the seekbar
progress [Link]((int) timeElapsed);
1 // play mp3 song
3 [Link]();
4 timeElapsed = [Link]();
5 [Link]((int) timeElapsed);
6 [Link](updateSeekBarTime, 100);
7}
You can also learn more about Android SeekBar in the JavaCodeGeeks Android SeekBar
Example.
As you can see, we use a Handler in order to continuously update the seekbar progress and
the time remaining duration. In order to achive this we have added the method:
01 //handler to change seekBarTime
05 timeElapsed = [Link]();
07 [Link]((int) timeElapsed);
11
13 [Link](this, 100);
14 }
15 };
This method is continuously executed, with a delay of 100 milliseconds. You can also learn
more about Android Handler in the JavaCodeGeeks Android Handler Example.
We alse move our current playback back position forwards and backwards, but we should in
the first place check if this move is valid by:
01 // go forward at forwardTime seconds
06
08 [Link]((int) timeElapsed);
09 }
10 }
4. Android Manifest
The [Link] of our project is simple and basic. We have only blocked our
orientation to portait by adding the line: android:screenOrientation="portrait"
[Link]
01 <?xml version="1.0" encoding="utf-8"?>
02 <manifest xmlns:android="[Link]
03 package="[Link]"
04 android:versionCode="1"
05 android:versionName="1.0" >
06
07 <uses-sdk
08 android:minSdkVersion="8"
09 android:targetSdkVersion="19" />
10
11 <application
12 android:allowBackup="true"
13 android:icon="@drawable/ic_launcher"
14 android:label="@string/app_name" >
15 <activity
1 android:name="[Link]
6 dMediaPlayerExample"
17 android:screenOrientation="portrait"
18 android:label="@string/app_name" >
19 <intent-filter>
22 </intent-filter>
23 </activity>
24 </application>
25
26 </manifest>
Files .
Also there is a Launch CheckList that provide us advice for successful product launch
on Google Play .
Click “Browse…” button and choose the project you want to export. If it has no errors, click
Next. Otherwise you can’t continue and you have to fix the errors. You can go to the next
picture directly, if you right click on the current project → Android Tools → Export Signed
Application Package.
In the next window, choose “Create new keystore”. Then, click “Browse…” to put it in a
location locally to your pc and write down a password. After the password confirmation,
press again Next button.
Now you have to create the key, so you should complete some of the fields, like shown in
the image below. It is necessary to fill in some of these fields, but not all of them. Then click
Next.
Specify the destination of the .apk file that you want to export and give it an appropriate
name, like in the next picture. Finally press Finish.
You can ensure the certification of your APK file from Eclipse Console, as you can see in the
image below.
02 xmlns:tools="[Link]
03 android:layout_width="match_parent"
04 android:layout_height="match_parent"
05 tools:context=".MainActivity" >
06
07 <TextView
08 android:id="@+id/textView"
09 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:layout_alignParentLeft="true"
12 android:layout_alignParentRight="true"
13 android:layout_alignParentTop="true"
14 android:layout_margin="10dp"
15 android:textSize="20dp"
16 android:gravity="center"
18
19 <TextView
20 android:id="@+id/textView1"
21 android:layout_width="wrap_content"
22 android:layout_height="wrap_content"
23 android:layout_alignLeft="@+id/textView"
24 android:layout_alignRight="@+id/textView"
25 android:layout_below="@+id/textView"
26 android:gravity="center"
27 android:text="TextView" />
28
29 <ProgressBar
30 android:id="@+id/progressBar1"
31 style="?android:attr/progressBarStyleHorizontal"
32 android:layout_width="wrap_content"
33 android:layout_height="wrap_content"
34 android:layout_above="@+id/textView1"
35 android:layout_alignParentLeft="true"
36 android:layout_alignParentRight="true" />
37
38 </RelativeLayout>
2 </uses-permission>
[Link]
01 <?xml version="1.0" encoding="utf-8"?>
02 <manifest xmlns:android="[Link]
03 package="[Link]"
04 android:versionCode="1"
05 android:versionName="1.0" >
06
07 <uses-sdk
08 android:minSdkVersion="8"
09 android:targetSdkVersion="17" />
10
12 </uses-permission>
13
14 <application
15 android:allowBackup="true"
16 android:icon="@drawable/ic_launcher"
17 android:label="@string/app_name"
18 android:theme="@style/AppTheme" >
19 <activity
android:name="[Link]
20
[Link]"
21 android:label="@string/app_name" >
22 <intent-filter>
24
26 </intent-filter>
27 </activity>
28 </application>
29
30 </manifest>
[Link]:
01 package [Link];
02
03 import [Link];
04 import [Link];
05 import [Link];
06 import [Link];
07 import [Link];
08 import [Link];
09 import [Link];
10
13
14 @Override
16 [Link](savedInstanceState);
17 setContentView([Link]);
19 fetchContacts();
20 }
21
23
26
String HAS_PHONE_NUMBER =
30
[Link].HAS_PHONE_NUMBER;
31
Uri PhoneCONTENT_URI =
32
[Link].CONTENT_URI;
String Phone_CONTACT_ID =
33
[Link].CONTACT_ID;
35
Uri EmailCONTENT_URI =
36
[Link].CONTENT_URI;
String EmailCONTACT_ID =
37
[Link].CONTACT_ID;
39
41
43
Cursor cursor =
44
[Link](CONTENT_URI, null,null, null, null);
45
47 if ([Link]() > 0) {
48
49 while ([Link]()) {
50
String name =
52
[Link]([Link]( DISPLAY_NAME ));
53
54 int hasPhoneNumber =
[Link]([Link]([Link]( HAS_PHONE_NUMBER )
));
55
56 if (hasPhoneNumber > 0) {
57
59
Cursor phoneCursor =
61 [Link](PhoneCONTENT_URI, null, Phone_CONTACT_ID + "
= ?", new String[] { contact_id }, null);
62
63 while ([Link]()) {
phoneNumber =
64
[Link]([Link](NUMBER));
66
67 }
68
69 [Link]();
70
Cursor emailCursor =
72 [Link](EmailCONTENT_URI, null, EmailCONTACT_ID+ "
= ?", new String[] { contact_id }, null);
73
74 while ([Link]()) {
75
email =
76
[Link]([Link](DATA));
77
78 [Link]("\nEmail:" + email);
79
80 }
81
82 [Link]();
83 }
84
85 [Link]("\n");
86 }
87
88 [Link](output);
89 }
90 }
91
92 }