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