blob: 5ab441dca6e870655203940610cd58bf02753c98 [file] [log] [blame]
Selim Cinek4ffd6362015-12-29 15:12:23 +01001/*
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.text.TextUtils;
20import android.util.Pools;
21import android.view.View;
22import android.widget.TextView;
23
24/**
25 * A transform state of a mText view.
26*/
27public class TextViewTransformState extends TransformState {
28
29 private static Pools.SimplePool<TextViewTransformState> sInstancePool
30 = new Pools.SimplePool<>(40);
31 private CharSequence mText;
32
33 @Override
34 public void initFrom(View view) {
35 super.initFrom(view);
36 if (view instanceof TextView) {
37 TextView txt = (TextView) view;
38 mText = txt.getText();
39 }
40 }
41
42 @Override
43 protected boolean sameAs(TransformState otherState) {
44 if (otherState instanceof TextViewTransformState) {
45 TextViewTransformState otherTvs = (TextViewTransformState) otherState;
46 return TextUtils.equals(otherTvs.mText, mText);
47 }
48 return super.sameAs(otherState);
49 }
50
51 public static TextViewTransformState obtain() {
52 TextViewTransformState instance = sInstancePool.acquire();
53 if (instance != null) {
54 return instance;
55 }
56 return new TextViewTransformState();
57 }
58
59 @Override
60 public void recycle() {
Selim Cinek0ffbda62016-01-01 20:29:12 +010061 super.recycle();
Selim Cinek4ffd6362015-12-29 15:12:23 +010062 sInstancePool.release(this);
63 }
64
65 @Override
66 protected void reset() {
67 super.reset();
68 mText = null;
69 }
70}