Monday, April 18, 2016

Testing Location based Apps on Android Emulator

Things have changed for the good with Emulator 2.0. I think this is the first time I might end up spending more development time on the emulator than on the device.

In this post, I'll be explaining two approaches of how to effectively test location-based apps using the emulator:

1. Testing a single location for the app

From the Extended Controls > Location you can send specific Latitude, Longitude & Altitude to the device. Here's a GIF which shows how we can send Latitude and Longitude and that gets detected by the application

2. Testing multiple locations using KML

For the demo I'm using a KML file from here: https://developers.google.com/kml/documentation/kml_tut#paths which specifies multiple locations in the Placemark section (To learn more about KML, here's a tutorial: https://developers.google.com/kml/documentation/kml_tut)
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Paths</name>
    <description>Examples of paths. Note that the tessellate tag is by default
      set to 0. If you want to create tessellated lines, they must be authored
      (or edited) directly in KML.</description>
    <Style id="yellowLineGreenPoly">
      <LineStyle>
        <color>7f00ffff</color>
        <width>4</width>
      </LineStyle>
      <PolyStyle>
        <color>7f00ff00</color>
      </PolyStyle>
    </Style>
    <Placemark>
      <name>Absolute Extruded</name>
      <description>Transparent green wall with yellow outlines</description>
      <styleUrl>#yellowLineGreenPoly</styleUrl>
      <LineString>
        <extrude>1</extrude>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <coordinates> -112.2550785337791,36.07954952145647,2357
          -112.2549277039738,36.08117083492122,2357
          -112.2552505069063,36.08260761307279,2357
          -112.2564540158376,36.08395660588506,2357
          -112.2580238976449,36.08511401044813,2357
          -112.2595218489022,36.08584355239394,2357
          -112.2608216347552,36.08612634548589,2357 
          -112.2633204928495,36.08621519860091,2357
          -112.2644963846444,36.08627897945274,2357
          -112.2656969554589,36.08649599090644,2357 
        </coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>

Steps

  • Select and Load KML file: From the Extended Controls > Location click on Load GPX/XML 
  • The above step would load locations from KML file in the table 
  • Select the speed at which you want to change the location, for example, Speed 2x would change location every 2 seconds
Here's the pictorial representation of the above steps :

Here's a GIF image showing how it iterates through locations in the table and updates the Latitude & Longitude on the emulator

Wednesday, February 10, 2016

Embedded Fragment Lifecycle

The whole intention of this post is to go through the lifecycle transitions between an activity and an embedded fragment. A fragment can be added to an activity by using the fragment tag and is referred by a class (EmbeddedFragment in example below)

<fragment    
    android:id="@+id/EmbeddedFragment"
    android:name="com.android.example.EmbeddedFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</fragment>






Sunday, January 10, 2016

A fair game.

I've been a carrom fanatic since I was a kid. It runs in the family. The standard carrom game is a 4-player game with 2 teams and the team which scores 29 points first, wins the game.



Last week at a friend's place 4 of us were playing carrom and one of us had to leave early. To not let go off the board, we wished if there could be a standard carrom strategy with 3 players. The discussion and thoughts led to a fair game strategy. I thought of sharing it here, in case just like us, you don't find a 4th player. 

2/4-player game

It's pretty well documented on Wikipedia and wikiHow 

3-player version

This is a modified version of 2/4 player. 
  • Each player has to pocket 6 coins - 3 black and 3 white (18 coins distributed equally among 3 players) 
  • Pocketing the queen must be followed by pocketing another coin in the same strike
  • Point system is a bit different from the standard game
    • The game is over when one of the player reaches 29 points 
    • A player with least points wins the game 
    • When a board is over, the winner gets 0 points, the other 2 players loose the points 
    • If winner pockets the queen, the other player looses 5 points 
    • Here's the points tally based on certain chain of events to understand the point system 
    •    Event  Player A    Player B    Player C  
       Player A won the board and pocketed queen as well
       Player B pocketed 2 coins
       Player C pocketed 4 coins 
      0
      9
      7
       Player A won the board and didn't pocket queen
       Player B pocketed 2 coins
       Player C pocketed 4 coins
      0
      4
      2
  • Foul system
    • If a player takes another black/white after pocketing 3 black/3 white coins, it's considered a foul. The pocketed coin would come back on the board and also the player needs to put an extra coin from his already pocketed coins on the board
Let me know how you feel about it in your comments below.