正在查看: WeatherSense v1.8.9 应用的 MapActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: WeatherSense v1.8.9 应用的 MapActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.emax.weather.ui.activity;
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Location;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.CharacterStyle;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.alibaba.pdns.DNSResolver;
import com.emax.weahter.R;
import com.emax.weather.adapter.AddressAdapter;
import com.emax.weather.adapter.AmapAddressAdapter;
import com.emax.weather.base.MvpBaseActivity;
import com.emax.weather.base.RxBus;
import com.emax.weather.bean.Device;
import com.emax.weather.bean.DeviceLocation;
import com.emax.weather.bean.LatLngData;
import com.emax.weather.bean.RxBusEvent;
import com.emax.weather.bean.db.DaoHadle;
import com.emax.weather.bean.yahoo.YahooWeather;
import com.emax.weather.event.IMapManager;
import com.emax.weather.event.MapLocationEvent;
import com.emax.weather.presenter.MapLocationPresenterImp;
import com.emax.weather.util.AndroidScheduler;
import com.emax.weather.utils.MapFactory;
import com.emax.weather.utils.MyInternalStorage;
import com.emax.weather.widget.MapPopWindow;
import com.emax.weather.widget.SetLocationDialog;
import com.ezon.health.utils_lib.ToastUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.places.AutocompletePrediction;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.gson.Gson;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
public class MapActivity extends MvpBaseActivity<MapLocationEvent.MapLocationView, MapLocationPresenterImp> implements MapLocationEvent.MapLocationView, AddressAdapter.ItemAddressListener, MapFactory.OnMapMoveListener, SetLocationDialog.retryListener {
private String action;
private AddressAdapter addressAdapter;
@BindView(R.id.address_list)
RecyclerView addressList;
private AmapAddressAdapter amapAddressAdapter;
@BindView(R.id.back_location)
ImageView backLocation;
@BindView(R.id.back_sub)
ImageView backSub;
@BindView(R.id.cancel)
TextView cancel;
private DeviceLocation deviceLocation;
private Disposable disposable;
private LatLngData latLng;
private Location mLocation;
private String mac;
private MapFactory mapFactory;
private IMapManager mapManager;
private MapPopWindow mapPopWindow;
@BindView(R.id.marker_img)
ImageView markerImg;
private Address moveAddress;
@BindView(R.id.my_location)
ImageView myLocation;
@BindView(R.id.page_layout)
RelativeLayout pageLayout;
@BindView(R.id.parent_map)
FrameLayout parentMap;
@BindView(R.id.search_et)
EditText searchEt;
@BindView(R.id.search_rl)
LinearLayout searchRl;
@BindView(R.id.setting)
TextView setting;
@BindView(R.id.title_rl)
RelativeLayout titleRl;
@BindView(R.id.title_sub)
TextView titleSub;
private int type;
private static final CharacterStyle STYLE_BOLD = new StyleSpan(1);
private static final LatLngBounds BOUNDS_GREATER_SYDNEY = new LatLngBounds(new LatLng(-34.041458d, 150.7901d), new LatLng(-33.682247d, 151.383362d));
private Boolean isSearch = true;
private Boolean isMove = false;
private Boolean isInChina = false;
private boolean isLog = true;
@Override
protected int getActivityRId() {
return R.layout.activity_map;
}
@Override
public Context getContext() {
return this;
}
@Override
public String getDeviceMac() {
return "";
}
@Override
public void showLoadingViews() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
this.mapFactory = new MapFactory(this, this.parentMap, getFragmentManager(), this);
initView();
this.disposable = RxBus.getInstance().toObserverable(RxBusEvent.class).subscribeOn(AndroidScheduler.mainThread()).subscribe(new Consumer() {
public final void accept(Object obj) {
MapActivity.this.lambda$onCreate$0$MapActivity((RxBusEvent) obj);
}
});
}
public void lambda$onCreate$0$MapActivity(RxBusEvent rxBusEvent) throws Exception {
if (MainActivity.NOT_DEVICE.equals(rxBusEvent.getUpdateTheData()) && this.isLog) {
this.isLog = false;
dismissLoadingViews();
Toast.makeText(this, rxBusEvent.getError(), 0).show();
}
}
private void checkDevice() {
String stringExtra = getIntent().getStringExtra("ACTION");
this.action = stringExtra;
if (DNSResolver.QTYPE_IPV4.equals(stringExtra)) {
DeviceLocation deviceLocation = DaoHadle.getDeviceLocation();
this.deviceLocation = deviceLocation;
if (deviceLocation == null) {
showLocation();
return;
}
Log.i("MapActivity", "lyq deviceLocation lat:" + this.deviceLocation.getLat() + ",lng:" + this.deviceLocation.getLng());
if (this.deviceLocation.getLat() == 0.0f && this.deviceLocation.getLng() == 0.0f) {
showLocation();
return;
} else {
showLocation(this.deviceLocation.getCity(), this.deviceLocation.getLat(), this.deviceLocation.getLng());
return;
}
}
showLocation();
}
@Override
public MapLocationPresenterImp createPresenter() {
return new MapLocationPresenterImp(this, this);
}
private void initView() {
this.titleSub.setText(getString(R.string.Device_Location));
int intExtra = getIntent().getIntExtra("TYPE", 0);
this.type = intExtra;
if (intExtra == 1) {
this.setting.setText(getString(R.string.Done));
} else {
this.setting.setText(getString(R.string.next));
}
this.setting.setVisibility(0);
this.addressList.setLayoutManager(new LinearLayoutManager(this));
this.addressList.setItemAnimator(new DefaultItemAnimator());
this.addressList.setHasFixedSize(true);
this.mapPopWindow = new MapPopWindow(this);
}
private void showLocation(String city, double lat, double lon) {
this.latLng = new LatLngData(lat, lon);
if (this.mapManager == null) {
this.mapManager = this.mapFactory.getMapManager();
}
this.mapManager.bind(city, this.latLng.getLatitude(), this.latLng.getLongitude());
this.isSearch = true;
}
private void showLocation() {
if (this.mapManager == null) {
this.mapManager = this.mapFactory.getMapManager();
}
this.mapManager.bind();
this.isSearch = true;
}
@Override
public void initGoogleApi(GoogleApiClient googleApiClient) {
AddressAdapter addressAdapter = new AddressAdapter(this, googleApiClient, BOUNDS_GREATER_SYDNEY, null, this);
this.addressAdapter = addressAdapter;
this.addressList.setAdapter(addressAdapter);
}
@Override
public void mapManager(IMapManager mapManager, final boolean isInChina) {
this.mapManager = mapManager;
this.isInChina = Boolean.valueOf(isInChina);
if (isInChina) {
AmapAddressAdapter amapAddressAdapter = new AmapAddressAdapter(this, this);
this.amapAddressAdapter = amapAddressAdapter;
this.addressList.setAdapter(amapAddressAdapter);
}
checkDevice();
this.searchEt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
String obj = MapActivity.this.searchEt.getText().toString();
if (isInChina) {
return;
}
if (!TextUtils.isEmpty(obj)) {
if (MapActivity.this.isSearch.booleanValue()) {
MapActivity.this.addressAdapter.getFilter().filter(obj);
}
MapActivity.this.searchRl.setPadding(20, 20, 20, 20);
MapActivity.this.cancel.setVisibility(0);
return;
}
MapActivity.this.isSearch = true;
MapActivity.this.cancel.setVisibility(8);
MapActivity.this.addressAdapter.setCleanData();
MapActivity.this.searchRl.setPadding(60, 20, 60, 20);
}
});
}
@Override
public void dismissLoadingViews() {
System.out.println("lyq MapActivity dismissLoadingViews");
showDialogNoMsg();
dismissProgressDialog();
}
public void showLoadingViews(String msg) {
showDialogMsg(msg);
showProgressDialog();
}
@Override
public void showErrorViews(int errorCode, String msg) {
try {
ToastUtil.show(msg, this);
dismissProgressDialog();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void refreshContentView(int type, DeviceLocation data) {
this.deviceLocation = data;
}
@Override
public void showToastMessage(int msg) {
ToastUtil.show(getString(msg), this);
}
@Override
protected void onPause() {
super.onPause();
IMapManager iMapManager = this.mapManager;
if (iMapManager != null) {
iMapManager.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
IMapManager iMapManager = this.mapManager;
if (iMapManager != null) {
iMapManager.onResume();
}
}
@Override
public void onDestroy() {
IMapManager iMapManager = this.mapManager;
if (iMapManager != null) {
iMapManager.onDestroy();
}
super.onDestroy();
Disposable disposable = this.disposable;
if (disposable == null || disposable.isDisposed()) {
return;
}
this.disposable.dispose();
}
@Override
public void select(View v, AutocompletePrediction prediction) {
this.isSearch = false;
if (this.isInChina.booleanValue()) {
return;
}
this.searchEt.setText(prediction.getFullText(STYLE_BOLD).toString());
this.addressAdapter.setCleanData();
this.mapManager.getPlaceInfo(prediction);
}
@OnClick({R.id.setting, R.id.cancel, R.id.my_location, R.id.back_location, R.id.marker_img})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.back_location:
IMapManager iMapManager = this.mapManager;
if (iMapManager != null) {
DeviceLocation deviceLocation = this.deviceLocation;
if (deviceLocation != null) {
iMapManager.bind(deviceLocation.getCity(), this.deviceLocation.getLat(), this.deviceLocation.getLng());
break;
} else {
iMapManager.bind();
break;
}
}
break;
case R.id.cancel:
this.addressAdapter.setCleanData();
break;
case R.id.my_location:
IMapManager iMapManager2 = this.mapManager;
if (iMapManager2 != null) {
iMapManager2.myLocation();
break;
}
break;
case R.id.setting:
if (this.mapManager != null) {
showProgressDialog();
this.mapManager.getAddressDetail();
break;
}
break;
}
}
@Override
public void move() {
if (this.isMove.booleanValue()) {
return;
}
this.isMove = true;
this.markerImg.setVisibility(0);
}
@Override
public void step(LatLngData latLngData) {
if (this.isMove.booleanValue()) {
this.latLng = latLngData;
}
}
@Override
public void setMoveAddress(Address moveAddress) {
System.out.println("lyq setMoveAddress");
this.moveAddress = moveAddress;
((MapLocationPresenterImp) this.mPresenter).saveLocationInfo();
}
@Override
public void setMoveAddressFail() {
System.out.println("lyq setMoveAddressFail");
dismissProgressDialog();
Toast.makeText(this, getString(R.string.location_failed), 0).show();
}
@Override
public void saveLocationSuccess(DeviceLocation deviceLocation) {
System.out.println("lyq saveLocationSuccess 去请求雅虎天气");
((MapLocationPresenterImp) this.mPresenter).getYahooData(deviceLocation.getCountry() + "," + deviceLocation.getCity());
}
@Override
public Address getAddress() {
return this.moveAddress;
}
@Override
public Boolean isChina() {
return this.isInChina;
}
@Override
public Long getTime() {
return this.mapManager.getLocationTime();
}
@Override
public int getType() {
return this.type;
}
@Override
public void refreshYahooDataSuccess(YahooWeather weather) {
System.out.println("lyq MapActivity dismissLoadingViews refreshYahooDataSuccess");
dismissLoadingViews();
final String json = new Gson().toJson(weather);
Observable.create(new ObservableOnSubscribe() {
public final void subscribe(ObservableEmitter observableEmitter) {
MapActivity.this.lambda$refreshYahooDataSuccess$1$MapActivity(json, observableEmitter);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidScheduler.mainThread()).subscribe(new Consumer() {
public final void accept(Object obj) {
MapActivity.this.lambda$refreshYahooDataSuccess$2$MapActivity((String) obj);
}
});
}
public void lambda$refreshYahooDataSuccess$1$MapActivity(String str, ObservableEmitter observableEmitter) throws Exception {
try {
new MyInternalStorage(this).save("YahooData.txt", str);
observableEmitter.onNext("");
} catch (Exception unused) {
observableEmitter.onNext(str);
}
observableEmitter.onComplete();
}
public void lambda$refreshYahooDataSuccess$2$MapActivity(String str) throws Exception {
if (this.type == 1) {
startActivity(new Intent(this, (Class<?>) MainActivity.class));
} else {
startActivity(new Intent(this, (Class<?>) SelectW1W2Activity.class));
}
}
@Override
public void refreshYahooDataFail() {
dismissLoadingViews();
Toast.makeText(this, getResources().getString(R.string.get_online_weather_fail), 0).show();
}
@Override
public void bindDeviceSuccess(Device device) {
this.mapManager.myLocation();
}
@Override
public void onBackPressed() {
super.onBackPressed();
startActivity(new Intent(this, (Class<?>) MainActivity.class));
}
@Override
public void retry() {
this.mapManager.getAddressDetail();
}
}