Added ability to see images with fullscreen mode
This commit is contained in:
parent
c53619bde4
commit
aa001e7c37
Binary file not shown.
@ -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'
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="ru.volgorobot.vrcatalog">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
@ -23,6 +24,9 @@
|
||||
</activity>
|
||||
<activity android:name=".view.SettingsActivity" />
|
||||
<activity android:name=".view.AboutActivity" />
|
||||
<activity
|
||||
android:name=".view.FullScreenImageActivity"
|
||||
android:theme="@style/AppTheme.Fullscreen"/>
|
||||
<activity
|
||||
android:name=".view.DetailActivity"
|
||||
android:theme="@style/ItemActivityTheme"/>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
27
app/src/main/res/layout/activity_fullscreenimage.xml
Normal file
27
app/src/main/res/layout/activity_fullscreenimage.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="ru.volgorobot.vrcatalog.view.FullScreenImageActivity"
|
||||
android:background="@android:color/black">
|
||||
|
||||
<com.github.chrisbanes.photoview.PhotoView
|
||||
android:id="@+id/photo_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="#33000000"
|
||||
android:fitsSystemWindows="true"
|
||||
android:theme="@style/TransparentActionBar"
|
||||
android:popupTheme="@style/AppTheme.AppBarOverlay" />
|
||||
|
||||
</RelativeLayout>
|
@ -5,12 +5,19 @@
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
<style name="AppTheme.Fullscreen">
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
<item name="android:windowTranslucentNavigation">true</item>
|
||||
</style>
|
||||
<style name="ItemActivityTheme" parent="AppTheme">
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
|
||||
<style name="TransparentActionBar" parent="Widget.AppCompat.ActionBar.Solid">
|
||||
<item name="android:background">@android:color/transparent</item>
|
||||
<item name="background">@android:color/transparent</item>
|
||||
</style>
|
||||
|
@ -20,5 +20,10 @@
|
||||
<style name="ItemActivityTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
</style>
|
||||
<style name="AppTheme.Fullscreen">
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@ -21,6 +21,7 @@ allprojects {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user