ImageTransformState.java revision 646d2054dd76d7213ced8a73f2352f0d63f20043
1/* 2 * Copyright (C) 2016 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 17package com.android.systemui.statusbar.notification; 18 19import android.graphics.drawable.Icon; 20import android.util.Pools; 21import android.view.View; 22import android.widget.ImageView; 23 24import com.android.systemui.R; 25 26/** 27 * A transform state of a image view. 28*/ 29public class ImageTransformState extends TransformState { 30 31 public static final int ICON_TAG = R.id.image_icon_tag; 32 private static Pools.SimplePool<ImageTransformState> sInstancePool 33 = new Pools.SimplePool<>(40); 34 private Icon mIcon; 35 36 @Override 37 public void initFrom(View view) { 38 super.initFrom(view); 39 if (view instanceof ImageView) { 40 mIcon = (Icon) view.getTag(ICON_TAG); 41 } 42 } 43 44 @Override 45 protected boolean sameAs(TransformState otherState) { 46 if (otherState instanceof ImageTransformState) { 47 return mIcon != null && mIcon.sameAs(((ImageTransformState) otherState).getIcon()); 48 } 49 return super.sameAs(otherState); 50 } 51 52 public Icon getIcon() { 53 return mIcon; 54 } 55 56 public static ImageTransformState obtain() { 57 ImageTransformState instance = sInstancePool.acquire(); 58 if (instance != null) { 59 return instance; 60 } 61 return new ImageTransformState(); 62 } 63 64 @Override 65 public void recycle() { 66 super.recycle(); 67 sInstancePool.release(this); 68 } 69 70 @Override 71 protected void reset() { 72 super.reset(); 73 mIcon = null; 74 } 75} 76