public class PhotoViewFragment extends Fragment implements LoaderManager.LoaderCallbacks<PhotoBitmapLoaderInterface.BitmapResult>, View.OnClickListener, PhotoViewCallbacks.OnScreenListener, PhotoViewCallbacks.CursorChangedListener
Modifier and Type | Class and Description |
---|---|
static interface |
PhotoViewFragment.HorizontallyScrollable
Interface for components that are internally scrollable left-to-right.
|
Fragment.InstantiationException, Fragment.SavedState
Modifier and Type | Field and Description |
---|---|
protected static String |
ARG_INTENT |
protected static String |
ARG_POSITION |
protected static String |
ARG_SHOW_SPINNER |
protected PhotoPagerAdapter |
mAdapter |
protected PhotoViewCallbacks |
mCallback |
protected boolean |
mConnected
Whether or not there is currently a connection to the internet
|
protected String |
mContentDescription |
protected boolean |
mDisplayThumbsFullScreen
Whether or not we can display the thumbnail at fullscreen size
|
protected TextView |
mEmptyText |
protected boolean |
mFullScreen
Whether or not the fragment should make the photo full-screen
|
protected Intent |
mIntent
The intent we were launched with
|
protected BroadcastReceiver |
mInternetStateReceiver |
protected boolean |
mOnlyShowSpinner
Whether or not this fragment will only show the loading spinner
|
protected View |
mPhotoPreviewAndProgress |
protected ImageView |
mPhotoPreviewImage |
protected ProgressBarWrapper |
mPhotoProgressBar |
protected PhotoView |
mPhotoView |
protected int |
mPosition |
protected boolean |
mProgressBarNeeded
Whether or not the progress bar is showing valid information about the progress stated
|
protected String |
mResolvedPhotoUri
The URL of a photo to display
|
protected ImageView |
mRetryButton |
protected boolean |
mThumbnailShown |
protected String |
mThumbnailUri |
protected boolean |
mWatchNetworkState
True if the PhotoViewFragment should watch the network state in order to restart loaders.
|
protected static String |
STATE_INTENT_KEY |
Constructor and Description |
---|
PhotoViewFragment()
Public no-arg constructor for allowing the framework to handle orientation changes
|
Modifier and Type | Method and Description |
---|---|
void |
enableImageTransforms(boolean enable)
Enable or disable image transformations.
|
protected PhotoViewCallbacks |
getCallbacks() |
Drawable |
getDrawable() |
TextView |
getEmptyText() |
ProgressBarWrapper |
getPhotoProgressBar() |
String |
getPhotoUri() |
int |
getPosition() |
ImageView |
getRetryButton() |
static void |
initializeArguments(Intent intent,
int position,
boolean onlyShowSpinner,
PhotoViewFragment f) |
protected void |
initializeView(View view) |
boolean |
isPhotoBound()
Returns
true if a photo has been bound. |
boolean |
isProgressBarNeeded() |
static PhotoViewFragment |
newInstance(Intent intent,
int position,
boolean onlyShowSpinner)
Create a
PhotoViewFragment . |
void |
onActivityCreated(Bundle savedInstanceState)
Called when the fragment's activity has been created and this
fragment's view hierarchy instantiated.
|
void |
onClick(View v)
Called when a view has been clicked.
|
void |
onCreate(Bundle savedInstanceState)
Called to do initial creation of a fragment.
|
Loader<PhotoBitmapLoaderInterface.BitmapResult> |
onCreateLoader(int id,
Bundle args)
Instantiate and return a new Loader for the given ID.
|
View |
onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view.
|
void |
onCursorChanged(Cursor cursor)
Called when the cursor that contains the photo list data
is updated.
|
void |
onDestroyView()
Called when the view previously created by
Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) has
been detached from the fragment. |
void |
onDetach()
Called when the fragment is no longer attached to its activity.
|
void |
onFullScreenChanged(boolean fullScreen)
The full screen state has changed.
|
boolean |
onInterceptMoveLeft(float origX,
float origY)
Called when a right-to-left touch move intercept is about to occur.
|
boolean |
onInterceptMoveRight(float origX,
float origY)
Called when a left-to-right touch move intercept is about to occur.
|
void |
onLoaderReset(Loader<PhotoBitmapLoaderInterface.BitmapResult> loader)
Called when a previously created loader is being reset, and thus
making its data unavailable.
|
void |
onLoadFinished(Loader<PhotoBitmapLoaderInterface.BitmapResult> loader,
PhotoBitmapLoaderInterface.BitmapResult result)
Called when a previously created loader has finished its load.
|
void |
onPause()
Called when the Fragment is no longer resumed.
|
void |
onResume()
Called when the fragment is visible to the user and actively running.
|
void |
onSaveInstanceState(Bundle outState)
Called to ask the fragment to save its current dynamic state, so it
can later be reconstructed in a new instance of its process is
restarted.
|
void |
onViewActivated()
A new view has been activated and the previous view de-activated.
|
void |
onViewUpNext()
This view is a candidate for being the next view.
|
void |
resetViews()
Reset the views to their default states
|
void |
setFullScreen(boolean fullScreen)
Sets full-screen mode for the views.
|
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isVisible, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onRequestPermissionsResult, onStart, onStop, onViewCreated, onViewStateRestored, registerForContextMenu, requestPermissions, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, toString, unregisterForContextMenu
protected static final String STATE_INTENT_KEY
protected static final String ARG_INTENT
protected static final String ARG_POSITION
protected static final String ARG_SHOW_SPINNER
protected String mResolvedPhotoUri
protected String mThumbnailUri
protected String mContentDescription
protected Intent mIntent
protected PhotoViewCallbacks mCallback
protected PhotoPagerAdapter mAdapter
protected BroadcastReceiver mInternetStateReceiver
protected PhotoView mPhotoView
protected ImageView mPhotoPreviewImage
protected TextView mEmptyText
protected ImageView mRetryButton
protected ProgressBarWrapper mPhotoProgressBar
protected int mPosition
protected boolean mFullScreen
protected boolean mWatchNetworkState
protected boolean mOnlyShowSpinner
protected boolean mProgressBarNeeded
protected View mPhotoPreviewAndProgress
protected boolean mThumbnailShown
protected boolean mConnected
protected boolean mDisplayThumbsFullScreen
public PhotoViewFragment()
public static PhotoViewFragment newInstance(Intent intent, int position, boolean onlyShowSpinner)
PhotoViewFragment
.intent
- position
- onlyShowSpinner
- public static void initializeArguments(Intent intent, int position, boolean onlyShowSpinner, PhotoViewFragment f)
public void onActivityCreated(Bundle savedInstanceState)
Fragment
Fragment.setRetainInstance(boolean)
to retain their instance,
as this callback tells the fragment when it is fully associated with
the new activity instance. This is called after Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
and before Fragment.onViewStateRestored(Bundle)
.onActivityCreated
in class Fragment
savedInstanceState
- If the fragment is being re-created from
a previous saved state, this is the state.protected PhotoViewCallbacks getCallbacks()
public void onDetach()
Fragment
Fragment.onDestroy()
.public void onCreate(Bundle savedInstanceState)
Fragment
Fragment.onAttach(Activity)
and before
Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
.
Note that this can be called while the fragment's activity is
still in the process of being created. As such, you can not rely
on things like the activity's content view hierarchy being initialized
at this point. If you want to do work once the activity itself is
created, see Fragment.onActivityCreated(Bundle)
.
Any restored child fragments will be created before the base
Fragment.onCreate
method returns.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Fragment
Fragment.onCreate(Bundle)
and Fragment.onActivityCreated(Bundle)
.
If you return a View from here, you will later be called in
Fragment.onDestroyView()
when the view is being released.
onCreateView
in class Fragment
inflater
- The LayoutInflater object that can be used to inflate
any views in the fragment,container
- If non-null, this is the parent view that the fragment's
UI should be attached to. The fragment should not add the view itself,
but this can be used to generate the LayoutParams of the view.savedInstanceState
- If non-null, this fragment is being re-constructed
from a previous saved state as given here.protected void initializeView(View view)
public void onResume()
Fragment
Activity.onResume
of the containing
Activity's lifecycle.public void onPause()
Fragment
Activity.onPause
of the containing
Activity's lifecycle.public void onDestroyView()
Fragment
Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
has
been detached from the fragment. The next time the fragment needs
to be displayed, a new view will be created. This is called
after Fragment.onStop()
and before Fragment.onDestroy()
. It is called
regardless of whether Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
returned a
non-null view. Internally it is called after the view's state has
been saved but before it has been removed from its parent.onDestroyView
in class Fragment
public String getPhotoUri()
public void onSaveInstanceState(Bundle outState)
Fragment
Fragment.onCreate(Bundle)
,
Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
, and
Fragment.onActivityCreated(Bundle)
.
This corresponds to Activity.onSaveInstanceState(Bundle)
and most of the discussion there
applies here as well. Note however: this method may be called
at any time before Fragment.onDestroy()
. There are many situations
where a fragment may be mostly torn down (such as when placed on the
back stack with no UI showing), but its state will not be saved until
its owning activity actually needs to save its state.
onSaveInstanceState
in class Fragment
outState
- Bundle in which to place your saved state.public Loader<PhotoBitmapLoaderInterface.BitmapResult> onCreateLoader(int id, Bundle args)
LoaderManager.LoaderCallbacks
onCreateLoader
in interface LoaderManager.LoaderCallbacks<PhotoBitmapLoaderInterface.BitmapResult>
id
- The ID whose loader is to be created.args
- Any arguments supplied by the caller.public void onLoadFinished(Loader<PhotoBitmapLoaderInterface.BitmapResult> loader, PhotoBitmapLoaderInterface.BitmapResult result)
LoaderManager.LoaderCallbacks
FragmentManager.openTransaction()
for further discussion on this.
This function is guaranteed to be called prior to the release of the last data that was supplied for this Loader. At this point you should remove all use of the old data (since it will be released soon), but should not do your own release of the data since its Loader owns it and will take care of that. The Loader will take care of management of its data so you don't have to. In particular:
The Loader will monitor for changes to the data, and report
them to you through new calls here. You should not monitor the
data yourself. For example, if the data is a Cursor
and you place it in a CursorAdapter
, use
the CursorAdapter.CursorAdapter(android.content.Context,
android.database.Cursor, int)
constructor without passing
in either CursorAdapter.FLAG_AUTO_REQUERY
or CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER
(that is, use 0 for the flags argument). This prevents the CursorAdapter
from doing its own observing of the Cursor, which is not needed since
when a change happens you will get a new Cursor throw another call
here.
Cursor
from a CursorLoader
,
you should not call close() on it yourself. If the Cursor is being placed in a
CursorAdapter
, you should use the
CursorAdapter.swapCursor(android.database.Cursor)
method so that the old Cursor is not closed.
onLoadFinished
in interface LoaderManager.LoaderCallbacks<PhotoBitmapLoaderInterface.BitmapResult>
loader
- The Loader that has finished.result
- The data generated by the Loader.public Drawable getDrawable()
public void enableImageTransforms(boolean enable)
public void onLoaderReset(Loader<PhotoBitmapLoaderInterface.BitmapResult> loader)
LoaderManager.LoaderCallbacks
onLoaderReset
in interface LoaderManager.LoaderCallbacks<PhotoBitmapLoaderInterface.BitmapResult>
loader
- The Loader that is being reset.public void onClick(View v)
View.OnClickListener
onClick
in interface View.OnClickListener
v
- The view that was clicked.public void onFullScreenChanged(boolean fullScreen)
PhotoViewCallbacks.OnScreenListener
onFullScreenChanged
in interface PhotoViewCallbacks.OnScreenListener
public void onViewUpNext()
PhotoViewCallbacks.OnScreenListener
onViewUpNext
in interface PhotoViewCallbacks.OnScreenListener
public void onViewActivated()
PhotoViewCallbacks.OnScreenListener
onViewActivated
in interface PhotoViewCallbacks.OnScreenListener
public void resetViews()
public boolean onInterceptMoveLeft(float origX, float origY)
PhotoViewCallbacks.OnScreenListener
onInterceptMoveLeft
in interface PhotoViewCallbacks.OnScreenListener
origX
- the raw x coordinate of the initial touchorigY
- the raw y coordinate of the initial touchtrue
if the touch should be intercepted.public boolean onInterceptMoveRight(float origX, float origY)
PhotoViewCallbacks.OnScreenListener
onInterceptMoveRight
in interface PhotoViewCallbacks.OnScreenListener
origX
- the raw x coordinate of the initial touchorigY
- the raw y coordinate of the initial touchtrue
if the touch should be intercepted.public boolean isPhotoBound()
true
if a photo has been bound. Otherwise, returns false
.public void setFullScreen(boolean fullScreen)
public void onCursorChanged(Cursor cursor)
PhotoViewCallbacks.CursorChangedListener
onCursorChanged
in interface PhotoViewCallbacks.CursorChangedListener
cursor
- the cursor containing the photo list datapublic int getPosition()
public ProgressBarWrapper getPhotoProgressBar()
public TextView getEmptyText()
public ImageView getRetryButton()
public boolean isProgressBarNeeded()