Performance improvement for photoViewer

I noticed that when we bring up the photoViewer,
it always initializes the first two fragments, and
then switches to whatever fragments we actually
want to look at based upon the intent parameters.
This issue is that we were assigning the adapter
to the ViewPager before we had any cursor at all.
If we hold off on setting the adpater until we have
a cursor, then this doesn't happen.  This improves
startup time of the PhotoViewActivity noticeably.

Also, made a few changes to make it easier to
extend PhotoViewActivity and PhotoViewFragment,
to change its behavior.

Change-Id: Icc4c397529bd147d0ac6818f79a48db1c4a25f32
Merge photo viewer changes from master

Change-Id: I3d4835aa10bbcccc8cf07ba53182da2ca017a1b9
Merge "Fix problem where part of wrong photo shows"

This is a manual merge of:
https://googleplex-android-review.googlesource.com/#/c/260544/1

Change-Id: Id872c4dd23db5c0d4e107a52a50a43c4b12a291d
Merge "Fix for panorama icon not always showing up in photo viewer"

Merge CL: https://googleplex-android-review.googlesource.com/#/c/246161

Change-Id: I8cc5f339b4ffde31eadc2412aa6389354cfea45b
Merge: "Restart loader on attachment cursor updates:

This merges: https://googleplex-android-review.googlesource.com/#/c/245483

Change-Id: I86440eacd0b48b9be1cf1c80574c3634fc6bdd79
Merge: "Set the scale type for the default image icon"

This merges: https://googleplex-android-review.googlesource.com/#/c/238674

Change-Id: I038e08bd4cc3ca58737a48c6caaccdc52f1015cd
Fix some build errors

These need to be fixed before switching to the photoviewer library
in frameworks/opt

Change-Id: Ie02e759edecfb3c47c2db7534ae881761ecc2d95
Merge "Fix some build errors" into jb-ub-mail-ur8
Set the fullscreen timeout, even with no actionbar

We need to set the timeout even when there is no action bar, as it
still will affect lights out mode.

Renamed the variable & methods to better names

Change-Id: I1752a5c9a1f2212f3a17af2e8aa2d78a2377e1fa
Allow any class to be used for viewing photos

You no longer need to extend PhotoViewActivity.

Change-Id: Ia18f2d984668b397335c8fd337f02a9200ced7bb
Load image attachments from live conversations.

MessageAttachmentTile automatically downloads image attachment thumbnails when
missing.

PhotoViewFragment first loads thumbnail, then loads the full image. Shows and
hides the progressbar correctly.

Added ability for UiProvider to specify which rendition of an attachment to
download.

Bug: 7987412
Change-Id: I7aec4dd80e6fda1b7f4b5f25caffa69380d269d3
Modify image attachments previews to conform to UX specs

Thumbnail and full image start loading at the same time.

Once thumbnail is shown, we display a determinate progress bar while downloading
the full image.

Remove progress bar from image tiles in ConversationView.

Bug: 8021747
Change-Id: Ic1c7e7fcdc5683ad9e899c82b6bbdb5861d16a55
Allow the use of any fragment instead of a PhotoViewFragment

This lets other users build their own photoViewFragment

Change-Id: I7c915b7ed3ccdadf00bc9e46c7a686cb0146188f
Starts a pending download immediately when swiping to that image.

Add a new Attachment state, PAUSED, for when we've queued the attachment in the
DownloadManager, but it hasn't started yet.

Modified onViewActivated() so it would only get triggered once when you swipe to
that fragment.

Bug: 8023818
Change-Id: I319f12235559feb1f716515155881188894d6f05
Save/Restore Actionbar title

In rare cases, we cannot restore the actionbar title in the photo
viewer because we require the fragment to be visible on the screen to
update the title.

Since this is a rather rare problem, the easiest fix is to save the
actionbar title to a bundle and restore it on orientation changes.

Bug: 8124251 Action bar text for the attachment disappears on
             orientation change

Change-Id: I27b2768b3e7edb18e1ddd272f48a3ad8ebdd408a
Let the framework manage fragments

The original crash is deep in the framework. Looking into the code, I
found the following strangeness, which this change fixes:

1. Fragments don't have a public no-arg constructor, which is required
   for the framework to restore state.

2. Fragments keep a reference to the adapter, passed through the
   constructor. This is a terrible idea: the adapter might get stale,
   it might not be tied to the current activity, it can't be parcelled
   into a bundle, .... At the very least, the adapter should come
   directly via the activity.

3. A lot of computation is happening in onAttach(Activity) which is
   too early. At this point, the activity is made, but has not gone
   through onCreate() yet, so might be uninitialized. Most of this
   code should move to onCreateView() or, even better,
   onActivityCreated()

4. The index of the current fragment might still be negative in
   onCreate(). This causes problems with the ViewPager when it tries
   to load the current fragment from the adapter.  We should never set
   the current position to -1.

5. The computation for currentPosition is incorrect in
   PhotoViewActivity.onCreate(), from a cursory glance at
   MessageAttachmentTile.viewAttachment() where both the photo index
   and the photo uri are populated at the same time.  Once the index
   is read, it will be > 0, and the URI won't be set. This is a bug.

These changes ameliorate the original issue, but don't fix it
altogether.  The remaining issues will be fixed in a subsequent CL.

Bug: 8143282 PhotoViewerActivity crashes on orientation change

Change-Id: Ia0652b2eea9e976603f0d6686077b9f6a75abb78
Merge "Let the framework manage fragments" into jb-ub-mail-ur8
Ignore the SecurityException for now so that Gmail does not crash. A later CL
will fix the underlying issue.

Bug: 8184899
Change-Id: Iae9e452367237442d723794b95313e3afbb36a48
Merge branch 'goog/jb-ub-mail-ur8' into master

Change-Id: Ie28475b31bb0d5d214c948c498d88e540d6f93a9
Continuously attempt to load thumbnail if it fails the first time. This behavior
is the same as loading the full image.

Bug: 8235723
Change-Id: I2b0786cb7482afe6dd1464be8f54d8f6e810eab8