Debian Codegraph @

extensions/library/src/main/java/android/databinding/ObservableDouble.java

raw
1 /*
2 * Copyright (C) 2015 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.databinding;
17
18 import android.os.Parcel;
19 import android.os.Parcelable;
20
21 import java.io.Serializable;
22
23 /**
24 * An observable class that holds a primitive double.
25 * <p>
26 * Observable field classes may be used instead of creating an Observable object:
27 * <pre><code>public class MyDataObject {
28 * public final ObservableDouble temperature = new ObservableDouble();
29 * }</code></pre>
30 * Fields of this type should be declared final because bindings only detect changes in the
31 * field's value, not of the field itself.
32 * <p>
33 * This class is parcelable and serializable but callbacks are ignored when the object is
34 * parcelled / serialized. Unless you add custom callbacks, this will not be an issue because
35 * data binding framework always re-registers callbacks when the view is bound.
36 */
37 public class ObservableDouble extends BaseObservable implements Parcelable, Serializable {
38 static final long serialVersionUID = 1L;
39 private double mValue;
40
41 /**
42 * Creates an ObservableDouble with the given initial value.
43 *
44 * @param value the initial value for the ObservableDouble
45 */
46 public ObservableDouble(double value) {
47 mValue = value;
48 }
49
50 /**
51 * Creates an ObservableDouble with the initial value of <code>0</code>.
52 */
53 public ObservableDouble() {
54 }
55
56 /**
57 * @return the stored value.
58 */
59 public double get() {
60 return mValue;
61 }
62
63 /**
64 * Set the stored value.
65 */
66 public void set(double value) {
67 if (value != mValue) {
68 mValue = value;
69 notifyChange();
70 }
71 }
72
73 @Override
74 public int describeContents() {
75 return 0;
76 }
77
78 @Override
79 public void writeToParcel(Parcel dest, int flags) {
80 dest.writeDouble(mValue);
81 }
82
83 public static final Parcelable.Creator<ObservableDouble> CREATOR
84 = new Parcelable.Creator<ObservableDouble>() {
85
86 @Override
87 public ObservableDouble createFromParcel(Parcel source) {
88 return new ObservableDouble(source.readDouble());
89 }
90
91 @Override
92 public ObservableDouble[] newArray(int size) {
93 return new ObservableDouble[size];
94 }
95 };
96 }