From aa001e7c37edd928b613235c6d4ac0586baaac7a Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Tue, 19 Feb 2019 19:30:26 +0400 Subject: [PATCH 1/2] Added ability to see images with fullscreen mode --- .idea/caches/gradle_models.ser | Bin 108690 -> 111999 bytes app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 6 +- .../additional/ImagePagerAdapter.java | 11 ++ .../vrcatalog/view/DetailActivity.java | 35 +---- .../view/FullScreenImageActivity.java | 123 ++++++++++++++++++ .../res/layout/activity_fullscreenimage.xml | 27 ++++ app/src/main/res/values-v21/styles.xml | 9 +- app/src/main/res/values/styles.xml | 5 + build.gradle | 1 + 10 files changed, 182 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java create mode 100644 app/src/main/res/layout/activity_fullscreenimage.xml diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 6c9fd28ec6b54f09c652af1fdaa7284ff856e5e0..7b679832e0362ff6aca3af764c692ec06f3af29a 100644 GIT binary patch delta 7097 zcmc&(dstM}7N0dU=Kv}S3SQGn(Ca%M!(*6H909{usbG+ot5O4uf-eRcUlk%MDZY}9 zvNba?^E0&)Bt2T0qTYOEf%eiaDca4hW{IX3>neBeeVo1K^Yi=ecc(utf2=+Gw|;x= z-`;EQb!HB)*2^tdIY{AvT9N!PJIr8=`;&5<6?-&@@wN5bC+?-s}MhY&Rp^H`Od-tlToc)YXas2GGCZ|i+Cp&*y z_@q2n?#!(4?A#f7g<1CLj>7&ax%saAXY(Ah`$vVF!ebKb_8Cq(kN!*{v(0CFlm)wV zeu6~<1wS+pWgDKP+IW;-&!=`~<8^^99XXr^=HVhh7$=0&X(AliCUZ`#Im_yZv|8;k zj_9mdYfg4fq$4Ia&YF`I8(}Xjbhrv<>va)x+|gDmwbSD!Jh+Mo5k7*4kI0_rh>DGl zHpRq6TB9v-jvRArR^-Hq_NXj#Oq3}m%VN!rip@61;Xu@-B%B!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5T?gY5;fdJjA@oLurB!5kOo diff --git a/app/build.gradle b/app/build.gradle index da165a5..dffabc9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,4 +34,5 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.squareup.picasso:picasso:2.71828' + implementation 'com.github.chrisbanes:PhotoView:2.1.4' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c565685..ac11670 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ - @@ -23,6 +24,9 @@ + diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java index 8a37717..2f15b0d 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java @@ -1,6 +1,7 @@ package ru.volgorobot.vrcatalog.additional; import android.content.Context; +import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.provider.MediaStore; @@ -16,6 +17,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import ru.volgorobot.vrcatalog.R; +import ru.volgorobot.vrcatalog.view.DetailActivity; +import ru.volgorobot.vrcatalog.view.FullScreenImageActivity; public class ImagePagerAdapter extends PagerAdapter { /** @@ -60,6 +63,14 @@ public class ImagePagerAdapter extends PagerAdapter { .resize(0, 313) .centerCrop() .into(imageView); + imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context, FullScreenImageActivity.class); + intent.putExtra("path", imageUris[position]); + context.startActivity(intent); + } + }); container.addView(imageView); return imageView; diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java index 04673ba..8a007d0 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java @@ -139,7 +139,7 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It @Override public void setViewPagerContent(String[] uris) { imagePagerAdapter = new ImagePagerAdapter(DetailActivity.this, uris); - TabLayout tabLayout = (TabLayout) findViewById(R.id.tabDots); + TabLayout tabLayout = findViewById(R.id.tabDots); viewPager.setAdapter(imagePagerAdapter); setViewPagerScrollListener(); tabLayout.setupWithViewPager(viewPager); @@ -203,37 +203,4 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It }; viewPager.setOnPageChangeListener(listener); } - - public static boolean setListViewHeightBasedOnItems(ListView listView) { - - ListAdapter listAdapter = listView.getAdapter(); - if (listAdapter != null) { - - int numberOfItems = listAdapter.getCount(); - - // Get total height of all items. - int totalItemsHeight = 0; - for (int itemPos = 0; itemPos < numberOfItems; itemPos++) { - View item = listAdapter.getView(itemPos, null, listView); - item.measure(0, 0); - totalItemsHeight += item.getMeasuredHeight(); - } - - // Get total height of all item dividers. - int totalDividersHeight = listView.getDividerHeight() * - (numberOfItems - 1); - - // Set list height. - ViewGroup.LayoutParams params = listView.getLayoutParams(); - params.height = totalItemsHeight + totalDividersHeight; - listView.setLayoutParams(params); - listView.requestLayout(); - - return true; - - } else { - return false; - } - - } } diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java new file mode 100644 index 0000000..92eadc6 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java @@ -0,0 +1,123 @@ +package ru.volgorobot.vrcatalog.view; + +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; +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; + +public class FullScreenImageActivity extends AppCompatActivity implements View.OnSystemUiVisibilityChangeListener { + private Toolbar mToolbar; + private boolean mIsFullScreen; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_fullscreenimage); + + mToolbar = findViewById(R.id.toolbar); + + mToolbar.setTitle(""); + + if (mToolbar != null) { + setSupportActionBar(mToolbar); + } + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material); + upArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); + getSupportActionBar().setHomeAsUpIndicator(upArrow); + mToolbar.bringToFront(); + + mIsFullScreen = true; + + Window window = getWindow(); + WindowManager.LayoutParams winParams = window.getAttributes(); + winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; + window.setAttributes(winParams); + + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE + |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); + } + + + + @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()) { + case android.R.id.home: + finish(); + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/res/layout/activity_fullscreenimage.xml b/app/src/main/res/layout/activity_fullscreenimage.xml new file mode 100644 index 0000000..5e2a573 --- /dev/null +++ b/app/src/main/res/layout/activity_fullscreenimage.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 5aff55f..40a0aa5 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -5,12 +5,19 @@ true @android:color/transparent + - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f49f94b..78f61cf 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -20,5 +20,10 @@ + diff --git a/build.gradle b/build.gradle index ab22a0a..e09656f 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ allprojects { google() jcenter() mavenCentral() + maven { url "https://jitpack.io" } } } From b92a9d0c58a8f0433fe000a73da72e4571fa55ad Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Tue, 19 Feb 2019 20:08:00 +0400 Subject: [PATCH 2/2] Added ability to leaf images in fullscreen mode --- .../FullscreenImagePagerAdapter.java | 98 +++++++++++++++++++ .../additional/ImagePagerAdapter.java | 2 +- .../view/FullScreenImageActivity.java | 65 ++---------- .../res/layout/activity_fullscreenimage.xml | 4 +- 4 files changed, 108 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/additional/FullscreenImagePagerAdapter.java diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/FullscreenImagePagerAdapter.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/FullscreenImagePagerAdapter.java new file mode 100644 index 0000000..b237edf --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/FullscreenImagePagerAdapter.java @@ -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(); + } + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java index 2f15b0d..befb9fb 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/ImagePagerAdapter.java @@ -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); } }); diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java index 92eadc6..ff9cacd 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/FullScreenImageActivity.java @@ -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); } } diff --git a/app/src/main/res/layout/activity_fullscreenimage.xml b/app/src/main/res/layout/activity_fullscreenimage.xml index 5e2a573..f09d840 100644 --- a/app/src/main/res/layout/activity_fullscreenimage.xml +++ b/app/src/main/res/layout/activity_fullscreenimage.xml @@ -9,8 +9,8 @@ tools:context="ru.volgorobot.vrcatalog.view.FullScreenImageActivity" android:background="@android:color/black"> -