1/* 2 * Copyright (C) 2017 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 android.car.cluster; 18 19import android.annotation.Nullable; 20import android.graphics.Rect; 21import android.os.Bundle; 22 23/** 24 * Helper class that represents activity state in the cluster and can be serialized / deserialized 25 * to/from bundle. 26 * @hide 27 */ 28public class ClusterActivityState { 29 private static final String KEY_VISIBLE = "android.car:activityState.visible"; 30 private static final String KEY_UNOBSCURED_BOUNDS = "android.car:activityState.unobscured"; 31 private static final String KEY_EXTRAS = "android.car:activityState.extras"; 32 33 private boolean mVisible = true; 34 private Rect mUnobscuredBounds; 35 private Bundle mExtras; 36 37 public boolean isVisible() { 38 return mVisible; 39 } 40 41 @Nullable public Rect getUnobscuredBounds() { 42 return mUnobscuredBounds; 43 } 44 45 public ClusterActivityState setVisible(boolean visible) { 46 mVisible = visible; 47 return this; 48 } 49 50 public ClusterActivityState setUnobscuredBounds(Rect unobscuredBounds) { 51 mUnobscuredBounds = unobscuredBounds; 52 return this; 53 } 54 55 public ClusterActivityState setExtras(Bundle bundle) { 56 mExtras = bundle; 57 return this; 58 } 59 60 /** Use factory methods instead. */ 61 private ClusterActivityState() {} 62 63 public static ClusterActivityState create(boolean visible, Rect unobscuredBounds) { 64 return new ClusterActivityState() 65 .setVisible(visible) 66 .setUnobscuredBounds(unobscuredBounds); 67 } 68 69 public static ClusterActivityState fromBundle(Bundle bundle) { 70 return new ClusterActivityState() 71 .setVisible(bundle.getBoolean(KEY_VISIBLE, true)) 72 .setUnobscuredBounds((Rect) bundle.getParcelable(KEY_UNOBSCURED_BOUNDS)) 73 .setExtras(bundle.getBundle(KEY_EXTRAS)); 74 } 75 76 public Bundle toBundle() { 77 Bundle b = new Bundle(); 78 b.putBoolean(KEY_VISIBLE, mVisible); 79 b.putParcelable(KEY_UNOBSCURED_BOUNDS, mUnobscuredBounds); 80 b.putBundle(KEY_EXTRAS, mExtras); 81 return b; 82 } 83 84 @Override 85 public String toString() { 86 return this.getClass().getSimpleName() + " {" 87 + "visible: " + mVisible + ", " 88 + "unobscuredBounds: " + mUnobscuredBounds 89 + " }"; 90 } 91} 92