|
package com.electric.chargingpile.activity;
import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
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 androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.FileProvider;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
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.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
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.DES3;
import com.electric.chargingpile.util.DensityUtil;
import com.electric.chargingpile.util.FileUtils;
import com.electric.chargingpile.util.ImageItem;
import com.electric.chargingpile.util.ImageUtils;
import com.electric.chargingpile.util.JsonUtils;
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 com.tencent.bugly.crashreport.CrashReport;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import org.json.JSONArray;
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.net.URLEncoder;
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 okhttp3.Call;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
public class ShareTwoEditActivity 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;
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;
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<Zhan> list = new ArrayList<Zhan>();
private Zhan zhan;
ToggleButton carType;
private String suit_car2 = "国标";
private TextView et_share_address;
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 EditText zhanName, fastNum, slowNum, parkCost, chargeCost, et_serviceCost, et_remark;
private CustomProgressDialog pd_info;
private RadioButton rb_guo, rb_te, rb_shang, rb_xia;
private RadioGroup rg_claimtype, rg_park;
public static Bitmap bimap;
private View parentView;
private PopupWindow pop = null;
private LinearLayout ll_popup;
private TextView open_time, close_time;
private RelativeLayout rl_address;
private ProgressDialog insertDialog;
private static final int RC_ALBUM_PERM = 123;
public static ImageItem[] selectBitmap = new ImageItem[4];
private int selectIndex = 0;
private ArrayList<ImageView> takeImageViewList = new ArrayList<>();
private ArrayList<ImageView> takeImageCameraList = new ArrayList<>();
private boolean isTakePhoto = false; // 是否更新图片
public static final int REQUEST_CODE_CHOOSE = 334;
private Handler handler = new Handler() {
// 主线程通过这个方法处理消息
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
int index = msg.arg1;
ImageView iv = takeImageViewList.get(index);
iv.setImageBitmap(selectBitmap[index].getBitmap());
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) iv.getLayoutParams();
lp.width = DensityUtil.dip2px(ShareTwoEditActivity.this, 82);
lp.height = DensityUtil.dip2px(ShareTwoEditActivity.this, 70);
iv.setLayoutParams(lp);
takeImageCameraList.get(index).setVisibility(View.GONE);
break;
case 2:
Toast.makeText(ShareTwoEditActivity.this, "提交信息成功,感谢您的分享", Toast.LENGTH_SHORT).show();
dismissDialog();
SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication());
sharedPreferencesUtil.setFileName("shareInfo");
sharedPreferencesUtil.clearData();
finish();
break;
case 3:
dismissDialog();
Toast.makeText(ShareTwoEditActivity.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(ShareTwoEditActivity.this).builder()
.setMsg(s + "\n" + s1)
.setNegativeButton("确认关闭", new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ShareTwoEditActivity.this, ShareListActivity.class));
finish();
}
}).show();
} else {
dismissDialog();
Toast.makeText(ShareTwoEditActivity.this, "提交失败", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
};
private EditText chargeCostWay;
private EditText telephone;
private ConstraintLayout take_image_0;
private ConstraintLayout take_image_1;
private ConstraintLayout take_image_2;
private ConstraintLayout take_image_3;
private String zhanId;
private String recordId = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tempFile = getFile(PHOTO_FILE_PATH + "/" + PHOTO_FILE_NAME);
Res.init(this);
bimap = BitmapFactory.decodeResource(
getResources(),
R.drawable.addpic65);
PublicWayFour.activityList.add(this);
setContentView(R.layout.activity_share_two_edit);
list = new ArrayList<>();
mContext = this;
BarColorUtil.initStatusBarColor(ShareTwoEditActivity.this);
initView();
Init();
zhanId = getIntent().getStringExtra("zhan_id");
if (zhanId == null || zhanId.equals("")) {
Toast.makeText(this, "获取站点信息失败", Toast.LENGTH_SHORT).show();
finish();
} else {
getZhanInfo();
}
}
private void showTextToast(String msg) {
if (toast == null) {
toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
public void dismissDialog() {
if (pd_info != null) {
pd_info.dismiss();
pd_info = null;
}
}
public void Init() {
selectBitmap[0] = null;
selectBitmap[1] = null;
selectBitmap[2] = null;
selectBitmap[3] = null;
pop = new PopupWindow(ShareTwoEditActivity.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(ShareTwoEditActivity.this,
AlbumActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.activity_translate_in, R.anim.activity_translate_out);
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pop.dismiss();
ll_popup.clearAnimation();
}
});
}
/**
* 调用图库选择
*/
private void callGallery() {
Matisse.from(ShareTwoEditActivity.this)
.choose(MimeType.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF))
.showSingleMediaType(true)
.countable(true)
.maxSelectable(1)
.capture(true)
.captureStrategy(new CaptureStrategy(true, "com.electric.chargingpile.provider"))
.imageEngine(new GlideEngine())
.forResult(REQUEST_CODE_CHOOSE);
}
@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 == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
//异步方式插入图片
insertImagesSync(data);
}
}
}
}
/**
* 异步方式插入图片
*
* @param data
*/
private void insertImagesSync(final Intent data) {
insertDialog.show();
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> subscriber) throws Exception {
try {
List<Uri> uriList = Matisse.obtainResult(data);
Uri uri = uriList.get(0);
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
File file = FileUtils.from(ShareTwoEditActivity.this, uri);
bitmap = FileUtils.rotateIfRequired(file, bitmap);
bitmap = imageZoom(bitmap);
ImageItem takePhoto = new ImageItem();
takePhoto.setBitmap(bitmap);
selectBitmap[selectIndex] = takePhoto;
isTakePhoto = true;
subscriber.onNext("");
subscriber.onComplete();
} catch (Exception e) {
e.printStackTrace();
subscriber.onError(e);
}
}
})
.subscribeOn(Schedulers.io())//生产事件在io
.observeOn(AndroidSchedulers.mainThread())//消费事件在UI线程
.subscribe(new Observer<String>() {
@Override
public void onComplete() {
Log.e(TAG, "onCompleted: -------------");
insertDialog.dismiss();
Message msg = new Message();
msg.arg1 = selectIndex;
msg.what = 1;
handler.sendMessage(msg);
}
@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() {
pd_info = CustomProgressDialog.createDialog(mContext);
pd_info.setMessage(mContext.getResources().getString(
R.string.version_refreshing));
pd_info.show();
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);
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);
chargeCostWay = findViewById(R.id.et_charge_cost_way); // 收费方式
costWay = (TextView) findViewById(R.id.tv_costtype);
telephone = findViewById(R.id.et_telephone); // 运营商电话
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);
et_share_address = (TextView) findViewById(R.id.et_share_address);
zhuangType = (TextView) findViewById(R.id.tv_zhuangType);
take_image_0 = findViewById(R.id.take_image_0);
take_image_1 = findViewById(R.id.take_image_1);
take_image_2 = findViewById(R.id.take_image_2);
take_image_3 = findViewById(R.id.take_image_3);
take_image_0.setOnClickListener(this);
take_image_1.setOnClickListener(this);
take_image_2.setOnClickListener(this);
take_image_3.setOnClickListener(this);
ImageView take_image_view_0 = findViewById(R.id.take_image_view_0);
ImageView take_image_view_1 = findViewById(R.id.take_image_view_1);
ImageView take_image_view_2 = findViewById(R.id.take_image_view_2);
ImageView take_image_view_3 = findViewById(R.id.take_image_view_3);
takeImageViewList.add(take_image_view_0);
takeImageViewList.add(take_image_view_1);
takeImageViewList.add(take_image_view_2);
takeImageViewList.add(take_image_view_3);
ImageView take_image_camera_0 = findViewById(R.id.take_image_camera_0);
ImageView take_image_camera_1 = findViewById(R.id.take_image_camera_1);
ImageView take_image_camera_2 = findViewById(R.id.take_image_camera_2);
ImageView take_image_camera_3 = findViewById(R.id.take_image_camera_3);
takeImageCameraList.add(take_image_camera_0);
takeImageCameraList.add(take_image_camera_1);
takeImageCameraList.add(take_image_camera_2);
takeImageCameraList.add(take_image_camera_3);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.take_image_0:
selectIndex = 0;
if (selectBitmap[0] == null) {
permissionTask();
} else {
Intent intent = new Intent(ShareTwoEditActivity.this, ShareTwoPictureActivity.class);
intent.putExtra("selectIndex", selectIndex);
intent.putExtra("from", "edit");
startActivity(intent);
}
break;
case R.id.take_image_1:
selectIndex = 1;
if (selectBitmap[1] == null) {
permissionTask();
} else {
Intent intent = new Intent(ShareTwoEditActivity.this, ShareTwoPictureActivity.class);
intent.putExtra("selectIndex", selectIndex);
intent.putExtra("from", "edit");
startActivity(intent);
}
break;
case R.id.take_image_2:
selectIndex = 2;
if (selectBitmap[2] == null) {
permissionTask();
} else {
Intent intent = new Intent(ShareTwoEditActivity.this, ShareTwoPictureActivity.class);
intent.putExtra("selectIndex", selectIndex);
intent.putExtra("from", "edit");
startActivity(intent);
}
break;
case R.id.take_image_3:
selectIndex = 3;
if (selectBitmap[3] == null) {
permissionTask();
} else {
Intent intent = new Intent(ShareTwoEditActivity.this, ShareTwoPictureActivity.class);
intent.putExtra("selectIndex", selectIndex);
intent.putExtra("from", "edit");
startActivity(intent);
}
break;
case R.id.iv_chakan:
new ShareDialog(this).builder()
.setCancelable(true)
.show();
break;
case R.id.ll_address:
startActivity(new Intent(ShareTwoEditActivity.this, ShareMapActivity.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.tv_notice:
tv_notice.setVisibility(View.GONE);
break;
case R.id.tv_costtype:
startActivity(new Intent(ShareTwoEditActivity.this, ChargeCostWayActivity.class));
break;
case R.id.share_next: // 立即提交
if (!checkPictureOk()) {
} else 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 (chargeCostWay.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 (telephone.getText().toString().equals("")) {
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");
}
if (pd_info == null) {
pd_info = CustomProgressDialog.createDialog(mContext);
}
pd_info.setMessage(mContext.getResources().getString(R.string.version_updating));
pd_info.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
shite("");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
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) {
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.iv_back:
SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication());
sharedPreferencesUtil.setFileName("shareInfo");
sharedPreferencesUtil.clearData();
finish();
break;
}
}
private boolean checkPictureOk() {
if (selectBitmap[0] == null) {
Toast.makeText(this, "请上传建筑或小区图片", Toast.LENGTH_SHORT).show();
return false;
}
if (selectBitmap[1] == null) {
Toast.makeText(this, "请上传站点图片", Toast.LENGTH_SHORT).show();
return false;
}
if (selectBitmap[2] == null) {
Toast.makeText(this, "请上传充电桩图片", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
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 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<String, String> par = new HashMap<String, String>();
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);
if (selectBitmap[0] == null || selectBitmap[1] == null || selectBitmap[2] == null) {
isTakePhoto = true;
}
if (isTakePhoto) {
for (int i = 0; i < selectBitmap.length; i++) {
if (selectBitmap[i] != null) {
try {
bm = imageZoom(selectBitmap[i].getBitmap());
file = bitmapToBase64(bm);
par.put("file" + (i + 1), file);
par.put("filename" + (i + 1), "androidapp.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
par.put("id", recordId);
par.put("zhan_name", zhanName.getText().toString());
par.put("zhan_id", zhanId);
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);
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("telephone", telephone.getText().toString());
par.put("charge_cost_way", chargeCostWay.getText().toString());
par.put("other_cost", et_serviceCost.getText().toString());
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(MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/add", par, null);
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<String> perms) {
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
}
@AfterPermissionGranted(RC_ALBUM_PERM)
public void permissionTask() {
if (isPermissionOK()) {
callGallery();
} else {
// Ask for one permission
EasyPermissions.requestPermissions(
this, "充电桩想要获取您的图片读取权限,是否允许?",
RC_ALBUM_PERM,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA);
}
}
private boolean isPermissionOK() {
return EasyPermissions.hasPermissions(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
);
}
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() {
super.onRestart();
}
private static final int TAKE_PICTURE = 0x000001;
public void photo() {
if (hasSdcard()) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", tempFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(intent, PHOTO_REQUEST_CAMERA);
}
}
@Override
protected void onDestroy() {
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");
intent.putExtra("outputFormat", "JPEG");
intent.putExtra("noFaceDetection", true);
intent.putExtra("return-data", false);
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);
return bitmap;
}
@Override
protected void onResume() {
super.onResume();
SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication());
sharedPreferencesUtil.setFileName("shareInfo");
jing = sharedPreferencesUtil.getString("poi_jing", "");
wei = sharedPreferencesUtil.getString("poi_wei", "");
for (int i = 0; i < selectBitmap.length; i++) {
ImageItem imageItem = selectBitmap[i];
if (imageItem == null) {
takeImageCameraList.get(i).setVisibility(View.VISIBLE);
ImageView takeImageView = takeImageViewList.get(i);
takeImageView.setImageResource(Res.getDrawableID("add_picture_" + (i + 1)));
takeImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) takeImageView.getLayoutParams();
lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
takeImageView.setLayoutParams(lp);
} else {
takeImageCameraList.get(i).setVisibility(View.GONE);
}
}
}
private void getZhanInfo() {
try {
long appTime1 = System.currentTimeMillis() / 1000;
long updatetime = appTime1 - MainMapActivity.cha - 3;
String token = String.valueOf(updatetime);
final String replace = URLEncoder.encode(DES3.encode(token));
String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/getdeny?zhan_id=" + zhanId
+ "&token=" + replace;
OkHttpUtils.get().url(url).build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
dismissDialog();
ToastUtil.showToast(getApplicationContext(), "网络异常,请检查您的网络连接", Toast.LENGTH_SHORT);
CrashReport.postCatchedException(e);
finish();
}
@Override
public void onResponse(String response) {
dismissDialog();
String info = JsonUtils.getKeyResult(response, "info");
String pic = JsonUtils.getKeyResult(response, "pic");
if (info != null && !info.equals("")) {
initZhanInfo(info, pic);
} else {
showTextToast("获取站点信息错误");
finish();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
private void initZhanInfo(String info, String pic) {
try {
JSONObject jsonObject = new JSONObject(info);
recordId = jsonObject.getString("id");
zhanName.setText(jsonObject.getString("zhan_name"));
et_share_address.setText(jsonObject.getString("zhan_address"));
suit_car2 = jsonObject.getString("suit_car");
if ("特斯拉".equals(suit_car2)) {
rb_guo.setBackgroundResource(R.drawable.icon_guonormal1105);
rb_te.setBackgroundResource(R.drawable.icon_teselected1105);
} else {
rb_guo.setBackgroundResource(R.drawable.icon_guoselected1105);
rb_te.setBackgroundResource(R.drawable.icon_tenormal1105);
}
fastNum.setText(jsonObject.getString("fast_num"));
slowNum.setText(jsonObject.getString("slow_num"));
chargeCost.setText(jsonObject.getString("charge_cost"));
et_serviceCost.setText(jsonObject.getString("other_cost"));
chargeCostWay.setText(jsonObject.getString("charge_cost_way"));
parkCost.setText(jsonObject.getString("stop_cost"));
costWay.setText(jsonObject.getString("supplier"));
telephone.setText(jsonObject.getString("telephone"));
park = jsonObject.getString("park_location");
if ("1".equals(park)) {
rb_shang.setBackgroundResource(R.drawable.icon_shangselected1105);
rb_xia.setBackgroundResource(R.drawable.icon_xianormal1105);
} else {
rb_shang.setBackgroundResource(R.drawable.icon_shangnormal1105);
rb_xia.setBackgroundResource(R.drawable.icon_xiaselected1105);
}
open_time.setText(jsonObject.getString("work_open"));
close_time.setText(jsonObject.getString("work_close"));
SharedPreferences mSharedPreferences = getSharedPreferences("shareInfo", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putString("poi_jing", jsonObject.getString("poi_jing"));
editor.putString("poi_wei", jsonObject.getString("poi_wei"));
editor.commit();
jing = jsonObject.getString("poi_jing");
wei = jsonObject.getString("poi_wei");
et_remark.setText(jsonObject.getString("remarks"));
} catch (Exception e) {
e.printStackTrace();
showTextToast("获取站点信息错误");
}
try {
JSONArray jsonArray = new JSONArray(pic);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = new JSONObject(jsonArray.get(i).toString());
String url = jo.get("url").toString();
int finalI = i;
Glide.with(this).load(MainApplication.url + "/zhannew/uploadfile/" + url).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
takeImageCameraList.get(finalI).setVisibility(View.GONE);
ImageView iv = takeImageViewList.get(finalI);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) iv.getLayoutParams();
lp.width = DensityUtil.dip2px(ShareTwoEditActivity.this, 82);
lp.height = DensityUtil.dip2px(ShareTwoEditActivity.this, 70);
iv.setLayoutParams(lp);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable();
Bitmap bitmap = drawable.getBitmap();
ImageItem takePhoto = new ImageItem();
takePhoto.setBitmap(bitmap);
selectBitmap[finalI] = takePhoto;
}
}, 500);// 0.5秒后,执行
return false;
}
}).into(takeImageViewList.get(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|