Home | History | Annotate | Download | only in notification
      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 
     17 package com.android.systemui.statusbar.notification;
     18 
     19 import android.graphics.drawable.Icon;
     20 import android.util.Pools;
     21 import android.view.View;
     22 import android.widget.ImageView;
     23 
     24 import com.android.systemui.R;
     25 
     26 /**
     27  * A transform state of a image view.
     28 */
     29 public 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     protected boolean transformScale() {
     66         return true;
     67     }
     68 
     69     @Override
     70     public void recycle() {
     71         super.recycle();
     72         sInstancePool.release(this);
     73     }
     74 
     75     @Override
     76     protected void reset() {
     77         super.reset();
     78         mIcon = null;
     79     }
     80 }
     81