Android Open Source - lastfm-android-music-discovery Main Activity






From Project

Back to project page lastfm-android-music-discovery.

License

The source code is released under:

Apache License

If you think the Android project lastfm-android-music-discovery listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mikeladze.musicdiscovery.main.activity;
/*from   w w  w  .j av a 2s.com*/
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;

import com.mikeladze.musicdiscovery.R;
import com.mikeladze.musicdiscovery.base.activity.BaseFragmentActivity;
import com.mikeladze.musicdiscovery.base.adapter.SectionsPagerAdapter;
import com.mikeladze.musicdiscovery.main.fragment.HypedArtistsFragment;
import com.mikeladze.musicdiscovery.main.fragment.TopArtistsFragment;

import fm.last.lastfm.LastFM;

/**
 * The MainActivity, showed when app is started. Displays popular artists.
 * 
 * @author Tim Mikeladze
 */
public class MainActivity extends BaseFragmentActivity implements ActionBar.TabListener {
  
  private static final String ACTION_BAR_TITLE = "Top Artists";
  private SectionsPagerAdapter sectionsPagerAdapter;
  private ViewPager viewPager;
  
  @Override
  /**
   * Creates the activity and adds the fragments.
   */
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setTitle(ACTION_BAR_TITLE);
    
    initialize();
    
    setContentView(R.layout.activity_main);
    
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    
    sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
    
    sectionsPagerAdapter.addFragment(Fragment.instantiate(this, TopArtistsFragment.class.getName()));
    sectionsPagerAdapter.addFragment(Fragment.instantiate(this, HypedArtistsFragment.class.getName()));
    
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);
    
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
      
      @Override
      public void onPageSelected(int position) {
        actionBar.setSelectedNavigationItem(position);
      }
    });
    
    for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) {
      actionBar.addTab(actionBar.newTab()
                    .setText(sectionsPagerAdapter.getPageTitle(i))
                    .setTabListener(this));
    }
    
  }
  
  /**
   * Set the API key for Last.FM
   */
  private void initialize() {
    LastFM.setApiKey("aa4b32f5ab59754424905e8bb3576143");
  }
  
  @Override
  public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    viewPager.setCurrentItem(tab.getPosition());
  }
  
  @Override
  public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  }
  
  @Override
  public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    return true;
  }
  
}




Java Source Code List

com.mikeladze.musicdiscovery.album.activity.AlbumActivity.java
com.mikeladze.musicdiscovery.album.adapter.LastFMTrack.java
com.mikeladze.musicdiscovery.album.adapter.OnTrackClickListener.java
com.mikeladze.musicdiscovery.album.adapter.TrackListAdapter.java
com.mikeladze.musicdiscovery.album.fragment.AlbumInfoFragment.java
com.mikeladze.musicdiscovery.album.fragment.AlbumTracksFragment.java
com.mikeladze.musicdiscovery.artist.activity.ArtistActivity.java
com.mikeladze.musicdiscovery.artist.fragment.ArtistAlbumsFragment.java
com.mikeladze.musicdiscovery.artist.fragment.ArtistInfoFragment.java
com.mikeladze.musicdiscovery.artist.fragment.SimilarArtistsFragment.java
com.mikeladze.musicdiscovery.base.activity.BaseFragmentActivity.java
com.mikeladze.musicdiscovery.base.adapter.SectionsPagerAdapter.java
com.mikeladze.musicdiscovery.base.fragment.BaseTabFragment.java
com.mikeladze.musicdiscovery.base.fragment.ImageGridViewFragment.java
com.mikeladze.musicdiscovery.http.LastFMResult.java
com.mikeladze.musicdiscovery.http.RestClient.java
com.mikeladze.musicdiscovery.main.activity.MainActivity.java
com.mikeladze.musicdiscovery.main.fragment.HypedArtistsFragment.java
com.mikeladze.musicdiscovery.main.fragment.TopArtistsFragment.java
com.mikeladze.musicdiscovery.search.activity.SearchResultsActivity.java
com.mikeladze.musicdiscovery.search.adapter.SearchResultsAdapter.java
com.mikeladze.musicdiscovery.util.IntentUtils.java
com.mikeladze.musicdiscovery.view.gridview.DynamicImageView.java
com.mikeladze.musicdiscovery.view.gridview.ImageGridAdapter.java
com.mikeladze.musicdiscovery.view.gridview.loader.FileCache.java
com.mikeladze.musicdiscovery.view.gridview.loader.ImageLoader.java
com.mikeladze.musicdiscovery.view.gridview.loader.MemoryCache.java
com.mikeladze.musicdiscovery.view.gridview.loader.Utils.java