package com.electric.chargingpile.activity; import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ProgressDialog; import android.app.TimePickerDialog; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.content.FileProvider; import android.util.Base64; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RelativeLayout; import android.widget.Switch; import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; import android.widget.ToggleButton; import com.electric.chargingpile.R; import com.electric.chargingpile.application.MainApplication; import com.electric.chargingpile.data.Zhan; import com.electric.chargingpile.util.BarColorUtil; import com.electric.chargingpile.util.Bimp; import com.electric.chargingpile.util.DES3; import com.electric.chargingpile.util.ImageItem; import com.electric.chargingpile.util.ImageUtils; import com.electric.chargingpile.util.OkHttpUtil; import com.electric.chargingpile.util.PublicWayFour; import com.electric.chargingpile.util.Res; import com.electric.chargingpile.util.SharedPreferencesUtil; import com.electric.chargingpile.util.ToastUtil; import com.electric.chargingpile.util.UploadUtil; import com.electric.chargingpile.view.CustomProgressDialog; import com.electric.chargingpile.view.ShareDialog; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TimeZone; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; import io.reactivex.ObservableOnSubscribe; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import me.iwf.photopicker.PhotoPicker; import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.EasyPermissions; public class ShareTwoActivity extends Activity implements View.OnClickListener, EasyPermissions.PermissionCallbacks { private static final String TAG = "ShareTwoActivity"; private static final int PIC_NUM = 4; private ImageView ivBack, ivType; Bitmap bm = null; private TextView shareList, tvO, tvT, tvTh, tvF, tvFi, zhuangType, costWay, shareNext; // public MyLocationListenner myListener = new MyLocationListenner(); // BaiduMapOptions mapOptions; private TimePickerDialog tpd_open = null; private TimePickerDialog tpd_close = null; private String camePath;//拍照路径 private static final String PHOTO_FILE_NAME = "android.jpg"; private static final String PHOTO_FILE_PATH = getPath(Environment.getExternalStorageDirectory() + "/" + "cdz"); private File tempFile; private static final int PHOTO_REQUEST_CAMERA = 1; private static final int PHOTO_REQUEST_GALLERY = 2; private static final int PHOTO_REQUEST_CUT = 3; private ImageView inBtn, outBtn; private String jing, wei; private int sdkVersion; // private LocationMode mCurrentMode; public static boolean isFirstLoc = true; private Switch sh_cost; private Button submitLocation; private ImageView test, iv1, iv2, iv3, iv4, iv_back; private LinearLayout ll_tvOne, ll_tvTwo, ll_tvThree, ll_tvFour, ll_buchong, ll_type, ll_costWay; private List list = new ArrayList(); private Zhan zhan; ToggleButton carType; private String suit_car2 = "国标"; // BitmapDescriptor mCurrentMarker; private static boolean isGetData = false; private static String location; private static String city; private static String district; private EditText et_totalNum; private TextView et_share_address; private Button confirmButton; private Button cancleButton; private PopupWindow popupWindow; Context mContext; TextView tv; private Toast toast = null; private String park = "1"; private ImageView ib_loaction, ib_add, ib_jian, iv_chakan; private RelativeLayout tv_notice; // private String cost = "收费"; private EditText zhanName, fastNum, slowNum, parkCost, chargeCost, et_serviceCost, et_remark; private CustomProgressDialog pd_info; private String zhan_id, poi_jing, poi_wei, zhan_address; private RadioButton rb_guo, rb_te, rb_shang, rb_xia; private RadioGroup rg_claimtype, rg_park; public static Bitmap bimap; private GridView noScrollgridview; private GridAdapter adapter; private View parentView; private PopupWindow pop = null; private LinearLayout ll_popup; private TextView open_time, close_time, share_list; private RelativeLayout rl_address; private ProgressDialog insertDialog; private static final int RC_ALBUM_PERM = 123; private Handler handler = new Handler() { // 主线程通过这个方法处理消息 @Override public void handleMessage(Message msg) { switch (msg.what) { case 2: Toast.makeText(ShareTwoActivity.this, "提交信息成功,感谢您的分享", Toast.LENGTH_SHORT).show(); dismissDialog(); // for(int i=0;i< PublicWay.activityList.size();i++){ // if (null != PublicWay.activityList.get(i)) { // 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(); break; case 3: dismissDialog(); Toast.makeText(ShareTwoActivity.this, "服务器处理错误", Toast.LENGTH_SHORT).show(); break; case 5: break; case 6: try { Log.e("!!!", msg.toString()); JSONObject jsonObject = new JSONObject(msg.obj.toString()); Log.e("!!!!!!", msg.obj.toString()); String rtnCode = jsonObject.getString("rtnCode"); String rtnMsg = jsonObject.getString("rtnMsg"); if (rtnCode.equals("01")) { dismissDialog(); String s = "“雷锋同志”您提交的信息已成功"; String s1 = "非常感谢您的支持,我们将尽快审核添加到APP中"; new com.electric.chargingpile.view.AlertDialog(ShareTwoActivity.this).builder() .setMsg(s + "\n" + s1) .setNegativeButton("确认关闭", new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(ShareTwoActivity.this, ShareListActivity.class)); // for(int i=0;i(); mContext = this; BarColorUtil.initStatusBarColor(ShareTwoActivity.this); // map = new HashMap<>(); initView(); Init(); // initData(); // firstSelect(); } private void showTextToast(String msg) { if (toast == null) { toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT); } else { toast.setText(msg); } toast.show(); } private void initDate() { zhan_id = getIntent().getStringExtra("zhan_id"); zhan_address = getIntent().getStringExtra("zhan_address"); poi_jing = getIntent().getStringExtra("poi_jing"); poi_wei = getIntent().getStringExtra("poi_wei"); } public void createDialog() { if (pd_info == null) { pd_info = CustomProgressDialog.createDialog(mContext); pd_info.setMessage(mContext.getResources().getString( R.string.version_updating)); pd_info.show(); } } public void dismissDialog() { if (pd_info != null) { pd_info.dismiss(); pd_info = null; } } public void Init() { pop = new PopupWindow(ShareTwoActivity.this); View view = getLayoutInflater().inflate(R.layout.item_popupwindows, null); ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup); pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); pop.setBackgroundDrawable(new BitmapDrawable()); pop.setFocusable(true); pop.setOutsideTouchable(true); pop.setContentView(view); final RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent); Button bt1 = (Button) view .findViewById(R.id.item_popupwindows_camera); Button bt2 = (Button) view .findViewById(R.id.item_popupwindows_Photo); Button bt3 = (Button) view .findViewById(R.id.item_popupwindows_cancel); parent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub pop.dismiss(); ll_popup.clearAnimation(); } }); bt1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); if (MainScanActivity.isCameraUseable()) { photo(); } else { ToastUtil.showToast(getApplicationContext(), "您当前关闭了调用摄像头权限,可前往设置开启权限", Toast.LENGTH_SHORT); } } }); bt2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ShareTwoActivity.this, AlbumActivity.class); startActivity(intent); overridePendingTransition(R.anim.activity_translate_in, R.anim.activity_translate_out); // startActivityForResult(intent, 1); pop.dismiss(); ll_popup.clearAnimation(); } }); bt3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); } }); noScrollgridview = (GridView) findViewById(R.id.noScrollgridview); noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT)); adapter = new GridAdapter(this); adapter.update(); noScrollgridview.setAdapter(adapter); noScrollgridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { if (arg2 == Bimp.tempSelectBitmap.size()) { // Log.i("ddddddd", "----------"); // ll_popup.startAnimation(AnimationUtils.loadAnimation(ShareTwoActivity.this,R.anim.activity_translate_in)); // pop.showAtLocation(parent, Gravity.CENTER, 0, 0); permissionTask(); } else { Intent intent = new Intent(ShareTwoActivity.this, GalleryActivity.class); intent.putExtra("position", "1"); intent.putExtra("ID", arg2); startActivity(intent); } } }); } /** * 调用图库选择 */ private void callGallery() { Log.e(TAG, "callGallery: " + (Bimp.max - Bimp.tempSelectBitmap.size())); //调用第三方图库选择 PhotoPicker.builder() .setPhotoCount(PIC_NUM - Bimp.tempSelectBitmap.size())//可选择图片数量 .setShowCamera(true)//是否显示拍照按钮 .setShowGif(true)//是否显示动态图 .setPreviewEnabled(true)//是否可以预览 .start(this, PhotoPicker.REQUEST_CODE); // PhotoPreview.builder() // .setPhotos(selectedPhotos) // .setCurrentItem(position) // .setShowDeleteButton(false) // .start(MainActivity.this); } @Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (data != null) { if (requestCode == 1) { //处理调用系统图库 } else if (requestCode == PhotoPicker.REQUEST_CODE) { //异步方式插入图片 insertImagesSync(data); } } } } /** * 异步方式插入图片 * * @param data */ private void insertImagesSync(final Intent data) { insertDialog.show(); Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter subscriber) throws Exception { try { ArrayList photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS); //可以同时插入多张图片 for (String imagePath : photos) { Log.e(TAG, "call: imagePath " + imagePath); Bitmap bitmap = BitmapFactory.decodeFile(imagePath);//压缩图片 if (ImageUtils.readPictureDegree(imagePath) != 0) { bitmap = imageZoom(ImageUtils.toturn(bitmap)); } else { bitmap = imageZoom(bitmap); } ImageItem takePhoto = new ImageItem(); takePhoto.setBitmap(bitmap); takePhoto.setImagePath(imagePath); Bimp.tempSelectBitmap.add(takePhoto); // subscriber.onNext(imagePath); } subscriber.onComplete(); } catch (Exception e) { e.printStackTrace(); subscriber.onError(e); } } }) .subscribeOn(Schedulers.io())//生产事件在io .observeOn(AndroidSchedulers.mainThread())//消费事件在UI线程 .subscribe(new Observer() { @Override public void onComplete() { Log.e(TAG, "onCompleted: -------------"); insertDialog.dismiss(); adapter.update(); } @Override public void onError(Throwable e) { insertDialog.dismiss(); Log.e(TAG, "onError: " + "图片插入失败:" + e.getMessage()); ToastUtil.showToast(getApplicationContext(), "图片插入失败", Toast.LENGTH_SHORT); } @Override public void onSubscribe(Disposable d) { } @Override public void onNext(String imagePath) { } }); } private void initView() { insertDialog = new ProgressDialog(this); insertDialog.setMessage("正在插入图片..."); insertDialog.setCanceledOnTouchOutside(false); et_serviceCost = (EditText) findViewById(R.id.et_serviceCost); iv_chakan = (ImageView) findViewById(R.id.iv_chakan); iv_chakan.setOnClickListener(this); inBtn = (ImageView) findViewById(R.id.zoomin1); outBtn = (ImageView) findViewById(R.id.zoomout1); inBtn.setOnClickListener(this); outBtn.setOnClickListener(this); rl_address = (RelativeLayout) findViewById(R.id.ll_address); rl_address.setOnClickListener(this); shareNext = (TextView) findViewById(R.id.share_next); shareNext.setOnClickListener(this); share_list = (TextView) findViewById(R.id.tv_share_list); share_list.setOnClickListener(this); et_serviceCost = (EditText) findViewById(R.id.et_serviceCost); et_remark = (EditText) findViewById(R.id.et_remarkclaim); et_remark = (EditText) findViewById(R.id.et_remarkclaim); zhanName = (EditText) findViewById(R.id.et_zhanName); fastNum = (EditText) findViewById(R.id.et_fastNum); slowNum = (EditText) findViewById(R.id.et_slowNum); parkCost = (EditText) findViewById(R.id.et_parkCost); chargeCost = (EditText) findViewById(R.id.et_chargeCost); costWay = (TextView) findViewById(R.id.tv_costtype); costWay.setOnClickListener(this); ib_loaction = (ImageView) findViewById(R.id.ib_location); ib_loaction.setOnClickListener(this); tv_notice = (RelativeLayout) findViewById(R.id.tv_notice); tv_notice.setOnClickListener(this); rg_claimtype = (RadioGroup) findViewById(R.id.rg_claimtype); rg_claimtype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == rb_guo.getId()) { suit_car2 = "国标"; } if (checkedId == rb_te.getId()) { suit_car2 = "特斯拉"; } } }); rg_park = (RadioGroup) findViewById(R.id.rg_park); rg_park.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == rb_shang.getId()) { park = "1"; } if (checkedId == rb_xia.getId()) { park = "0"; } } }); rb_guo = (RadioButton) findViewById(R.id.rb_guo); rb_guo.setOnClickListener(this); rb_te = (RadioButton) findViewById(R.id.rb_te); rb_te.setOnClickListener(this); rb_shang = (RadioButton) findViewById(R.id.rb_shang); rb_shang.setOnClickListener(this); rb_xia = (RadioButton) findViewById(R.id.rb_xia); rb_xia.setOnClickListener(this); ivBack = (ImageView) findViewById(R.id.iv_back); ivBack.setOnClickListener(this); open_time = (TextView) findViewById(R.id.tv_prefect_start_time); open_time.setOnClickListener(this); close_time = (TextView) findViewById(R.id.tv_ferfect_time); close_time.setOnClickListener(this); // mMapView = (MapView) findViewById(R.id.mapView_share); et_share_address = (TextView) findViewById(R.id.et_share_address); zhuangType = (TextView) findViewById(R.id.tv_zhuangType); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_chakan: new ShareDialog(this).builder() .setCancelable(true) .show(); break; case R.id.ll_address: startActivity(new Intent(ShareTwoActivity.this, ShareMapActivity.class)); break; case R.id.tv_share_list: startActivity(new Intent(ShareTwoActivity.this, ShareListActivity.class)); break; case R.id.rb_guo: rb_guo.setBackgroundResource(R.drawable.icon_guoselected1105); rb_te.setBackgroundResource(R.drawable.icon_tenormal1105); break; case R.id.rb_te: rb_guo.setBackgroundResource(R.drawable.icon_guonormal1105); rb_te.setBackgroundResource(R.drawable.icon_teselected1105); break; case R.id.rb_shang: rb_shang.setBackgroundResource(R.drawable.icon_shangselected1105); rb_xia.setBackgroundResource(R.drawable.icon_xianormal1105); break; case R.id.rb_xia: rb_shang.setBackgroundResource(R.drawable.icon_shangnormal1105); rb_xia.setBackgroundResource(R.drawable.icon_xiaselected1105); break; // case R.id.ib_location: // if (!isFirstLoc) { // isFirstLoc = true; // // Toast.makeText(this,"正在定位当前位置...",Toast.LENGTH_LONG); // mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL; // mBaiduMap // .setMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // mBaiduMap.setMapStatus(MapStatusUpdateFactory // .newMapStatus(new MapStatus.Builder().zoom(15f).build())); // mBaiduMap.setMyLocationEnabled(true); // mLocClient.start(); // } // break; case R.id.tv_notice: tv_notice.setVisibility(View.GONE); break; case R.id.tv_costtype: startActivity(new Intent(ShareTwoActivity.this, ChargeCostWayActivity.class)); // LayoutInflater inflater1 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); // popupWindowView = inflater1.inflate(R.layout.popupwindow_cost, null); // popupWindow = new PopupWindow(popupWindowView, // ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, // true); // popupWindow.setBackgroundDrawable(new BitmapDrawable()); // // 设置PopupWindow的弹出和消失效果 // popupWindow.setAnimationStyle(R.style.popupAnimation); //// confirmButton = (Button) popupWindowView //// .findViewById(R.id.confirmButton); //// confirmButton.setOnClickListener(new OnClickListener() { //// @Override //// public void onClick(View view) { //// popupWindow.dismiss(); //// } //// }); // cancleButton = (Button) popupWindowView // .findViewById(R.id.cancleButton); // cancleButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // popupWindow.dismiss(); // } // }); // TextView tvO1 = (TextView) popupWindowView.findViewById(R.id.tvOne); // tvO1.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("国网电卡"); // popupWindow.dismiss(); // } // }); // TextView tvT2 = (TextView) popupWindowView.findViewById(R.id.tvTwo); // tvT2.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("普天电卡"); // popupWindow.dismiss(); // } // }); // TextView tvTh3 = (TextView) popupWindowView.findViewById(R.id.tvThree); // tvTh3.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("特来电APP"); // popupWindow.dismiss(); // } // }); // TextView tvF4 = (TextView) popupWindowView.findViewById(R.id.tvFour); // tvF4.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("现金"); // popupWindow.dismiss(); // } // }); // tvFi = (TextView) popupWindowView.findViewById(R.id.tvFive); // tvFi.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("其他"); // popupWindow.dismiss(); // } // }); // TextView tvF6 = (TextView) popupWindowView.findViewById(R.id.tvSix); // tvF6.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("4S店电卡"); // popupWindow.dismiss(); // } // }); // TextView tvF7 = (TextView) popupWindowView.findViewById(R.id.tvSeven); // tvF7.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("小易充电"); // popupWindow.dismiss(); // } // }); // TextView tvF8 = (TextView) popupWindowView.findViewById(R.id.tvEight); // tvF8.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("国网高速公路专用卡"); // popupWindow.dismiss(); // } // }); // TextView tvXingXing = (TextView) popupWindowView.findViewById(R.id.tvXingXing); // tvXingXing.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Log.e("!!!","点击"); // costWay.setText("星星充电APP"); // popupWindow.dismiss(); // // } // }); // // // TextView tvJuDian = (TextView) popupWindowView.findViewById(R.id.tvJuDian); // tvJuDian.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Log.e("!!!","点击"); // costWay.setText("聚电桩APP"); // popupWindow.dismiss(); // } // }); // TextView tvEv = (TextView) popupWindowView.findViewById(R.id.tvev); // tvEv.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("EVCARD电卡"); // popupWindow.dismiss(); // // } // }); // // TextView tvyi = (TextView) popupWindowView.findViewById(R.id.tvYiChong); // tvyi.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // costWay.setText("易充卡"); // popupWindow.dismiss(); // // } // }); // popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0); break; // case R.id.iv_back: // finish(); // break; case R.id.share_next: if (et_share_address.getText().toString().equals("")) { Toast.makeText(this, "请选择充电站地址", Toast.LENGTH_SHORT).show(); } else if (zhanName.getText().toString().equals("")) { Toast.makeText(this, "请填写名称", Toast.LENGTH_SHORT).show(); } else if (fastNum.getText().toString().equals("") && slowNum.getText().toString().equals("")) { Toast.makeText(this, "请填写桩数量", Toast.LENGTH_SHORT).show(); } else if (chargeCost.getText().toString().equals("")) { Toast.makeText(this, "请填写充电费", Toast.LENGTH_SHORT).show(); } else if (et_serviceCost.getText().toString().equals("")) { Toast.makeText(this, "请填写服务费", Toast.LENGTH_SHORT).show(); } else if (parkCost.getText().toString().equals("")) { Toast.makeText(this, "请填写停车费", Toast.LENGTH_SHORT).show(); } else if (costWay.getText().toString().equals("")) { Toast.makeText(this, "请选择运营商", Toast.LENGTH_SHORT).show(); } else if (Bimp.tempSelectBitmap.size() == 0) { Toast.makeText(this, "请上传图片", Toast.LENGTH_SHORT).show(); } else { if (fastNum.getText().toString().equals("") && !slowNum.getText().toString().equals("")) { fastNum.setText("0"); } if (!fastNum.getText().toString().equals("") && slowNum.getText().toString().equals("")) { slowNum.setText("0"); } if (open_time.getText().toString().equals("")) { open_time.setText("00:00"); } if (close_time.getText().toString().equals("")) { close_time.setText("24:00"); } createDialog(); new Thread(new Runnable() { @Override public void run() { // submitShareTwo(); try { shite(""); } catch (Exception e) { e.printStackTrace(); } // uploadFile(); } }).start(); } // if (!zhanName.getText().toString().equals("") && !fastNum.getText().toString().equals("") && !slowNum.getText().toString().equals("") // && !chargeCost.getText().toString().equals("") && !costWay.getText().toString().equals("请选择支付方式") // && !parkCost.getText().toString().equals("") && !et_share_address.getText().toString().equals("") // && !et_serviceCost.getText().toString().equals("")) { // createDialog(); // new Thread(new Runnable() { // @Override // public void run() { //// submitShareTwo(); // // try { // // shite(""); // // // } catch (Exception e) { // e.printStackTrace(); // } // //// uploadFile(); // } // }).start(); // }else{ // Toast.makeText(ShareTwoActivity.this,"请确认必填项是否全部填写",Toast.LENGTH_SHORT).show(); // } break; // case R.id.rl_open_object: // LayoutInflater inflater1 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); // popupWindowView = inflater1.inflate(R.layout.popupwindow_open, null); // popupWindow = new PopupWindow(popupWindowView, // ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, // true); // popupWindow.setBackgroundDrawable(new BitmapDrawable()); // // 设置PopupWindow的弹出和消失效果 // popupWindow.setAnimationStyle(R.style.popupAnimation); //// confirmButton = (Button) popupWindowView //// .findViewById(R.id.confirmButton); //// confirmButton.setOnClickListener(new View.OnClickListener() { //// @Override //// public void onClick(View view) { //// Toast.makeText(ShareTwoActivity.this, "YES", Toast.LENGTH_SHORT).show(); //// popupWindow.dismiss(); //// } //// }); // cancleButton = (Button) popupWindowView // .findViewById(R.id.cancleButton); // cancleButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { //// Toast.makeText(ShareTwoActivity.this, "NO", Toast.LENGTH_SHORT).show(); // popupWindow.dismiss(); // } // }); // TextView tvOne1 = (TextView) popupWindowView.findViewById(R.id.tvOne); // tvOne1.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_open_object.setText("开放"); // popupWindow.dismiss(); // } // }); // TextView tvTwo1 = (TextView) popupWindowView.findViewById(R.id.tvTwo); // tvTwo1.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_open_object.setText("对内开放"); // popupWindow.dismiss(); // } // }); // popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0); // break; // case R.id.rl_charge_cost_style: // LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); // popupWindowView = inflater.inflate(R.layout.popupwindow_cost, null); // popupWindow = new PopupWindow(popupWindowView, // ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, // true); // popupWindow.setBackgroundDrawable(new BitmapDrawable()); // // 设置PopupWindow的弹出和消失效果 // popupWindow.setAnimationStyle(R.style.popupAnimation); //// confirmButton = (Button) popupWindowView // .findViewById(R.id.confirmButton); // confirmButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Toast.makeText(ShareTwoActivity.this, "YES", Toast.LENGTH_SHORT).show(); // popupWindow.dismiss(); // } // }); // cancleButton = (Button) popupWindowView // .findViewById(R.id.cancleButton); // cancleButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { //// Toast.makeText(ShareTwoActivity.this, "NO", Toast.LENGTH_SHORT).show(); // popupWindow.dismiss(); // } // }); // tvOne = (TextView) popupWindowView.findViewById(R.id.tvOne); // tvOne.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_style.setText("北京国家电网充电卡"); // popupWindow.dismiss(); // } // }); // tvTwo = (TextView) popupWindowView.findViewById(R.id.tvTwo); // tvTwo.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_style.setText("北京富电科技充电卡"); // popupWindow.dismiss(); // } // }); // tvThree = (TextView) popupWindowView.findViewById(R.id.tvThree); // tvThree.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_style.setText("北京普天新能源充电卡"); // popupWindow.dismiss(); // } // }); // tvFour = (TextView) popupWindowView.findViewById(R.id.tvFour); // tvFour.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_style.setText("上海国家电网充电卡"); // popupWindow.dismiss(); // } // }); // tvFive = (TextView) popupWindowView.findViewById(R.id.tvFive); // tvFive.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_style.setText("上海普天新能源充电卡"); // popupWindow.dismiss(); // } // }); // tvSix = (TextView) popupWindowView.findViewById(R.id.tvSix); // tvSix.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // et_style.setFocusableInTouchMode(true); // popupWindow.dismiss(); // } // }); // popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0); // break; // case R.id.ll_add_photo: // CharSequence[] items = { "手机相册","拍照" }; // // CharSequence[] items = { "手机相册", "手机拍照" }; // imageChooseItem(items); // // // break; // case R.id.tv_holiday_start_time: // if (tpd_holiday_open == null) { // TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() { // public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // holiday_open.setText(((hourOfDay < 10 ? 0 + "" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? 0 + "" + minute : minute)).toString()); // //close_time.setText(((hourOfDay < 10 ? 0 +""+ hourOfDay : hourOfDay)+":"+(minute<10?0+""+minute:minute)).toString()); // tpd_holiday_open.dismiss(); // } // }; // Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); // int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // int minute = calendar.get(Calendar.MINUTE); // tpd_holiday_open = new TimePickerDialog(this, otsl, hourOfDay, minute, true); // } // tpd_holiday_open.show(); // break; // // case R.id.tv_holiday_stop_time: // if (tpd_holiday_close == null) { // TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() { // public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // holiday_close.setText(((hourOfDay < 10 ? 0 + "" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? 0 + "" + minute : minute)).toString()); // //close_time.setText(((hourOfDay < 10 ? 0 +""+ hourOfDay : hourOfDay)+":"+(minute<10?0+""+minute:minute)).toString()); // tpd_holiday_close.dismiss(); // } // }; // Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); // int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // int minute = calendar.get(Calendar.MINUTE); // tpd_holiday_close = new TimePickerDialog(this, otsl, hourOfDay, minute, true); // } // tpd_holiday_close.show(); // break; case R.id.tv_prefect_start_time: if (tpd_open == null) { TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { open_time.setText(((hourOfDay < 10 ? 0 + "" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? 0 + "" + minute : minute)).toString()); //close_time.setText(((hourOfDay < 10 ? 0 +""+ hourOfDay : hourOfDay)+":"+(minute<10?0+""+minute:minute)).toString()); tpd_open.dismiss(); } }; Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); tpd_open = new TimePickerDialog(this, otsl, hourOfDay, minute, true); } tpd_open.show(); break; case R.id.tv_ferfect_time: if (tpd_close == null) { TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { //open_time.setText(((hourOfDay < 10 ? 0 +""+ hourOfDay : hourOfDay)+":"+(minute<10?0+""+minute:minute)).toString()); close_time.setText(((hourOfDay < 10 ? 0 + "" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? 0 + "" + minute : minute)).toString()); tpd_close.dismiss(); } }; Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); tpd_close = new TimePickerDialog(this, otsl, hourOfDay, minute, true); } tpd_close.show(); break; // case R.id.tv_next: // Intent intent = new Intent(getApplication(), ShareThreeActivity.class); // intent.putExtra("location", share_address); // intent.putExtra("POI_jing", poi_jing); // intent.putExtra("POI_wei", poi_wei); // intent.putExtra("fast_num", et_fast_num.getText().toString()); // intent.putExtra("slow_num", et_slow_num.getText().toString()); // intent.putExtra("suit_car", tv_suit_car.getText().toString()); // intent.putExtra("belong_attribute", tv_belong_type.getText().toString()); // intent.putExtra("telephone", et_phone.getText().toString()); // intent.putExtra("Person_name", et_belong.getText().toString()); // intent.putExtra("company_name", et_belong.getText().toString()); // intent.putExtra("open_time", open_time.getText().toString()); // intent.putExtra("zhan_name", et_name.getText().toString()); // intent.putExtra("close_time", close_time.getText().toString()); // intent.putExtra("holiday_open", holiday_open.getText().toString()); // intent.putExtra("holiday_close", holiday_close.getText().toString()); // intent.putExtra("open_object", et_open_object.getText().toString()); // intent.putExtra("run_state", tv_run_state.getText().toString()); // intent.putExtra("pic", srcPath); // intent.putExtra("city", city); // if (checkText()) { // startActivity(intent); // } // break; case R.id.iv_back: SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication()); sharedPreferencesUtil.setFileName("shareInfo"); sharedPreferencesUtil.clearData(); finish(); break; // case R.id.iv_run_state: // final String[] operationSelect = {"正常", "故障", "废弃", "调试"}; // new AlertDialog.Builder(ShareTwoActivity.this) // .setTitle("请选择") // .setItems(operationSelect, new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // tv_run_state.setText(operationSelect[0]); // break; // case 1: // tv_run_state.setText(operationSelect[1]); // break; // case 2: // tv_run_state.setText(operationSelect[2]); // break; // case 3: // tv_run_state.setText(operationSelect[3]); // default: // break; // } // } // }) // .setNegativeButton("取消", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // dialog.cancel(); // } // }).show(); // break; // case R.id.iv_prefect_change_suit: // // String[] changeSelect = {"国标充电", "特斯拉", "德系"}; // new AlertDialog.Builder(ShareTwoActivity.this) // .setTitle("请选择") // .setItems(changeSelect, new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // tv_suit_car.setText("国标充电"); // break; // case 1: // tv_suit_car.setText("特斯拉"); // break; // case 2: // tv_suit_car.setText("德系"); // break; // default: // break; // } // } // }) // .setNegativeButton("取消", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // dialog.cancel(); // } // }).show(); // break; // case R.id.rl_perfect_belong: // final String[] belongSelect = {"企业", "私人"}; // new AlertDialog.Builder(ShareTwoActivity.this) // .setTitle("请选择") // .setItems(belongSelect, new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // tv_belong_type.setText(belongSelect[0]); // break; // case 1: // tv_belong_type.setText(belongSelect[1]); //// tv_belong_style.setText("联系人"); //// et_belong.setText("王先生"); // break; // default: // break; // } // } // }) // .setNegativeButton("取消", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // dialog.cancel(); // } // }).show(); // LayoutInflater inflater2 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); // popupWindowView = inflater2.inflate(R.layout.popupwindow_belong, null); // popupWindow = new PopupWindow(popupWindowView, // ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, // true); // popupWindow.setBackgroundDrawable(new BitmapDrawable()); // // 设置PopupWindow的弹出和消失效果 // popupWindow.setAnimationStyle(R.style.popupAnimation); // confirmButton = (Button) popupWindowView // .findViewById(R.id.confirmButton); // confirmButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Toast.makeText(ShareTwoActivity.this, "YES", Toast.LENGTH_SHORT).show(); // popupWindow.dismiss(); // } // }); // cancleButton = (Button) popupWindowView // .findViewById(R.id.cancleButton); // cancleButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { //// Toast.makeText(ShareTwoActivity.this, "NO", Toast.LENGTH_SHORT).show(); // popupWindow.dismiss(); // } // }); // TextView tvOne2 = (TextView) popupWindowView.findViewById(R.id.tvOne); // tvOne2.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // tv_belong_type.setText("企业"); // popupWindow.dismiss(); // } // }); // TextView tvTwo2 = (TextView) popupWindowView.findViewById(R.id.tvTwo); // tvTwo2.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // tv_belong_type.setText("私人"); // popupWindow.dismiss(); // } // }); // popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0); // break; // case R.id.tv_submit: // if (!et_serviceCost.getText().toString().equals("")&& Bimp.tempSelectBitmap.size() != 0) { // createDialog(); // new Thread(new Runnable() { // @Override // public void run() { //// submitShareTwo(); // // try { // // shite(""); // // // } catch (Exception e) { // e.printStackTrace(); // } // //// uploadFile(); // } // }).start(); // }else if (Bimp.tempSelectBitmap.size() == 0){ // Toast.makeText(getApplication(),"请提交站点照片",Toast.LENGTH_SHORT).show(); // } else{ // Toast.makeText(ClaimSurveyTwoActivity.this,"请确认必填项是否全部填写",Toast.LENGTH_SHORT).show(); // } // break; // case R.id.zoomin1: // mBaiduMap.setMapStatus(MapStatusUpdateFactory // .zoomTo(mapStatus.zoom + 1)); // controlZoomShow(); // break; // case R.id.zoomout1: // mBaiduMap.setMapStatus(MapStatusUpdateFactory // .zoomTo(mapStatus.zoom - 1)); // controlZoomShow(); // break; } // mapStatus = mBaiduMap.getMapStatus(); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication()); sharedPreferencesUtil.setFileName("shareInfo"); sharedPreferencesUtil.clearData(); finish(); } return false; } //地图缩放方法 // private void controlZoomShow() { // float zoom = mBaiduMap.getMapStatus().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(); // } // // } // public void getPoint() { // if (!isGetData) { // isGetData = true; // new Handler().postDelayed(new Runnable() { // // @Override // public void run() { // MyLocationData locCenter = mBaiduMap.getLocationData(); // if (locCenter != null) { // center = new LatLng(locCenter.latitude, // locCenter.longitude); // //// mBaiduMap.addOverlay(new MarkerOptions().position(center).icon( //// BitmapDescriptorFactory //// .fromResource(R.drawable.position_icon))); // } else { // return; // } //// Point p1 = new Point(0, 0); //// LatLng locLeftTop = mBaiduMap.getProjection() //// .fromScreenLocation(p1); //// Point p2 = new Point(MainApplication.mScreenWidth, mMapView //// .getHeight()); //// LatLng llRightBottom = mBaiduMap.getProjection() //// .fromScreenLocation(p2); //// MainMap(); // } // }, 500); // } // } // private void MainMap() { // new Thread(new Runnable() { // Point p1 = new Point(0,0); // LatLng locLeftTop = mBaiduMap.getProjection() // .fromScreenLocation(p1); // Point p2 = new Point(MainApplication.mScreenWidth, mMapView // .getHeight()); // LatLng llRightBottom = mBaiduMap.getProjection() // .fromScreenLocation(p2); // // // // GeoPoint centerPoint = mapview.getMapCenter();// 地图中心坐标 //// int tbSpan = mapview.getLatitudeSpan();// 当前纬线的跨度(从地图的上边缘到下边缘) //// int lrSpan = mapview.getLongitudeSpan();// 当前经度的跨度(从地图的左边缘到地图的右边缘) //// GeoPoint ltPoint = new GeoPoint(centerPoint.getLatitudeE6() - tbSpan / 2, centerPoint.getLongitudeE6() - lrSpan //// / 2);// 左上角坐标 //// GeoPoint rbPoint = new GeoPoint(centerPoint.getLatitudeE6()// 右下角坐标 //// + tbSpan / 2, centerPoint.getLongitudeE6() + lrSpan / 2); // @Override // public void run() { // String url=MainApplication.url+"/zhannew/basic/web/index.php/zhanlist/getlist?poi_lux="+ locLeftTop.longitude+""+"&poi_luy="+ locLeftTop.latitude+"" +"&poi_rdx="+ llRightBottom.longitude+""+"&poi_rdy="+ llRightBottom.latitude+ ""+"&suit_car2="+MainApplication.userTpye; // submitShowMap(url); // } // }).start(); // // } private void submitShowMap(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 = 5; 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 String bitmapToBase64(Bitmap bitmap) { String result = null; ByteArrayOutputStream baos = null; try { if (bitmap != null) { baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); baos.flush(); baos.close(); byte[] bitmapBytes = baos.toByteArray(); result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (baos != null) { baos.flush(); baos.close(); } } catch (IOException e) { e.printStackTrace(); } } return result; } public static String roundByScale(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); } if (scale == 0) { return new DecimalFormat("0").format(v); } String formatStr = "0."; for (int i = 0; i < scale; i++) { formatStr = formatStr + "0"; } return new DecimalFormat(formatStr).format(v); } public void shite(String s) throws Exception { Map par = new HashMap(); String file; long appTime1 = System.currentTimeMillis() / 1000; Log.i("appTime(long)---", appTime1 + ""); long updatetime = appTime1 - MainMapActivity.cha; Log.i("updatetime(long)---", updatetime + ""); Log.i("cha---", MainMapActivity.cha + ""); String token = String.valueOf(updatetime); Log.i("token---", token); for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) { try { bm = imageZoom(Bimp.tempSelectBitmap.get(i).getBitmap()); file = bitmapToBase64(bm); par.put("file" + (i + 1), file); Log.i("file--------" + (i + 1), file); par.put("filename" + (i + 1), "androidapp.jpg"); } catch (Exception e) { e.printStackTrace(); } } // String fast = fastNum par.put("zhan_name", zhanName.getText().toString()); par.put("zhan_id", zhan_id); par.put("user_id", MainApplication.userId); par.put("zhan_address", et_share_address.getText().toString()); String jingg = roundByScale(Double.parseDouble(jing), 16); ; String weii = roundByScale(Double.parseDouble(wei), 16); par.put("poi_jing", jingg); par.put("poi_wei", weii); // Log.e("poi_jing",jingg); // Log.e("poi_wei",weii); par.put("total_num", ""); par.put("fast_num", fastNum.getText().toString()); par.put("slow_num", slowNum.getText().toString()); par.put("open_object", ""); par.put("charges", ""); par.put("stop_cost", parkCost.getText().toString()); par.put("stop_cost_way", ""); par.put("charge_cost", chargeCost.getText().toString()); par.put("charge_cost_way", ""); par.put("other_cost", et_serviceCost.getText().toString()); par.put("telephone", ""); par.put("zhuang_produce", ""); par.put("remarks", et_remark.getText().toString()); Log.e("remarks", et_remark.getText().toString()); par.put("city", ""); par.put("supplier", costWay.getText().toString()); par.put("facilities_classify", ""); par.put("belong_attribute", ""); par.put("operation_state", ""); par.put("work_open", open_time.getText().toString()); par.put("work_close", close_time.getText().toString()); par.put("holiday_open", ""); par.put("holiday_close", ""); par.put("company_name", ""); par.put("person_name", ""); par.put("zhuang_num", ""); par.put("zy_num", ""); par.put("suit_car", suit_car2); par.put("park_location", park); par.put("token", DES3.encode(token)); try { String u = UploadUtil.post( // "http://123.57.6.131/zhannew/basic/web/index.php/zhanlist/add", MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/add", par, null); System.err.println(u); // submit(u); Message msg = new Message(); msg.obj = u; msg.what = 2; handler.sendMessage(msg); } catch (IOException e) { e.printStackTrace(); } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); // EasyPermissions handles the request result. EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); } @Override public void onPermissionsGranted(int requestCode, List perms) { } @Override public void onPermissionsDenied(int requestCode, List perms) { } @AfterPermissionGranted(RC_ALBUM_PERM) public void permissionTask() { if (isPermissionOK()) { callGallery(); // Have permission, do the thing! // Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show(); // ifTimeout(); } else { // Ask for one permission EasyPermissions.requestPermissions( this, "充电桩想要获取您的图片读取权限,是否允许?", RC_ALBUM_PERM, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); } } private boolean isPermissionOK() { return EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE ); } @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() == 4) { return 4; } 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 == 4) { 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().getAbsolutePath() + "/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);//��������� if (sdkVersion < 19) { intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); } else { Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", tempFile); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); } // intent.putExtra(MediaStore.EXTRA_OUTPUT, cutImgUri); startActivityForResult(intent, PHOTO_REQUEST_CAMERA); } // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File( // Environment.getExternalStorageDirectory(), "androidapp.jpg"))); // ((Activity) mContext).startActivityForResult(intent, 2); } // 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); // } // protected void onActivityResult(int requestCode, int resultCode, Intent data) { // System.out.println("--------data------->"+data); // //���ѡȡ // if(requestCode == PHOTO_REQUEST_CAMERA && resultCode == Activity.RESULT_OK ){ // //��������ͼƬ�ͽ�ȡ���ͼƬ�ļ���д����ͬһ���ļ���photo.jpg // // // new Handler().post(new Runnable() { // @Override // public void run() { // if (sdkVersion < 19){ // crop(Uri.fromFile(tempFile),Uri.fromFile(tempFile)); // }else { // Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", tempFile); // crop(photoURI,photoURI); // } // } // }); // // // // } // //���ؽ�ȡ��ͼƬ // else if(requestCode == PHOTO_REQUEST_CUT ){ // //���д�ͼʹ��Uri // Bitmap bitmap ; // // if (sdkVersion <19){ // bitmap = decodeUriAsBitmap(Uri.fromFile(tempFile));//decode bitmap // }else { // Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", tempFile); // bitmap = decodeUriAsBitmap(photoURI);//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); // } @Override protected void onDestroy() { Bimp.tempSelectBitmap.clear(); Bimp.max = 0; super.onDestroy(); } private Bitmap compressBmpFromBmp(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int options = 100; image.compress(Bitmap.CompressFormat.JPEG, 60, baos); while (baos.toByteArray().length / 1024 > 200) { baos.reset(); options -= 10; image.compress(Bitmap.CompressFormat.JPEG, options, baos); } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null); return bitmap; } 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; } private Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 80, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 int options = 70; while (baos.toByteArray().length / 1024 > 300) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩 baos.reset();//重置baos即清空baos options -= 10;//每次都减少10 image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中 Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片 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; } @Override protected void onResume() { super.onResume(); SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication()); sharedPreferencesUtil.setFileName("shareInfo"); String costway = sharedPreferencesUtil.getString("costWay", ""); String address = sharedPreferencesUtil.getString("address", ""); 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); } }