Category: Android

The Essential Android Developer Toolbox and Reference

"XML is crap. Really. There's just no reason for that horrible crap to exist"

First off this list has nothing on Codepath's useful tools

Another top resource is DroidToolbox

Interacting with an API

  • Retrofit - The Best REST Client for Android (Don't use anything else), you will need the lower level
  • OKHTTP as a client for adding cookie/session to headers and to trust self-signed certificates
  • Json to Pojo - Generate plain old java objects from the JSON response from an API. Saves a lot of Time, you can also use android studio to create the setters and getters -> highlight the attributes of the class -> right click -> generate -> setters & getters
  • Picasso - Aynchronously set images from url's

Views and Layout Elements

Memory Management and Leaking

  • Leak Canary - Detect Memory Leaks in Android and Java

Local Storage

References

Design and Colour Pallete

View Elements

Podcasts

  • Fragmented Podcast - Podcast that gets to grips with issues that are difficult for the community

android-developer-toolkit

How to Debug or Sniff Network Activity on Android Emulator?

Checking network activity is a very important task especially when your app is accessing an API.
However the emulator runs in a virtual environment and hence is often not picked up by default on network sniffing debugging and activity tools.
Fear not we can use Fiddler to view network requests made on your android emulator or even a test device.
Even better we can do this on a linux machine.

How to Install Fiddler

On Windows: Download Fiddler to view network traffic

On Linux(ubuntu):

  1. Install Mono - an open source implementation of the .net framework (basically lets you run .exe on linux)
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
    echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
    sudo apt-get update
    sudo apt-get install mono-complete
  2. Download Fiddler for Mono
  3. Run Fiddler
    mono Fiddler.exe
  4. Tools -> Fiddler Options -> Connections -> Make sure Allow remote computers to connect is checked

Set your Emulator or Device to Proxy Traffic to Fiddler

On the device

  1. Go to Settings
  2. Select Wifi
  3. Hold down the wifi connection for 2 seconds
  4. Click Modify Network
  5. set the Following:
    Proxy Hostname: 10.0.3.2 (Genymotion Emulator) | 10.0.2.2 (Normal Emulator)
    Proxy port: 8888
    
  6. Turn Off and On The Wifi to Refresh

Start Debugging

Now your life is made a little bit easier you can check the headers, cookies and form data sent with requests and check responses.

Source: Stack Overflow Emulator Port, Genymotion port MSDN The Real Source

 

Android Material Design Best Practices in a Bottle

This post provides a compressed tl;dr of the Android Material Design guide with Android Devices in Mind.

Raising Things

We need to raise view elements, which is essentially giving a shadow and emphasis to elements. Make use of the elevation attribute. As a short guide:

  • app bar: 2dp
  • floating button: 6dp
  • card: 2dp
  • anything raised: 2dp
  • anything pressed: Add 6dp
<TextView
    android:id="@+id/my_textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next"
    android:background="@color/white"
    android:elevation="5dp" />

 

Animations

We now need to reveal things and change screens in cool ways, check:

Colour

You can only use certain colours. List of colours you can use in Material Design. Which I think it a great idea, no more chopping and changing to match the clients requirements. Keeping it uniform, keeps it simple.

Know how to set the colour palette for you app.

How to Change the colour palette for Android Material Design

1. Set colours in res/values/colors.xml

 <color name="primary">#2E7D32</color>
 <color name="primary_dark">#1B5E20</color>
 <color name="accent">#76FF03</color>
 <color name="background">#37474F</color>

2. Set the style of the theme. This only works in versions higher than 20 so put it in a folder: res/values-v21/styles.xml:

  <!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
<!-- text colour -->
<item name="android:textColor">@android:color/black</item>
<!-- Navigation Bar -->
<item name="android:navigationBarColor">@color/primary</item>

 

The end product will look something like this: