|
|
@@ -1,24 +1,48 @@
|
|
|
package com.xzjmyk.pm.activity.ui.me;
|
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
import android.widget.Button;
|
|
|
-import android.widget.ListView;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.baidu.mapapi.search.core.PoiInfo;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.bean.oa.SelectBean;
|
|
|
import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.oa.LocationSearchActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.oa.SelectActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.view.MyListView;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by FANGlh on 2017/1/16.
|
|
|
* function: 办公地址设置
|
|
|
*/
|
|
|
public class OfficeAddressSettingsActivity extends BaseActivity{
|
|
|
+ private static final int EFFECTIVE_DISTANCE = 0x117;
|
|
|
private TextView range_value; //范围
|
|
|
- private ListView address_lv; //地址列表
|
|
|
+ private MyListView address_lv; //地址列表
|
|
|
private RelativeLayout add_address; // + 添加办公地址
|
|
|
private Button save_btn; // 保存
|
|
|
+ private OfficeAddressAdapter myadapter;
|
|
|
+ private int search_rangge = 0;
|
|
|
+ private final int ADDRESS_CHANGE = 0x14;
|
|
|
+ private List<String> address_names;
|
|
|
+ private List<String> address_latitud; //经度
|
|
|
+ private List<String> address_longitude; //纬度
|
|
|
+ private int address_size;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -29,23 +53,48 @@ public class OfficeAddressSettingsActivity extends BaseActivity{
|
|
|
}
|
|
|
private void initView() {
|
|
|
range_value = (TextView) findViewById(R.id.of_add_set_range_value);
|
|
|
- address_lv = (ListView) findViewById(R.id.of_add_set_address_lv);
|
|
|
+ address_lv = (MyListView) findViewById(R.id.of_add_set_address_lv);
|
|
|
add_address = (RelativeLayout) findViewById(R.id.of_add_set_addaddress_rl);
|
|
|
save_btn = (Button) findViewById(R.id.of_add_set_save_bt);
|
|
|
+
|
|
|
+ address_names = new ArrayList<>();
|
|
|
+ address_latitud = new ArrayList<>();
|
|
|
+ address_longitude = new ArrayList<>();
|
|
|
+ myadapter = new OfficeAddressAdapter();
|
|
|
+ address_lv.setAdapter(myadapter);
|
|
|
}
|
|
|
|
|
|
private void clickEvent(){
|
|
|
+
|
|
|
range_value.setOnClickListener(new View.OnClickListener() {
|
|
|
+ int requestCode = 0;
|
|
|
+ String[] distance = null;
|
|
|
+
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
+ requestCode = EFFECTIVE_DISTANCE;
|
|
|
+ distance = getResources().getStringArray(R.array.effective_distance);
|
|
|
|
|
|
+ ArrayList<SelectBean> beans = new ArrayList<>();
|
|
|
+ SelectBean bean = null;
|
|
|
+ for (String e : distance) {
|
|
|
+ bean = new SelectBean();
|
|
|
+ bean.setName(e);
|
|
|
+ bean.setClick(false);
|
|
|
+ beans.add(bean);
|
|
|
+ }
|
|
|
+ Intent intent = new Intent(ct, SelectActivity.class);
|
|
|
+ intent.putExtra("type", 2);
|
|
|
+ intent.putParcelableArrayListExtra("data", beans);
|
|
|
+ intent.putExtra("title", "选择时间");
|
|
|
+ startActivityForResult(intent, requestCode);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
add_address.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- address_lv.setVisibility(View.VISIBLE);
|
|
|
+ searchAddress();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -57,4 +106,121 @@ public class OfficeAddressSettingsActivity extends BaseActivity{
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void searchAddress() {
|
|
|
+ search_rangge = CommonUtil.getNumByString(range_value.getText().toString());
|
|
|
+
|
|
|
+ Intent intent = new Intent(ct, LocationSearchActivity.class);
|
|
|
+ intent.putExtra("type", 1);
|
|
|
+ intent.putExtra("title", "添加办公地址");
|
|
|
+ intent.putExtra("single", true);
|
|
|
+ intent.putExtra("radius", search_rangge);
|
|
|
+// intent.putExtra("latlng", new LatLng(companyLongitude, companyLatitude));
|
|
|
+ intent.putExtra("resultCode", ADDRESS_CHANGE);
|
|
|
+ intent.putExtra("resultName", "resultName");
|
|
|
+ startActivityForResult(intent, ADDRESS_CHANGE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ myadapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (data == null) return;
|
|
|
+ if (resultCode == 0x20) {
|
|
|
+ SelectBean b = data.getParcelableExtra("data");
|
|
|
+ if (b == null) return;
|
|
|
+ String selected_distance = StringUtils.isEmpty(b.getName()) ? "" : b.getName();
|
|
|
+ if (requestCode == EFFECTIVE_DISTANCE) {
|
|
|
+ range_value.setText(selected_distance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (requestCode == ADDRESS_CHANGE && resultCode == ADDRESS_CHANGE) {//地址微调
|
|
|
+ PoiInfo poi = data.getParcelableExtra("resultName");
|
|
|
+ if (poi == null) return;
|
|
|
+ //TODO 将每次点击地址返回的值add到自定义列表中,
|
|
|
+ address_lv.setVisibility(View.VISIBLE);
|
|
|
+ address_names.add(poi.name);
|
|
|
+// address_latitud.add(String.valueOf(poi.location.latitude));
|
|
|
+// address_longitude.add(String.valueOf(poi.location.longitude));
|
|
|
+ }
|
|
|
+ myadapter.setAddress_names(address_names);
|
|
|
+ address_size = address_names.size();
|
|
|
+ myadapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ public class OfficeAddressAdapter extends BaseAdapter{
|
|
|
+ private List<String> address_names;
|
|
|
+ private int mPosition;
|
|
|
+
|
|
|
+ public List<String> getAddress_names() {
|
|
|
+ return address_names;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAddress_names(List<String> address_names) {
|
|
|
+ this.address_names = address_names;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return address_size;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getItem(int position) {
|
|
|
+ return address_names.get(position);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getItemId(int position) {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
+ ViewHolder viewHolder = null;
|
|
|
+ if (convertView == null){
|
|
|
+ convertView = View.inflate(mContext, R.layout.office_address_item,null);
|
|
|
+ viewHolder = new ViewHolder();
|
|
|
+ viewHolder.item_address_tv = (TextView) convertView.findViewById(R.id.item_address_tv);
|
|
|
+ viewHolder.office_address_delete_im = (ImageView) convertView.findViewById(R.id.item_address_delete_im);
|
|
|
+ convertView.setTag(viewHolder);
|
|
|
+ }else {
|
|
|
+ viewHolder = (ViewHolder) convertView.getTag();
|
|
|
+ }
|
|
|
+ //ToDo 带回地址的显示
|
|
|
+ if (!ListUtils.isEmpty(address_names)){
|
|
|
+ viewHolder.item_address_tv.setText(address_names.get(position));
|
|
|
+ }
|
|
|
+ //TODo 地址的删除操作
|
|
|
+ viewHolder.office_address_delete_im.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ new AlertDialog.Builder(mContext)
|
|
|
+ .setTitle("温馨提示")
|
|
|
+ .setMessage("确认删除该条已选办公地址?")
|
|
|
+ .setNegativeButton("取消",null)
|
|
|
+ .setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ mPosition = position;
|
|
|
+ doDeleteAddress();
|
|
|
+ }
|
|
|
+ }).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doDeleteAddress() {
|
|
|
+ address_names.remove(mPosition);
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHolder{
|
|
|
+ TextView item_address_tv;
|
|
|
+ ImageView office_address_delete_im;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|