1 /* 2 * Copyright (C) 2018 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 android.car.settings; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import java.util.Objects; 23 24 /** 25 * A configuration struct that holds information for tweaking SpeedBump settings. 26 * 27 * @see androidx.car.moderator.SpeedBumpView 28 */ 29 public final class SpeedBumpConfiguration implements Parcelable { 30 private final double mAcquiredPermitsPerSecond; 31 private final double mMaxPermitPool; 32 private final long mPermitFillDelay; 33 SpeedBumpConfiguration(double permitsPerSecond, double maxPermitPool, long permitFillDelay)34 public SpeedBumpConfiguration(double permitsPerSecond, double maxPermitPool, 35 long permitFillDelay) { 36 mAcquiredPermitsPerSecond = permitsPerSecond; 37 mMaxPermitPool = maxPermitPool; 38 mPermitFillDelay = permitFillDelay; 39 } 40 41 /** 42 * Returns the number of permitted actions that are acquired each second that the user has not 43 * interacted with the {@code SpeedBumpView}. 44 */ getAcquiredPermitsPerSecond()45 public double getAcquiredPermitsPerSecond() { 46 return mAcquiredPermitsPerSecond; 47 } 48 49 /** 50 * Returns the maximum number of permits that can be acquired when the user is idling. 51 */ getMaxPermitPool()52 public double getMaxPermitPool() { 53 return mMaxPermitPool; 54 } 55 56 /** 57 * Returns the delay time before when the permit pool has been depleted and when it begins to 58 * refill. 59 */ getPermitFillDelay()60 public long getPermitFillDelay() { 61 return mPermitFillDelay; 62 } 63 64 @Override toString()65 public String toString() { 66 return String.format( 67 "[acquired_permits_per_second: %f, max_permit_pool: %f, permit_fill_delay: %d]", 68 mAcquiredPermitsPerSecond, 69 mMaxPermitPool, 70 mPermitFillDelay); 71 } 72 73 @Override equals(Object object)74 public boolean equals(Object object) { 75 if (object == this) { 76 return true; 77 } 78 79 if (!(object instanceof SpeedBumpConfiguration)) { 80 return false; 81 } 82 83 SpeedBumpConfiguration other = (SpeedBumpConfiguration) object; 84 return mAcquiredPermitsPerSecond == other.getAcquiredPermitsPerSecond() 85 && mMaxPermitPool == other.getMaxPermitPool() 86 && mPermitFillDelay == other.getPermitFillDelay(); 87 } 88 89 @Override hashCode()90 public int hashCode() { 91 return Objects.hash(mAcquiredPermitsPerSecond, mMaxPermitPool, mPermitFillDelay); 92 } 93 94 @Override writeToParcel(Parcel desk, int flags)95 public void writeToParcel(Parcel desk, int flags) { 96 desk.writeDouble(mAcquiredPermitsPerSecond); 97 desk.writeDouble(mMaxPermitPool); 98 desk.writeLong(mPermitFillDelay); 99 } 100 101 @Override describeContents()102 public int describeContents() { 103 return 0; 104 } 105 SpeedBumpConfiguration(Parcel in)106 private SpeedBumpConfiguration(Parcel in) { 107 mAcquiredPermitsPerSecond = in.readDouble(); 108 mMaxPermitPool = in.readDouble(); 109 mPermitFillDelay = in.readLong(); 110 } 111 112 public static final Parcelable.Creator<SpeedBumpConfiguration> CREATOR = 113 new Parcelable.Creator<SpeedBumpConfiguration>() { 114 public SpeedBumpConfiguration createFromParcel(Parcel in) { 115 return new SpeedBumpConfiguration(in); 116 } 117 118 public SpeedBumpConfiguration[] newArray(int size) { 119 return new SpeedBumpConfiguration[size]; 120 } 121 }; 122 } 123