Skip to content

Commit a1f8771

Browse files
committed
Fixing exercise udacity#6.
1 parent 230144a commit a1f8771

File tree

11 files changed

+437
-407
lines changed

11 files changed

+437
-407
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/build
88
/captures
99
.externalNativeBuild
10+
.idea

app/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 25
5-
buildToolsVersion "25.0.2"
5+
buildToolsVersion '28.0.3'
66
defaultConfig {
77
applicationId "com.example.android.android_me"
88
minSdkVersion 16
@@ -17,13 +17,17 @@ android {
1717
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1818
}
1919
}
20+
compileOptions {
21+
sourceCompatibility = '1.8'
22+
targetCompatibility = '1.8'
23+
}
2024
}
2125

2226
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27+
implementation fileTree(dir: 'libs', include: ['*.jar'])
28+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
2529
exclude group: 'com.android.support', module: 'support-annotations'
2630
})
27-
compile 'com.android.support:appcompat-v7:25.1.0'
28-
testCompile 'junit:junit:4.12'
31+
implementation 'com.android.support:appcompat-v7:25.1.0'
32+
testImplementation 'junit:junit:4.12'
2933
}
Lines changed: 89 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
* Copyright (C) 2017 The Android Open Source Project
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright (C) 2017 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
package com.example.android.android_me.data;
1818

@@ -24,77 +24,88 @@
2424
// Class for storing all the image drawable resources in ArrayLists
2525
public class AndroidImageAssets {
2626

27-
// Lists for all AndroidMe images
28-
// Broken down into heads, bodies, legs, and all images
27+
// Lists for all AndroidMe images
28+
// Broken down into heads, bodies, legs, and all images
2929

30-
private static final List<Integer> heads = new ArrayList<Integer>() {{
31-
add(R.drawable.head1);
32-
add(R.drawable.head2);
33-
add(R.drawable.head3);
34-
add(R.drawable.head4);
35-
add(R.drawable.head5);
36-
add(R.drawable.head6);
37-
add(R.drawable.head7);
38-
add(R.drawable.head8);
39-
add(R.drawable.head9);
40-
add(R.drawable.head10);
41-
add(R.drawable.head11);
42-
add(R.drawable.head12);
43-
}};
30+
private static final List<Integer> heads =
31+
new ArrayList<Integer>() {
32+
{
33+
add(R.drawable.head1);
34+
add(R.drawable.head2);
35+
add(R.drawable.head3);
36+
add(R.drawable.head4);
37+
add(R.drawable.head5);
38+
add(R.drawable.head6);
39+
add(R.drawable.head7);
40+
add(R.drawable.head8);
41+
add(R.drawable.head9);
42+
add(R.drawable.head10);
43+
add(R.drawable.head11);
44+
add(R.drawable.head12);
45+
}
46+
};
4447

45-
private static final List<Integer> bodies = new ArrayList<Integer>() {{
46-
add(R.drawable.body1);
47-
add(R.drawable.body2);
48-
add(R.drawable.body3);
49-
add(R.drawable.body4);
50-
add(R.drawable.body5);
51-
add(R.drawable.body6);
52-
add(R.drawable.body7);
53-
add(R.drawable.body8);
54-
add(R.drawable.body9);
55-
add(R.drawable.body10);
56-
add(R.drawable.body11);
57-
add(R.drawable.body12);
58-
}};
48+
private static final List<Integer> bodies =
49+
new ArrayList<Integer>() {
50+
{
51+
add(R.drawable.body1);
52+
add(R.drawable.body2);
53+
add(R.drawable.body3);
54+
add(R.drawable.body4);
55+
add(R.drawable.body5);
56+
add(R.drawable.body6);
57+
add(R.drawable.body7);
58+
add(R.drawable.body8);
59+
add(R.drawable.body9);
60+
add(R.drawable.body10);
61+
add(R.drawable.body11);
62+
add(R.drawable.body12);
63+
}
64+
};
5965

60-
private static final List<Integer> legs = new ArrayList<Integer>() {{
61-
add(R.drawable.legs1);
62-
add(R.drawable.legs2);
63-
add(R.drawable.legs3);
64-
add(R.drawable.legs4);
65-
add(R.drawable.legs5);
66-
add(R.drawable.legs6);
67-
add(R.drawable.legs7);
68-
add(R.drawable.legs8);
69-
add(R.drawable.legs9);
70-
add(R.drawable.legs10);
71-
add(R.drawable.legs11);
72-
add(R.drawable.legs12);
73-
}};
66+
private static final List<Integer> legs =
67+
new ArrayList<Integer>() {
68+
{
69+
add(R.drawable.legs1);
70+
add(R.drawable.legs2);
71+
add(R.drawable.legs3);
72+
add(R.drawable.legs4);
73+
add(R.drawable.legs5);
74+
add(R.drawable.legs6);
75+
add(R.drawable.legs7);
76+
add(R.drawable.legs8);
77+
add(R.drawable.legs9);
78+
add(R.drawable.legs10);
79+
add(R.drawable.legs11);
80+
add(R.drawable.legs12);
81+
}
82+
};
7483

75-
private static final List<Integer> all = new ArrayList<Integer>() {{
76-
addAll(heads);
77-
addAll(bodies);
78-
addAll(legs);
79-
}};
84+
private static final List<Integer> all =
85+
new ArrayList<Integer>() {
86+
{
87+
addAll(heads);
88+
addAll(bodies);
89+
addAll(legs);
90+
}
91+
};
8092

93+
// Getter methods that return lists of all head images, body images, and leg images
8194

82-
// Getter methods that return lists of all head images, body images, and leg images
95+
public static List<Integer> getHeads() {
96+
return heads;
97+
}
8398

84-
public static List<Integer> getHeads() {
85-
return heads;
86-
}
99+
public static List<Integer> getBodies() {
100+
return bodies;
101+
}
87102

88-
public static List<Integer> getBodies() {
89-
return bodies;
90-
}
103+
public static List<Integer> getLegs() {
104+
return legs;
105+
}
91106

92-
public static List<Integer> getLegs() {
93-
return legs;
94-
}
95-
96-
// Returns a list of all the images combined: heads, bodies, and legs in that order
97-
public static List<Integer> getAll() {
98-
return all;
99-
}
107+
// Returns a list of all the images combined: heads, bodies, and legs in that order
108+
public static List<Integer> getAll() {
109+
return all;
110+
}
100111
}
Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,66 @@
11
/*
2-
* Copyright (C) 2017 The Android Open Source Project
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright (C) 2017 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
package com.example.android.android_me.ui;
1818

19+
import android.os.Bundle;
1920
import android.support.v4.app.FragmentManager;
2021
import android.support.v7.app.AppCompatActivity;
21-
import android.os.Bundle;
2222

2323
import com.example.android.android_me.R;
2424
import com.example.android.android_me.data.AndroidImageAssets;
2525

26-
// This activity will display a custom Android image composed of three body parts: head, body, and legs
26+
// This activity will display a custom Android image composed of three body parts: head, body, and
27+
// legs
2728
public class AndroidMeActivity extends AppCompatActivity {
2829

30+
@Override
31+
protected void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
setContentView(R.layout.activity_android_me);
2934

30-
@Override
31-
protected void onCreate(Bundle savedInstanceState) {
32-
super.onCreate(savedInstanceState);
33-
setContentView(R.layout.activity_android_me);
34-
35-
// Only create new fragments when there is no previously saved state
36-
if(savedInstanceState == null) {
37-
38-
// TODO (5) Retrieve list index values that were sent through an intent; use them to display the desired Android-Me body part image
39-
// Use setListindex(int index) to set the list index for all BodyPartFragments
40-
41-
// Create a new head BodyPartFragment
42-
BodyPartFragment headFragment = new BodyPartFragment();
43-
44-
// Set the list of image id's for the head fragment and set the position to the second image in the list
45-
headFragment.setImageIds(AndroidImageAssets.getHeads());
46-
headFragment.setListIndex(1);
35+
// Only create new fragments when there is no previously saved state
36+
if (savedInstanceState == null) {
4737

48-
// Add the fragment to its container using a FragmentManager and a Transaction
49-
FragmentManager fragmentManager = getSupportFragmentManager();
38+
int headIndex = 0, bodyIndex = 0, legIndex = 0;
5039

51-
fragmentManager.beginTransaction()
52-
.add(R.id.head_container, headFragment)
53-
.commit();
40+
Bundle bundle = getIntent().getExtras();
41+
if (bundle != null) {
42+
headIndex = bundle.getInt("headIndex");
43+
bodyIndex = bundle.getInt("bodyIndex");
44+
legIndex = bundle.getInt("legIndex");
45+
}
5446

55-
// Create and display the body and leg BodyPartFragments
47+
// Add the fragment to its container using a FragmentManager and a Transaction
48+
FragmentManager fragmentManager = getSupportFragmentManager();
5649

57-
BodyPartFragment bodyFragment = new BodyPartFragment();
58-
bodyFragment.setImageIds(AndroidImageAssets.getBodies());
59-
fragmentManager.beginTransaction()
60-
.add(R.id.body_container, bodyFragment)
61-
.commit();
50+
BodyPartFragment headFragment = new BodyPartFragment();
51+
headFragment.setImageIds(AndroidImageAssets.getHeads());
52+
headFragment.setListIndex(headIndex);
53+
fragmentManager.beginTransaction().add(R.id.head_container, headFragment).commit();
6254

63-
BodyPartFragment legFragment = new BodyPartFragment();
64-
legFragment.setImageIds(AndroidImageAssets.getLegs());
65-
fragmentManager.beginTransaction()
66-
.add(R.id.leg_container, legFragment)
67-
.commit();
68-
}
55+
BodyPartFragment bodyFragment = new BodyPartFragment();
56+
bodyFragment.setImageIds(AndroidImageAssets.getBodies());
57+
bodyFragment.setListIndex(bodyIndex);
58+
fragmentManager.beginTransaction().add(R.id.body_container, bodyFragment).commit();
6959

60+
BodyPartFragment legFragment = new BodyPartFragment();
61+
legFragment.setImageIds(AndroidImageAssets.getLegs());
62+
legFragment.setListIndex(legIndex);
63+
fragmentManager.beginTransaction().add(R.id.leg_container, legFragment).commit();
7064
}
65+
}
7166
}

0 commit comments

Comments
 (0)