public class PhotoViewController extends Object implements LoaderManager.LoaderCallbacks<Cursor>, ViewPager.OnPageChangeListener, PhotoViewPager.OnInterceptTouchListener, ActionBarInterface.OnMenuVisibilityListener, PhotoViewCallbacks
PhotoViewActivity
and override just
createController
to instantiate your controller
subclass.Modifier and Type | Class and Description |
---|---|
static interface |
PhotoViewController.ActivityInterface
Defines the interface between the Activity and this class.
|
PhotoViewCallbacks.CursorChangedListener, PhotoViewCallbacks.OnScreenListener
Modifier and Type | Field and Description |
---|---|
static int |
ALBUM_COUNT_UNKNOWN
Count used when the real photo count is unknown [but, may be determined]
|
protected static String |
ARG_IMAGE_URI |
static int |
ENTER_ANIMATION_DURATION_MS |
static int |
EXIT_ANIMATION_DURATION_MS |
static String |
KEY_MESSAGE
Argument key for the dialog message
|
static int |
LOADER_PHOTO_LIST |
protected boolean |
mActionBarHiddenInitially |
protected String |
mActionBarSubtitle
The subtitle in the actionbar
|
protected String |
mActionBarTitle
The title in the actionbar
|
protected PhotoPagerAdapter |
mAdapter
Adapter to create pager views
|
protected int |
mAlbumCount
The total number of photos; only valid if
mIsEmpty is false . |
protected int |
mAnimationStartHeight |
protected int |
mAnimationStartWidth |
protected int |
mAnimationStartX |
protected int |
mAnimationStartY |
protected View |
mBackground
Background image that contains nothing, so it can be alpha faded from
transparent to black without affecting any other views.
|
protected com.android.ex.photo.PhotoViewController.BitmapCallback |
mBitmapCallback |
protected boolean |
mDisplayThumbsFullScreen |
protected boolean |
mFullScreen
Whether or not we're in "full screen" mode
|
protected Handler |
mHandler |
protected boolean |
mIsEmpty
true if the view is empty. |
protected boolean |
mIsPaused
Whether or not this activity is paused
|
protected boolean |
mIsTimerLightsOutEnabled
Whether lights out should invoked based on timer
|
protected float |
mMaxInitialScale
The maximum scale factor applied to images when they are initially displayed
|
protected View |
mRootView
the main root view
|
protected boolean |
mScaleAnimationEnabled |
protected ImageView |
mTemporaryImage
The temporary image so that we can quickly scale up the fullscreen thumbnail
|
protected PhotoViewPager |
mViewPager
The main pager; provides left/right swipe between photos
|
static int |
sMaxPhotoSize |
static int |
sMemoryClass |
BITMAP_LOADER_AVATAR, BITMAP_LOADER_PHOTO, BITMAP_LOADER_THUMBNAIL
Constructor and Description |
---|
PhotoViewController(PhotoViewController.ActivityInterface activity) |
Modifier and Type | Method and Description |
---|---|
void |
addCursorListener(PhotoViewCallbacks.CursorChangedListener listener) |
void |
addScreenListener(int position,
PhotoViewCallbacks.OnScreenListener listener) |
PhotoPagerAdapter |
createPhotoPagerAdapter(Context context,
FragmentManager fm,
Cursor c,
float maxScale) |
protected View |
findViewById(int id) |
PhotoViewController.ActivityInterface |
getActivity() |
PhotoPagerAdapter |
getAdapter()
Returns the adapter associated with this activity.
|
protected View |
getBackground()
Returns the android view for the viewer's background view, if it has one.
|
protected int |
getContentViewId()
Returns the android layout id of the root layout that should be inflated for the viewer.
|
Cursor |
getCursor() |
Cursor |
getCursorAtProperPosition()
Utility method that will return the cursor that contains the data
at the current position so that it refers to the current image on screen.
|
protected String |
getPhotoAccessibilityAnnouncement(int position)
Returns a string used as an announcement for accessibility after the user moves to a new
photo.
|
View |
getRootView() |
protected int |
getRootViewId()
Returns the android id of the viewer's root view.
|
View.OnSystemUiVisibilityChangeListener |
getSystemUiVisibilityChangeListener()
Note: This should only be called when API level is 11 or above.
|
protected ImageView |
getTemporaryImage()
Returns the android view for the viewer's temporary image, if it has one.
|
protected boolean |
hasBackground()
Returns whether or not the view has a background object.
|
protected boolean |
hasTemporaryImage()
Returns whether or not the view has a temporary image view.
|
void |
hideActionBar() |
boolean |
isEnterAnimationFinished() |
boolean |
isFragmentActive(Fragment fragment) |
boolean |
isFragmentFullScreen(Fragment fragment) |
protected boolean |
isFullScreen() |
boolean |
isScaleAnimationEnabled() |
void |
onActivityResult(int requestCode,
int resultCode,
Intent data) |
boolean |
onBackPressed() |
void |
onCreate(Bundle savedInstanceState) |
Loader<PhotoBitmapLoaderInterface.BitmapResult> |
onCreateBitmapLoader(int id,
Bundle args,
String uri) |
Loader<Cursor> |
onCreateLoader(int id,
Bundle args)
Instantiate and return a new Loader for the given ID.
|
boolean |
onCreateOptionsMenu(Menu menu) |
void |
onCursorChanged(PhotoViewFragment fragment,
Cursor cursor) |
void |
onDestroy() |
void |
onEnterAnimationComplete() |
void |
onFragmentPhotoLoadComplete(PhotoViewFragment fragment,
boolean success) |
void |
onFragmentVisible(PhotoViewFragment fragment) |
void |
onLoaderReset(Loader<Cursor> loader)
Called when a previously created loader is being reset, and thus
making its data unavailable.
|
void |
onLoadFinished(Loader<Cursor> loader,
Cursor data)
Called when a previously created loader has finished its load.
|
void |
onMenuVisibilityChanged(boolean isVisible)
Called when an action bar menu is shown or hidden.
|
void |
onNewPhotoLoaded(int position) |
boolean |
onOptionsItemSelected(MenuItem item) |
void |
onPageScrolled(int position,
float positionOffset,
int positionOffsetPixels)
This method will be invoked when the current page is scrolled, either as part
of a programmatically initiated smooth scroll or a user initiated touch scroll.
|
void |
onPageScrollStateChanged(int state)
Called when the scroll state changes.
|
void |
onPageSelected(int position)
This method will be invoked when a new page becomes selected.
|
void |
onPause() |
void |
onPhotoRemoved(long photoId) |
boolean |
onPrepareOptionsMenu(Menu menu) |
void |
onResume() |
void |
onSaveInstanceState(Bundle outState) |
void |
onStart() |
void |
onStop() |
PhotoViewPager.InterceptType |
onTouchIntercept(float origX,
float origY)
Called when a touch intercept is about to occur.
|
void |
removeCursorListener(PhotoViewCallbacks.CursorChangedListener listener) |
void |
removeScreenListener(int position) |
protected void |
setActionBarTitles(ActionBarInterface actionBar)
Sets the Action Bar title to
mActionBarTitle and the subtitle to
mActionBarSubtitle |
protected void |
setFullScreen(boolean fullScreen,
boolean setDelayedRunnable)
Updates the title bar according to the value of
mFullScreen . |
void |
setImmersiveMode(boolean enabled) |
protected void |
setLightsOutMode(boolean enabled) |
protected void |
setPhotoIndex(int index) |
void |
setViewActivated(int position) |
void |
showActionBar() |
void |
toggleFullScreen() |
void |
updateActionBar()
Adjusts the activity title and subtitle to reflect the photo name and count.
|
void |
updateActionItems() |
protected static final String ARG_IMAGE_URI
public static final int LOADER_PHOTO_LIST
public static final int ALBUM_COUNT_UNKNOWN
public static final int ENTER_ANIMATION_DURATION_MS
public static final int EXIT_ANIMATION_DURATION_MS
public static final String KEY_MESSAGE
public static int sMemoryClass
public static int sMaxPhotoSize
protected int mAlbumCount
mIsEmpty
is false
.protected boolean mIsEmpty
true
if the view is empty. Otherwise, false
.protected View mRootView
@Nullable protected View mBackground
protected PhotoViewPager mViewPager
@Nullable protected ImageView mTemporaryImage
protected PhotoPagerAdapter mAdapter
protected boolean mFullScreen
protected boolean mIsPaused
protected float mMaxInitialScale
protected String mActionBarTitle
protected String mActionBarSubtitle
protected boolean mScaleAnimationEnabled
protected int mAnimationStartX
protected int mAnimationStartY
protected int mAnimationStartWidth
protected int mAnimationStartHeight
protected boolean mIsTimerLightsOutEnabled
protected boolean mActionBarHiddenInitially
protected boolean mDisplayThumbsFullScreen
protected com.android.ex.photo.PhotoViewController.BitmapCallback mBitmapCallback
protected final Handler mHandler
public PhotoViewController(PhotoViewController.ActivityInterface activity)
public PhotoPagerAdapter createPhotoPagerAdapter(Context context, FragmentManager fm, Cursor c, float maxScale)
public PhotoViewController.ActivityInterface getActivity()
public void onCreate(Bundle savedInstanceState)
public boolean onCreateOptionsMenu(Menu menu)
public boolean onPrepareOptionsMenu(Menu menu)
public void onActivityResult(int requestCode, int resultCode, Intent data)
protected View findViewById(int id)
@IdRes protected int getRootViewId()
@IdRes protected int getContentViewId()
@Nullable protected View getBackground()
protected boolean hasBackground()
@Nullable protected ImageView getTemporaryImage()
protected boolean hasTemporaryImage()
public void onStart()
public void onResume()
public void onPause()
public void onStop()
public void onDestroy()
public boolean onBackPressed()
public void onSaveInstanceState(Bundle outState)
public boolean onOptionsItemSelected(MenuItem item)
public void addScreenListener(int position, PhotoViewCallbacks.OnScreenListener listener)
addScreenListener
in interface PhotoViewCallbacks
public void removeScreenListener(int position)
removeScreenListener
in interface PhotoViewCallbacks
public void addCursorListener(PhotoViewCallbacks.CursorChangedListener listener)
addCursorListener
in interface PhotoViewCallbacks
public void removeCursorListener(PhotoViewCallbacks.CursorChangedListener listener)
removeCursorListener
in interface PhotoViewCallbacks
public boolean isFragmentFullScreen(Fragment fragment)
isFragmentFullScreen
in interface PhotoViewCallbacks
public void toggleFullScreen()
toggleFullScreen
in interface PhotoViewCallbacks
public void onPhotoRemoved(long photoId)
public Loader<Cursor> onCreateLoader(int id, Bundle args)
LoaderManager.LoaderCallbacks
onCreateLoader
in interface LoaderManager.LoaderCallbacks<Cursor>
id
- The ID whose loader is to be created.args
- Any arguments supplied by the caller.public Loader<PhotoBitmapLoaderInterface.BitmapResult> onCreateBitmapLoader(int id, Bundle args, String uri)
onCreateBitmapLoader
in interface PhotoViewCallbacks
public void onLoadFinished(Loader<Cursor> loader, Cursor data)
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<Cursor>
loader
- The Loader that has finished.data
- The data generated by the Loader.public void onLoaderReset(Loader<Cursor> loader)
LoaderManager.LoaderCallbacks
onLoaderReset
in interface LoaderManager.LoaderCallbacks<Cursor>
loader
- The Loader that is being reset.public void updateActionItems()
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
ViewPager.OnPageChangeListener
onPageScrolled
in interface ViewPager.OnPageChangeListener
position
- Position index of the first page currently being displayed.
Page position+1 will be visible if positionOffset is nonzero.positionOffset
- Value from [0, 1) indicating the offset from the page at position.positionOffsetPixels
- Value in pixels indicating the offset from position.public void onPageSelected(int position)
ViewPager.OnPageChangeListener
onPageSelected
in interface ViewPager.OnPageChangeListener
position
- Position index of the new selected page.public void onPageScrollStateChanged(int state)
ViewPager.OnPageChangeListener
onPageScrollStateChanged
in interface ViewPager.OnPageChangeListener
state
- The new scroll state.ViewPager.SCROLL_STATE_IDLE
,
ViewPager.SCROLL_STATE_DRAGGING
,
ViewPager.SCROLL_STATE_SETTLING
public boolean isFragmentActive(Fragment fragment)
isFragmentActive
in interface PhotoViewCallbacks
public void onFragmentVisible(PhotoViewFragment fragment)
onFragmentVisible
in interface PhotoViewCallbacks
public PhotoViewPager.InterceptType onTouchIntercept(float origX, float origY)
PhotoViewPager.OnInterceptTouchListener
onTouchIntercept
in interface PhotoViewPager.OnInterceptTouchListener
origX
- the raw x coordinate of the initial touchorigY
- the raw y coordinate of the initial touchprotected void setFullScreen(boolean fullScreen, boolean setDelayedRunnable)
mFullScreen
.protected void setLightsOutMode(boolean enabled)
public void setViewActivated(int position)
setViewActivated
in interface PhotoViewCallbacks
public void updateActionBar()
protected String getPhotoAccessibilityAnnouncement(int position)
updateActionBar()
has been called.position
- the index in the album of the currently active photoprotected final void setActionBarTitles(ActionBarInterface actionBar)
mActionBarTitle
and the subtitle to
mActionBarSubtitle
public Cursor getCursorAtProperPosition()
PhotoViewPager
is null.public Cursor getCursor()
public void onMenuVisibilityChanged(boolean isVisible)
ActionBarInterface.OnMenuVisibilityListener
onMenuVisibilityChanged
in interface ActionBarInterface.OnMenuVisibilityListener
isVisible
- True if an action bar menu is now visible, false if no action bar
menus are visible.public void onNewPhotoLoaded(int position)
onNewPhotoLoaded
in interface PhotoViewCallbacks
protected void setPhotoIndex(int index)
public void onFragmentPhotoLoadComplete(PhotoViewFragment fragment, boolean success)
onFragmentPhotoLoadComplete
in interface PhotoViewCallbacks
protected boolean isFullScreen()
public void onCursorChanged(PhotoViewFragment fragment, Cursor cursor)
onCursorChanged
in interface PhotoViewCallbacks
public PhotoPagerAdapter getAdapter()
PhotoViewCallbacks
getAdapter
in interface PhotoViewCallbacks
public void onEnterAnimationComplete()
public void showActionBar()
public void hideActionBar()
public boolean isScaleAnimationEnabled()
public boolean isEnterAnimationFinished()
public View getRootView()
public void setImmersiveMode(boolean enabled)
public View.OnSystemUiVisibilityChangeListener getSystemUiVisibilityChangeListener()