blob: 8d8b9b2af04e710d9de52dc674eb681183985b9a [file] [log] [blame]
Christine Franks7119e992019-03-14 17:28:21 -07001/*
2 * Copyright (C) 2019 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.server.display.color;
18
19import android.animation.ValueAnimator;
20import android.content.Context;
Anthony Han00a490b2019-08-26 14:00:28 -070021import android.util.Slog;
Christine Franks7119e992019-03-14 17:28:21 -070022
23import java.io.PrintWriter;
24
25abstract class TintController {
26
27 private ValueAnimator mAnimator;
28 private Boolean mIsActivated;
29
30 public ValueAnimator getAnimator() {
31 return mAnimator;
32 }
33
34 public void setAnimator(ValueAnimator animator) {
35 mAnimator = animator;
36 }
37
38 /**
39 * Cancel the animator if it's still running.
40 */
41 public void cancelAnimator() {
42 if (mAnimator != null) {
43 mAnimator.cancel();
44 }
45 }
46
47 /**
48 * End the animator if it's still running, jumping to the end state.
49 */
50 public void endAnimator() {
51 if (mAnimator != null) {
52 mAnimator.end();
53 mAnimator = null;
54 }
55 }
56
57 public void setActivated(Boolean isActivated) {
58 mIsActivated = isActivated;
59 }
60
61 public boolean isActivated() {
62 return mIsActivated != null && mIsActivated;
63 }
64
65 public boolean isActivatedStateNotSet() {
66 return mIsActivated == null;
67 }
68
69 /**
70 * Dump debug information.
71 */
72 public void dump(PrintWriter pw) {
73 }
74
75 /**
76 * Set up any constants needed for computing the matrix.
77 */
78 public abstract void setUp(Context context, boolean needsLinear);
79
80 /**
81 * Sets the 4x4 matrix to apply.
82 */
83 public abstract void setMatrix(int value);
84
85 /**
86 * Get the 4x4 matrix to apply.
87 */
88 public abstract float[] getMatrix();
89
90 /**
91 * Get the color transform level to apply the matrix.
92 */
93 public abstract int getLevel();
94
95 /**
96 * Returns whether or not this transform type is available on this device.
97 */
98 public abstract boolean isAvailable(Context context);
Anthony Han00a490b2019-08-26 14:00:28 -070099
100 /**
101 * Format a given matrix into a string.
102 *
103 * @param matrix the matrix to format
104 * @param columns number of columns in the matrix
105 */
106 static String matrixToString(float[] matrix, int columns) {
107 if (matrix == null || columns <= 0) {
108 Slog.e(ColorDisplayService.TAG, "Invalid arguments when formatting matrix to string,"
109 + " matrix is null: " + (matrix == null)
110 + " columns: " + columns);
111 return "";
112 }
113
114 final StringBuilder sb = new StringBuilder("");
115 for (int i = 0; i < matrix.length; i++) {
116 if (i % columns == 0) {
117 sb.append("\n ");
118 }
119 sb.append(String.format("%9.6f", matrix[i]));
120 }
121 return sb.toString();
122 }
123
Christine Franks7119e992019-03-14 17:28:21 -0700124}