toggle fullscreen mode at viewpager on click

This commit is contained in:
tibbi 2016-02-23 21:50:47 +01:00
parent 46a8f67c02
commit 4196dfb215
2 changed files with 47 additions and 1 deletions

View file

@ -9,7 +9,9 @@ import android.view.ViewGroup;
import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; 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; private String path;
public void setPath(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); final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo);
imageView.setImage(ImageSource.uri(path)); imageView.setImage(ImageSource.uri(path));
imageView.setMaxScale(5f); imageView.setMaxScale(5f);
imageView.setOnClickListener(this);
} }
return view; return view;
} }
@Override
public void onClick(View v) {
((ViewPagerActivity) getActivity()).photoClicked();
}
} }

View file

@ -5,6 +5,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,6 +19,7 @@ import gallery.simplemobiletools.com.adapters.MyPagerAdapter;
public class ViewPagerActivity extends AppCompatActivity { public class ViewPagerActivity extends AppCompatActivity {
private int pos; private int pos;
private boolean isFullScreen;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -25,11 +27,23 @@ public class ViewPagerActivity extends AppCompatActivity {
setContentView(R.layout.activity_photo); setContentView(R.layout.activity_photo);
pos = 0; pos = 0;
isFullScreen = true;
hideSystemUI();
final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager); final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager);
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager()); final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
adapter.setPaths(getPhotos()); adapter.setPaths(getPhotos());
pager.setAdapter(adapter); pager.setAdapter(adapter);
pager.setCurrentItem(pos); 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<String> getPhotos() { private List<String> getPhotos() {
@ -62,4 +76,28 @@ public class ViewPagerActivity extends AppCompatActivity {
} }
return photos; 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);
}
} }