Skip to main content

TheLostBrothers


For quite some time now, my father and my uncle have been debating over the coordinates of their houses with respect to each others. Albeit barely 750 meters from each other, there is not much visible reference points or landmarks to figure it out accurately. The blame is on the molasses thick concrete jungle of Kathmandu valley. (Side-note: Kathmandu will soon be synonymous to the word asphyxiation). Although, I sincerely appreciate their curiosity, I think it is time to end this for once and for all.

I have used photos of my sister (Ashma) and my cousin (Samip) as labels to the directions.

The app implements Canvas to "draw" the direction. The two GPS coordinates (obtained from Google Earth) were hard-coded into the program and Azimuth from orientation sensor was used to calculate the direction. Basically, it is a compass that points the direction from one house to the other instead of pointing North. 

Apart from this rather trivial implementation, the code can be modified to achieve some fun/interesting/useful developments. For instance, the direction of Mecca for Muslim prayers is one that comes to mind. Or, it could be modified into a bearing pointer app by using GPS data and some input EditTexts.

Code Snippet

onCreate
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mCustomDrawableView = new CustomDrawableView(this);
  setContentView(mCustomDrawableView); // Register the sensor listeners
  Resources res = getResources();
  samip = BitmapFactory.decodeResource(res, R.drawable.samip);
  ashma = BitmapFactory.decodeResource(res, R.drawable.ashma);
  // Fill in correct latitude and longitude
  currentLoc.setLatitude(0.000000);
  currentLoc.setLongitude(0.00000);
  currentLoc.setAltitude(00);
  destinationLoc.setLatitude(0.00000);
  destinationLoc.setLongitude(0.0000);
  mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
  accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
 }

Canvas

 Float azimuth;
 public Bitmap samip;
 public Bitmap ashma;

 public class CustomDrawableView extends View {
  Paint compassAxis = new Paint();
  Paint compassCircle = new Paint();
  Paint compasAarrow = new Paint();

  public CustomDrawableView(Context context) {
   super(context);
   compassAxis.setColor(0xff00ff00);
   compassAxis.setStyle(Style.STROKE);
   compassAxis.setStrokeWidth(2);
   compassAxis.setAntiAlias(true);
   compassCircle.setColor(0xff000000);
   compassCircle.setStyle(Style.STROKE);
   compassCircle.setStrokeWidth(10);
   compassCircle.setAntiAlias(true);
   compasAarrow.setColor(0xff0000ff);
   compasAarrow.setStyle(Style.STROKE);
   compasAarrow.setStrokeWidth(3);
   compasAarrow.setAntiAlias(true);

  };

  protected void onDraw(Canvas canvas) {
   int width = getWidth(), height = getHeight();
   int centerx = width / 2, centery = height / 2;
   /*
    * Drawing the axis and circle Being symmetrical, these don't need
    * to be rotated
    */
   // Axis
   canvas.drawLine(centerx, 0, centerx, height, compassAxis);
   canvas.drawLine(0, centery, width, centery, compassAxis);
   // Circle
   canvas.drawCircle(centerx, centery, 200, compassCircle);

   /*
    * since this was a pretty small scope app, magnetic north was not
    * changed to real north. See: "GeomagneticField"
    */
   // Used Float instead of float for this check
   if (azimuth != null) {
    // Converting radians to degrees
    float temp = (float) Math.toDegrees(azimuth);
    float bearing = currentLoc.bearingTo(destinationLoc);
    float direction = temp - bearing;
    canvas.rotate(-direction, centerx, centery);
   }
   canvas.drawLine(centerx, centery - 200, centerx, centery, compasAarrow);
   canvas.drawBitmap(samip, centerx + 5, centery - 200, compassAxis);
   canvas.drawBitmap(ashma, centerx + 5, centery - 15, compassAxis);

  }
 }

Screenshots: 




And after some time wasting:


Popular posts from this blog

SalsaNight

Zorgania

The Zorganian Republic has some very strange customs. Couples only wish to have female children as only females can inherit the family's wealth, so if they have a male child they keep having more children until they have a girl. If they have a girl, they stop having children. What is the ratio of girls to boys in Zorgania?
The ratio of girls to boys in Zorgania is 1:1. This might be a little counter-intuitive at first. Here are some ways of tackling this problem. 1. Monte Carlo Simulation: Although, Monte Carlo simulation does not necessarily show why the result is 1:1, it is appropriate because of the very counter-intuitive nature of the problem. At the very least, it helps us see that the result is indeed 1:1. Therefore, this is a good start.
The following R code estimates the probability of a child being a boy in Zorgania. 
couples <-100000 boycount <-0for (i in1:couples){ # 0: boywhile (sample(c(0,1),1) ==0) { boycount=boycount+1 } } probability <- boycount/(co…

Simple Launcher

A simple minimal launcher application for Android devices that shows battery percentage using lzyzsd's CirclProgress library (ArchProgress used in this case) and BroadcastReciever for battery state, Android's clock widgets, a built-in flash light switch and an app list view that can be toggled. Currently, the toggle simply filters all the app that I am working on at present. Future implementation can allow users to select their favorite apps or populate second toggle based on the most used applications.