Android - The Home Screen (Without Good Design)

For Android, I'll start by defining the same four events in EventManager.java:

  1. package com.crowleyworks.futilefishing;
  2.  
  3. public interface EventManager {
  4.  
  5. public static final int EM_USER_LOGOUT = 100;
  6. public static final int EM_USER_LOGIN = 101;
  7. public static final int EM_REQUEST_LOGOUT = 102;
  8.  
  9. public static final int EM_NAV_PLAN_TRIP = 103;
  10. public static final int EM_NAV_LOG_TRIP = 104;
  11. public static final int EM_NAV_CAPTURE_CATCH = 105;
  12. public static final int EM_NAV_LOCAL_SPOTS_MAP = 106;
  13.  
  14. public void handleEvent(int eventID, Object data);
  15. }

I'll next create a new Android layout file (home_view.xml):

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <Button
  8. android:id="@+id/btnPlanTrip"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="@string/sBtnPlanTrip"/>
  12.  
  13. <Button
  14. android:id="@+id/btnLogTrip"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:text="@string/sBtnLogTrip" />
  18.  
  19. <Button
  20. android:id="@+id/btnCaptureCatch"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:text="@string/sBtnCaptureCatch" />
  24.  
  25. <Button
  26. android:id="@+id/btnLocalSpots"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:text="@string/sBtnLocalSpots" />
  30.  
  31. </LinearLayout>

This layout file simply defines four buttons.

I'll next create the HomeViewController.java class as follows:

  1. package com.crowleyworks.futilefishing.view;
  2.  
  3. import com.crowleyworks.futilefishing.EventManager;
  4. import com.crowleyworks.futilefishing.R;
  5.  
  6. import android.content.Context;
  7. import android.util.SparseIntArray;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11.  
  12. public class HomeViewController extends ViewController {
  13.  
  14. private SparseIntArray events;
  15.  
  16. public HomeViewController(Context context, int layoutId) {
  17. super(context, layoutId);
  18.  
  19. // Map each button ID to the associated event it triggers
  20. events = new SparseIntArray();
  21. events.put(R.id.btnPlanTrip, EventManager.EM_NAV_PLAN_TRIP);
  22. events.put(R.id.btnLogTrip, EventManager.EM_NAV_LOG_TRIP);
  23. events.put(R.id.btnCaptureCatch, EventManager.EM_NAV_CAPTURE_CATCH);
  24. events.put(R.id.btnLocalSpots, EventManager.EM_NAV_LOCAL_SPOTS_MAP);
  25. }
  26.  
  27. @Override
  28. protected void viewDidLoad() {
  29. super.viewDidLoad();
  30. OnClickListener ocl = new OnClickListener() {
  31. @Override
  32. public void onClick(View v) {
  33. int iEvent = events.get(v.getId());
  34. if ((eventManager != null) && (iEvent != 0)) {
  35. eventManager.handleEvent(iEvent, null);
  36. }
  37. }
  38. };
  39. // Set up the actions for each button
  40. ((Button)view.findViewById(R.id.btnPlanTrip)).setOnClickListener(ocl);
  41. ((Button)view.findViewById(R.id.btnLogTrip)).setOnClickListener(ocl);
  42. ((Button)view.findViewById(R.id.btnCaptureCatch)).setOnClickListener(ocl);
  43. ((Button)view.findViewById(R.id.btnLocalSpots)).setOnClickListener(ocl);
  44.  
  45. }
  46.  
  47. }

Comments:

  • Lines 19 - 24: Map each button to a navigation event. This provides a clean separation between the button and the associated action.
  • Lines 30 - 38: Define an OnClickListener to generically respond to the clicking of a button. The listener simply fires the navigation event associated with the button.
  • Lines 40 - 43: Assign the OnClickListener to each button.

After completing the code and running the application, I'm presented with the following:

Again, this is a very unappealing first impression of the app. (It's even worse than the experience with iOS.) In the next section, I'll try to assemble something that's more palatable to a user.