예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDataSource = new TrackDataSource(this);
    mDataSource.open();

    // get preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mPreferenceUser = prefs.getString("gpsiesUsername", null);
    mPreferenceUpdate = prefs.getLong("gpsiesLastUpdate", 0);

    // no gpsies user set
    if (mPreferenceUser == null || mPreferenceUser.trim().length() == 0) {
      Toast.makeText(this, R.string.missingGpsiesUsername, Toast.LENGTH_LONG).show();
      Intent preferencesActivity = new Intent(this, Preferences.class);
      startActivity(preferencesActivity);
    }
    // load data for the first time
    else if (mPreferenceUser != null && mPreferenceUpdate == 0) {
      updateTrackList();
    }

    setContentView(R.layout.fragment_tabs);
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

    mTabManager = new TabManager(this, mTabHost, R.id.realtabcontent);

    mTabManager.addTab(
        mTabHost.newTabSpec("tracks").setIndicator(getResources().getString(R.string.myTracks)),
        TrackListOwn.class,
        null);
    mTabManager.addTab(
        mTabHost.newTabSpec("notepad").setIndicator(getResources().getString(R.string.notepad)),
        TrackListNotepad.class,
        null);

    if (savedInstanceState != null) {
      mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }
  }
예제 #2
0
  public void updateTrackList() {
    // clear list
    mDataSource.deleteAll();

    TrackListAbstract tracksFragment =
        (TrackListAbstract) getSupportFragmentManager().findFragmentByTag("tracks");
    TrackAdapter tracksAdapter = null;
    if (null != tracksFragment) {
      tracksAdapter = tracksFragment.getAdapter();
    }
    new TrackListUpdater(this, mDataSource, tracksAdapter, TrackListUpdater.URL_TRACKS)
        .execute(mPreferenceUser);

    TrackListAbstract notepadFragment =
        (TrackListAbstract) getSupportFragmentManager().findFragmentByTag("notepad");
    TrackAdapter notepadAdapter = null;
    if (null != notepadFragment) {
      notepadAdapter = notepadFragment.getAdapter();
    }
    new TrackListUpdater(this, mDataSource, notepadAdapter, TrackListUpdater.URL_NOTEPAD)
        .execute(mPreferenceUser);
  }