@Override
  public void onTrackInfoAvailable(String trackId, TrackInfo track) {
    loadTrackList(mViewType, trackId);
    boolean allTracks = (ScheduleContract.Tracks.ALL_TRACK_ID.equals(trackId));

    switch (mViewType) {
      case TracksDropdownFragment.VIEW_TYPE_SESSIONS:
        loadSessionList(
            (allTracks
                    ? ScheduleContract.Sessions.CONTENT_URI
                    : ScheduleContract.Tracks.buildSessionsUri(trackId))
                .buildUpon()
                .appendQueryParameter(
                    ScheduleContract.Sessions.QUERY_PARAMETER_FILTER,
                    ScheduleContract.Sessions.QUERY_VALUE_FILTER_SESSIONS_CODELABS_ONLY)
                .build(),
            mTrackInfoLoadCookie);
        break;

      case TracksDropdownFragment.VIEW_TYPE_OFFICE_HOURS:
        loadSessionList(
            (allTracks
                    ? ScheduleContract.Sessions.CONTENT_URI
                    : ScheduleContract.Tracks.buildSessionsUri(trackId))
                .buildUpon()
                .appendQueryParameter(
                    ScheduleContract.Sessions.QUERY_PARAMETER_FILTER,
                    ScheduleContract.Sessions.QUERY_VALUE_FILTER_OFFICE_HOURS_ONLY)
                .build(),
            mTrackInfoLoadCookie);
        break;

      case TracksDropdownFragment.VIEW_TYPE_SANDBOX:
        loadSandboxList(
            allTracks
                ? ScheduleContract.Sandbox.CONTENT_URI
                : ScheduleContract.Tracks.buildSandboxUri(trackId),
            mTrackInfoLoadCookie);
        break;
    }
  }
  private void routeIntent(Intent intent, boolean updateSurfaceOnly) {
    Uri uri = intent.getData();
    if (uri == null) {
      return;
    }

    if (intent.hasExtra(Intent.EXTRA_TITLE)) {
      setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
    }

    String mimeType = getContentResolver().getType(uri);

    if (ScheduleContract.Tracks.CONTENT_ITEM_TYPE.equals(mimeType)) {
      // Load track details
      showFullUI(true);
      if (!updateSurfaceOnly) {
        // TODO: don't assume the URI will contain the track ID
        int defaultViewType =
            intent.getIntExtra(EXTRA_DEFAULT_VIEW_TYPE, TracksDropdownFragment.VIEW_TYPE_SESSIONS);
        String selectedTrackId = ScheduleContract.Tracks.getTrackId(uri);
        loadTrackList(defaultViewType, selectedTrackId);
        getSupportActionBar().setSelectedNavigationItem(defaultViewType);
        onTrackSelected(selectedTrackId);
        mSlidingPaneLayout.openPane();
      }

    } else if (ScheduleContract.Sessions.CONTENT_TYPE.equals(mimeType)) {
      // Load a session list, hiding the tracks dropdown and the tabs
      mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS;
      showFullUI(false);
      if (!updateSurfaceOnly) {
        loadSessionList(uri, null);
        mSlidingPaneLayout.openPane();
      }

    } else if (ScheduleContract.Sessions.CONTENT_ITEM_TYPE.equals(mimeType)) {
      // Load session details
      if (intent.hasExtra(EXTRA_MASTER_URI)) {
        mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS;
        showFullUI(false);
        if (!updateSurfaceOnly) {
          loadSessionList(
              (Uri) intent.getParcelableExtra(EXTRA_MASTER_URI),
              ScheduleContract.Sessions.getSessionId(uri));
          loadSessionDetail(uri);
        }
      } else {
        mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS; // prepare for onTrackInfo...
        showFullUI(true);
        if (!updateSurfaceOnly) {
          loadSessionDetail(uri);
          loadTrackInfoFromSessionUri(uri);
        }
      }

    } else if (ScheduleContract.Sandbox.CONTENT_TYPE.equals(mimeType)) {
      // Load a sandbox company list
      mViewType = TracksDropdownFragment.VIEW_TYPE_SANDBOX;
      showFullUI(false);
      if (!updateSurfaceOnly) {
        loadSandboxList(uri, null);
        mSlidingPaneLayout.openPane();
      }

    } else if (ScheduleContract.Sandbox.CONTENT_ITEM_TYPE.equals(mimeType)) {
      // Load company details
      mViewType = TracksDropdownFragment.VIEW_TYPE_SANDBOX;
      showFullUI(false);
      if (!updateSurfaceOnly) {
        Uri masterUri = intent.getParcelableExtra(EXTRA_MASTER_URI);
        if (masterUri == null) {
          masterUri = ScheduleContract.Sandbox.CONTENT_URI;
        }
        loadSandboxList(masterUri, ScheduleContract.Sandbox.getCompanyId(uri));
        loadSandboxDetail(uri);
      }
    }

    updateDetailBackground();
  }
  public void loadTrack(Cursor cursor, boolean loadTargetFragment) {
    final String trackId;
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
      trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);
      trackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

      mTitle.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME));
      mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

    } else {
      trackColor = res.getColor(R.color.all_track_color);
      trackId = ScheduleContract.Tracks.ALL_TRACK_ID;

      mTitle.setText(
          TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType)
              ? R.string.all_sessions_title
              : R.string.all_sandbox_title);
      mAbstract.setText(
          TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType)
              ? R.string.all_sessions_subtitle
              : R.string.all_sandbox_subtitle);
    }

    boolean isDark = UIUtils.isColorDark(trackColor);
    mRootView.setBackgroundColor(trackColor);

    if (isDark) {
      mTitle.setTextColor(res.getColor(R.color.body_text_1_inverse));
      mAbstract.setTextColor(res.getColor(R.color.body_text_2_inverse));
      mRootView
          .findViewById(R.id.track_dropdown_arrow)
          .setBackgroundResource(R.drawable.track_dropdown_arrow_light);
    } else {
      mTitle.setTextColor(res.getColor(R.color.body_text_1));
      mAbstract.setTextColor(res.getColor(R.color.body_text_2));
      mRootView
          .findViewById(R.id.track_dropdown_arrow)
          .setBackgroundResource(R.drawable.track_dropdown_arrow_dark);
    }

    if (loadTargetFragment) {
      final Intent intent = new Intent(Intent.ACTION_VIEW);
      final Uri trackUri = ScheduleContract.Tracks.buildTrackUri(trackId);
      intent.putExtra(SessionDetailFragment.EXTRA_TRACK, trackUri);

      if (NEXT_TYPE_SESSIONS.equals(mNextType)) {
        if (cursor == null) {
          intent.setData(ScheduleContract.Sessions.CONTENT_URI);
        } else {
          intent.setData(ScheduleContract.Tracks.buildSessionsUri(trackId));
        }
      } else if (NEXT_TYPE_VENDORS.equals(mNextType)) {
        if (cursor == null) {
          intent.setData(ScheduleContract.Vendors.CONTENT_URI);
        } else {
          intent.setData(ScheduleContract.Tracks.buildVendorsUri(trackId));
        }
      }

      ((BaseActivity) getActivity()).openActivityOrFragment(intent);
    }
  }