1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.messaging.ui.photoviewer; 17 18 import android.content.Intent; 19 import android.graphics.drawable.Drawable; 20 import android.support.rastermill.FrameSequenceDrawable; 21 import androidx.loader.content.Loader; 22 23 import com.android.ex.photo.PhotoViewCallbacks; 24 import com.android.ex.photo.fragments.PhotoViewFragment; 25 import com.android.ex.photo.loaders.PhotoBitmapLoaderInterface.BitmapResult; 26 27 public class BuglePhotoViewFragment extends PhotoViewFragment { 28 29 /** Public no-arg constructor for allowing the framework to handle orientation changes */ BuglePhotoViewFragment()30 public BuglePhotoViewFragment() { 31 // Do nothing. 32 } 33 newInstance(Intent intent, int position, boolean onlyShowSpinner)34 public static PhotoViewFragment newInstance(Intent intent, int position, 35 boolean onlyShowSpinner) { 36 final PhotoViewFragment f = new BuglePhotoViewFragment(); 37 initializeArguments(intent, position, onlyShowSpinner, f); 38 return f; 39 } 40 41 @Override onLoadFinished(Loader<BitmapResult> loader, BitmapResult result)42 public void onLoadFinished(Loader<BitmapResult> loader, BitmapResult result) { 43 super.onLoadFinished(loader, result); 44 // Need to check for the first time when we load the photos 45 if (PhotoViewCallbacks.BITMAP_LOADER_PHOTO == loader.getId() 46 && result.status == BitmapResult.STATUS_SUCCESS 47 && mCallback.isFragmentActive(this)) { 48 startGif(); 49 } 50 } 51 52 @Override onResume()53 public void onResume() { 54 super.onResume(); 55 startGif(); 56 } 57 58 @Override onPause()59 public void onPause() { 60 stopGif(); 61 super.onPause(); 62 } 63 64 @Override onViewActivated()65 public void onViewActivated() { 66 super.onViewActivated(); 67 startGif(); 68 } 69 70 @Override resetViews()71 public void resetViews() { 72 super.resetViews(); 73 stopGif(); 74 } 75 stopGif()76 private void stopGif() { 77 final Drawable drawable = getDrawable(); 78 if (drawable != null && drawable instanceof FrameSequenceDrawable) { 79 ((FrameSequenceDrawable) drawable).stop(); 80 } 81 } 82 startGif()83 private void startGif() { 84 final Drawable drawable = getDrawable(); 85 if (drawable != null && drawable instanceof FrameSequenceDrawable) { 86 ((FrameSequenceDrawable) drawable).start(); 87 } 88 } 89 } 90