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.animation.ValueAnimator; 20 import android.content.Context; 21 import android.util.Slog; 22 23 import java.io.PrintWriter; 24 25 abstract class TintController { 26 27 private ColorDisplayService.TintValueAnimator mAnimator; 28 private Boolean mIsActivated; 29 getAnimator()30 public ColorDisplayService.TintValueAnimator getAnimator() { 31 return mAnimator; 32 } 33 setAnimator(ColorDisplayService.TintValueAnimator animator)34 public void setAnimator(ColorDisplayService.TintValueAnimator animator) { 35 mAnimator = animator; 36 } 37 38 /** 39 * Cancel the animator if it's still running. 40 */ cancelAnimator()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 */ endAnimator()50 public void endAnimator() { 51 if (mAnimator != null) { 52 mAnimator.end(); 53 mAnimator = null; 54 } 55 } 56 setActivated(Boolean isActivated)57 public void setActivated(Boolean isActivated) { 58 mIsActivated = isActivated; 59 } 60 isActivated()61 public boolean isActivated() { 62 return mIsActivated != null && mIsActivated; 63 } 64 isActivatedStateNotSet()65 public boolean isActivatedStateNotSet() { 66 return mIsActivated == null; 67 } 68 69 /** 70 * Dump debug information. 71 */ dump(PrintWriter pw)72 public void dump(PrintWriter pw) { 73 } 74 75 /** 76 * Set up any constants needed for computing the matrix. 77 */ setUp(Context context, boolean needsLinear)78 public abstract void setUp(Context context, boolean needsLinear); 79 80 /** 81 * Sets the 4x4 matrix to apply. 82 */ setMatrix(int value)83 public abstract void setMatrix(int value); 84 85 /** 86 * Get the 4x4 matrix to apply. 87 */ getMatrix()88 public abstract float[] getMatrix(); 89 90 /** 91 * Get the color transform level to apply the matrix. 92 */ getLevel()93 public abstract int getLevel(); 94 95 /** 96 * Returns whether or not this transform type is available on this device. 97 */ isAvailable(Context context)98 public abstract boolean isAvailable(Context context); 99 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 */ matrixToString(float[] matrix, int columns)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 124 } 125