From 4196dfb215557368ed8f98df2de9b55c70818353 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 23 Feb 2016 21:50:47 +0100 Subject: [PATCH] toggle fullscreen mode at viewpager on click --- .../com/ViewPagerFragment.java | 10 ++++- .../com/activities/ViewPagerActivity.java | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java b/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java index 0d04e3c57..dac9877c7 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java +++ b/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java @@ -9,7 +9,9 @@ import android.view.ViewGroup; import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; -public class ViewPagerFragment extends Fragment { +import gallery.simplemobiletools.com.activities.ViewPagerActivity; + +public class ViewPagerFragment extends Fragment implements View.OnClickListener { private String path; public void setPath(String path) { @@ -24,8 +26,14 @@ public class ViewPagerFragment extends Fragment { final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo); imageView.setImage(ImageSource.uri(path)); imageView.setMaxScale(5f); + imageView.setOnClickListener(this); } return view; } + + @Override + public void onClick(View v) { + ((ViewPagerActivity) getActivity()).photoClicked(); + } } diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java index c38a9df44..f2dcd0b08 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java @@ -5,6 +5,7 @@ import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; +import android.view.View; import java.io.File; import java.util.ArrayList; @@ -18,6 +19,7 @@ import gallery.simplemobiletools.com.adapters.MyPagerAdapter; public class ViewPagerActivity extends AppCompatActivity { private int pos; + private boolean isFullScreen; @Override protected void onCreate(Bundle savedInstanceState) { @@ -25,11 +27,23 @@ public class ViewPagerActivity extends AppCompatActivity { setContentView(R.layout.activity_photo); pos = 0; + isFullScreen = true; + hideSystemUI(); + final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager); final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager()); adapter.setPaths(getPhotos()); pager.setAdapter(adapter); pager.setCurrentItem(pos); + + getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { + @Override + public void onSystemUiVisibilityChange(int visibility) { + if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { + isFullScreen = false; + } + } + }); } private List getPhotos() { @@ -62,4 +76,28 @@ public class ViewPagerActivity extends AppCompatActivity { } return photos; } + + public void photoClicked() { + isFullScreen = !isFullScreen; + if (isFullScreen) { + hideSystemUI(); + } else { + showSystemUI(); + } + } + + private void hideSystemUI() { + 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_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_FULLSCREEN | + View.SYSTEM_UI_FLAG_IMMERSIVE); + } + + private void showSystemUI() { + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } }