Debian Codegraph @

core/java/android/app/time/TimeConfiguration.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.app.time;
18
19 import android.annotation.NonNull;
20 import android.annotation.StringDef;
21 import android.os.Bundle;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 import java.util.Objects;
28
29 /**
30 * User visible settings that control the behavior of the time zone detector / manual time zone
31 * entry.
32 *
33 * @hide
34 */
35 public final class TimeConfiguration implements Parcelable {
36
37 public static final @NonNull Creator<TimeConfiguration> CREATOR =
38 new Creator<TimeConfiguration>() {
39 @Override
40 public TimeConfiguration createFromParcel(Parcel source) {
41 return TimeConfiguration.readFromParcel(source);
42 }
43
44 @Override
45 public TimeConfiguration[] newArray(int size) {
46 return new TimeConfiguration[size];
47 }
48 };
49
50 @StringDef(SETTING_AUTO_DETECTION_ENABLED)
51 @Retention(RetentionPolicy.SOURCE)
52 @interface Setting {}
53
54 @Setting
55 private static final String SETTING_AUTO_DETECTION_ENABLED = "autoDetectionEnabled";
56
57 @NonNull
58 private final Bundle mBundle;
59
60 private TimeConfiguration(Builder builder) {
61 this.mBundle = builder.mBundle;
62 }
63
64 /**
65 * Returns the value of the {@link #SETTING_AUTO_DETECTION_ENABLED} setting. This
66 * controls whether a device will attempt to determine the time automatically using
67 * contextual information if the device supports auto detection.
68 */
69 public boolean isAutoDetectionEnabled() {
70 return mBundle.getBoolean(SETTING_AUTO_DETECTION_ENABLED);
71 }
72
73 @Override
74 public int describeContents() {
75 return 0;
76 }
77
78 @Override
79 public void writeToParcel(@NonNull Parcel dest, int flags) {
80 dest.writeBundle(mBundle);
81 }
82
83 private static TimeConfiguration readFromParcel(Parcel in) {
84 return new TimeConfiguration.Builder()
85 .merge(in.readBundle())
86 .build();
87 }
88
89 @Override
90 public boolean equals(Object o) {
91 if (this == o) return true;
92 if (o == null || getClass() != o.getClass()) return false;
93 TimeConfiguration that = (TimeConfiguration) o;
94 return mBundle.kindofEquals(that.mBundle);
95 }
96
97 @Override
98 public int hashCode() {
99 return Objects.hash(mBundle);
100 }
101
102 @Override
103 public String toString() {
104 return "TimeConfiguration{"
105 + "mBundle=" + mBundle
106 + '}';
107 }
108
109 /**
110 * A builder for {@link TimeConfiguration} objects.
111 *
112 * @hide
113 */
114 public static final class Builder {
115 private final Bundle mBundle = new Bundle();
116
117 public Builder() {}
118
119 public Builder(@NonNull TimeConfiguration configuration) {
120 mBundle.putAll(configuration.mBundle);
121 }
122
123 /** Sets whether auto detection is enabled or not. */
124 @NonNull
125 public Builder setAutoDetectionEnabled(boolean enabled) {
126 mBundle.putBoolean(SETTING_AUTO_DETECTION_ENABLED, enabled);
127 return this;
128 }
129
130 Builder merge(@NonNull Bundle bundle) {
131 mBundle.putAll(bundle);
132 return this;
133 }
134
135 /** Returns {@link TimeConfiguration} object. */
136 @NonNull
137 public TimeConfiguration build() {
138 return new TimeConfiguration(this);
139 }
140 }
141 }