/**
   * ***************************************************
   *
   * <p>Called with the current top-most fragment.
   *
   * <p>***************************************************
   */
  protected void onNotifyTop(AKiteFragment topFragment) {
    ActionBar actionBar = getActionBar();

    // Determine which fragment is top-most

    String tag = topFragment.getTag();

    if (tag != null && tag.equals(ChooseProductGroupFragment.TAG)) {
      ///// Home page /////

      // We only enable the menu on the home page
      mDrawerToggle.setDrawerIndicatorEnabled(true);
      mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

      // We display the logo on the home page
      actionBar.setDisplayShowTitleEnabled(false);
      actionBar.setDisplayShowCustomEnabled(true);
    } else {
      mDrawerToggle.setDrawerIndicatorEnabled(false);
      mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

      // On other pages we show a title
      actionBar.setDisplayShowTitleEnabled(true);
      actionBar.setDisplayShowCustomEnabled(false);
    }

    super.onNotifyTop(topFragment);
  }
  /**
   * ***************************************************
   *
   * <p>Called after the activity has been created.
   *
   * <p>***************************************************
   */
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
  }
  /**
   * ***************************************************
   *
   * <p>Called when the activity becomes visible.
   *
   * <p>***************************************************
   */
  @Override
  protected void onResume() {
    super.onResume();

    // We display a hint of the menu by simulating a pointer down touch event, and then releasing
    // it after a short time.

    if (mShowDrawerOnResume) {
      mShowDrawerOnResume = false;

      final Handler handler = new Handler();

      handler.postDelayed(
          new Runnable() {
            public void run() {
              final long uptimeMillis = SystemClock.uptimeMillis();

              mDrawerLayout.onTouchEvent(
                  MotionEvent.obtain(
                      uptimeMillis,
                      uptimeMillis,
                      MotionEvent.ACTION_DOWN,
                      SIMULATED_TOUCH_X,
                      SIMULATED_TOUCH_Y,
                      NORMAL_PRESSURE,
                      SIMULATED_TOUCH_SIZE,
                      NO_META_STATE_FLAGS,
                      SIMULATED_X_PRECISION,
                      SIMULATED_Y_PRECISION,
                      DEVICE_ID,
                      MotionEvent.EDGE_LEFT));

              handler.postDelayed(
                  new Runnable() {
                    public void run() {
                      mDrawerLayout.onTouchEvent(
                          MotionEvent.obtain(
                              uptimeMillis + UP_EVENT_DELAY_MILLIS,
                              uptimeMillis + UP_EVENT_DELAY_MILLIS,
                              MotionEvent.ACTION_UP,
                              SIMULATED_TOUCH_X,
                              SIMULATED_TOUCH_Y,
                              NORMAL_PRESSURE,
                              SIMULATED_TOUCH_SIZE,
                              NO_META_STATE_FLAGS,
                              SIMULATED_X_PRECISION,
                              SIMULATED_Y_PRECISION,
                              DEVICE_ID,
                              MotionEvent.EDGE_LEFT));
                    }
                  },
                  UP_EVENT_DELAY_MILLIS);
            }
          },
          DOWN_EVENT_DELAY_MILLIS);
    }
  }
  /**
   * ***************************************************
   *
   * <p>Called when an activity result is received.
   *
   * <p>***************************************************
   */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // For the Sticky 9 app, we don't want to exit the activity once check-out is
    // complete - we want to go back to the landing page - the choose product group
    // fragment.

    if (requestCode == ACTIVITY_REQUEST_CODE_CHECKOUT && resultCode == RESULT_OK) {
      mFragmentManager.popBackStackImmediate(ChooseProductGroupFragment.TAG, 0);

      // If we have successfully completed a check-out, then also clear out any cached
      // assets. (This won't clear any product images).
      AssetHelper.clearCachedImages(this);
    } else {
      super.onActivityResult(requestCode, resultCode, data);
    }
  }
  /**
   * ***************************************************
   *
   * <p>Called when the activity is created.
   *
   * <p>***************************************************
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up the navigation drawer

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationDrawerListView = (ListView) findViewById(R.id.navigation_drawer_list_view);

    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, R.string.drawer_open, R.string.drawer_closed);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // On devices running older versions of Android, there is no menu icon, so the user may not
    // know there's a menu. We want to let them know by showing a hint of the menu.

    if (savedInstanceState == null && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
      mShowDrawerOnResume = true;
    }
  }
  /**
   * ***************************************************
   *
   * <p>Called after the configuration changes.
   *
   * <p>***************************************************
   */
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    mDrawerToggle.onConfigurationChanged(newConfig);
  }