Monday 23 June 2014

Android Development (Java JDK with Eclipse IDE)

Activities @ Lynda - 


Java Essential Training with David Gassner  DONE

JDK (Java Dev Kit)
  • Cross-Platform Java IDE { Eclipse (Open Source) JRE (Java Runtime Env) includes Google Android SDK }
    • XML Configuration Files (.classpath, .project)
    • Output Files to /bin
  • Eclipse Shortcuts
    • Hover Filename (popup appears with Filepath)
    • Move Rows Up and Down (PRESS OPT + UP or OPT + DOWN)
    • API References
      • Hover Class Name, PRESS FN + F2 (Mac) to Focus, Drag/Expand popup
    • Help View ( Double Click to select Class, Menu > Help > Dynamic Help )
    • Hover Properties (of Class) (popup appears, PRESS FN + F2 to Focus, Drag/Expand
    • Custom Perspectives ( Window > Save Perspective As )
    • Detached Views ( View > Detach )
    • Custom Appearance ( ADT > Prefs > General > Appearance ... )
    • Task Tags (i.e. // TODO)
    • Code Template proposals { PRESS CTRL + SPACE, TAB }
  • JVM (Java Virtual Machine) - protected and robust
    • JNI (Java  Native Interface) calls low-level native functions 
    • Memory Management 
      • Garbage Collection (GC) autonomy for expired Non-Referenced Objects (Retain Object until lifetime expired Scope of code block)
      • Fast Memory ( for Primitive Variables )
      • Heap Memory ( for Complex Objects )
      • Persistent Vars (Fields of Objects) Explicit Expire by set to Null (for GC)
      • Architect Bundling and Reuse of Objects for Efficiency
      • Runtime.freememory()
  • Javadocs { comments
    • Element Comments { comment on Classes, Methods, and Fields. Select Class Name > Menu > Source > Generate Element Comment i.e. /** }
      • Annotations { Type @ and Select from Drop-down }
      • HTML Tags { markup comments with HTML for appearance in Javadocs }
      • Exporting { File > Export > Java > Javadocs }
      • Exploring
        • PackageExplorer Right Click > Refresh. Navigate to Doc Folder > Open Index.HTML
        • Select Element and View Element Comments in Javadoc View (bottom)
  • File Manipulation { using Core Class Library with Try Catch Blocks (FileNotFound and IO Exceptions) Select PackageExplorer > Right Click > Refresh }
    • Input Stream { read file contents, Buffer Arrays for manageable bytes  }
    • Output Stream { write file contents }
    • Apache Commons { expanded Tools that are free and reusable Java components to eliminate complexity }
      • FileUtils { download JAR files and add to Library (lib) Folder, and add to Build Path (JRE System Library) Right Click > Build Path > Add to Build Path for all Classes to be available to Project }
      • Network Communications { Parsing RSS Feed from XML streams from network and with Document Object Model (DOM) Interface defined by W3C using Document Class (PRESS CTRL + SPACE) programming interface, Element ClassNodeList API, and DocumentBuilderFactory Factory API } 
    • JAR (Java Archive Files) { File > Export > JAR File > Select Entire App (Deselect Config Files). Rename .JAR to .ZIP to extract Package in Folder structure }
  • Declarations { Package, Class }
  • Compiling { portable b/w platforms compiling to Bytecode .class }
  • Object-Oriented Programming (OOP)
    • Encapsulation (wrap and overcome monolithic code complexity into Black Box) broken down and group functionality into maintainable Classes testable at granular level { enables restricted access, Abstraction with hidden data by calling protected methods with data stored in superclass (i.e. this.setSomething(1);) }
      • Architecturing Custom Class (hidden complexity within subclass class implementations) { declare private object, constructor method to pass data in from each created class instance, public method accessible throughout application encapsulating complexity, i.e. named ___Helper }
      • Loose-Coupling { Binding between functionality and data Classes }
      • Calling Customer Class (simple) { create instance, pass in args, call the Custom Class method to retrieve result } 
    • Inheritance Relationships { Java has Single Inheritance relationship between Superclass and Subclass that extends functionality (Subclass can only have one Superclass) }
      • Subclass Creation { Select Package > Right Click > New > Class > Browse (as Full Pathname required) } 
      • Subclasses Getting and Setting Specific Field Values for Types Declared in Superclass
      • Superclass Constructor Methods { Not Inherited by Subclasses. Subclasses require implementation of Explicit Constructor Methods Right Click > Source > Generate Constructors from Superclass... where super(); calls the Constructor Method of the Superclass }
      • Overriding Superclass Methods Inherited in Subclass { PRESS CTRL + SPACE in Subclass > Select "Override method in '....'" (Creates New Version of Superclasses Method with @Override using matching Data Type). Click Upward Arrow in Trough to transfer to respective Superclass Method }
      • Casting Objects { using Subclass Objects treated as Superclass }
        • Upcasting { Subclass upward conversion to Superclass } 
        • Downcasting { Superclass general form of Object to specific form of Object in Subclass achieved by telling compiler to treat it as the Subclass. i.e.  <class_name> <instance variable> = (<native_type_of_object>)<field_reference_to_object>.get(0) }
      • Interfaces { define a Class structure contract including public methods signatures (without implementation), methods, and final fields (constants). Instantiating Class implements Interfaces methods with @Override, adopting Inheritance and Polymorphism concepts. i.e. java.util Interface Collection (where ArrayList implements Collection Interface }
        • Flexibility gained by Upcasting Instances of a Superclass to Instances of an Interface (change Data Type PRESS CTRL + SPACE)
      • Custom Interfaces { use for modelling behaviour }
        • Interface Creation { Select Package > Right Click > New > Interface
      • Abstract Classes { improve definition of Class structure contract to promise that any Subclasses extending the Abstract Class must implement a certain specific concrete functionality (i.e. a method). Overcomes Downcasting in Superclass. Allows Anonymous Inner Type creation (PRESS CTRL + SPACEto Instantiate Superclass directly (if implement Abstract Method inline to satisfy contract) in Superclass. i.e. public abstract ...
        • Abstract Constructor Method Stub Creation { in Subclass Right Click > Source > Override/Implement Methods... }
    • Polymorphism { in an inheritance relationship between Superclass and Subclass, dealing with Objects instantiated from the Subclass declared either as its native type (from subclass) or as an inherited type (from its Superclass) to allow passing of the Subclass object to to other methods that calling the Superclass (i.e. using constructor method of the Subclass whilst using the data type of Superclass) }
  • UML (Unified Modelling Language)
  • Refactoring ( Menu > Refactor > Extract Method ) { include Runtime Exceptions option }
  • Packages { Sub Package (shallow) within Default Package containing Helper Methods of Project Classes with common characteristics }
    • Reverse Domain Notation { achieves universal uniqueness in organisation structure Right Click Class, Refactor > Rename i.e. com.ceenos.calc.helpers. Wildcard Import i.e. com.ceenos.calc.* }
    • Move Classes { Right Click Class, Refactor > Move . Adds a Package Declaration with Import i.e. #import helpers.InputHelpers }
  • Dates
    • java.util { i.e. Date Class, GregorianCalendar ( getTime() returns Instance. add() ) }
    • java.text { i.e. DateFormat ( getDateInstance(DateFormat.FULL) returns Instance (with extended formatting) and is Factory Method. format() }
  • Classes { Long-hand i.e. java.lang.String }
    • Explicit Importing of Classes required for some Packages (Click Class, PRESS CMD + SPACE, Select Package i.e. java.util). Fix Organising Imports Issues by PRESS CMD + SHIFT + O (Menu > Source > Organise Imports)
    • Import Class required if not in current Package
    • toString() is a Method of all Classes 
  • Methods 
    • Jump To Method ( Select Method, PRESS CMD + Click, Hover Over Method > Open Declaration )
    • Constructor Methods (no return type, accept Multiple Arguments) 
      • This { Current Instance of Current Class. Argument of Method is Not Prefixed with This }
      • Super { Call Super Method of the Constructor Class (Inheriting from) }
      • Eclipse Constructor Method Generation { Right Click > Source > Generate Constructor using Fields
      • No Arguments Constructor (Default action of nothing)
    • Class Methods (called from Definition of a Class, static) { use for Utility Function Library creation }
    • Instance Methods (called from Instance of a Class or Object static) { use for handling persistent data }
    • Getter and Setter Methods { Java uses Explicit Setters and Getters for validating, modifying and securing data (i.e. only current Class Sets, read-only so other Classes only allow Get) }
      • Generating Getter and Setter Methods { Right Click > Source > Generate Getters and Setters, use to Refactor code to Get and Set Fields through Centralised Methods }
      • Design for Set Incrementally versus Rewriting Values to Instance each time Called { i.e. replace =  to +=  }
    • Defaults { 'main' method automatically called by JVM }
    • Autocreate Method Signatures { i.e. type say testValues(s1, s2), Hover over Method name, select 'Create method ....' from Popup}
    • Arguments ( use quotes to overcome Delimiting due to spaces )
      • Eclipse Args ( Menu > Run > Run Configurations > Arguments
    • Arguments by Copy (rather than Reference) in Java
      • Passing by Copy { New Instance (Copy) made inside Function the Variable passed to. Note: Passing Primitives Wrapped in Complex Objects (which have Reference Variables pointing to Values both inside and outside Function) make copies of Object with Reference pointing to Value inside and outside Function }
    • Access Modifiers and Other Prefixes
      • public (allow call method from anywhere)
      • private (only avail within Class)
      • protected (avail to Class and Sub Class due to Inheritance)
      • <undeclared> protected package  (avail to Class and other Classes in same Package)
      • static (not require instance of Class to be created)
      • void (not return anything)
    • Factory Methods (of a Class) { return Instance of Class }
  • Custom Methods 
    • Variable Arguments Syntax Array (of same Data Type) <fn_name>(double ... values) { <loop_through>
    • Method Overload (different method signatures i.e. args qty, data type)
  • Variable (Field) Types 
    • Primitive Numeric Values (individual Value)
    • Complex Objects (capable of referencing many Objects) declared with new Class Constructor Method named to match Class name. Big Decimal Class (precision)
    • Class Fields (aka Class Variables access directly from Class Definition and defined by using static)
      • Constant Values achieved by using static final (Value cannot change after being Set) and Uppercase Constant Value
    • Instance Fields { aka Instance Variables / Properties assigned at the Class level (persistent data values, exist for lifetime of Object) } 
      • Declaration { Assess Modifier, Data Type, Name }
    • Characters 
      • Literal Chars (i.e. ' ')
      • Unicode Chars (i.e. '\u0024')
      • Wrapper Class is java.lang.Character  (i.e. toCharArray() )
    • Strings and Substrings (Immutable) { cannot change after Declared }
      • Changing String Variables { use less Memory and Objects by using Methods .insert() and .append() from Utility Class StringBuilder (Single-threading) and StringBuffer (Multi-threading) }
      • Strings within Strings ( substring() )
      • Removing Whitespace ( trim() )
    • Boolean
      • Wrap in parenthesis to eval before assign
      • Wrapper Class is java.lang.Boolean
    • Anonymous Objects { i.e. new myThing() }
  • Conversion of Variables
    • Simple Casting Syntax (avoids extra Objects in memory)
    • Helper Class Methods Wrapper from Java Class Library (long-term storage and usage) applied to Instance for Reference to Complex Object and access to its Methods
      • Upward Conversion Implicit (Safe and Reliable)
      • Downward Conversion Explicitly using Casting 
  • Operators and Comparison
    • Assignment and Math Operators
    • Post and Prefix Incrementing
    • Post and Prefix (Unary) Operation
    • Conditional Complex Operations and Ternary (Short-hand Conditional __ ? <true> : <false> )
    • Comparisons with String Class requires use of .equals() or contains()(unreliable to use ==)
    • Conditional { If, Switch (Break, Return), Enums, Loops (Numeric Counter), For Each, While, Do While }
  • Data Collections 
    • Simple Arrays (same Data Types, non-resizable)
    • Multi-Dimensional Arrays (same Data Types, non-resizable) { Top level and Child Arrays, Nested Loops }
    • ArrayList (ordered collection, resizable items, add(), remove(), .get() and .indexOf() to search features. Import java.util, i.e. ArrayList<insert_data_type_/class_name_instances_of> )
      • ListIterator { Iterators from Collections Framework .listIterator().hasNext().next()(with While Loop). Import java.util, i.e. ListIterator<insert_data_type> }
    • HashMaps {unordered collection, associative arrays, key-value pairs (KVP). map.put(K, V), map.get(K), map.remove(V), etc. Import java.util, i.e. HashMap<declare_data_type_key, declare_data_type_value>  }
      • ListIterator { iterate either keys or values .values()map.keySet() (set of keys of Set Class), keys.Iterator() (Iterator Class), .hasNext().next()(with While Loop). Import java.util, i.e. Set<insert_data_type>, Iterator<insert_data_type> }
  • Handling Errors and Debugging { Compile-Time, Runtime }
    • Exception Objects { Instance of Exception Class is created upon error }
    • Try Block { Wraps code to handle Exception Instances or sub class of it }
    • Catch Block { Handles the Exception. Clears error and continues running. Replace with Exception Class Subclass to only run for specific Exceptions }
    • Try-Catch Block { Select Code > Right Click > Surround with ... > Try/Catch Block
    • Throw { Refactor code anticipated to throw an Exception Class type into its own Method (Select "Declare thrown runtime exceptions" option)  }
  • Eclipse Debugger {
    • Unhandled Exceptions (defined in Java Documentation)
    • Breakpoint { inspect Exception Object structure by freezing app execution in Catch Block (where Exception Object in Scope available) to view information available }
      • Toggle Breakpoint (in trough)
      • Run in Debug Mode (uses Debug Perspective)
      • Variable 
    • Debug Perspective
      • Call Stack View
      • Variable and Breakpoint View { Click Exception Object 'e' to Expand and Inspect Details, Terminate Button, Return to Perspective Menu > Window > Open Perspective }
      • e.printStackTrace() and e.getMessage()
  • Command-Line
    • JAR File
      • Set the Class Path   java -classpath .:<jar_file.jar> com.<reverse_domain_notation>
      • Set the Class Path as Environment Variable (Semicolon separates Values)  set CLASSPATH=.:<jar_file.jar> (Bash Script is alternative)
      • Reverse Domain Notation followed by Class Name  java com.<reverse_domain_notation>.<class_name>
    • Version
      • java -version (Java verson)
      • javac -version  (Compiler version)
    • Commands Listing
      • cd /System/Library/Frameworks/
      • cd JavaVM.framework/
      • cd Commands
      • ls
    • Compiling
      • javac Main.java -d -verbose ..\bin  // create Main.class in \bin. verbose displays compiler background activities
      • cd bin 
      • java Main

Tuesday 17 June 2014

iOS Sprite Kit Game (Luke's Paddle Tree Game)

Activities @ Lynda - 




Screen Recording in iPhone Simulator


iOS Game Dev with Sprite Kit with Simon Allardice 
    (thanks Lynda for an awesome course!!) DONE
Screenshots of My First Game (Adapted from Copyright Lynda.com Tutorial)
  • GitHub Link: Luke's Breaking Bricks iOS Sprite Kit Game
  • Instructions: 
    • Touch and hold the bottom Paddle to play and prevent it falling. 
    • Move left and right to stop the ball hitting the bottom. 
    • Pause feature activates if you let go of paddle! Touch again to Unpause.
    • Destroy upper bricks to cause Tree to fall down. 
    • Win if Tree touches bottom of screen (tough luck if you deflect it elsewhere haha)
    • Lose if bottom Paddle or Ball touches bottom of screen.
    • Note: The paddle rapidly impulses automatically, so the ball is propelled faster with each contact with the paddle (brace yourself!)
    • Note: Win screen Screenshot not shown (you have to Win to see it!!!), Audio for winning was prepared by yours truly :)
  • Wondering how I preparing the game? It took under 2 days to prepare this game. The purpose of preparing it was to learn iOS Sprite Kit fundamentals programming in Objective-C using Xcode. Most of the code used to prepare the game came from following the Lynda.com course video. I added the following extensions to the game of my own in order to test the framework, but I expended minimal effort in doing so:
    • Custom background (simply a few random coloured brush strokes in Photoshop)
    • Custom sounds (silly 'You Win' and 'You Lose' sounds recorded using Quicktime Player)
    • Custom particle effects (simply replaced the particle effect snow flakes with an image of my head and slightly modified the effect in Particle Effects Editor)
    • Pause feature that activates when use stops touching screen (adapted from this post on Stackoverflow.com). Pause deactivates when the user touches the screen again
    • Tree shaped and coloured object and an animation sequence associated with it. The animation sequence throws the tree it into the screen amongst the bricks at the start of each game. The animation helps it slowly wiggle out of them
    • 'You Win' screen which appears upon contact between the tree object and the bottom of screen (the user may need to destroy the bricks to make it fall)
    • Impulses are automatically applied to the paddle so when the user holds down on the paddle and moves it left and right, the paddle will rapidly spring up and down in this defensive approach, so that each time the ball bounces off the paddle the ball speed increases, which in turn rapidly increases the game difficulty so you can fail or win fast and often! Alternatively an offensive approach can be taken during gameplay if the user chooses to simply hold down on the paddle but does not move left or right, as this will cause the paddle to only rise upward toward the bricks (until the user moves their touch left or right again)
    • If you'd like to know more, please feel free to contact me! Please ensure that you appropriately credit me and the sources I used if you share.

Game Elements 
Scenes (Architecture)
  • Node Types (Sprite, Label, Video, Shape, Emitter, Crop, Effect, etc) 
  • Node Use (manipulable independent Visual Elements Creation and Artwork, Property Configuration, Scene Inclusion, Manipulation, Drawing Order), FPS 
  • Node Association and Inheritance
  • Node Positioning and Coordinate System
    • Anchor Points of Scene and Nodes (Default to Parent Scene)
    • CGPoint (Core Graphics framework) (Explicit and Inline Creation)
  • Physics World (connect and configure different Scene {gravity, zero gravity} and Node Physics Body Properties
    • Physics Bodies (Volume-based (Default is Dynamic Volume or use Static) {simple Draw Path and Play-Testing for complex shapes to minimise Performance impact} , Edge-based). Each one has Bitmask Properties
      • categoryBitMask (Turned On by Default, each Physics Body can belong to multiple Categories and belong to all by Default)
      • collisionBitMask (Turned On by Default, cross-references all Categories where Physics Body should Register a Collision and provide notification of an event)
      • contactBitMask (Turned Off by Default, cross-references all Categories where Physics Body should Register a Contact and provide notification of an event)
    • Physics Body Properties (Mass, Density, Friction {object resistance at collision}, Linear Damping {object resistance moving across space}, Restitution {object bounciness at collision 0 to 1.0f}, Angular Damping, Velocity, etc)
    • Vectors (Magnitude {Force, Impulse}, Direction)
    • Touch Events 
    • Flexibility (Rotation Orientation Compatibility)
    • Collisions (causes them to bounce on impact, and prevents intersection of objects)
    • Contact (apply manually with custom code to be informed when touch detected between objects and apply logic to event)
      • didBeginContact and didEndContact  (reacts to contact using SKPhysicsContactDelegate Protocol)
    • Categories (meaningful Groupings of objects Defined for association with different Physics Body Objects, where Bitmasks are used to describe the actions upon touch between objects of different Categories {inform us, allow or disallow cross-over, bounce, nothing}, 32 Categories allowed to be toggled)
      • Bitwise Operators for defining Multiple Constants for each Categories
    • Landscape Orientation
      • CMD + Right Arrow (in Simulator)
    • Rendering/Game Loop 
      • update method (called at beginning of every frame)
      • didEvaluationActions method (check modifications after Sprite Kit evaluates actions and before any nodes changed are rendered to frame)
      • didSimulatePhysics methods (check mods of Physics Simulation but before affected nodes rendered to screen)
    • Texture Atlases (Manage Artwork Assets for Higher Performance by Grouping images)
      • Animation by Iterating Multiple Images
  • Game Play
    • Scene Transitions (Transition to Second Scene, Win and Lose Scene, Restart First Scene)
    • Sound Effects (SKAction in CAF format)
    • Convert to CAF Format (i.e. M4A from QuickTime Player to CAF Format File)
    • Apple Audio File Convert Tool use by type at Command-Line: 
                /usr/bin/afconvert -f caff -d LEI16 {INPUT} {OUTPUT}
    • Particle Systems (use Small Image and repeat Multiple times)
    • Particle Emitter controls effects under defined Particle Effect Rules using transitioning and Particle Emitter Inheritance to link gradually between nodes
    • Particle Emitter Editor (alternative to creating and setting properties of emitter node object with SKEmitterNode in code, instead simply define properties and save to SKS File for use to create Emitter Nodes)
    • iOS > New File > Resources > Sprite Kit Particle File
    • Actions (SKAction Class)
      • Methods with Reversible Actions
      • Combinations of Sequencing, Grouping, and Repeating Actions
      • Wait Action
  • Refactor 
    • Select Code Snippet > Right Click > Refactor > Extract 
Purchases:
Challenges:
  • Overcoming error "The model used to open the store is incompatible with the one used to create the store”?". 
    • Solution: Delete the SQL file in the apps documents directory
  • Display SQL syntax in Xcode Debugging Area
    • Solution: 
Menu > Product > Scheme > Edit Scheme > Arguments  "-com.apple.CoreData.SQLDebug 1"
  • Discovered how to overcome app always crashing (lost so much time trying to work this out) when attempting to save enum data to core data persistent store. I simply followed this Stackoverflow post from Paras Joshi to reset session and cache data in iPhone Simulator. Absolute lifesaver, this is now my favourite Xcode feature (how sad)!
         Menu > iOS Simulator > Reset Content and Settings

Friday 13 June 2014

Keepal App Update (YouTube Video & Download) Launched!


Click here on your Android mobile to download Keepal App from Google Play Store)

We'll be coding the iOS version using Apple's new Swift programming language!

Thursday 12 June 2014

Upcoming Event Bookings

Events
  • ATTENDED muru-D Intern Night, Thur, 19 June 2014 6pm to 8:30pm, 363 Oxford St, Paddington
  • GRADUATED! Sydney NodeSchool, Sydney, 9am - 4pm June 21st, 2014, NICTA, Level 5, 13 Garden St, Eveleigh 
  • ATTENDED Intersect - FASS eResearch: Working with big data sets – data mining, 1:30pm to 5pm, 23 June 2014, eLearning Lab CR322, Building A18 Brennan MacCallum University of Sydney
  • ATTENDED Google I/O 2014 Live Keynote @ Fishburners, 11:30pm, Wed, 25 June 2014 
  • ATTENDED Startup Weekend Education (SWEDU) Sydney, at Muru-d SWEDU Sydney, Fri, June 27, 2014 at 6pm Sunday to June 29 2014 at 9:00pm, Paddington
  • SECOND SHOOTER Wedding Photography, 5 July 2014
  • PART ATTENDED Intersect - Introduction to UNIX for High Performance Computing (HPC), (2 day course) Wed, 9 July 2014 at 10am to Thu, 10 July 2014 at 4pm, Room CB02.04.20 (Building 2), University of Technology, 15 Broadway, Ultimo
  • UNABLE Intersect - Data Visualisation with Google Fusion Tables, 10am to 12:30pm 15 July 2013, University of Technology, Room CB02.04.20 (Building 2), 15 Broadway Ultimo
  • UNABLE SydInMotion, 6:30 for 7pm start, 15 July 2014, King St Brewhouse
  • ATTENDING Confidential @ NSW Pitch Night, 15 July 2014, NewSouth Innovations, Level 2, Rupert Myers Building (South), UNSW Kensington Campus, Near Gate 14, Barker Street
  • ATTENDED CocoaHeads Sydney, 6:30, 17 July 2014, Atlassian
  • UNABLE RORO Dev Hub, 6:30 - 9:30pm, 29 July 2014, Ninefold
  • ATTENDING TKSOBU Annual Dinner, Fri, 1 Aug 2014, The Star Room (Level 6, Imax Theatre Complex), 31 Wheat Road, Darling Harbour
  • UNABLE Sydney Educational Technology Meetup, 6 - 7:30pm, 5th Aug 2014, Level 1 @ Fishburners, Ultimo 

Curiosity
Vouchers