Commit 9d8d1e55 authored by Ryan Rowe's avatar Ryan Rowe
Browse files

EX2 Layout stub

parent 936a6e52
# See https://github.com/github/gitignore/blob/master/Android.gitignore
# Built application files
*.apk
*.ap_
*.aab
# 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 lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
# 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
.DS_Store
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Layout.iml" filepath="$PROJECT_DIR$/Layout.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "cse340.layout"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.3'
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design: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'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cse340.layout">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package cse340.layout;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.RelativeLayout;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* This is a driver activity for the Layout exercise. The main activity view consists of
* of tab bar located at the bottom of the window and a RelativeLayout where it displays
* the appropriate view for the selected tab. You will not need to modify this file as
* part of the assignment.
*/
public class MainActivity extends AppCompatActivity {
/** Default params for tab views, just match parents. */
public static final RelativeLayout.LayoutParams PARAMS = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
/**
* List of food_ drawables to display in part 3 and 4.
*/
@IdRes
public static final int[] DEFAULT_IMAGES = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
public static final int V_MARGIN = 16;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout contents = findViewById(R.id.tab_contents);
BottomNavigationView nav = findViewById(R.id.bottom_nav);
nav.setOnNavigationItemSelectedListener((item) -> {
contents.removeAllViews();
switch (item.getItemId()) {
case R.id.action_part_1:
contents.addView(getLayoutInflater().inflate(R.layout.part1, null), PARAMS);
return true;
case R.id.action_part_2:
contents.addView(getLayoutInflater().inflate(R.layout.part2, null), PARAMS);
return true;
case R.id.action_part_3:
int vMargin = getIntent().getIntExtra("vMargin", V_MARGIN);
contents.addView(new Part3View(this, getImageStrings(), vMargin), PARAMS);
return true;
case R.id.action_part_4:
vMargin = getIntent().getIntExtra("vMargin", V_MARGIN);
contents.addView(new Part4View(this, getImageStrings(), vMargin), PARAMS);
return true;
default:
Log.e("CSE340","Unrecognized nav item selected: " + item.getTitle());
}
return false;
});
nav.setSelectedItemId(R.id.action_part_1);
}
@NonNull
private List<String> getImageStrings() {
int[] images = getIntent().getIntArrayExtra("images");
if (images == null) {
images = DEFAULT_IMAGES;
}
return Arrays.stream(images).mapToObj(id -> "food_" + id).collect(Collectors.toList());
}
}
package cse340.layout;
import android.content.Context;
import android.widget.ScrollView;
import java.util.Collections;
import java.util.List;
public class Part3View extends ScrollView {
public Part3View(Context context) {
this(context, Collections.emptyList(), 0);
}
/**
* Create a ConstraintLayout to contain arbitrary number of images.
*
* For each image:
* Create ImageView and add to ConstraintLayout (parent)
* Constraint: Center image horizontally
* Constraint: Follow previous image (or parent if first image) with (vMargin*i)dp margin
* between image i and i-1 (except vMargin from parent if first image).
* NOTE: vMargin is in dp but margins are specified at runtime in px. Conversion between the
* two is messy and will result in a double. Please ROUND the result of your
* conversion. If you coerce the result to an integer some other way, your layout will
* be different from ours!
*
* @param imageNames List of drawable names, e.g. "food_0", to put in the view.
* @param vMargin Base vertical margin for function. Default is 16dp.
*/
public Part3View(Context context, List<String> imageNames, int vMargin) {
super(context);
}
}
\ No newline at end of file
package cse340.layout;
import android.content.Context;
import android.widget.ScrollView;
import java.util.Collections;
import java.util.List;
public class Part4View extends ScrollView {
public Part4View(Context context) {
this(context, Collections.emptyList(), 0);
}
/**
* We want to create a Pinterest-link image flow container.
* <p>
* Inflate a ConstraintLayout from part4_grid.xml and two LinearLayouts inside to evenly divide
* the width. When the view is rotated, the columns should change width to maintain the 50%
* split. Add each image into one of the LinearLayout columns. Track the "height" of each column
* and insert the next image in the column with the lower height, or leftmost one if equal.
* <p>
* Note: Do not track the height of the Drawables in each column, but the height of the
* ImageView on the screen. This is done as high-resolution images should not affect the
* ordering more than lower ones.
* <p>
* Each image should be vMargin from the previous image vertically (or parent if first image).
* There should be a vMargin gap between the two columns, however, the center of the gap must be
* in the exact center of the screen. The bottom of the last image should be flush with the
* bottom of the column.
* <p>
* Each image should expand to fill the width as constrained by the margins described above. The
* height should be such that the aspect ratio matches the source drawable.
*
* @param imageNames List of drawable names, e.g. "food_0", to put in the view.
* @param vMargin Base vertical margin for function. Default is 16dp.
*/
public Part4View(Context context, List<String> imageNames, int vMargin) {
super(context);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment