1905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev/* 2905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * Copyright (C) 2017 The Android Open Source Project 3905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * 4905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * Licensed under the Apache License, Version 2.0 (the "License"); 5905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * you may not use this file except in compliance with the License. 6905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * You may obtain a copy of the License at 7905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * 8905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * http://www.apache.org/licenses/LICENSE-2.0 9905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * 10905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * Unless required by applicable law or agreed to in writing, software 11905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * distributed under the License is distributed on an "AS IS" BASIS, 12905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * See the License for the specific language governing permissions and 14905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * limitations under the License. 15905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev */ 16905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 17905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsevpackage android.car.cluster; 18905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 19905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsevimport android.annotation.Nullable; 20905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsevimport android.graphics.Rect; 21905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsevimport android.os.Bundle; 22905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 23905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev/** 24905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * Helper class that represents activity state in the cluster and can be serialized / deserialized 25905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * to/from bundle. 26905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev * @hide 27905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev */ 28905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsevpublic class ClusterActivityState { 29905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private static final String KEY_VISIBLE = "android.car:activityState.visible"; 30905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private static final String KEY_UNOBSCURED_BOUNDS = "android.car:activityState.unobscured"; 31905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private static final String KEY_EXTRAS = "android.car:activityState.extras"; 32905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 33905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private boolean mVisible = true; 34905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private Rect mUnobscuredBounds; 35905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private Bundle mExtras; 36905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 37905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public boolean isVisible() { 38905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return mVisible; 39905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 40905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 41905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev @Nullable public Rect getUnobscuredBounds() { 42905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return mUnobscuredBounds; 43905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 44905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 45905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public ClusterActivityState setVisible(boolean visible) { 46905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev mVisible = visible; 47905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return this; 48905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 49905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 50905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public ClusterActivityState setUnobscuredBounds(Rect unobscuredBounds) { 51905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev mUnobscuredBounds = unobscuredBounds; 52905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return this; 53905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 54905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 55905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public ClusterActivityState setExtras(Bundle bundle) { 56905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev mExtras = bundle; 57905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return this; 58905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 59905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 60905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev /** Use factory methods instead. */ 61905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev private ClusterActivityState() {} 62905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 63905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public static ClusterActivityState create(boolean visible, Rect unobscuredBounds) { 64905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return new ClusterActivityState() 65905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev .setVisible(visible) 66905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev .setUnobscuredBounds(unobscuredBounds); 67905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 68905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 69905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public static ClusterActivityState fromBundle(Bundle bundle) { 70905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return new ClusterActivityState() 71905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev .setVisible(bundle.getBoolean(KEY_VISIBLE, true)) 72905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev .setUnobscuredBounds((Rect) bundle.getParcelable(KEY_UNOBSCURED_BOUNDS)) 73905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev .setExtras(bundle.getBundle(KEY_EXTRAS)); 74905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 75905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 76905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public Bundle toBundle() { 77905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev Bundle b = new Bundle(); 78905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev b.putBoolean(KEY_VISIBLE, mVisible); 79905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev b.putParcelable(KEY_UNOBSCURED_BOUNDS, mUnobscuredBounds); 80905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev b.putBundle(KEY_EXTRAS, mExtras); 81905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return b; 82905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 83905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev 84905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev @Override 85905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev public String toString() { 86905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev return this.getClass().getSimpleName() + " {" 87905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev + "visible: " + mVisible + ", " 88905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev + "unobscuredBounds: " + mUnobscuredBounds 89905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev + " }"; 90905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev } 91905968cf95d4c8608d6d9351b5dd10fe994a1220Pavel Maltsev} 92