Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit b32773d

Browse files
cezannecAsser
authored andcommitted
TFragments.00-StartingCode
1 parent 4f4bcaa commit b32773d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+252
-31
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
android:label="@string/app_name"
99
android:supportsRtl="true"
1010
android:theme="@style/AppTheme">
11-
<activity android:name=".MainActivity">
11+
<activity android:name=".ui.AndroidMeActivity">
1212
<intent-filter>
1313
<action android:name="android.intent.action.MAIN" />
1414

app/src/main/java/com/example/android/android_me/MainActivity.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
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+
*/
16+
17+
package com.example.android.android_me.data;
18+
19+
import com.example.android.android_me.R;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
// Class for storing all the image drawable resources in ArrayLists
25+
public class AndroidImageAssets {
26+
27+
// Lists for all AndroidMe images
28+
// Broken down into heads, bodies, legs, and all images
29+
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+
}};
44+
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+
}};
59+
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+
}};
74+
75+
private static final List<Integer> all = new ArrayList<Integer>() {{
76+
addAll(heads);
77+
addAll(bodies);
78+
addAll(legs);
79+
}};
80+
81+
82+
// Getter methods that return lists of all head images, body images, and leg images
83+
84+
public static List<Integer> getHeads() {
85+
return heads;
86+
}
87+
88+
public static List<Integer> getBodies() {
89+
return bodies;
90+
}
91+
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+
}
100+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
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+
*/
16+
17+
package com.example.android.android_me.ui;
18+
19+
import android.support.v7.app.AppCompatActivity;
20+
import android.os.Bundle;
21+
22+
import com.example.android.android_me.R;
23+
24+
// This activity will display a custom Android image composed of three body parts: head, body, and legs
25+
public class AndroidMeActivity extends AppCompatActivity {
26+
27+
@Override
28+
protected void onCreate(Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_android_me);
31+
}
32+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
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+
*/
16+
17+
package com.example.android.android_me.ui;
18+
19+
import android.content.Context;
20+
import android.view.View;
21+
import android.view.ViewGroup;
22+
import android.widget.BaseAdapter;
23+
import android.widget.GridView;
24+
import android.widget.ImageView;
25+
26+
import java.util.List;
27+
28+
29+
// Custom adapter class that displays a list of Android-Me images in a GridView
30+
public class MasterListAdapter extends BaseAdapter {
31+
32+
// Keeps track of the context and list of images to display
33+
private Context mContext;
34+
private List<Integer> mImageIds;
35+
36+
/**
37+
* Constructor method
38+
* @param imageIds The list of images to display
39+
*/
40+
public MasterListAdapter(Context context, List<Integer> imageIds) {
41+
mContext = context;
42+
mImageIds = imageIds;
43+
}
44+
45+
/**
46+
* Returns the number of items the adapter will display
47+
*/
48+
@Override
49+
public int getCount() {
50+
return mImageIds.size();
51+
}
52+
53+
@Override
54+
public Object getItem(int i) {
55+
return null;
56+
}
57+
58+
@Override
59+
public long getItemId(int i) {
60+
return 0;
61+
}
62+
63+
/**
64+
* Creates a new ImageView for each item referenced by the adapter
65+
*/
66+
public View getView(final int position, View convertView, ViewGroup parent) {
67+
ImageView imageView;
68+
if (convertView == null) {
69+
// If the view is not recycled, this creates a new ImageView to hold an image
70+
imageView = new ImageView(mContext);
71+
// Define the layout parameters
72+
imageView.setAdjustViewBounds(true);
73+
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
74+
imageView.setPadding(8, 8, 8, 8);
75+
} else {
76+
imageView = (ImageView) convertView;
77+
}
78+
79+
// Set the image resource and return the newly created ImageView
80+
imageView.setImageResource(mImageIds.get(position));
81+
return imageView;
82+
}
83+
84+
}
9.06 KB
10.7 KB
5.67 KB
5.15 KB
14.8 KB

0 commit comments

Comments
 (0)