try { // if (baos != null) { // baos.flush(); // baos.close(); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // return result; // } // private void submitShare( String sms) { // // Log.e("url", sms); // Request request = new Request.Builder().url(sms).build(); // Response response = null; // try{ // if(request==null){ // Message msg = new Message(); // msg.what=3; // handler.sendMessage(msg); // return; // } // response = OkHttpUtil.execute(request); // if (response.code() == 200) { // String json = ""; // try { // json = response.body().string(); // Message msg = new Message(); // msg.obj = json; // msg.what=2; // handler.sendMessage(msg); // Log.e("url", json); // }catch (Exception e){ // e.printStackTrace(); // Message msg = new Message(); // msg.what=3; // handler.sendMessage(msg); // } // } // }catch (Exception e){ // e.printStackTrace(); // Message msg = new Message(); // msg.what=3; // handler.sendMessage(msg); // } // } // private boolean checkText() { //// String name = et_name.getText().toString(); //// String address = et_address.getText().toString().trim(); //// String phone = et_phone.getText().toString().trim(); // if (TextUtils.isEmpty(name)) { // Toast.makeText(this, "请输入充电桩名称", Toast.LENGTH_SHORT).show(); // return false; // } // if (TextUtils.isEmpty(address)) { // Toast.makeText(this, "请输入具体地址", Toast.LENGTH_SHORT).show(); // return false; // } // // if (TextUtils.isEmpty(phone)) { // Toast.makeText(this, "请输入您的电话", Toast.LENGTH_SHORT).show(); // return false; // } // if (CheckMobileNum.isMobileNum(phone) == false) { // Toast.makeText(this, "请输入正确的电话号码", Toast.LENGTH_SHORT).show(); // return false; // } // return true; // } // public class MyLocationListenner implements BDLocationListener { // // // @Override // public void onReceiveLocation(BDLocation location) { // try { // if (location == null || mMapView == null) // return; // MyLocationData locData = new MyLocationData.Builder() // .accuracy(location.getRadius()) // .direction(100).latitude(Double.parseDouble(poi_wei)) // .longitude(Double.parseDouble(poi_jing)).build(); // mBaiduMap.setMyLocationData(locData); // if (isFirstLoc) { // isFirstLoc = false; // mLocClient.stop(); // mBaiduMap.setMyLocationEnabled(false); // LatLng ll = new LatLng(Double.parseDouble(poi_wei),Double.parseDouble(poi_jing)); //// LatLng lll = new LatLng() // MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); // mBaiduMap.animateMapStatus(u); // llposition = ll; // city = location.getCity(); // district = location.getDistrict(); // initOverlay(); // } // }catch (Exception e){ // e.printStackTrace(); // // // } // // } // // public void onReceivePoi(BDLocation poiLocation) { // } // } @SuppressLint("HandlerLeak") public class GridAdapter extends BaseAdapter { private LayoutInflater inflater; private int selectedPosition = -1; private boolean shape; public boolean isShape() { return shape; } public void setShape(boolean shape) { this.shape = shape; } public GridAdapter(Context context) { inflater = LayoutInflater.from(context); } public void update() { loading(); } public int getCount() { if (Bimp.tempSelectBitmap.size() == 3) { return 3; } return (Bimp.tempSelectBitmap.size() + 1); } public Object getItem(int arg0) { return null; } public long getItemId(int arg0) { return 0; } public void setSelectedPosition(int position) { selectedPosition = position; } public int getSelectedPosition() { return selectedPosition; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { convertView = inflater.inflate(R.layout.item_published_grida, parent, false); holder = new ViewHolder(); holder.image = (ImageView) convertView .findViewById(R.id.item_grida_image); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (position == Bimp.tempSelectBitmap.size()) { holder.image.setImageBitmap(BitmapFactory.decodeResource( getResources(), R.drawable.icon_defaultadd1105)); if (position == 3) { holder.image.setVisibility(View.GONE); } } else { holder.image.setImageBitmap(Bimp.tempSelectBitmap.get(position).getBitmap()); } return convertView; } public class ViewHolder { public ImageView image; } Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1: adapter.notifyDataSetChanged(); break; } super.handleMessage(msg); } }; public void loading() { new Thread(new Runnable() { public void run() { while (true) { if (Bimp.max == Bimp.tempSelectBitmap.size()) { Message message = new Message(); message.what = 1; handler.sendMessage(message); break; } else { Bimp.max += 1; Message message = new Message(); message.what = 1; handler.sendMessage(message); } } } }).start(); } } public String getString(String s) { String path = null; if (s == null) return ""; for (int i = s.length() - 1; i > 0; i++) { s.charAt(i); } return path; } protected void onRestart() { adapter.update(); super.onRestart(); } private static final int TAKE_PICTURE = 0x000001; // public void photo() { // Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // startActivityForResult(openCameraIntent, TAKE_PICTURE); //// Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //// File file = new File(Environment.getExternalStorageDirectory() + "/myimage/", String.valueOf(System //// .currentTimeMillis()) + ".jpg"); //// camePath = file.getPath(); //// Uri imageUri = Uri.fromFile(file); //// intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); //// startActivityForResult(intent, TAKE_PICTURE); // } public void photo() { // Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // startActivityForResult(openCameraIntent, TAKE_PICTURE); // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // File file = new File(Environment.getExternalStorageDirectory() + "/myimage/", String.valueOf(System // .currentTimeMillis()) + ".jpg"); // camePath = file.getPath(); // Uri imageUri = Uri.fromFile(file); // intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // startActivityForResult(intent, TAKE_PICTURE); if (hasSdcard()) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//��������� intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); // intent.putExtra(MediaStore.EXTRA_OUTPUT, cutImgUri); startActivityForResult(intent, PHOTO_REQUEST_CAMERA); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Log.e("isTouch===",isTouch+""); if (isTouch == true) { MarkerOptions oobd = new MarkerOptions().position(llposition) .icon(bdLocation1).zIndex(9).draggable(true).title(zhan_address).period(30); mMarker = (Marker) (aMap.addMarker(oobd)); mMarker.showInfoWindow(); } else { MarkerOptions oobd1 = new MarkerOptions().position(llposition) .icon(bdLocation).zIndex(9).draggable(true); mMarker1 = (Marker) (aMap.addMarker(oobd1)); } System.out.println("--------data------->" + data); //���ѡȡ if (requestCode == PHOTO_REQUEST_CAMERA && resultCode == Activity.RESULT_OK) { //��������ͼƬ�ͽ�ȡ���ͼƬ�ļ���д����ͬһ���ļ���photo.jpg crop(Uri.fromFile(tempFile), Uri.fromFile(tempFile)); } //���ؽ�ȡ��ͼƬ else if (requestCode == PHOTO_REQUEST_CUT && data != null) { //���д�ͼʹ��Uri Bitmap bitmap = decodeUriAsBitmap(Uri.fromFile(tempFile));//decode bitmap // mFace.setImageBitmap(bitmap); String fileName = String.valueOf(System.currentTimeMillis()); ImageItem takePhoto = new ImageItem(); takePhoto.setBitmap(bitmap); takePhoto.setImagePath(FileUtils.SDPATH + fileName + ".JPEG"); Bimp.tempSelectBitmap.add(takePhoto); } else { // Toast.makeText(getApplicationContext(), "��ȡͼƬʧ��", Toast.LENGTH_SHORT).show(); } super.onActivityResult(requestCode, resultCode, data); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { for (int i = 0; i < PublicWay.activityList.size(); i++) { if (null != PublicWay.activityList.get(i)) { PublicWay.activityList.get(i).finish(); } } System.exit(0); } return true; } // private void sendRequest(Map<String, Object> params) { // RequestTask.task("http://app.ulinkmedia.cn/AppHanlder.aspx?callMethod=NewsListPage",params, handler); // } Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 2: try { JSONObject jsonObject = new JSONObject(msg.obj.toString()); String rtnCode = jsonObject.getString("rtnCode"); String rtnMsg = jsonObject.getString("rtnMsg"); if (rtnCode.equals("01")) { dismissDialog(); new com.electric.chargingpile.view.AlertDialog(ClaimSurveyTwoActivity.this).builder() .setMsg("勘察信息提交成功") .setNegativeButton("确定", new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(ClaimSurveyTwoActivity.this, ClaimListActivity.class)); SharedPreferences sharedPreferences = getSharedPreferences("userClaimInfo", Activity.MODE_PRIVATE); sharedPreferences.edit().clear().commit(); // Bimp.tempSelectBitmap.clear(); // PublicWay.activityList.get(i).finish(); // startActivity(new Intent(getApplication(),ShareListActivity.class)); SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication()); sharedPreferencesUtil.setFileName("shareInfo"); sharedPreferencesUtil.clearData(); finish(); } }).show(); // Toast.makeText(ShareTwoActivity.this, rtnMsg, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } break; case StatusConstants.REQUEST_WHAT_SUCCESS: break; } super.handleMessage(msg); } }; @Override protected void onPause() { // aMap.getUiSettings().setAllGesturesEnabled(false); mapView.onPause(); super.onPause(); MobclickAgent.onPause(this); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } @Override protected void onResume() { // aMap.getUiSettings().setAllGesturesEnabled(true); mapView.onResume(); super.onResume(); SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication()); sharedPreferencesUtil.setFileName("shareInfo"); // String address =sharedPreferencesUtil.getString("address", ""); String costway = sharedPreferencesUtil.getString("costWay", ""); // jing =sharedPreferencesUtil.getString("poi_jing", ""); // wei =sharedPreferencesUtil.getString("poi_wei", ""); // String tel =sharedPreferencesUtil.getString("tel", ""); //// String car =sharedPreferencesUtil.getString("car", ""); // String alipay =sharedPreferencesUtil.getString("alipay", ""); // carType.setText(car); // et_share_address.setText(address); costWay.setText(costway); // if (location == null || mMapView == null) // return; // MyLocationData locData = new MyLocationData.Builder() // .accuracy(location.getRadius()) // .direction(100).latitude(Double.parseDouble(poi_wei)) // .longitude(Double.parseDouble(poi_jing)).build(); // mBaiduMap.setMyLocationData(locData); // if (isFirstLoc) { // isFirstLoc = false; // mLocClient.stop(); // mBaiduMap.setMyLocationEnabled(false); // LatLng ll = new LatLng(Double.parseDouble(poi_wei), Double.parseDouble(poi_jing)); //// LatLng lll = new LatLng() // MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); // mBaiduMap.animateMapStatus(u); // llposition = ll; // city = location.getCity(); // district = location.getDistrict(); // initOverlay(); // } // if (isFirstLoc) { // isFirstLoc = false; // mLocClient.stop(); // mBaiduMap.setMyLocationEnabled(false); // LatLng ll = new LatLng(Double.parseDouble(poi_wei),Double.parseDouble(poi_jing)); //// LatLng lll = new LatLng() // MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); // mBaiduMap.animateMapStatus(u); // llposition = ll; // city = location.getCity(); // district = location.getDistrict(); // initOverlay(); // } MobclickAgent.onResume(this); } @Override protected void onDestroy() { Bimp.tempSelectBitmap.clear(); Bimp.max = 0; mapView.onDestroy(); // mMapView = null; super.onDestroy(); // bdLocation.recycle(); } private void crop(Uri uri, Uri cutImgUri) { // �ü�ͼƬ��ͼ Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); // �ü���ı�����1��1 // intent.putExtra("aspectX", 4); // intent.putExtra("aspectY", 3); // �ü������ͼƬ�ijߴ��С // intent.putExtra("outputX", 400); // intent.putExtra("outputY", 300); // ͼƬ��ʽ intent.putExtra("outputFormat", "JPEG"); intent.putExtra("noFaceDetection", true);// ȡ������ʶ�� intent.putExtra("return-data", false);// true:������uri��false������uri intent.putExtra(MediaStore.EXTRA_OUTPUT, cutImgUri);//д���ȡ��ͼƬ startActivityForResult(intent, PHOTO_REQUEST_CUT); } private boolean hasSdcard() { if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { return true; } else { return false; } } private static String getPath(String path) { File f = new File(path); if (!f.exists()) { f.mkdirs(); } return f.getAbsolutePath(); } private File getFile(String path) { File f = new File(path); if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return f; } public Bitmap decodeUriAsBitmap(Uri uri) { Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return bitmap; } private Bitmap imageZoom(Bitmap bm) { // 图片允许最大空间 单位:KB double maxSize = 200.00; // 将bitmap放至数组中,意在bitmap的大小(与实际读取的原文件要大) ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); // 将字节换成KB double mid = b.length / 1024; // 判断bitmap占用空间是否大于允许最大空间 如果大于则压缩 小于则不压缩 if (mid > maxSize) { // 获取bitmap大小 是允许最大大小的多少倍 double i = mid / maxSize; // 开始压缩 此处用到平方根 将宽带和高度压缩掉对应的平方根倍 // (1.保持刻度和高度和原bitmap比率一致,压缩后也达到了最大大小占用空间的大小) bm = zoomImage(bm, bm.getWidth() / Math.sqrt(i), bm.getHeight() / Math.sqrt(i)); } return bm; } public Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) { // 获取这个图片的宽和高 float width = bgimage.getWidth(); float height = bgimage.getHeight(); // 创建操作图片用的matrix对象 Matrix matrix = new Matrix(); // 计算宽高缩放率 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 缩放图片动作 matrix.postScale(scaleWidth, scaleHeight); Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width, (int) height, matrix, true); // iv_2.setImageBitmap(bitmap); // tv_2.setText(bitmap.getRowBytes() * bitmap.getHeight() + ""); return bitmap; } //地图缩放方法 private void controlZoomShow() { float zoom = aMap.getCameraPosition().zoom; try { if (zoom >= maxZoomLevel) { inBtn.setImageResource(R.drawable.icon_nojia2_0); inBtn.setEnabled(false); // Toast.makeText(getApplication(), "已放大到最大级别", Toast.LENGTH_SHORT) // .show(); return; } else { inBtn.setImageResource(R.drawable.icon_jia2_0); inBtn.setEnabled(true); } if (zoom <= minZoomLevel) { outBtn.setImageResource(R.drawable.icon_nojian2_0); outBtn.setEnabled(false); // Toast.makeText(getApplication(), "已缩小到最小级别", Toast.LENGTH_SHORT) // .show(); return; } else { outBtn.setImageResource(R.drawable.icon_jian2_0); outBtn.setEnabled(true); } } catch (Exception e) { e.printStackTrace(); } } private void initMap() { if (aMap == null) { aMap = mapView.getMap(); // View v = mapView.getChildAt(0); // v.setOnTouchListener(new View.OnTouchListener() { // // @Override // public boolean onTouch(View v, MotionEvent event) { // if(event.getAction() == MotionEvent.ACTION_SCROLL){ // scrollView.requestDisallowInterceptTouchEvent(false); // }else{ // scrollView.requestDisallowInterceptTouchEvent(true); // } // return false; // } // }); MyLocationStyle myLocationStyle = new MyLocationStyle(); myLocationStyle.myLocationIcon(BitmapDescriptorFactory .fromResource(R.drawable.point_icon));// 设置小蓝点的图标 aMap.setMyLocationStyle(myLocationStyle); mUiSettings = aMap.getUiSettings(); //获得地图的最大和最小缩放级别 maxZoomLevel = aMap.getMaxZoomLevel(); minZoomLevel = aMap.getMinZoomLevel(); geocoderSearch = new GeocodeSearch(this); geocoderSearch.setOnGeocodeSearchListener(this); setUpMap(); } } private void setUpMap() { aMap.setOnCameraChangeListener(this); aMap.setLocationSource(this);// 设置定位监听 aMap.setOnMapLoadedListener(this); aMap.setInfoWindowAdapter(this); aMap.setOnMapClickListener(this); aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示 aMap.getUiSettings().setZoomControlsEnabled(false);// 设置默认缩放按钮是否显示 aMap.getUiSettings().setScaleControlsEnabled(true);// 设置比例尺是否显示 aMap.getUiSettings().setRotateGesturesEnabled(false);// 设置地图是否旋转 aMap.setOnMapTouchListener(this); } @Override public void onCameraChange(CameraPosition cameraPosition) { } @Override public void onCameraChangeFinish(CameraPosition cameraPosition) { } @Override public void activate(OnLocationChangedListener onLocationChangedListener) { mListener = onLocationChangedListener; if (mlocationClient == null) { mlocationClient = new AMapLocationClient(this); mLocationOption = new AMapLocationClientOption(); //设置定位监听 mlocationClient.setLocationListener(this); //设置为高精度定位模式 mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); //设置定位参数 mlocationClient.setLocationOption(mLocationOption); // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, // 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求 // 在定位结束后,在合适的生命周期调用onDestroy()方法 // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除 // 设置是否只定位一次,默认为false mLocationOption.setOnceLocation(true); //设置是否强制刷新WIFI,默认为强制刷新 mLocationOption.setWifiActiveScan(false); mlocationClient.startLocation(); } } @Override public void deactivate() { mListener = null; if (mlocationClient != null) { mlocationClient.stopLocation(); mlocationClient.onDestroy(); } mlocationClient = null; } private void getGaode(Double jing, Double wei) { // Log.e("jing", jing + ""); // Log.e("wei", wei + ""); double x_pi = 3.14159265358979324 * 3000.0 / 180.0; double gg_lon; double gg_lat; double x = jing - 0.0065, y = wei - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); gg_lon = z * Math.cos(theta); gd_jing = String.valueOf(gg_lon); // Log.e("gg_lon", gg_lon + ""); gg_lat = z * Math.sin(theta); gd_wei = String.valueOf(gg_lat); // Log.e("gg_lat", gg_lat + ""); } @Override public void onMapLoaded() { aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种 aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE); // aMap.moveCamera(); aMap.moveCamera(CameraUpdateFactory.zoomTo(16)); getGaode(Double.parseDouble(poi_jing), Double.parseDouble(poi_wei)); LatLng ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing)); // LatLng lll = new LatLng() // MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); // mBaiduMap.animateMapStatus(u); llposition = ll; //设置缩放级别 aMap.moveCamera(CameraUpdateFactory.zoomTo(16)); //将地图移动到定位点 aMap.moveCamera(CameraUpdateFactory.changeLatLng(llposition)); initOverlay(); } @Override public void onRegeocodeSearched(RegeocodeResult result, int i) { if (i == 1000) { if (result != null && result.getRegeocodeAddress() != null && result.getRegeocodeAddress().getFormatAddress() != null) { et_share_address.setText(result.getRegeocodeAddress().getFormatAddress()); // tv_submit.setBackgroundColor(getResources().getColor(R.color.lvse)); } } } @Override public void onGeocodeSearched(GeocodeResult geocodeResult, int i) { } @Override public void onMapClick(LatLng latLng) { isTouch = true; llposition = latLng; Log.e("jing", llposition.longitude + ""); Log.e("wei", llposition.latitude + ""); // initOverlay1(); // getAddress(); } @Override public void onLocationChanged(AMapLocation amapLocation) { // if (mListener != null && amapLocation != null) { if (amapLocation != null && amapLocation.getErrorCode() == 0) { try { // tv_addressName.setText(amapLocation.getAddress()); // poi_jing = String.valueOf(amapLocation.getLongitude()); // poi_wei = String.valueOf(amapLocation.getLatitude()); } catch (NullPointerException e) { e.printStackTrace(); } // ProfileManager.getInstance().setAtCity(getApplicationContext(), MainApplication.atCity); if (!isFirstLoc) { center = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude()); // Log.e("!@#$",amapLocation.getLatitude()+"```"+amapLocation.getLongitude()); //// Toast.makeText(this, amapLocation.getAddress(), Toast.LENGTH_SHORT).show(); //// Toast.makeText(this, amapLocation.getCity(), Toast.LENGTH_SHORT).show(); // ete("{\"fun\":\"timer\"}"); //设置缩放级别 aMap.moveCamera(CameraUpdateFactory.zoomTo(16)); //将地图移动到定位点 aMap.moveCamera(CameraUpdateFactory.changeLatLng(center)); //点击定位按钮 能够将地图的中心移动到定位点 mListener.onLocationChanged(amapLocation); } isFirstLoc = false; } else { String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo(); Log.e("AmapErr", errText); // mLocationErrText.setVisibility(View.VISIBLE); Toast.makeText(this, errText, Toast.LENGTH_SHORT).show(); } } } Observateurs - Gogs: Go Git Service