Search in sources :

Example 1 with Photo

use of us.koller.cameraroll.data.models.Photo in project Camera-Roll-Android-App by kollerlukas.

the class ItemActivity method onAlbumLoaded.

private void onAlbumLoaded(Bundle savedInstanceState) {
    if (albumItem == null) {
        if (savedInstanceState == null) {
            int position = getIntent().getIntExtra(ITEM_POSITION, 0);
            if (album != null && position >= 0 && position < album.getAlbumItems().size()) {
                albumItem = album.getAlbumItems().get(position);
                albumItem.isSharedElement = true;
            }
        } else {
            albumItem = savedInstanceState.getParcelable(ALBUM_ITEM);
            if (albumItem != null && albumItem instanceof Photo) {
                Photo photo = (Photo) albumItem;
                ImageViewState imageViewState = (ImageViewState) savedInstanceState.getSerializable(IMAGE_VIEW_SAVED_STATE);
                photo.putImageViewSavedState(imageViewState);
            }
            if (savedInstanceState.getBoolean(INFO_DIALOG_SHOWN, false)) {
                showInfoDialog();
            }
        }
    }
    if (albumItem == null) {
        return;
    }
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(albumItem.getName());
    }
    viewPager = findViewById(R.id.view_pager);
    viewPager.setAdapter(new ItemAdapter(album));
    int currentItem = album.getAlbumItems().indexOf(albumItem);
    viewPager.setCurrentItem(currentItem >= 0 ? currentItem : 0, false);
    if (showAnimations()) {
        viewPager.setPageTransformer(false, new ParallaxTransformer());
    }
    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        private final int color = ContextCompat.getColor(ItemActivity.this, R.color.white);

        @Override
        public void onPageSelected(int position) {
            // set new AlbumItem
            albumItem = album.getAlbumItems().get(position);
            ColorFade.fadeToolbarTitleColor(toolbar, color, new ColorFade.ToolbarTitleFadeCallback() {

                @Override
                public void setTitle(Toolbar toolbar) {
                    toolbar.setTitle(albumItem.getName() != null ? albumItem.getName() : "");
                }
            });
            ViewHolder viewHolder = ((ItemAdapter) viewPager.getAdapter()).findViewHolderByTag(albumItem.getPath());
            if (viewHolder != null) {
                onShowViewHolder(viewHolder);
            }
        }
    });
    if (!enterTransitionPostponed()) {
        albumItem.isSharedElement = false;
        // there is no sharedElementTransition
        ItemAdapter adapter = (ItemAdapter) viewPager.getAdapter();
        ViewHolder viewHolder = adapter.findViewHolderByTag(albumItem.getPath());
        if (viewHolder != null) {
            onShowViewHolder(viewHolder);
        } else {
            ((ItemAdapter) viewPager.getAdapter()).addOnInstantiateItemCallback(new ViewPagerOnInstantiateItemCallback() {

                @Override
                public boolean onInstantiateItem(ViewHolder viewHolder) {
                    if (viewHolder.albumItem.getPath().equals(albumItem.getPath())) {
                        onShowViewHolder(viewHolder);
                        return false;
                    }
                    return true;
                }
            });
        }
    }
}
Also used : Photo(us.koller.cameraroll.data.models.Photo) ImageViewState(com.davemorrissey.labs.subscaleview.ImageViewState) ViewPager(android.support.v4.view.ViewPager) ParallaxTransformer(us.koller.cameraroll.util.ParallaxTransformer) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) ActionBar(android.support.v7.app.ActionBar) ItemAdapter(us.koller.cameraroll.adapter.item.ItemAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with Photo

use of us.koller.cameraroll.data.models.Photo in project Camera-Roll-Android-App by kollerlukas.

the class ItemActivity method printPhoto.

public void printPhoto() {
    if (!(albumItem instanceof Photo)) {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
        return;
    }
    PrintHelper photoPrinter = new PrintHelper(this);
    photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
    try {
        photoPrinter.printBitmap(albumItem.getPath(), albumItem.getUri(this));
    } catch (FileNotFoundException e) {
        Toast.makeText(this, "Error (FileNotFoundException)", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Photo(us.koller.cameraroll.data.models.Photo) PrintHelper(android.support.v4.print.PrintHelper)

Example 3 with Photo

use of us.koller.cameraroll.data.models.Photo in project Camera-Roll-Android-App by kollerlukas.

the class PhotoViewHolder method inflateView.

@Override
public View inflateView(ViewGroup container) {
    ViewGroup v = super.inflatePhotoView(container);
    final View view = v.findViewById(R.id.subsampling);
    final View transitionView = itemView.findViewById(R.id.image);
    // hide transitionView, when config was changed
    if (albumItem instanceof Photo && ((Photo) albumItem).getImageViewSavedState() != null) {
        transitionView.setVisibility(View.INVISIBLE);
    }
    ItemViewUtil.bindTransitionView((ImageView) transitionView, albumItem);
    view.setVisibility(View.INVISIBLE);
    return v;
}
Also used : ViewGroup(android.view.ViewGroup) Photo(us.koller.cameraroll.data.models.Photo) ImageView(android.widget.ImageView) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) View(android.view.View)

Example 4 with Photo

use of us.koller.cameraroll.data.models.Photo in project Camera-Roll-Android-App by kollerlukas.

the class ItemActivity method setPhotoAs.

public void setPhotoAs() {
    if (!(albumItem instanceof Photo)) {
        return;
    }
    Uri uri = albumItem.getUri(this);
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setDataAndType(uri, MediaType.getMimeType(this, uri));
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    try {
        startActivityForResult(Intent.createChooser(intent, getString(R.string.set_as)), 13);
    } catch (SecurityException se) {
        Toast.makeText(this, "Error (SecurityException)", Toast.LENGTH_SHORT).show();
        se.printStackTrace();
    } catch (ActivityNotFoundException anfe) {
        Toast.makeText(this, "No App found", Toast.LENGTH_SHORT).show();
        anfe.printStackTrace();
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Photo(us.koller.cameraroll.data.models.Photo) Intent(android.content.Intent) Uri(android.net.Uri)

Example 5 with Photo

use of us.koller.cameraroll.data.models.Photo in project Camera-Roll-Android-App by kollerlukas.

the class ItemActivity method onSaveInstanceState.

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (albumItem instanceof Photo) {
        View itemView = viewPager.findViewWithTag(albumItem.getPath());
        if (itemView != null) {
            View view = itemView.findViewById(R.id.subsampling);
            if (view instanceof SubsamplingScaleImageView) {
                SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view;
                ImageViewState state = imageView.getState();
                if (state != null) {
                    outState.putSerializable(IMAGE_VIEW_SAVED_STATE, state);
                }
            }
        }
    }
    // outState.putParcelable(ALBUM, album);
    outState.putParcelable(ALBUM_ITEM, albumItem);
    outState.putBoolean(WAS_SYSTEM_UI_HIDDEN, !systemUiVisible);
    outState.putBoolean(INFO_DIALOG_SHOWN, infoDialog != null);
}
Also used : Photo(us.koller.cameraroll.data.models.Photo) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) ImageView(android.widget.ImageView) View(android.view.View) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) RecyclerView(android.support.v7.widget.RecyclerView) ImageViewState(com.davemorrissey.labs.subscaleview.ImageViewState)

Aggregations

Photo (us.koller.cameraroll.data.models.Photo)6 View (android.view.View)3 ImageView (android.widget.ImageView)3 SubsamplingScaleImageView (com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView)3 Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ImageViewState (com.davemorrissey.labs.subscaleview.ImageViewState)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 PrintHelper (android.support.v4.print.PrintHelper)1 ViewPager (android.support.v4.view.ViewPager)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewGroup (android.view.ViewGroup)1 FileNotFoundException (java.io.FileNotFoundException)1 InfoRecyclerViewAdapter (us.koller.cameraroll.adapter.item.InfoRecyclerViewAdapter)1