Search in sources :

Example 1 with ImageViewState

use of com.davemorrissey.labs.subscaleview.ImageViewState 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 ImageViewState

use of com.davemorrissey.labs.subscaleview.ImageViewState in project Camera-Roll-Android-App by kollerlukas.

the class ItemViewUtil method bindSubsamplingImageView.

public static void bindSubsamplingImageView(SubsamplingScaleImageView imageView, Photo photo, SubsamplingScaleImageView.DefaultOnImageEventListener onImageEventListener) {
    imageView.recycle();
    ImageViewState imageViewState = null;
    if (photo.getImageViewSavedState() != null) {
        imageViewState = (ImageViewState) photo.getImageViewSavedState();
        photo.putImageViewSavedState(null);
    }
    imageView.setImage(ImageSource.uri(photo.getUri(imageView.getContext())), imageViewState);
    if (onImageEventListener != null) {
        imageView.setOnImageEventListener(onImageEventListener);
    }
}
Also used : ImageViewState(com.davemorrissey.labs.subscaleview.ImageViewState)

Example 3 with ImageViewState

use of com.davemorrissey.labs.subscaleview.ImageViewState 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)

Example 4 with ImageViewState

use of com.davemorrissey.labs.subscaleview.ImageViewState in project Camera-Roll-Android-App by kollerlukas.

the class SetWallpaperActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_set_wallpaper);
    Intent intent = getIntent();
    if (intent == null) {
        return;
    }
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("");
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    imageUri = intent.getData();
    if (!MediaType.suitableAsWallpaper(this, imageUri)) {
        Toast.makeText(this, R.string.wallpaper_file_format_not_supported, Toast.LENGTH_SHORT).show();
        finish();
    }
    final SubsamplingScaleImageView imageView = findViewById(R.id.imageView);
    ImageViewState imageViewState = null;
    if (savedInstanceState != null && savedInstanceState.containsKey(IMAGE_VIEW_STATE)) {
        imageViewState = (ImageViewState) savedInstanceState.getSerializable(IMAGE_VIEW_STATE);
    }
    imageView.setMinimumTileDpi(196);
    // use custom decoders
    imageView.setRegionDecoderClass(CustomRegionDecoder.class);
    imageView.setImage(ImageSource.uri(imageUri), imageViewState);
    imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
    if (imageViewState == null) {
        imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {

            @Override
            public void onImageLoaded() {
                super.onImageLoaded();
                float scale = imageView.getScale();
                PointF center = new PointF(imageView.getWidth() / 2, 0.0f);
                imageView.setScaleAndCenter(scale, center);
            }
        });
    }
    // setting window insets manually
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        toolbar.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @Override
            @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
            public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
                // clear this listener so insets aren't re-applied
                toolbar.setOnApplyWindowInsetsListener(null);
                toolbar.setPadding(toolbar.getPaddingStart() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
                return insets.consumeSystemWindowInsets();
            }
        });
    } else {
        toolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                toolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                // hacky way of getting window insets on pre-Lollipop
                // somewhat works...
                int[] screenSize = Util.getScreenSize(SetWallpaperActivity.this);
                int[] windowInsets = new int[] { Math.abs(screenSize[0] - toolbar.getLeft()), Math.abs(screenSize[1] - toolbar.getTop()), Math.abs(screenSize[2] - toolbar.getRight()), Math.abs(0) };
                toolbar.setPadding(toolbar.getPaddingStart() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
            }
        });
    }
    // needed to achieve transparent navBar
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);
}
Also used : PointF(android.graphics.PointF) Intent(android.content.Intent) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) ImageViewState(com.davemorrissey.labs.subscaleview.ImageViewState) View(android.view.View) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) WindowInsets(android.view.WindowInsets) RequiresApi(android.support.annotation.RequiresApi) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ImageViewState (com.davemorrissey.labs.subscaleview.ImageViewState)4 ActionBar (android.support.v7.app.ActionBar)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 SubsamplingScaleImageView (com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView)2 Photo (us.koller.cameraroll.data.models.Photo)2 Intent (android.content.Intent)1 PointF (android.graphics.PointF)1 RequiresApi (android.support.annotation.RequiresApi)1 ViewPager (android.support.v4.view.ViewPager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewTreeObserver (android.view.ViewTreeObserver)1 WindowInsets (android.view.WindowInsets)1 ImageView (android.widget.ImageView)1 ItemAdapter (us.koller.cameraroll.adapter.item.ItemAdapter)1 ViewHolder (us.koller.cameraroll.adapter.item.viewHolder.ViewHolder)1 ParallaxTransformer (us.koller.cameraroll.util.ParallaxTransformer)1