Skip to content
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
65 changes: 65 additions & 0 deletions Android_Intents_ActivityLifeCycle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
29 changes: 29 additions & 0 deletions Android_Intents_ActivityLifeCycle/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Android_Intents_ActivityLifeCycle/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Android_Intents_ActivityLifeCycle/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Android_Intents_ActivityLifeCycle/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Android_Intents_ActivityLifeCycle/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions Android_Intents_ActivityLifeCycle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Android Intents

### Requirements
For this project, you will be creating a multi page app. The first page will allow the user to import images and list them by name. The second will allow the user to view and edit details of a single image (these are details that you choose and do not need to be permanent). The third will allow the user to view the selected image in full screen.
This will encompass many of the skills you have developed over the Intro to Android course. We'll give you a few tips on how to process.

### Part 1 - Create an Android Studio Project

1. Create a new Android Studio project
2. Name the project "Image Viewer"
3. Make sure that the target API level is below that of your testing environment.

### Part 2 - Build layout for the Add and List activity

1. Open the app's activity_main.xml file.
2. Change the parent viewgroup to a linear layout
> Set the `orientation` attribute to `vertical` to best utilize the screen real estate
4. Add a `ScrollView` to list all previously viewed images. Give it a linear layout child.
5. Add a `Button` so the user select an image to add to the list
6. Add IDs to all the views that will need to be accessed in the code.

### Part 3 - Create an ImageData Class

1. Create a class to store desired data from retreived image.
> The only required data is a name and a `Uri` stored as a String.
> Convert a `Uri` to a string with `.toString()` method and back with `Uri.parse(stringUri)`.
2. Class must contain the keywords `implements Serializable` in the class signature
> This provides the necessary methods to the `Intent.putExtra` method can store the class's data
3. Make all the data members private and create getters and setters for them
> The `Uri` setter should convert the `Uri` to a `String` and the getter should convert it back.
> This is because a `Uri` object can't be serialized.

### Part 4 - Write a method to generate a TextView object

1. Add a `TextView` to your layout xml file.
2. Manipulate its attributes until you find a design that you like.
3. Write a method that will create a `TextView` object and add those attributes to it programatically.
4. The method must accept a `String` to be the view's text attribute and an `int` which is the index where the element is stored in the `List`.
5. Return the `TextView` from the method.
6. To add the `TextView` to the ui, pass it to your `ScrollView`'s `LinearLayout` child's `.addView()` method.

### Part 5 - Create an Intent to Get an Image

1. Create a listener and event handler for the add button in MainActivity.java
2. In the click event method, write a Get Content Implicit Event that retreives an image from the system.
3. Broadcast that intent with a `startActivityForResult` method call.
4. Override the `onActivityResult` method to create the `ImageData` object, add it to an `ArrayList` class data memeber have a `TextView` generated and added to your UI.

### Part 6 - Test your App

1. Thoroughly test this activity before moving on.

### Part 7 - Add a click listener to the items in the list

1. In your `TextView` generator give the `TextView` object a listener that will get the tag from the element, use that to pull the `ImageData` object from the `List`.
2. Use `intent.putExtra()` to add the object to the intent

### Part 8 - Build the layout for the details activity

1. Design a layout that will display details about the file.
2. Display the image somewhere in the layout.

### Part 9 - Retreive the Object from the Intent

1. Use `getIntent()` to get the intent used to launch this activity.
2. Use the `intent.getSerializableExtra()` method to retreive the serialized data and then cast it to `ImageData`.
* the final line of code should look something like this `myObject = (ImageData)intent.getSerializableExtra("KEY")`

### Part 10 - Display object

1. Show the desired data in the UI.
2. Use `.setImageURI()` to get the image for your `ImageView` to the one in our `ImageData`

### Part 11 - Test your App

1. Thoroughly test these two activities before moving on.


## Challenge (Optional)
### Part 12 - Build Fullscreen Layout

1. Add an activity
> You can pick a Fullscreen activity from the new activity wizard and adapt it to your needs, or build an empty activity with full screen imageview element
2. Adapt generated layout to fit your needs

### Part 13 - Built an intent to go to the next activity

1. Build an intent to go to the next activity, but instead of passing the whole object, just pass the `String` value for the Uri.

### Part 14 - Add the image to the UI

1. Use the `intent.getStringExtra()` method to retreive the `String` `Uri` from the `Intent`
2. Use `.setImageURI()` to update the `Uri`

### Submit
Send your completed app to your Project Manager.
Binary file not shown.
1 change: 1 addition & 0 deletions Android_Intents_ActivityLifeCycle/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions Android_Intents_ActivityLifeCycle/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.imageveiwer3"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions Android_Intents_ActivityLifeCycle/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.imageveiwer3;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.example.imageveiwer3", appContext.getPackageName());
}
}
22 changes: 22 additions & 0 deletions Android_Intents_ActivityLifeCycle/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imageveiwer3">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ImageViewerDetails"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading