CompanyMainFragment.java
5.6 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.hh.xuetubao.fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MyLocationStyle;
import com.hh.xuetubao.MyServer;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.BaseObsever;
import com.hh.xuetubao.Utils.HttpUtils;
import com.hh.xuetubao.Utils.NetConfig;
import com.hh.xuetubao.bean.CompanyDetailBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* 公司主页
*/
public class CompanyMainFragment extends Fragment {
@BindView(R.id.nature)
TextView nature;
@BindView(R.id.count)
TextView count;
@BindView(R.id.address)
TextView address;
@BindView(R.id.web)
TextView web;
// @BindView(R.id.img_hotel)
// ImageView imgHotel;
@BindView(R.id.tv_content)
TextView tvContent;
@BindView(R.id.tv_dingwei)
TextView tvDingwei;
private Float precision;
private Float latitude;
Unbinder unbinder;
@BindView(R.id.map)
MapView map;
private MyServer mServers;
private AMap aMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_company_main, null);
unbinder = ButterKnife.bind(this, view);
map = (MapView) view.findViewById(R.id.map);
map.onCreate(savedInstanceState);
String companyOid = getTag();
doRequest(companyOid);
// initMap();
return view;
}
private void initMap(Float a, Float b) {
if (aMap == null) {
aMap = map.getMap();
}
CameraPosition cameraPosition = aMap.getCameraPosition();
CameraPosition cpNew = CameraPosition.fromLatLngZoom(new LatLng(a, b), cameraPosition.zoom);
CameraUpdate cu = CameraUpdateFactory.newCameraPosition(cpNew);
aMap.moveCamera(cu);
MyLocationStyle myLocationStyle;
myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE);//定位一次,且将视角移动到地图中心点
myLocationStyle.showMyLocation(true);
myLocationStyle.anchor(a, b);//设置定位蓝点图标的锚点方法
aMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style
//aMap.getUiSettings().setMyLocationButtonEnabled(true);设置默认定位按钮是否显示,非必需设置。
aMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
}
private void doRequest(String companyOid) {
mServers = HttpUtils.getInstance().getServer(NetConfig.zhaopinUrl);
mServers.CompanyDetailInfo(companyOid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
@Override
public void onNext(Object value) {
super.onNext(value);
CompanyDetailBean bean = (CompanyDetailBean) value;
latitude = Float.valueOf(bean.getLat());
precision = Float.valueOf(bean.getLng());
initMap(latitude, precision);
if (bean.getCompanyNature() != null)
nature.setText(bean.getCompanyNature());
if (bean.getCompanySize() != null)
count.setText(bean.getCompanySize());
if (bean.getAddress() != null)
address.setText(bean.getAddress());
if (bean.getWebSite() != null)
web.setText(bean.getWebSite());
if (bean.getCompanyLogoPic() != null)
// Glide.with(getActivity()).load(bean.getCompanyLogoPic()).into(imgHotel);
if (bean.getIntroduction() != null)
tvContent.setText(Html.fromHtml(bean.getIntroduction()));
if (bean.getFullAddress() != null)
tvDingwei.setText(bean.getFullAddress());
}
});
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
@Override
public void onResume() {
super.onResume();
map.onResume();
}
@Override
public void onPause() {
super.onPause();
map.onPause();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
map.onSaveInstanceState(outState);
}
}