1 /* 2 * Copyright (C) 2016 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 package android.car.cluster.renderer; 17 18 import android.annotation.Nullable; 19 import android.annotation.SystemApi; 20 import android.graphics.Rect; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * TODO: need to properly define this class and make it immutable. 26 * 27 * @hide 28 */ 29 @SystemApi 30 public class DisplayConfiguration implements Parcelable { 31 private final Rect mPrimaryRegion; 32 33 @Nullable 34 private final Rect mSecondaryRegion; 35 36 public static final Parcelable.Creator<DisplayConfiguration> CREATOR = 37 new Parcelable.Creator<DisplayConfiguration>() { 38 39 public DisplayConfiguration createFromParcel(Parcel in) { 40 return new DisplayConfiguration(in); 41 } 42 43 public DisplayConfiguration[] newArray(int size) { 44 return new DisplayConfiguration[size]; 45 } 46 }; 47 48 DisplayConfiguration(Parcel in)49 public DisplayConfiguration(Parcel in) { 50 mPrimaryRegion = in.readTypedObject(Rect.CREATOR); 51 mSecondaryRegion = in.readTypedObject(Rect.CREATOR); 52 } 53 DisplayConfiguration(Rect primaryRegion)54 public DisplayConfiguration(Rect primaryRegion) { 55 this(primaryRegion, null); 56 } 57 DisplayConfiguration(Rect primaryRegion, @Nullable Rect secondaryRegion)58 public DisplayConfiguration(Rect primaryRegion, @Nullable Rect secondaryRegion) { 59 mPrimaryRegion = primaryRegion; 60 mSecondaryRegion = secondaryRegion; 61 } 62 63 64 /** Region that will be fully visible in instrument cluster */ getPrimaryRegion()65 public Rect getPrimaryRegion() { 66 return mPrimaryRegion; 67 } 68 69 /** 70 * The region that includes primary region + may include some additional space that might 71 * be partially visible in the instrument cluster. It is useful to fade-out primary 72 * rendering for example or adding background image. 73 */ 74 @Nullable getSecondaryRegion()75 public Rect getSecondaryRegion() { 76 return mSecondaryRegion; 77 } 78 79 /** Returns true if secondary region is strongly greater then primary region */ hasSecondaryRegion()80 public boolean hasSecondaryRegion() { 81 return mSecondaryRegion != null 82 && mSecondaryRegion.width() > mPrimaryRegion.width() 83 && mSecondaryRegion.height() > mPrimaryRegion.height(); 84 } 85 86 @Override describeContents()87 public int describeContents() { 88 return 0; 89 } 90 91 @Override writeToParcel(Parcel dest, int flags)92 public void writeToParcel(Parcel dest, int flags) { 93 dest.writeTypedObject(mPrimaryRegion, 0); 94 dest.writeTypedObject(mSecondaryRegion, 0); 95 } 96 } 97