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;
}
});
}
}
}
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);
}
}
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);
}
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);
}
Aggregations