Added ability to leaf images in fullscreen mode

This commit is contained in:
ChronosX88 2019-02-19 20:08:00 +04:00
parent aa001e7c37
commit b92a9d0c58
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
4 changed files with 108 additions and 61 deletions

View File

@ -0,0 +1,98 @@
package ru.volgorobot.vrcatalog.additional;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import com.github.chrisbanes.photoview.OnPhotoTapListener;
import com.github.chrisbanes.photoview.PhotoView;
import com.squareup.picasso.Picasso;
public class FullscreenImagePagerAdapter extends PagerAdapter {
/**
* This class is designed to control the ViewPager (images of item) in the activity of viewing details of items (DetailActivity).
*/
private Context context;
private String[] imageUris;
private Toolbar mToolbar;
private boolean mIsFullScreen;
public FullscreenImagePagerAdapter(Context context, String[] imageUris, Toolbar toolbar, boolean isFullScreen) {
this.context = context;
this.imageUris = imageUris;
this.mToolbar = toolbar;
this.mIsFullScreen = isFullScreen;
}
@Override
public int getCount() {
return imageUris.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
/**
* This function initializes a new image from a URI.
* @return ImageView
*/
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
PhotoView photoView = new PhotoView(context);
Picasso.get()
.load(imageUris[position])
.into(photoView);
photoView.setOnPhotoTapListener(new PhotoTapListener());
container.addView(photoView);
return photoView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
private class PhotoTapListener implements OnPhotoTapListener, View.OnSystemUiVisibilityChangeListener {
@Override
public void onPhotoTap(ImageView view, float x, float y) {
updateView();
}
public void updateView() {
mIsFullScreen = !mIsFullScreen;
if (mIsFullScreen) {
hideSystemUI();
} else {
showSystemUI();
}
}
private void hideSystemUI() {
mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2)).start();
}
private void showSystemUI() {
mToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
}
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
mIsFullScreen = false;
}
updateView();
}
}
}

View File

@ -67,7 +67,7 @@ public class ImagePagerAdapter extends PagerAdapter {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, FullScreenImageActivity.class);
intent.putExtra("path", imageUris[position]);
intent.putExtra("uris", imageUris);
context.startActivity(intent);
}
});

View File

@ -6,24 +6,20 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import com.github.chrisbanes.photoview.OnPhotoTapListener;
import com.github.chrisbanes.photoview.PhotoView;
import com.squareup.picasso.Picasso;
import ru.volgorobot.vrcatalog.R;
import ru.volgorobot.vrcatalog.additional.FullscreenImagePagerAdapter;
public class FullScreenImageActivity extends AppCompatActivity implements View.OnSystemUiVisibilityChangeListener {
public class FullScreenImageActivity extends AppCompatActivity {
private Toolbar mToolbar;
private ViewPager fullscreenViewPager;
private boolean mIsFullScreen;
@Override
@ -56,60 +52,14 @@ public class FullScreenImageActivity extends AppCompatActivity implements View.O
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
String path = getIntent().getStringExtra("path");
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setOnPhotoTapListener(new OnPhotoTapListener() {
@Override
public void onPhotoTap(ImageView view, float x, float y) {
updateView();
}
});
Picasso.get()
.load(path)
.into(photoView);
fullscreenViewPager = findViewById(R.id.fullscreen_mode_viewpager);
FullscreenImagePagerAdapter adapter = new FullscreenImagePagerAdapter(FullScreenImageActivity.this, getIntent().getExtras().getStringArray("uris"), mToolbar, mIsFullScreen);
fullscreenViewPager.setAdapter(adapter);
}
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
mIsFullScreen = false;
}
updateView();
}
public void updateView() {
mIsFullScreen = !mIsFullScreen;
if (mIsFullScreen) {
hideSystemUI();
} else {
showSystemUI();
}
}
private void hideSystemUI() {
mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2)).start();
}
private void showSystemUI() {
mToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
}
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -117,7 +67,6 @@ public class FullScreenImageActivity extends AppCompatActivity implements View.O
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -9,8 +9,8 @@
tools:context="ru.volgorobot.vrcatalog.view.FullScreenImageActivity"
android:background="@android:color/black">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
<android.support.v4.view.ViewPager
android:id="@+id/fullscreen_mode_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />