lmw
2023-04-03 16ea883d3c03fd8b910f9282aa1bc08378d40d54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.beloo.widget.chipslayoutmanager.anchor;
 
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
 
import androidx.annotation.NonNull;
 
import java.util.Locale;
 
/**
 * represents View, which is highest visible left view
 */
 
public class AnchorViewState implements Parcelable {
    private Integer position = 0;
    private Rect anchorViewRect;
 
    private AnchorViewState() {
    }
 
    static AnchorViewState getNotFoundState() {
        return new AnchorViewState();
    }
 
    AnchorViewState(int position, @NonNull Rect anchorViewRect) {
        this.position = position;
        this.anchorViewRect = anchorViewRect;
    }
 
    public boolean isNotFoundState() {
        return anchorViewRect == null;
    }
 
    public Integer getPosition() {
        return position;
    }
 
    public void setPosition(Integer position) {
        this.position = position;
    }
 
    public Rect getAnchorViewRect() {
        return anchorViewRect;
    }
 
    public void setAnchorViewRect(Rect anchorViewRect) {
        this.anchorViewRect = anchorViewRect;
    }
 
    public boolean isRemoving() {
        return getPosition() == -1;
    }
 
    //parcelable logic below
 
    private AnchorViewState(Parcel parcel) {
        int parcelPosition = parcel.readInt();
        position = parcelPosition == -1? null : parcelPosition;
        anchorViewRect = parcel.readParcelable(AnchorViewState.class.getClassLoader());
    }
 
    @Override
    public int describeContents() {
        return 0;
    }
 
    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(position == null? -1 : position);
        parcel.writeParcelable(anchorViewRect, 0);
    }
 
    public static final Parcelable.Creator<AnchorViewState> CREATOR = new Parcelable.Creator<AnchorViewState>() {
        // unpack Object from Parcel
        public AnchorViewState createFromParcel(Parcel in) {
            return new AnchorViewState(in);
        }
 
        public AnchorViewState[] newArray(int size) {
            return new AnchorViewState[size];
        }
    };
 
    @Override
    public String toString() {
        return String.format(Locale.getDefault(), "AnchorState. Position = %d, Rect = %s", position, String.valueOf(anchorViewRect));
    }
}