com.android.email/com.android.mail.photo.MailPhotoViewActivity
界面图:
FrameLayout(id/ photo_activity_root_view)
1、View(id/ photo_activity_background) 2、PhotoViewPager(id/ photo_view_pager) 3、AppCompatImageView(id/ photo_activity_temporary_iamge)
2、(PhotoViewPager下的)
1、RelativeLayout 2、RelativeLayout .....
(1) PhotoView(id/ photo_view) //主要照片 (2)FrameLayout(id/ photo_preview) //缩略图 (3)AppCompatTextView(id/ empty_text) (4)AppCompatImageView(id/ retry_button)
(2)(photo_preview下的)
1)AppCompatImageView(id/ photo_preview_image) 2)ProgressBar(id/ indeterminate_progress) 3)ProgressBar(id/ determinate_progress)
packages\apps\UnifiedEmail\src\com\android\mail\photo\MailPhotoViewActivity.java
07-27 14:31:00.948 5307 5307 D PhotoViewFragment: onCreateLoader BITMAP_LOADER_THUMBNAIL mThumbnailUri=null
07-27 14:31:00.952 5307 5307 D PhotoViewFragment: onCreateLoader BITMAP_LOADER_THUMBNAIL mResolvedPhotoUri=content://com.android.email.attachmentprovider/1/1/RAW
07-27 14:31:00.978 5307 5307 D PhotoViewFragment: onCreateLoader BITMAP_LOADER_THUMBNAIL mThumbnailUri=null
07-27 14:31:00.980 5307 5307 D PhotoViewFragment: onCreateLoader BITMAP_LOADER_THUMBNAIL mResolvedPhotoUri=content://com.android.email.attachmentprovider/1/2/RAW
07-27 14:31:00.989 5307 5307 D PhotoViewFragment: onCreateLoader BITMAP_LOADER_THUMBNAIL mThumbnailUri=null
07-27 14:31:01.116 5307 5307 D PhotoViewFragment: onLoadFinished
07-27 14:31:01.150 5307 5307 D PhotoViewFragment: onLoadFinished
07-27 14:31:01.534 5307 5307 D PhotoViewFragment: onLoadFinished
07-27 14:31:01.535 5307 5307 D PhotoViewFragment: onLoadFinished BITMAP_LOADER_PHOTO
07-27 14:31:01.655 5307 5307 D PhotoViewFragment: onLoadFinished
07-27 14:31:01.656 5307 5307 D PhotoViewFragment: onLoadFinished BITMAP_LOADER_PHOTO
frameworks\opt\photoviewer\src\com\android\ex\photo\fragments\PhotoViewFragment.java
public void onResume() {
if (!isPhotoBound()) {
mProgressBarNeeded = true;
mPhotoPreviewAndProgress.setVisibility(View.VISIBLE);
getLoaderManager().initLoader(PhotoViewCallbacks.BITMAP_LOADER_THUMBNAIL,
null, this);
// FLAG: If we are displaying thumbnails at fullscreen size, then we
// could defer the loading of the fullscreen image until the thumbnail
// has finished loading, or even until the user attempts to zoom in.
getLoaderManager().initLoader(PhotoViewCallbacks.BITMAP_LOADER_PHOTO,
null, this);
}
}
public Loader<BitmapResult> onCreateLoader(int id, Bundle args) {
if(mOnlyShowSpinner) {
return null;
}
String uri = null;
switch (id) {
case PhotoViewCallbacks.BITMAP_LOADER_THUMBNAIL:
uri = mThumbnailUri;
Log.d("PhotoViewFragment","onCreateLoader BITMAP_LOADER_THUMBNAIL mThumbnailUri="+mThumbnailUri);
break;
case PhotoViewCallbacks.BITMAP_LOADER_PHOTO:
uri = mResolvedPhotoUri;
Log.d("PhotoViewFragment","onCreateLoader BITMAP_LOADER_THUMBNAIL mResolvedPhotoUri="+mResolvedPhotoUri);
break;
}
return mCallback.onCreateBitmapLoader(id, args, uri);
}
protected PhotoViewCallbacks getCallbacks() {
return ((ActivityInterface) getActivity()).getController();
}
packages\apps\UnifiedEmail\src\com\android\mail\photo\MailPhotoViewController.java
/**
* This class implements all the logic of the photo view activity. An activity should use this class
* calling through from relevant activity methods to the methods of the same name here.
*
* To customize the photo viewer activity, you should subclass this and implement your
* customizations here. Then subclass {@link PhotoViewActivity} and override just
* {@link PhotoViewActivity#createController createController} to instantiate your controller
* subclass.
*/
frameworks\opt\photoviewer\src\com\android\ex\photo\PhotoViewController.java
public void onCreate(Bundle savedInstanceState) {
mActivity.setContentView(getContentViewId());
// Create the adapter and add the view pager
mAdapter = createPhotoPagerAdapter(mActivity.getContext(),
mActivity.getSupportFragmentManager(), null, mMaxInitialScale);
final Resources resources = mActivity.getResources();
mRootView = findViewById(getRootViewId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mRootView.setOnSystemUiVisibilityChangeListener(getSystemUiVisibilityChangeListener());
}
mBackground = getBackground();
mTemporaryImage = getTemporaryImage();
mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager);
mViewPager.setAdapter(mAdapter);
mViewPager.setOnPageChangeListener(this);
mViewPager.setOnInterceptTouchListener(this);
mViewPager.setPageMargin(resources.getDimensionPixelSize(R.dimen.photo_page_margin));
public Loader<BitmapResult> onCreateBitmapLoader(int id, Bundle args, String uri) {
switch (id) {
case BITMAP_LOADER_AVATAR:
case BITMAP_LOADER_THUMBNAIL:
case BITMAP_LOADER_PHOTO:
return new PhotoBitmapLoader(mActivity.getContext(), uri);
default:
return null;
}
}
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if (id == LOADER_PHOTO_LIST) {
return new PhotoPagerLoader(mActivity.getContext(), Uri.parse(mPhotosUri), mProjection);
}
return null;
}
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
final int id = loader.getId();
boolean wasEmpty = mIsEmpty;
mIsEmpty = false;
mAdapter.swapCursor(data);
/**
* Loader for a set of photo IDs.
*/
frameworks\opt\photoviewer\src\com\android\ex\photo\loaders\PhotoPagerLoader.java
public Cursor loadInBackground() {
Cursor returnCursor = null;
final Uri loaderUri = mPhotosUri.buildUpon().appendQueryParameter(
PhotoContract.ContentTypeParameters.CONTENT_TYPE, "image/").build();
setUri(loaderUri);
setProjection(mProjection);
returnCursor = super.loadInBackground();
return returnCursor;
}
}
frameworks\opt\photoviewer\src\com\android\ex\photo\adapters\PhotoPagerAdapter.java
public Fragment getItem(Context context, Cursor cursor, int position) {
final String photoUri = getPhotoUri(cursor);
final String thumbnailUri = getThumbnailUri(cursor);
final String contentDescription = getPhotoName(cursor);
boolean loading = shouldShowLoadingIndicator(cursor);
boolean onlyShowSpinner = false;
if(photoUri == null && loading) {
onlyShowSpinner = true;
}
// create new PhotoViewFragment
final PhotoViewIntentBuilder builder =
Intents.newPhotoViewFragmentIntentBuilder(mContext, getPhotoViewFragmentClass());
builder
.setResolvedPhotoUri(photoUri) //photo在EmailProvider.db中的路劲
.setThumbnailUri(thumbnailUri)
.setContentDescription(contentDescription)
.setDisplayThumbsFullScreen(mDisplayThumbsFullScreen)
.setMaxInitialScale(mMaxScale);
return createPhotoViewFragment(builder.build(), position, onlyShowSpinner);
}
protected PhotoViewFragment createPhotoViewFragment(
Intent intent, int position, boolean onlyShowSpinner) {
return PhotoViewFragment.newInstance(intent, position, onlyShowSpinner);
}
//主要显示各个photo的界面
frameworks\opt\photoviewer\src\com\android\ex\photo\fragments\PhotoViewFragment.java
protected void initializeView(View view) {
// 显示photo的view
mPhotoView = (PhotoView) view.findViewById(R.id.photo_view);
mPhotoView.setMaxInitialScale(mIntent.getFloatExtra(Intents.EXTRA_MAX_INITIAL_SCALE, 1));
mPhotoView.setOnClickListener(this);
mPhotoView.setFullScreen(mFullScreen, false);
mPhotoView.enableImageTransforms(false);
mPhotoView.setContentDescription(mContentDescription);
mPhotoPreviewAndProgress = view.findViewById(R.id.photo_preview);
mPhotoPreviewImage = (ImageView) view.findViewById(R.id.photo_preview_image);
mThumbnailShown = false;
final ProgressBar indeterminate =
(ProgressBar) view.findViewById(R.id.indeterminate_progress);
final ProgressBar determinate =
(ProgressBar) view.findViewById(R.id.determinate_progress);
mPhotoProgressBar = new ProgressBarWrapper(determinate, indeterminate, true);
mEmptyText = (TextView) view.findViewById(R.id.empty_text);
mRetryButton = (ImageView) view.findViewById(R.id.retry_button);
// Don't call until we've setup the entire view
setViewVisibility();
}
private void displayPhoto(BitmapResult result) {
if (result.status == BitmapResult.STATUS_EXCEPTION) {
mProgressBarNeeded = false;
mEmptyText.setText(R.string.failed);
mEmptyText.setVisibility(View.VISIBLE);
mCallback.onFragmentPhotoLoadComplete(this, false /* success */);
} else {
mEmptyText.setVisibility(View.GONE);
final Drawable data = result.getDrawable(getResources());
bindPhoto(data);
mCallback.onFragmentPhotoLoadComplete(this, true /* success */);
}
}
/**
* Binds an image to the photo view.
*/
private void bindPhoto(Drawable drawable) {
if (drawable != null) {
if (mPhotoView != null) {
mPhotoView.bindDrawable(drawable);
}
enableImageTransforms(true);
mPhotoPreviewAndProgress.setVisibility(View.GONE);
mProgressBarNeeded = false;
}
}
frameworks\opt\photoviewer\src\com\android\ex\photo\loaders\PhotoBitmapLoader.java
public BitmapResult loadInBackground() {
BitmapResult result = new BitmapResult();
Context context = getContext();
if (context != null && mPhotoUri != null) {
final ContentResolver resolver = context.getContentResolver();
try {
result = ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri),
PhotoViewController.sMaxPhotoSize);
if (result.bitmap != null) {
result.bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM);
}
} catch (UnsupportedOperationException ex) {
// We got image bytes, but unable to decode to a Bitmap
result.status = BitmapResult.STATUS_EXCEPTION;
}
}
return result;
}