137 lines
6.2 KiB
Java
137 lines
6.2 KiB
Java
package o;
|
|
|
|
import android.location.Address;
|
|
import android.text.TextUtils;
|
|
import com.google.android.libraries.places.api.model.PlaceTypes;
|
|
import com.huawei.hms.support.feature.result.CommonConstant;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* renamed from: o.guz, reason: case insensitive filesystem */
|
|
/* loaded from: classes6.dex */
|
|
final class C15594guz implements InterfaceC13170fSr<List<Address>> {
|
|
private final double a;
|
|
private final int b;
|
|
private final double c;
|
|
private final Locale e;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public C15594guz(Locale locale, double d, double d2, int i) {
|
|
this.e = locale;
|
|
this.a = d;
|
|
this.c = d2;
|
|
this.b = i;
|
|
}
|
|
|
|
@Override // o.InterfaceC13170fSr
|
|
public final void b(InterfaceC13168fSp<List<Address>> interfaceC13168fSp) throws Exception {
|
|
try {
|
|
List<Address> b = b();
|
|
if (interfaceC13168fSp.isDisposed()) {
|
|
return;
|
|
}
|
|
interfaceC13168fSp.e(b);
|
|
interfaceC13168fSp.c();
|
|
} catch (Exception e) {
|
|
if (interfaceC13168fSp.isDisposed()) {
|
|
return;
|
|
}
|
|
interfaceC13168fSp.c(e);
|
|
}
|
|
}
|
|
|
|
private List<Address> b() throws IOException, JSONException {
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(String.format(Locale.ENGLISH, "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=true&language=%3$s", Double.valueOf(this.a), Double.valueOf(this.c), this.e.getLanguage())).openConnection();
|
|
StringBuilder sb = new StringBuilder();
|
|
ArrayList arrayList = new ArrayList();
|
|
try {
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8"));
|
|
while (true) {
|
|
String readLine = bufferedReader.readLine();
|
|
if (readLine == null) {
|
|
break;
|
|
}
|
|
sb.append(readLine);
|
|
}
|
|
JSONObject jSONObject = new JSONObject(sb.toString());
|
|
if ("ZERO_RESULTS".equalsIgnoreCase(jSONObject.getString(CommonConstant.KEY_STATUS))) {
|
|
return Collections.emptyList();
|
|
}
|
|
if (!"OK".equalsIgnoreCase(jSONObject.getString(CommonConstant.KEY_STATUS))) {
|
|
throw new RuntimeException("Wrong API response");
|
|
}
|
|
JSONArray jSONArray = jSONObject.getJSONArray("results");
|
|
for (int i = 0; i < jSONArray.length() && i < this.b; i++) {
|
|
Address address = new Address(Locale.getDefault());
|
|
JSONObject jSONObject2 = jSONArray.getJSONObject(i);
|
|
JSONArray jSONArray2 = jSONObject2.getJSONArray("address_components");
|
|
String str = "";
|
|
for (int i2 = 0; i2 < jSONArray2.length(); i2++) {
|
|
String string = jSONArray2.getJSONObject(i2).getString("long_name");
|
|
String string2 = jSONArray2.getJSONObject(i2).getString("short_name");
|
|
String string3 = jSONArray2.getJSONObject(i2).getJSONArray("types").getString(0);
|
|
if (!TextUtils.isEmpty(string)) {
|
|
if (string3.equalsIgnoreCase(PlaceTypes.STREET_NUMBER)) {
|
|
if (TextUtils.isEmpty(str)) {
|
|
str = string;
|
|
} else {
|
|
StringBuilder sb2 = new StringBuilder();
|
|
sb2.append(str);
|
|
sb2.append(" ");
|
|
sb2.append(string);
|
|
str = sb2.toString();
|
|
}
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.ROUTE)) {
|
|
if (!TextUtils.isEmpty(str)) {
|
|
StringBuilder sb3 = new StringBuilder();
|
|
sb3.append(string);
|
|
sb3.append(" ");
|
|
sb3.append(str);
|
|
str = sb3.toString();
|
|
}
|
|
str = string;
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.SUBLOCALITY)) {
|
|
address.setSubLocality(string);
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.LOCALITY)) {
|
|
address.setLocality(string);
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.ADMINISTRATIVE_AREA_LEVEL_2)) {
|
|
address.setSubAdminArea(string);
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.ADMINISTRATIVE_AREA_LEVEL_1)) {
|
|
address.setAdminArea(string);
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.COUNTRY)) {
|
|
address.setCountryName(string);
|
|
address.setCountryCode(string2);
|
|
} else if (string3.equalsIgnoreCase(PlaceTypes.POSTAL_CODE)) {
|
|
address.setPostalCode(string);
|
|
}
|
|
}
|
|
}
|
|
String string4 = jSONObject2.getString("formatted_address");
|
|
if (!TextUtils.isEmpty(string4)) {
|
|
String[] split = string4.split(",");
|
|
for (int i3 = 0; i3 < split.length; i3++) {
|
|
address.setAddressLine(i3, split[i3].trim());
|
|
}
|
|
} else if (!TextUtils.isEmpty(str)) {
|
|
address.setAddressLine(0, str);
|
|
}
|
|
arrayList.add(address);
|
|
}
|
|
httpURLConnection.disconnect();
|
|
return Collections.unmodifiableList(arrayList);
|
|
} finally {
|
|
httpURLConnection.disconnect();
|
|
}
|
|
}
|
|
}
|