Android Open Source - PhotoPicker Photo Chooser Activity






From Project

Back to project page PhotoPicker.

License

The source code is released under:

GNU General Public License

If you think the Android project PhotoPicker 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.thuytrinh.photopicker.controller.activity;
//  ww w .j a va2s  .c o  m
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import com.thuytrinh.photopicker.R;
import com.thuytrinh.photopicker.controller.fragment.AlbumsFragment;
import com.thuytrinh.photopicker.controller.fragment.PhotosFragment;
import com.thuytrinh.photopicker.model.Photo;

import java.util.ArrayList;

import rx.functions.Action1;

public class PhotoChooserActivity extends Activity {
  public static final String EXTRA_CHOSEN_PHOTO_LIST = "chosenPhotoList";

  private final String mPhotoListTag = "photoList";
  private final String mAlbumListTag = "albumList";

  public static Intent newIntent(Context context) {
    return new Intent(context, PhotoChooserActivity.class);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
      onBackPressed();
      return true;
    } else {
      return super.onOptionsItemSelected(item);
    }
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_chooser);

    if (getActionBar() != null) {
      getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    AlbumsFragment albumsFragment;
    if (savedInstanceState == null) {
      albumsFragment = new AlbumsFragment();

      getFragmentManager().beginTransaction()
          .add(R.id.container, albumsFragment, mAlbumListTag)
          .commit();
    } else {
      albumsFragment = (AlbumsFragment) getFragmentManager()
          .findFragmentByTag(mAlbumListTag);
    }

    albumsFragment.whenAlbumSelected().subscribe(new Action1<Long>() {
      @Override
      public void call(Long selectedAlbumId) {
        PhotosFragment photosFragment = PhotosFragment.newInstance(selectedAlbumId);
        photosFragment.whenChoicesChanged().subscribe(new Action1<Integer>() {
          @Override
          public void call(Integer choiceCount) {
            if (getActionBar() != null) {
              getActionBar().setTitle(choiceCount.toString());
            }
          }
        });
        photosFragment.whenChoicesDone().subscribe(new Action1<ArrayList<Photo>>() {
          @Override
          public void call(ArrayList<Photo> chosenPhotoList) {
            // Prepare data.
            Intent data = new Intent();
            data.putParcelableArrayListExtra(EXTRA_CHOSEN_PHOTO_LIST, chosenPhotoList);

            // Push result back.
            setResult(RESULT_OK, data);
            finish();
          }
        });

        getFragmentManager().beginTransaction()
            .replace(R.id.container, photosFragment, mPhotoListTag)
            .addToBackStack(mPhotoListTag)
            .commit();
      }
    });
  }
}




Java Source Code List

com.thuytrinh.photopicker.controller.GroupByBucketIdFunc.java
com.thuytrinh.photopicker.controller.ImageCursorMapperTest.java
com.thuytrinh.photopicker.controller.ImageCursorMapper.java
com.thuytrinh.photopicker.controller.SimpleLoaderListenerTest.java
com.thuytrinh.photopicker.controller.SimpleLoaderListener.java
com.thuytrinh.photopicker.controller.activity.PhotoChooserActivityTest.java
com.thuytrinh.photopicker.controller.activity.PhotoChooserActivity.java
com.thuytrinh.photopicker.controller.adapter.AlbumsAdapter.java
com.thuytrinh.photopicker.controller.adapter.PhotosAdapter.java
com.thuytrinh.photopicker.controller.fragment.AlbumsFragment.java
com.thuytrinh.photopicker.controller.fragment.PhotosFragment.java
com.thuytrinh.photopicker.controller.loader.AlbumsLoaderTest.java
com.thuytrinh.photopicker.controller.loader.AlbumsLoader.java
com.thuytrinh.photopicker.controller.loader.PhotosLoaderTest.java
com.thuytrinh.photopicker.controller.loader.PhotosLoader.java
com.thuytrinh.photopicker.model.PhotoTest.java
com.thuytrinh.photopicker.model.Photo.java
com.thuytrinh.photopicker.module.AppModule.java
com.thuytrinh.photopicker.module.ObjectLocator.java
com.thuytrinh.photopicker.view.AlbumView.java
com.thuytrinh.photopicker.view.PhotoItemLayoutTest.java
com.thuytrinh.photopicker.view.PhotoItemLayout.java