//****************************************************************************//
//*********** Gradle and Intro. Android - September 6th, 2017 ***************//
//**************************************************************************//

- So, we didn't finish going over Gradle; let's do that now, and then we'll go over some basics of Android you'll need to know for M3
    - "We'll also go over some basic MVC, which, basically, every UI ever programmed in the last 20 years uses some variant of"

- Gradle is actually NOT that bad; since it follows the "convention" standard instead of the "configuration" standard, it should "just work" if your code is structured in the "Gradle way"
    -"...which, fortunately for you, the M2 code should already be set up for Gradle's liking"
- First convention: ALWAYS name your build-file "build.gradle"; 
    - Gradle's build files are written in a language called "Groovy", a variant of Java
    - You can bring in a plugin called "Java" ("apply plugin: 'Java'"), and it'll already handle the most common tasks required for Java programs
        - "tasks/targets are interchangable; Gradle just calls its procedures tasks, but other programs like Ant, Maven, etc., call them targets"
    - For your homework, you don't REALLY have to write everything from scratch; PLEASE use the Java plugin, or else you'll need to do all the hard-work for no reason ("It'd be like trying to create your own array class in C++")
- If you just type "gradle" in the command line, it'll execute whatever you've set the default task to ("defaultTasks: 'taskNameGoesHere' ")
    - Otherwise, you can run a specific task by typing "gradle <taskNameGoesHere>"
- List your needed libraries in the "dependencies" section; list where to look for 3rd-party software/updates in "repositories" (by default, we'll be using mavenCentral()) 
- The part YOUR team'll probably have the most issues with, though, is the "jar" section
    - The ".jar" file is basically just a zipped folder of your class files; but how do we make sure it's EXECUTABLE, and actually runs when you click it?
    - Well, inside each .jar file is a "manifest" file that has a BUNCH of key-value pairs (in this case, we can SPECIFY the manifest's content in our Gradle build file)
        - The MOST IMPORTANT PART is the " 'Main-Class' : '<className>' ", which tells Gradle where the class with your "main" method is
            - If you're using packages in Java (which we WILL be using later), MAKE SURE that you have your class's FULLY qualified name (e.g. "edu.gatech.cs2340.PersonClassName")
        - You'll also need "'Class-Path' : <insertPathHere>" that tells Gradle the path of the final Jar, and the location of other dependencies relative to the final JAR'S classpath (NOT to the build-file's location) (????)
- Can run "gradle clean" to delete extra files generated by the previous build (e.g. class files, etc.); in Git, you do NOT want to try and upload stuff like .class files, etc.

-----------------------------
// Intro. Android Development
-----------------------------

- So, in 1331, you did a very little bit of GUI stuff with JavaFX, right? Sadly, Android handles GUI completely differently, so you're gonna have to relearn basically everything; some nice resources:
    - Lars Vogel has some NICE tutorials on Android dev. basics, and even covers some stuff like Gradle, recycler views, etc., that'll be useful for you (and even go a bit more in-depth than we need)
    - "thenewboston" has some tutorials that are a bit dated, but will still be helpful
    - ...and, of course, the Google Android Documentation!
        - Google also has a nice Udacity course called "Developing Android Apps"; it takes a lot of time, but is very thorough, and walks you through creating your very own working app

- So, what's "Android", anyway? It's a mobile operating system based on Linux; there are 2 main ways to program in it
    - The "Native Development Kit" (NDK) is a C++ API that lets you directly interact with the low-level OS code; this is WAYYYYYY beyond the scope of this course
    - The Android SDK is in Java, with the latest version being Oreo (8.0); REALISTICALLY, you want to try and target the OLDEST version of Android possible so that your softare will run on the most devices possible, but in this class, use whatever version you want

- Now, let's briefly talk about how basically EVERY Android/iPhone/Web app organizes their UI code: "Model-View-Controller", or "MVC"
    - Occasionally, this'll go by different names for slight variations ("Model-View-Presenter", etc.), but the BASIC IDEA is the same for all of them: to keep our "business logic" SEPARATE from our "display logic"
        - So, lat year, our app was a "clean water reporting app"
            - Our MODEL was the water's locations, reports from users, usernames/info, etc.; the raw data
            - The VIEW was the actual GUI; the buttons, images, etc.; how we PRESENT this data
            - And the CONTROLLER is how we map between the 2, and handle user interaction
    -...we'll finish going over this, though, on Friday 

==========================================
/// Gradle FAQ From T-Square Announcement
==========================================
Gradle FAQ
I'm reposting this FAQ from a previous semester (written by former head TA Jayden).
 
----------------------------------------
 
What is Gradle?
 
Gradle is a build automation software you can use to build a project and do other tasks (such as compiling the .java files, cleaning of all .class files, etc.) - in this case, you're using Gradle to build a project into a .jar file which you can run. 
 
The Gradle file you write should support the following commands
 
compileJava      compiles and builds the project
compileTest      compiles the unit tests for the project
javadoc          creates the html documentation for the project
clean            removes all the files created by this project
jar              creates the executable jar file for this project
 
Creating a Gradle file
 
Make a text in the same folder as your lib and src folders and save it as "gtidname.gradle" (so for me it'd be jgardiner6.gradle)
 
Writing a Gradle file
 
Some useful things to add to the file are:
 
    defaultTasks '<task>'

    apply plugin: '<plugin>'

    dependencies {
        _____________
    }

    jar { 
        manifest {
            attributes '<attribute>' : '______', <attribute>: '_______'
        }
    }
 
Documentation: https://docs.gradle.org/current/userguide/tutorial_java_projects.html
 
The assignment does specify a default task so make sure you specify that.
 
Applying the Java plugin will allow your gradle file to execute the Java tasks like clean (getting rid of .class files), compileJava (compiling your .java files), and so on. Writing jar { ___ } in your .gradle file will allow the jar task to work since you are defining the jar task.
 
To make your jar file, the Gradle file needs a reference to resources.jar through its dependencies. If you wish to add a compile dependency, you can do it as in example 44.4 in the documentation or by adding compile files('<file name/location>').
 
You will also need in your jar task to include the classpath to this jar in your manifest. Otherwise, you will get a runtime error that the class cannot be found. Remember that the classpath to resources.jar in the manifest is relative to your created jar's location.
 
Jar manifest attributes you can use include Implementation-Title, Implementation-Version, Main-Class, Class-Path, etc. Also, with packages, you must use the fully qualified name (package_name.class_name) not just the class name by itself when adding a Main-Class entry to the jar manifest.
 
Note: Compile dependency is relative to the gradle.build file. You are backing up out of your project directory. The runtime dependency in the manifest is relative to where the .jar file you create is located.

Running Gradle
 
Some command line statements you need to use:
    gradle -b gtid.gradle // should run whatever command you specified in your gtid.gradle file as being the defaultTask
    java -jar <path_to_generated_jar> // to run a jar file. running your generated jar should print something
    gradle <command> -b gtid.gradle // commands include clean, javadoc, etc