Skip to content

Commit

Permalink
Fixed fullscreen bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
aerovulpe committed Jun 11, 2015
1 parent 69f1d70 commit 773532d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 32 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/java/me/aerovulpe/crawler/PhotoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void createPhotoListInstance(int accountType, String albumTitle, String albumID,

PhotoViewerFragment createPhotoViewerInstance(String albumTitle, boolean isSlideShow);

void setFullScreen(boolean fullScreen, boolean restoreActionBar);
void setFullScreen(boolean fullScreen);

void toggleFullScreen();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public PhotoViewerFragment createPhotoViewerInstance(String albumTitle, boolean
}

@Override
public void setFullScreen(boolean fullScreen, boolean restoreActionBar) {
public void setFullScreen(boolean fullScreen) {
ActionBar actionBar = getSupportActionBar();
if (fullScreen) {
if (Build.VERSION.SDK_INT < 16) { //ye olde method
Expand Down Expand Up @@ -291,7 +291,7 @@ public void setFullScreen(boolean fullScreen, boolean restoreActionBar) {
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so !hide that too if necessary.
if (restoreActionBar && actionBar != null)
if (actionBar != null)
actionBar.show();
}
}
Expand All @@ -300,7 +300,7 @@ public void setFullScreen(boolean fullScreen, boolean restoreActionBar) {

@Override
public void toggleFullScreen() {
setFullScreen(!mIsFullScreen, true);
setFullScreen(!mIsFullScreen);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void onLoadingCancelled(String imageUri, View view) {
}
}

public void bufferLoad(final int position) {
public void bufferLoad(int position) {
final String[] photoUrls = new String[LOAD_BUFFER_SIZE];
Cursor cursor = getCursor();
cursor.moveToPosition(position);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.aerovulpe.crawler.fragments;

import android.app.Activity;
import android.app.Fragment;
import android.app.LoaderManager;
import android.content.CursorLoader;
Expand Down Expand Up @@ -76,6 +77,13 @@ public void onCreate(Bundle savedInstanceState) {
setRetainInstance(true);
}

@Override
public void onAttach(Activity activity) {
if (!(activity instanceof PhotoManager))
throw new IllegalArgumentException("Must be attached to a PhotoManager instance.");
super.onAttach(activity);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ public void onCreate(Bundle savedInstanceState) {
setRetainInstance(true);
}

@Override
public void onAttach(Activity activity) {
if (!(activity instanceof PhotoManager))
throw new IllegalArgumentException("Must be attached to a PhotoManager instance.");
super.onAttach(activity);
// If is loading, show progress dialog.
if (mIsRequesting || mIsLoading) {
makeProgressDialog();
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down Expand Up @@ -221,15 +232,6 @@ public void onDestroy() {
getActivity().sendBroadcast(new Intent(Request.buildShowAction(mAlbumID)));
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// If is loading, show progress dialog.
if (mIsRequesting || mIsLoading) {
makeProgressDialog();
}
}

@Override
public void onDetach() {
super.onDetach();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public void onCreate(Bundle savedInstanceState) {
setRetainInstance(true);
}

@Override
public void onAttach(Activity activity) {
if (!(activity instanceof PhotoManager))
throw new IllegalArgumentException("Must be attached to a PhotoManager instance.");
super.onAttach(activity);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand All @@ -101,17 +108,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return rootView;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}

@Override
public void onResume() {
super.onResume();
mViewPager.setCurrentItem(mCurrentPhotoIndex);

mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

Expand All @@ -130,7 +131,7 @@ public void onPageScrollStateChanged(int state) {
});

Activity activity = getActivity();
((PhotoManager) activity).setFullScreen(mIsFullscreen, true);
((PhotoManager) activity).setFullScreen(mIsFullscreen);
mViewPager.setPageTransformer(true, SettingsFragment.getPageTransformer(activity));
mAnimSlideshowDelay = SettingsFragment.getSlideshowIntervalMS(activity);
mDescInterval = SettingsFragment.getDescIntervalMS(activity);
Expand All @@ -150,8 +151,8 @@ public void onPause() {
slideShowTimer.cancel();
slideShowTimer = null;
}
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mIsFullscreen = ((PhotoManager) getActivity()).isFullScreen();
Activity activity = getActivity();
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
final RecyclerView photoList;
if (mPhotoListRef != null && (photoList = mPhotoListRef.get()) != null) {
GridLayoutManager layoutManager = (GridLayoutManager) photoList.getLayoutManager();
Expand All @@ -166,21 +167,21 @@ public void run() {
}
});
}
activity.getSharedPreferences(CrawlerApplication.APP_NAME_PATH, Context.MODE_PRIVATE).edit()
.putBoolean(CrawlerApplication.PHOTO_DETAIL_KEY, mShowText)
.putBoolean(CrawlerApplication.PHOTO_FULLSCREEN_KEY, mIsFullscreen).apply();
}

@Override
public void onStop() {
super.onStop();
Activity activity = getActivity();
activity.getSharedPreferences(CrawlerApplication.APP_NAME_PATH, Context.MODE_PRIVATE).edit()
.putBoolean(CrawlerApplication.PHOTO_DETAIL_KEY, mShowText)
.putBoolean(CrawlerApplication.PHOTO_FULLSCREEN_KEY, mIsFullscreen).apply();
mViewPager.clearOnPageChangeListeners();
}

@Override
public void onDestroy() {
super.onDestroy();
((PhotoManager) getActivity()).setFullScreen(false, true);
((PhotoManager) getActivity()).setFullScreen(false);
}

@Override
Expand Down Expand Up @@ -332,7 +333,7 @@ public void setUpSlideShowTask() {
if (activity == null)
return;

((PhotoManager) activity).setFullScreen(isSlideShowRunning, true);
((PhotoManager) activity).setFullScreen(isSlideShowRunning || mIsFullscreen);
if (isSlideShowRunning) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//schedule this to
Expand Down Expand Up @@ -447,8 +448,11 @@ public void setAsWallpaper(Photo photo) {
@Override
public void onClick(View v) {
PhotoManager photoManager = (PhotoManager) getActivity();
if (photoManager != null && !isSlideShowRunning) photoManager.toggleFullScreen();
else toggleSlideShow();
if (photoManager != null && !isSlideShowRunning) {
photoManager.toggleFullScreen();
mIsFullscreen = !mIsFullscreen;
} else
toggleSlideShow();
}

@Override
Expand Down

0 comments on commit 773532d

Please sign in to comment.