/** When user click a category in listview */
  @Override
  public void gotoCategoryPage(NavigationDrawerAdapter.ItemAdapter.TYPE pageType, int position) {
    Log.e("DEBUG", "category: " + pageType);
    Fragment fragment = null;
    Bundle arguments = new Bundle();
    switch (pageType) {
      case HOME:
        fragment = new WelcomeFragment();
        break;
      case SONGS:
        fragment = new SongListFragment();
        break;
      case MYPLAYLIST:
        fragment = new PlaylistManagerFragment();
        break;
      case FAVORITE:
        fragment = new FavoriteManagerFragment();
        break;
      case FIND_BY_CHORD:
        fragment = new SearchChordFragment();
        break;
      case SEARCH_CHORD:
        fragment = new ChordViewFragment();
        break;
      case SETTING:
        // fragment = new SettingFragment();
        break;
    }

    // assign parameters to fragment
    fragment.setArguments(arguments);

    // close Drawer List View
    if (mDrawerListView != null) {
      LogUtils.LOGE("TRUNGDQ", "NavDrawer set category: " + position);
      mDrawerListView.setItemChecked(position, true);
    }
    if (mDrawerLayout != null) {
      mDrawerLayout.closeDrawer(mFragmentContainerView);
    }

    // assign this work to main mActivity
    if (mCallbacks != null) {
      mCallbacks.onNavigationDrawerItemSelected(fragment);
    }
  }
  /** When user click to a playlist row and want to show detail */
  @Override
  public void gotoPlayList(int playlistId) {
    Playlist playlist = playlistList.get(playlistId);
    PlaylistDetailFragment fragment = new PlaylistDetailFragment();
    // setting parameters
    Bundle arguments = new Bundle();
    arguments.putParcelable("playlist", playlist);
    fragment.setArguments(arguments);

    // setting for Drawer List View
    if (mDrawerListView != null) {
      LogUtils.LOGE("TRUNGDQ", "NavDrawer set playlist: " + playlistId);
      mDrawerListView.setItemChecked(playlistId, true);
    }
    if (mDrawerLayout != null) {
      mDrawerLayout.closeDrawer(mFragmentContainerView);
    }

    // assign this work to main mActivity
    if (mCallbacks != null) {
      mCallbacks.onNavigationDrawerItemSelected(fragment);
    }
  }
Exemple #3
0
public abstract class ChordViewAdapter extends BaseAdapter implements SectionIndexer, IChordView {

  public static String TAG = LogUtils.makeLogTag(ChordViewAdapter.class);

  protected Context mContext;

  /** List all chords that adapter contains */
  protected String[] chords;

  /** currently index of chord */
  protected int[] index;

  /** String that using for SectionIndexer */
  protected static String sectionStr = "C,Cm,D,Dm,E,Em,F,Fm,G,Gm,A,Am,B,Bm";

  protected String[] sections = sectionStr.split(",");

  public ChordViewAdapter(Context mContext, String[] chords) {
    this.mContext = mContext.getApplicationContext();
    this.chords = chords;
    index = new int[chords.length];
  }

  public void setChordList(String[] chords) {
    this.chords = chords;
    index = new int[chords.length];
  }

  @Override
  public int getCount() {
    return chords.length;
  }

  @Override
  public Object getItem(int position) {
    return chords[position];
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public Object[] getSections() {
    return sections;
  }

  @Override
  public int getPositionForSection(int section) {
    for (int i = 0; i < chords.length; i++) {
      String item = chords[i];
      if (item.length() >= 2) item = item.substring(0, 2);
      if (sections[section].length() == 1 && item.length() >= 1) item = item.substring(0, 1);
      if (item.toLowerCase().equals(sections[section].toLowerCase())) {
        return i;
      }
    }
    return 0;
  }

  @Override
  public int getSectionForPosition(int position) {
    return 0;
  }
}