• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 com.android.ondevicepersonalization.services.data.user;
18 
19 import androidx.annotation.NonNull;
20 
21 /** Location information. */
22 public class LocationInfo {
23     // Time in milliseconds.
24     public long timeMillis = 0;
25 
26     // Latitude.
27     public double latitude = 0;
28 
29     // Longitude.
30     public double longitude = 0;
31 
32     // Location provider values.
33     public enum LocationProvider {
34         UNKNOWN,
35         GPS,
36         NETWORK;
37 
38         /**
39          * The converter from ordinal to enum.
40          * @param source the ordinal
41          * @return enum
42          */
fromInteger(int source)43         public static LocationProvider fromInteger(int source) {
44             switch (source) {
45                 case 1:
46                     return GPS;
47                 case 2:
48                     return NETWORK;
49                 default:
50                     return UNKNOWN;
51             }
52         }
53     };
54 
55     // Location provider.
56     public LocationProvider provider = LocationProvider.UNKNOWN;
57 
58     // Whether the location source is precise.
59     public boolean isPreciseLocation = false;
60 
LocationInfo()61     public LocationInfo() { }
62 
63     // Deep copy constructor.
LocationInfo(@onNull LocationInfo other)64     public LocationInfo(@NonNull LocationInfo other) {
65         this.timeMillis = other.timeMillis;
66         this.latitude = other.latitude;
67         this.longitude = other.longitude;
68         this.provider = other.provider;
69         this.isPreciseLocation = other.isPreciseLocation;
70     }
71 
72     // Constructor for LocationInfo.
LocationInfo(@onNull long timeMillis, @NonNull double latitude, @NonNull double longitude, @NonNull LocationProvider provider, @NonNull boolean isPrecise)73     public LocationInfo(@NonNull long timeMillis,
74             @NonNull double latitude,
75             @NonNull double longitude,
76             @NonNull LocationProvider provider,
77             @NonNull boolean isPrecise) {
78         this.timeMillis = timeMillis;
79         this.latitude = latitude;
80         this.longitude = longitude;
81         this.provider = provider;
82         this.isPreciseLocation = isPrecise;
83     }
84 
85     @Override
equals(Object o)86     public boolean equals(Object o) {
87         if (o == this) {
88             return true;
89         }
90         if (!(o instanceof LocationInfo)) {
91             return false;
92         }
93         LocationInfo other = (LocationInfo) o;
94         return this.latitude == other.latitude && this.longitude == other.longitude;
95     }
96 
97     @Override
hashCode()98     public int hashCode() {
99         int hash = 17;
100         hash = hash * 31 + Double.valueOf(latitude).hashCode();
101         hash = hash * 31 + Double.valueOf(longitude).hashCode();
102         return hash;
103     }
104 }
105