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

T fragments.01 exercise create body part fragment #42

Open
wants to merge 2 commits into
base: Initial_commit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".ui.AndroidMeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/example/android/android_me/MainActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.android_me.data;

import com.example.android.android_me.R;

import java.util.ArrayList;
import java.util.List;

// Class for storing all the image drawable resources in ArrayLists
public class AndroidImageAssets {

// Lists for all AndroidMe images
// Broken down into heads, bodies, legs, and all images

private static final List<Integer> heads = new ArrayList<Integer>() {{
add(R.drawable.head1);
add(R.drawable.head2);
add(R.drawable.head3);
add(R.drawable.head4);
add(R.drawable.head5);
add(R.drawable.head6);
add(R.drawable.head7);
add(R.drawable.head8);
add(R.drawable.head9);
add(R.drawable.head10);
add(R.drawable.head11);
add(R.drawable.head12);
}};

private static final List<Integer> bodies = new ArrayList<Integer>() {{
add(R.drawable.body1);
add(R.drawable.body2);
add(R.drawable.body3);
add(R.drawable.body4);
add(R.drawable.body5);
add(R.drawable.body6);
add(R.drawable.body7);
add(R.drawable.body8);
add(R.drawable.body9);
add(R.drawable.body10);
add(R.drawable.body11);
add(R.drawable.body12);
}};

private static final List<Integer> legs = new ArrayList<Integer>() {{
add(R.drawable.legs1);
add(R.drawable.legs2);
add(R.drawable.legs3);
add(R.drawable.legs4);
add(R.drawable.legs5);
add(R.drawable.legs6);
add(R.drawable.legs7);
add(R.drawable.legs8);
add(R.drawable.legs9);
add(R.drawable.legs10);
add(R.drawable.legs11);
add(R.drawable.legs12);
}};

private static final List<Integer> all = new ArrayList<Integer>() {{
addAll(heads);
addAll(bodies);
addAll(legs);
}};


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

public static List<Integer> getHeads() {
return heads;
}

public static List<Integer> getBodies() {
return bodies;
}

public static List<Integer> getLegs() {
return legs;
}

// Returns a list of all the images combined: heads, bodies, and legs in that order
public static List<Integer> getAll() {
return all;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.android_me.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.android.android_me.R;

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

// TODO (1) Create a layout file that displays one body part image named fragment_body_part.xml
// This layout should contain a single ImageView

// TODO (2) Create a new class called BodyPartFragment to display an image of an Android-Me body part
// In this class, you'll need to implement an empty constructor and the onCreateView method
// TODO (3) Show the first image in the list of head images
// Soon, you'll update this image display code to show any image you want



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_me);

// TODO (5) Create a new BodyPartFragment instance and display it using the FragmentManager
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.android_me.ui;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import java.util.List;


// Custom adapter class that displays a list of Android-Me images in a GridView
public class MasterListAdapter extends BaseAdapter {

// Keeps track of the context and list of images to display
private Context mContext;
private List<Integer> mImageIds;

/**
* Constructor method
* @param imageIds The list of images to display
*/
public MasterListAdapter(Context context, List<Integer> imageIds) {
mContext = context;
mImageIds = imageIds;
}

/**
* Returns the number of items the adapter will display
*/
@Override
public int getCount() {
return mImageIds.size();
}

@Override
public Object getItem(int i) {
return null;
}

@Override
public long getItemId(int i) {
return 0;
}

/**
* Creates a new ImageView for each item referenced by the adapter
*/
public View getView(final int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// If the view is not recycled, this creates a new ImageView to hold an image
imageView = new ImageView(mContext);
// Define the layout parameters
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}

// Set the image resource and return the newly created ImageView
imageView.setImageResource(mImageIds.get(position));
return imageView;
}

}
Binary file added app/src/main/res/drawable/body1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/body9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/head9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/legs1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/legs10.png
Binary file added app/src/main/res/drawable/legs11.png
Binary file added app/src/main/res/drawable/legs12.png
Binary file added app/src/main/res/drawable/legs2.png
Binary file added app/src/main/res/drawable/legs3.png
Binary file added app/src/main/res/drawable/legs4.png
Binary file added app/src/main/res/drawable/legs5.png
Binary file added app/src/main/res/drawable/legs6.png
Binary file added app/src/main/res/drawable/legs7.png
Binary file added app/src/main/res/drawable/legs8.png
Binary file added app/src/main/res/drawable/legs9.png
39 changes: 39 additions & 0 deletions app/src/main/res/layout/activity_android_me.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.-->

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.android_me.ui.AndroidMeActivity">

<!-- LinearLayout for holding three Android-Me images -->
<LinearLayout
android:id="@+id/android_me_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

<!-- TODO (4) Create a container to hold the head BodyPartFragment of the custom Android -->
<!--The container should be 180dp in height -->



</LinearLayout>

</ScrollView>
17 changes: 0 additions & 17 deletions app/src/main/res/layout/activity_main.xml

This file was deleted.