Android Open Source - CriminalIntent Crime Pager Activity






From Project

Back to project page CriminalIntent.

License

The source code is released under:

MIT License

If you think the Android project CriminalIntent 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.ambergleam.criminalintent.controller;
//from ww  w.java2 s.  c om
import java.util.ArrayList;
import java.util.UUID;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.ambergleam.criminalintent.R;
import com.ambergleam.criminalintent.model.Crime;
import com.ambergleam.criminalintent.model.CrimeLab;

public class CrimePagerActivity extends FragmentActivity implements CrimeFragment.Callbacks {

  public static final int OFF_SCREEN_PAGE_LIMIT = 2;

  private ViewPager mViewPager;
  private ArrayList<Crime> mCrimes;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.viewPager);
    mViewPager.setOffscreenPageLimit(OFF_SCREEN_PAGE_LIMIT);
    setContentView(mViewPager);

    mCrimes = CrimeLab.get(this).getCrimes();

    FragmentManager fm = getSupportFragmentManager();
    mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) {

      @Override
      public int getCount() {
        return mCrimes.size();
      }

      @Override
      public Fragment getItem(int pos) {
        Crime crime = mCrimes.get(pos);
        return CrimeFragment.newInstance(crime.getId());
      }
    });

    UUID crimeId = (UUID) getIntent().getSerializableExtra(CrimeFragment.EXTRA_CRIME_ID);
    for (int i = 0; i < mCrimes.size(); i++) {
      if (mCrimes.get(i).getId().equals(crimeId)) {
        mViewPager.setCurrentItem(i);
        setTitle(mCrimes.get(i).getTitle());
        break;
      }
    }

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

      @Override
      public void onPageSelected(int pos) {
        Crime crime = mCrimes.get(pos);
        if (crime.getTitle() != null) {
          setTitle(crime.getTitle());
        }
      }

      @Override
      public void onPageScrolled(int pos, float posOffset, int posOffsetPixels) {
      }

      @Override
      public void onPageScrollStateChanged(int state) {
      }

    });

  }

  @Override
  public void onCrimeUpdated(Crime crime) {
  }

}




Java Source Code List

com.ambergleam.criminalintent.controller.CrimeFragment.java
com.ambergleam.criminalintent.controller.CrimeListActivity.java
com.ambergleam.criminalintent.controller.CrimeListFragment.java
com.ambergleam.criminalintent.controller.CrimePagerActivity.java
com.ambergleam.criminalintent.controller.DatePickerFragment.java
com.ambergleam.criminalintent.helper.CriminalIntentJSONSerializer.java
com.ambergleam.criminalintent.helper.SingleFragmentActivity.java
com.ambergleam.criminalintent.model.CrimeLab.java
com.ambergleam.criminalintent.model.Crime.java