Skip to content

Instantly share code, notes, and snippets.

@joshfriend
Created April 28, 2017 14:45
Show Gist options
  • Save joshfriend/b68dd4ac6bb500c16ecba1390e4da6b7 to your computer and use it in GitHub Desktop.
Save joshfriend/b68dd4ac6bb500c16ecba1390e4da6b7 to your computer and use it in GitHub Desktop.

Session resumption: quick handshake for servers we've connected to before TLS v1.3 0-RTT session resumption

QWxhZGRpbjpPcGVuU2VzYW1l

Round trips: TLS 1.2: 2 TLS 1.2 session res: 1 TLS 1.3: 1 TLS 1.3 session res: 1 (but less data) TLS 1.3 0-RTT: 0

head of line blocking

HTTP/2 request/response tagged with ID inside frames headers/body are separate frames HPACK compresses header names and values into numbers -> look into gzip encoding for JSON bit.ly/ok-libs bit.ly/decoding-secrets

Direct actions vs Conversation actions Direct actions no available (yet)

Develop a "persona" to keep conversations consistent - whimsical vs serious - write sample dialogs - Google has a persona design guide sheet

API.AI

Welcome intent response could include available actions Always close the microphone when conversation ends (Hidden at page bottom under "Actions on Google")

Write once, run in fb messenger/slack

clip path does not support antialiasing

easing functions/interpolators - Linear (linear/@android:interpolator/linear) - Accelerate Decelerate (easeInOutSine/@android:interpolator/accelerate_decelerate) - Accelerate (cubic/@android:interpolator/accelerate_cubic) - Anticipate (easeInBack/@android:interpolator/anticipate) - Decelerate (easeOutCubic/@android:interpolator/decelerate_cubic) - Overshoot (easeOutBack/@android:interpolator/decelerate_cubic) - Bounce (easeOutBounce/@android:interpolator/bounce`)

https://jebware.com/interp/android-animation-interpolators.html

Animations should be: * Give life and character * Use an appropriate interpolator * Be consistent * BE SUBTLE * Remain true to your brand

Do not: * Move things for no reason * "Overstay your welcome" Don't make animations introduce "lag" * Be distracting "Always think of clippy" * Dont animate too many things at once

1

Choose your test case with care (start at the core)

1.1

lol duplicate META-INF/rxjava.properties proguard -keep external lib features unless you know what you are doing

2

Lazy init client/adapters by lazy

3

Combining similar endpoints kindof defeats the type saftey of retrofit * Sealed classes? beware of spots with switch statements

6

Inheritance based callbacks are a nightmare

multipath is hard

`Nearby.Messages.publish(client, new Message(bytes))

new play services apis can allow scanning for BTLE beacons without requiring location permission pre android M

Can have beacons show local notification for an app or website (without requiring app to be installed) * notifications are a reward for "good behavior", not a guarantee

Notifications can target users who dont have the app installed specifically. Can also target at specific times of day

AwarenessFence api is awesome. Looks like you can filter by geolocation, dwell time, even if the phone has headphones plugged in!

New stuff coming in I/O17

iOS nearby apis has "almost near feature parity" with android APIs. Background modes are more difficult though

"I just really wanted to practice beatboxing"

Handshake

  1. HTTP GET request with Connection: Upgrade header
  2. Response 101 Switching Protocols Upgrade: websocket header

1000 == 200 OK

github.com/ChrisGuzman/Quack

How to update UI from websocket messages

runOnUiThread() 🍰

EventBus 🍵

Manage threads 🍝

RxJava 🌯

github.com/jacek-marchwicki/JavaWebsocketClient

Ping/Pong to keep idle connections alive (OkHttp does this automatically)

Here there be dragons

  • Dont implement your own queue
  • Dont expect graceful shutdowns
  • Websockets lack ack. Have to implement this yourself if you really need it
  • Constantly open connections drain battery (ping/pong)
  • Might be negatively affected by Doze
    • Close idle connections
    • fallback to push notifications
  • Does not work directly with HTTP/2

Socket.io

  • Fallback to polling or "flash connections"? if no WS available
  • OSS
  • Message api

PubNub

  • Provides subsribe/publish key, & chanel name
  • has public channel for testing

Pusher

  • Fallback to HTTP
  • Beta GCM/FCM support

/r/place (!!!)

ALternatives

  • Long polling/Comet/Keep Alive
    • GET request without immediate response
  • Server side events
  • IRC (TCP)
  • MQTT (FB Messenger?)
  • XMPP (WHatsApp)
  • HTTP/2

WebRTC vs WebSocket

  • WebRTC is P2P
  • WebRTC better for audio/video, Websocket better for text

IOT = "A smart, connected device"

Software

Android Things provides: IoT Developer Console, Automatic security updates, Signed images, Verified boot

Managed by Google:

  • Android Framework
  • Hardware Libraries
  • Linux Kernel

Managed By Developers:

  • Apps
  • User Drivers

Hardware

Supported Platforms:

  • Raspberry Pi 3
  • Intel Edison
  • NXP Pico

An android things system runs 1 app (yours) Android System UI is not present, app gets the full window for display Can't assume that a display exists * All requested permissions granted at install time because there is no way to request them at runtime Otherwise the SDK is the same as regular Android

Reqs to make a things app

  • link to provided "com.google.android.things:androidthings support library
  • <uses-library android:name="com.google.android.things" /> in manifest
  • Tell andoid to launch app on boot with <intent-filter>

Things support lib

  • Peripheral I/O
    • GPIO, PWM, I2C, SPI, UART
  • User drivers
    • Bind data from peripherals into the android framework
    • Used to link a GPS peripheral to LocationManager API, etc.
    • Allows android to use your sensors intelligently and provide additional functionality (e.g. fused location provider apis)
  • Peripheral driver libraries (not actually in support lib, on github)
    • Drivers for common/popular periphperal devices

Animating Hardware :o

Can use ObjectAnimator and interpolators to control outputs

Links

  • github.com/androidthings
  • developer.android.com/things
  • g.co/iotdev

bit.ly/auto_roboto

Capabilities:

  • Navigaiton,
  • Telephony
  • Messaging
  • Music/Audio
  • Web searches

Android auto support is like a wear/chromecast extension Andorid auto handles rendering layouts for you, your app just provides the data

Setup

  • Android auto description xml resource
  • Reference android auto xml in manifest.xml

Messaging App

CarExtender makes notifications work with Android Auto - Provide proper intents for actions on notificaitons - Provide RemoteInput to capture reply

Audio App

  • MediaSession.Callback for playback actions
  • provide a MediaBrowserService
  • Register for voice actions with an intent filter in manifest
  • see google universal music player sample

Must support voice actions for audio apps Short form messages Touch actions must be completed within 6 clicks NO ADS No animations No games

!! Apps must pass driver saftey review (including updates)

DI separates the logic that creates the dependencies from the logic that uses them

Why Dagger?

  • Testing!
  • Instance management
    • Singletons
    • New instances each time injected
    • Release instance in response to memory pressure
    • Recycle objects

NEW STUFF! Dagger 2.11

AppComponent uses module AndroidSupportInjectionModule and extend AndroidComponent<App> App class extends DaggerApplication DaggerAppCompatActivity (Super types are convenience types, the stuff they do seems pretty simple and could be copied to a custom class) @ContributesAndroidInjector <- things that "just makes things work" No more @Subcomponent Common scopes - @ApplicationScope - @ActivityScope Common modules for system services RIP Thermosiphon

github.com/queencodemonkey/presentation-cool-constraintlayout

Build layouts as relationships between views

Performance! * Less nested == more performant

Constraints -> Equations -> Solver (Cassowary Linear Arithmetic Constraint Solving Algorithm like on iOS)

Vocabulary

  • Edge constraint
    • Source and target
    • One side of source view constrained to one side of target view
  • Center Constraint
    • Position center of a view on an axis
    • Adjustable bias controls distribution of space allocated to opposing edge constraints
  • Baseline constraint
    • Align TextViews based on their text baselines
  • Size constraints
    • Fixed
    • Wrap
    • Match constraints (like match_parent?)
      • REQUIRES 2 LAYOUT PASSES (like relative layouts)
  • Guidelines
    • Targets which are not views (like layout guides in storyboards)
    • Can define as:
      • offset from a view
      • Percent

What can it do?

  • Square image view
    • Dimension ratio layout_constraintDimensionRatio="W,1:1"
    • eliminates need for measuring code
    • Ratios can be defined as R.string resources

Better than RelativeLayout?

Relative layout has to make 2 passes for each layout StylingANdroid constraint layout blog post #6 Relative layout is very generic and not very powerful

CHAINS!

Seems like stackview/linear layout * spread chain * spread inside chain - set on head item in chain (left/top) * weighted chain - set weight on each item * packed chain * packed chain with bias

ConstraintSet

  • save a set of constraints and apply later
    • can create manually
    • from layout file
  • Animate between alternate constraint sets

List items can be constraint layouts Can be used to replace custom ViewGroups

groupBy operator requires input stream to complete

Check out rxlint to lint subscription/error handling issues

RxJava 2 throws some errors that Rx1 would swallow, like UndeliverableException Can add an errorhandler to catch, log, and suppress these

RxJava is a useful tool, but not for everything

Spectrum of Skeumorphism --> Flat design, material is in between, but more torwards flat

Material properties

  • Material is 1dp thick
  • Material occupies unique points in space
  • Material is impenetrable
    • transitions to elements underneath cannot "pass through", need to slide out of the way
  • Material is mutable
  • Material can join, split and heal with other sheets
  • Material can be destroyed and created

Deviate with purpose

github.com/swankjesse/concurrency

Code is abstract, Computers are concrete

Inefficient memory access * Unneccesary: Fetch what we already have * Repetitive: Fetch one at a time * Lazy: Not fetching until we need it urgently * Redundant: Writing values that will be re-written later

Reordered code and memory access make impossible things possible

github.com/googlesamples/android-architecture

Unit tests cant test concurrency One-in-a-million bugs happen all the time

⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️ ExecutorService - manages thread creation volatile (guards fields) * ALWAYS READS/WRITES TO/FROM RAM IMMEDITELY (not L1/2 cache) * reading/writing volatile field causes all reads to be refreshed * IS NOT ATOMIC, still reads, then writes synchronized (guards methods) * Every object has a lock * On entry, all reads are refreshed * On exit, all writes are flushed * github.com/square/okhttp/wiki/concurrency AtomicInteger etc CountDownLatch BlockingQueue * Watch your capacity! ScheduledThreadPoolExecutor * run after a delay or repeating interval * Handler.postDelayed() no!

Effective concurrency

Main thread is the Boss! * owns all the data * Delegates immutable tasks to worker threads * Workers post immutable results back to main thread Immutable values * Shared objects in threads are unsafe to change * AutoValue * Kotlin data classes! Models go on the main thread * App state on main thread * Keep main thread synchronous * Dont Handler.post() on main thread (unless wait for layout to complete) I/O goes on worker threads * be deliberate about posting back to the main thread * @MainThread @WorkerThread * Rx on main. Define a checkMainThread that crashes if not on main

No gratuitous animations! Motion should provide meaning 8dp baseline grid keylines ratios

changes in nested layouts require remeasuring parent components

Gone margins

Tools attributes

* tools:showIn - show this layout embedded in another one
* tools:layout - which layout to use for a fragment
* tools:listItem - Layout for item rows
* tools:parentTag - define which layout to use as parent for merge tag

Shortcuts

* <esc> select parent group
* <ctrl><shift> <r/l arrow> switch between xml/design mode

Inference

* Based on probability model for connections
* Automatically creates constraints for unconstrained views
* Doesn't move views or remove existing constraints

Inter-activity transitions

* explode, slide, fade
* Shared elements
    - Bounds, clip, transform, image transform
* Flow from one to the other

Constraint sets

* Separates views from how they are laid out
* Encapsulate all constraints into a single object
* Apply constraint set to an existing constraint layout
* Switch and transition between multiple constraint sets
* overriding `configChanges`???

ConstraintLayouts and Motion

* flat hierarchy == no clipping
* Scene graph
* Constraint set == a keyframe

Slice Editor !

* Shows the attributes from xlm _accross all files_ that affect selected object
    - Layout XML
    - Dimens
    - etc

ConstraintLayout 1.1 (!)

* Barriers - Min and Max for constraints
* Percent dimensions
    - current default on match parent is spread
    - define max dimension of spread as percentage of parent size
* Groups - Apply an operation to several views at once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment