apk(点击下载) / LocationAmapActivity.java
package com.gaoyuan.mianshu.location.activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.AMapUtils;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.UiSettings;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.gaoyuan.mianshu.l.b.b;
import com.gaoyuan.mianshu.l.b.c;
import com.gaoyuan.mianshu.location.model.NimLocation;
import com.netease.nim.uikit.api.model.location.LocationProvider;
import com.netease.nim.uikit.common.activity.UI;
import com.xiaomi.mipush.sdk.Constants;
import p001x2793113f.R;
public class LocationAmapActivity extends UI implements AMap.OnCameraChangeListener, View.OnClickListener, c.d {
private static LocationProvider.Callback t;
private TextView a;
private TextView b;
private ImageView c;
/* renamed from: d reason: collision with root package name */
private View f1272d;
private TextView e;
private com.gaoyuan.mianshu.l.b.c f = null;
private double g;
private double h;
private String i;
private double j = -1.0d;
private double k = -1.0d;
private String l;
private boolean m = true;
private com.gaoyuan.mianshu.l.b.b n;
AMap o;
private MapView p;
private Button q;
private b.f r = new b();
private Runnable s = new c();
/* access modifiers changed from: package-private */
public class a implements View.OnClickListener {
a() {
}
public void onClick(View view) {
LocationAmapActivity.this.finish();
}
}
class b implements b.f {
b() {
}
@Override // com.gaoyuan.mianshu.l.b.b.f
public void a(NimLocation nimLocation) {
if (LocationAmapActivity.this.g == nimLocation.c() && LocationAmapActivity.this.h == nimLocation.d()) {
if (nimLocation.e()) {
LocationAmapActivity.this.i = nimLocation.b();
} else {
LocationAmapActivity locationAmapActivity = LocationAmapActivity.this;
locationAmapActivity.i = locationAmapActivity.getString(R.string.location_address_unkown);
}
LocationAmapActivity.this.u(true);
LocationAmapActivity.this.m();
}
}
}
class c implements Runnable {
c() {
}
public void run() {
LocationAmapActivity locationAmapActivity = LocationAmapActivity.this;
locationAmapActivity.i = locationAmapActivity.getString(R.string.location_address_unkown);
LocationAmapActivity.this.u(true);
}
}
private void initView() {
this.a = (TextView) findView(R.id.tv_title);
TextView textView = (TextView) findView(R.id.tv_right_btn);
this.b = textView;
textView.setText(R.string.send);
this.b.setOnClickListener(this);
this.b.setVisibility(4);
((ImageButton) findView(R.id.btn_back)).setOnClickListener(new a());
this.c = (ImageView) findViewById(R.id.location_pin);
View findViewById = findViewById(R.id.location_info);
this.f1272d = findViewById;
this.e = (TextView) findViewById.findViewById(R.id.marker_address);
this.c.setOnClickListener(this);
this.f1272d.setOnClickListener(this);
Button button = (Button) findViewById(R.id.my_location);
this.q = button;
button.setOnClickListener(this);
this.q.setVisibility(8);
}
/* access modifiers changed from: private */
/* access modifiers changed from: public */
private void m() {
getHandler().removeCallbacks(this.s);
}
private String n() {
return "http://maps.google.cn/maps/api/staticmap?size=200x100&zoom=13&markers=color:red|label:YourPosition|" + this.g + Constants.ACCEPT_TIME_SEPARATOR_SP + this.h + "&maptype=roadmap&sensor=false&format=jpg";
}
private void o() {
try {
AMap map = this.p.getMap();
this.o = map;
map.setOnCameraChangeListener(this);
UiSettings uiSettings = this.o.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
uiSettings.setMyLocationButtonEnabled(false);
} catch (Exception e2) {
e2.printStackTrace();
}
}
private void p() {
LatLng latLng;
com.gaoyuan.mianshu.l.b.c cVar = new com.gaoyuan.mianshu.l.b.c(this, this);
this.f = cVar;
Location e2 = cVar.e();
float intExtra = (float) getIntent().getIntExtra("zoom_level", 15);
if (e2 == null) {
latLng = new LatLng(39.90923d, 116.397428d);
} else {
latLng = new LatLng(e2.getLatitude(), e2.getLongitude());
}
this.o.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng, intExtra, 0.0f, 0.0f)));
this.n = new com.gaoyuan.mianshu.l.b.b(this, this.r);
}
private boolean q() {
return this.f1272d.getVisibility() == 0;
}
private void r(double d2, double d3, String str) {
if (this.o != null) {
LatLng latLng = new LatLng(d2, d3);
CameraPosition cameraPosition = null;
try {
cameraPosition = this.o.getCameraPosition();
} catch (Throwable unused) {
}
this.o.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng, cameraPosition == null ? cameraPosition.zoom : 17.0f, 0.0f, 0.0f)));
this.i = str;
this.g = d2;
this.h = d3;
u(true);
}
}
private void s(LatLng latLng) {
if (TextUtils.isEmpty(this.i) || latLng.latitude != this.g || latLng.longitude != this.h) {
Handler handler = getHandler();
handler.removeCallbacks(this.s);
handler.postDelayed(this.s, 20000);
this.n.n(latLng.latitude, latLng.longitude);
this.g = latLng.latitude;
this.h = latLng.longitude;
this.i = null;
u(false);
}
}
private void t() {
Intent intent = new Intent();
intent.putExtra("latitude", this.g);
intent.putExtra("longitude", this.h);
String string = TextUtils.isEmpty(this.i) ? getString(R.string.location_address_unkown) : this.i;
this.i = string;
intent.putExtra("address", string);
intent.putExtra("zoom_level", this.o.getCameraPosition() == null ? this.o.getCameraPosition().zoom : 17.0f);
intent.putExtra("img_url", n());
LocationProvider.Callback callback = t;
if (callback != null) {
callback.onSuccess(this.h, this.g, this.i);
}
}
/* access modifiers changed from: private */
/* access modifiers changed from: public */
private void u(boolean z) {
if (!z || TextUtils.isEmpty(this.i)) {
this.f1272d.setVisibility(8);
} else {
this.f1272d.setVisibility(0);
this.e.setText(this.i);
}
x();
}
public static void v(Context context, LocationProvider.Callback callback) {
t = callback;
context.startActivity(new Intent(context, LocationAmapActivity.class));
}
private void w(CameraPosition cameraPosition) {
if (Math.abs(-1.0d - this.j) >= 0.10000000149011612d) {
int i2 = 0;
boolean z = AMapUtils.calculateLineDistance(new LatLng(this.j, this.k), cameraPosition.target) > 50.0f;
Button button = this.q;
if (!z) {
i2 = 8;
}
button.setVisibility(i2);
x();
}
}
private void x() {
if (!isFinishing()) {
int i2 = R.string.location_map;
if (TextUtils.isEmpty(this.i)) {
i2 = R.string.location_loading;
this.b.setVisibility(8);
} else {
this.b.setVisibility(0);
}
if (this.q.getVisibility() == 0 || Math.abs(-1.0d - this.j) < 0.10000000149011612d) {
this.a.setText(i2);
} else {
this.a.setText(R.string.my_location);
}
}
}
@Override // com.gaoyuan.mianshu.l.b.c.d
public void d(NimLocation nimLocation) {
if (nimLocation != null && nimLocation.f()) {
this.j = nimLocation.c();
this.k = nimLocation.d();
String a2 = nimLocation.a();
this.l = a2;
if (this.m) {
this.m = false;
r(this.j, this.k, a2);
}
}
}
@Override // com.amap.api.maps2d.AMap.OnCameraChangeListener
public void onCameraChange(CameraPosition cameraPosition) {
}
@Override // com.amap.api.maps2d.AMap.OnCameraChangeListener
public void onCameraChangeFinish(CameraPosition cameraPosition) {
if (!this.m) {
s(cameraPosition.target);
} else {
LatLng latLng = cameraPosition.target;
this.g = latLng.latitude;
this.h = latLng.longitude;
}
w(cameraPosition);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.location_info /*{ENCODED_INT: 2131296843}*/:
this.f1272d.setVisibility(8);
return;
case R.id.location_pin /*{ENCODED_INT: 2131296844}*/:
u(!q());
return;
case R.id.my_location /*{ENCODED_INT: 2131296943}*/:
r(this.j, this.k, this.l);
return;
case R.id.tv_right_btn /*{ENCODED_INT: 2131297414}*/:
t();
finish();
return;
default:
return;
}
}
@Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, androidx.fragment.app.FragmentActivity, com.netease.nim.uikit.common.activity.UI
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.map_view_amap_layout);
MapView mapView = (MapView) findViewById(R.id.autonavi_mapView);
this.p = mapView;
mapView.onCreate(bundle);
initView();
o();
p();
x();
}
/* access modifiers changed from: protected */
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.netease.nim.uikit.common.activity.UI
public void onDestroy() {
super.onDestroy();
this.p.onDestroy();
com.gaoyuan.mianshu.l.b.c cVar = this.f;
if (cVar != null) {
cVar.j();
}
t = null;
}
/* access modifiers changed from: protected */
@Override // androidx.fragment.app.FragmentActivity, com.netease.nim.uikit.common.activity.UI
public void onPause() {
super.onPause();
this.p.onPause();
this.f.j();
}
/* access modifiers changed from: protected */
@Override // androidx.fragment.app.FragmentActivity, com.netease.nim.uikit.common.activity.UI
public void onResume() {
super.onResume();
this.p.onResume();
this.f.i();
}
/* access modifiers changed from: protected */
@Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity
public void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
this.p.onSaveInstanceState(bundle);
}
}