|
@ -1,8 +1,10 @@
|
1
|
1
|
package com.electric.chargingpile.activity;
|
2
|
2
|
|
|
3
|
import androidx.annotation.NonNull;
|
3
|
4
|
import androidx.appcompat.app.AppCompatActivity;
|
4
|
5
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
5
|
6
|
|
|
7
|
import android.Manifest;
|
6
|
8
|
import android.app.ProgressDialog;
|
7
|
9
|
import android.content.Intent;
|
8
|
10
|
import android.graphics.Bitmap;
|
|
@ -11,21 +13,29 @@ import android.graphics.Matrix;
|
11
|
13
|
import android.graphics.drawable.Drawable;
|
12
|
14
|
import android.net.Uri;
|
13
|
15
|
import android.os.Bundle;
|
|
16
|
import android.text.TextUtils;
|
|
17
|
import android.util.Base64;
|
14
|
18
|
import android.view.View;
|
15
|
19
|
import android.view.WindowManager;
|
16
|
20
|
import android.widget.Button;
|
|
21
|
import android.widget.EditText;
|
17
|
22
|
import android.widget.ImageView;
|
|
23
|
import android.widget.LinearLayout;
|
18
|
24
|
import android.widget.TextView;
|
19
|
25
|
import android.widget.Toast;
|
20
|
26
|
|
21
|
27
|
import com.bumptech.glide.Glide;
|
22
|
28
|
import com.electric.chargingpile.R;
|
|
29
|
import com.electric.chargingpile.application.MainApplication;
|
23
|
30
|
import com.electric.chargingpile.entity.CarBrandGroupEntity;
|
24
|
31
|
import com.electric.chargingpile.entity.CarSeriesEntity;
|
25
|
32
|
import com.electric.chargingpile.event.CarBrandEvent;
|
26
|
33
|
import com.electric.chargingpile.event.CarSerieEvent;
|
27
|
34
|
import com.electric.chargingpile.util.BarColorUtil;
|
|
35
|
import com.electric.chargingpile.util.Base64Util;
|
|
36
|
import com.electric.chargingpile.util.DES3;
|
28
|
37
|
import com.electric.chargingpile.util.FileUtils;
|
|
38
|
import com.electric.chargingpile.util.ImageUitl;
|
29
|
39
|
import com.electric.chargingpile.util.JsonUtils;
|
30
|
40
|
import com.electric.chargingpile.util.LoadingDialog;
|
31
|
41
|
import com.electric.chargingpile.util.ToastUtil;
|
|
@ -46,8 +56,14 @@ import org.greenrobot.eventbus.ThreadMode;
|
46
|
56
|
|
47
|
57
|
import java.io.ByteArrayOutputStream;
|
48
|
58
|
import java.io.File;
|
|
59
|
import java.io.FileInputStream;
|
|
60
|
import java.io.IOException;
|
|
61
|
import java.io.InputStream;
|
|
62
|
import java.net.URLEncoder;
|
49
|
63
|
import java.util.ArrayList;
|
|
64
|
import java.util.HashMap;
|
50
|
65
|
import java.util.List;
|
|
66
|
import java.util.Map;
|
51
|
67
|
|
52
|
68
|
import io.reactivex.Observable;
|
53
|
69
|
import io.reactivex.ObservableEmitter;
|
|
@ -57,18 +73,20 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
57
|
73
|
import io.reactivex.disposables.Disposable;
|
58
|
74
|
import io.reactivex.schedulers.Schedulers;
|
59
|
75
|
import okhttp3.Call;
|
|
76
|
import okhttp3.MediaType;
|
|
77
|
import pub.devrel.easypermissions.AfterPermissionGranted;
|
|
78
|
import pub.devrel.easypermissions.EasyPermissions;
|
60
|
79
|
|
61
|
80
|
/**
|
62
|
81
|
* 车主认证
|
63
|
82
|
*/
|
64
|
83
|
|
65
|
|
public class CarOwnerCertificateActivity extends AppCompatActivity implements View.OnClickListener {
|
|
84
|
public class CarOwnerCertificateActivity extends AppCompatActivity implements View.OnClickListener, EasyPermissions.PermissionCallbacks {
|
66
|
85
|
|
67
|
86
|
private static final int RC_ALBUM_PERM = 123;
|
68
|
87
|
private static final int REQUEST_CODE_CHOOSE = 342;
|
69
|
88
|
private Bitmap insertBitmap;
|
70
|
|
private String u_path = "";
|
71
|
|
private int drivingLicenseType = 1;
|
|
89
|
private String drivingLicenseType = "自用";
|
72
|
90
|
private ProgressDialog insertDialog;
|
73
|
91
|
|
74
|
92
|
private TextView nav_title;
|
|
@ -91,6 +109,12 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
91
|
109
|
private TextView driving_license_text_view;
|
92
|
110
|
private Drawable selected;
|
93
|
111
|
private Drawable normal;
|
|
112
|
private LinearLayout driving_license_info;
|
|
113
|
private EditText plate_num;
|
|
114
|
private EditText engine_num;
|
|
115
|
private EditText register_date;
|
|
116
|
|
|
117
|
private String drivingLicenseBase64Data;
|
94
|
118
|
|
95
|
119
|
@Override
|
96
|
120
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@ -145,6 +169,11 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
145
|
169
|
driving_license_type_second.setOnClickListener(this);
|
146
|
170
|
driving_license_type_third.setOnClickListener(this);
|
147
|
171
|
|
|
172
|
driving_license_info = findViewById(R.id.driving_license_info);
|
|
173
|
plate_num = findViewById(R.id.plate_num);
|
|
174
|
engine_num = findViewById(R.id.engine_num);
|
|
175
|
register_date = findViewById(R.id.register_date);
|
|
176
|
|
148
|
177
|
selected = getResources().getDrawable(R.drawable.icon_radio_selected, null);
|
149
|
178
|
selected.setBounds(0, 0, selected.getMinimumWidth(), selected.getMinimumHeight());
|
150
|
179
|
normal = getResources().getDrawable(R.drawable.icon_radio_normal, null);
|
|
@ -158,10 +187,8 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
158
|
187
|
if (showLoading)
|
159
|
188
|
loadDialog.show();
|
160
|
189
|
// https://www.jianshu.com/p/10382cc71127
|
161
|
|
// String url = "https://api.touchev.com:83/car/api/v1000/brand/list.do";
|
162
|
|
String url = "http://car.d1ev.com/car/api/v1000/brand/list.do";
|
163
|
|
// String url = MainApplication.url + "/zhannew/basic/web/index.php/member/get-score?id=" + MainApplication.userId +
|
164
|
|
// "&phone=" + MainApplication.userPhone + "&password=" + MainApplication.userPassword + "&token=" + "xxxxxx";
|
|
190
|
String url = "https://api.touchev.com:83/car/api/v1000/brand/list.do";
|
|
191
|
// String url = "http://car.d1ev.com/car/api/v1000/brand/list.do";
|
165
|
192
|
OkHttpUtils.get().url(url).build().connTimeOut(5000).readTimeOut(5000).execute(new StringCallback() {
|
166
|
193
|
@Override
|
167
|
194
|
public void onError(Call call, Exception e) {
|
|
@ -211,39 +238,28 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
211
|
238
|
}
|
212
|
239
|
break;
|
213
|
240
|
case R.id.driving_license:
|
214
|
|
Matisse.from(CarOwnerCertificateActivity.this)
|
215
|
|
.choose(MimeType.of(MimeType.JPEG, MimeType.PNG))
|
216
|
|
.showSingleMediaType(true)
|
217
|
|
.countable(true)
|
218
|
|
.maxSelectable(1)
|
219
|
|
.capture(true)
|
220
|
|
.captureStrategy(new CaptureStrategy(true, "com.electric.chargingpile.provider"))
|
221
|
|
.imageEngine(new GlideEngine())
|
222
|
|
.forResult(REQUEST_CODE_CHOOSE);
|
|
241
|
permissionTask();
|
223
|
242
|
break;
|
224
|
243
|
case R.id.driving_license_type_first:
|
225
|
|
drivingLicenseType = 1;
|
|
244
|
drivingLicenseType = "自用";
|
226
|
245
|
driving_license_type_first.setCompoundDrawables(selected, null, null, null);
|
227
|
246
|
driving_license_type_second.setCompoundDrawables(normal, null, null, null);
|
228
|
247
|
driving_license_type_third.setCompoundDrawables(normal, null, null, null);
|
229
|
248
|
break;
|
230
|
249
|
case R.id.driving_license_type_second:
|
231
|
|
drivingLicenseType = 2;
|
|
250
|
drivingLicenseType = "运营";
|
232
|
251
|
driving_license_type_first.setCompoundDrawables(normal, null, null, null);
|
233
|
252
|
driving_license_type_second.setCompoundDrawables(selected, null, null, null);
|
234
|
253
|
driving_license_type_third.setCompoundDrawables(normal, null, null, null);
|
235
|
254
|
break;
|
236
|
255
|
case R.id.driving_license_type_third:
|
237
|
|
drivingLicenseType = 3;
|
|
256
|
drivingLicenseType = "公务";
|
238
|
257
|
driving_license_type_first.setCompoundDrawables(normal, null, null, null);
|
239
|
258
|
driving_license_type_second.setCompoundDrawables(normal, null, null, null);
|
240
|
259
|
driving_license_type_third.setCompoundDrawables(selected, null, null, null);
|
241
|
260
|
break;
|
242
|
261
|
case R.id.submit_btn:
|
243
|
|
if (carSeriesEntity == null) {
|
244
|
|
ToastUtil.showToast(this, "请添加车型" + drivingLicenseType, Toast.LENGTH_SHORT);
|
245
|
|
return;
|
246
|
|
}
|
|
262
|
addCarOwnerCertification();
|
247
|
263
|
break;
|
248
|
264
|
}
|
249
|
265
|
}
|
|
@ -327,8 +343,8 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
327
|
343
|
* @param data
|
328
|
344
|
*/
|
329
|
345
|
private void insertImagesSync(final Intent data) {
|
|
346
|
insertDialog.setMessage("正在插入图片...");
|
330
|
347
|
insertDialog.show();
|
331
|
|
|
332
|
348
|
Observable.create(new ObservableOnSubscribe<String>() {
|
333
|
349
|
@Override
|
334
|
350
|
public void subscribe(ObservableEmitter<String> subscriber) throws Exception {
|
|
@ -342,10 +358,6 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
342
|
358
|
bitmap = FileUtils.rotateIfRequired(file, bitmap);
|
343
|
359
|
bitmap = imageZoom(bitmap);
|
344
|
360
|
insertBitmap = bitmap;
|
345
|
|
|
346
|
|
u_path = SDCardUtil.saveToSdCard(bitmap);
|
347
|
|
|
348
|
|
subscriber.onNext(u_path);
|
349
|
361
|
subscriber.onComplete();
|
350
|
362
|
} catch (Exception e) {
|
351
|
363
|
e.printStackTrace();
|
|
@ -362,7 +374,8 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
362
|
374
|
driving_license_icon.setImageBitmap(insertBitmap);
|
363
|
375
|
driving_license_upload_icon.setVisibility(View.GONE);
|
364
|
376
|
driving_license_text_view.setVisibility(View.GONE);
|
365
|
|
// uploadPic(insertBitmap, u_path); // TODO EditAnswerActivity
|
|
377
|
String base64 = bitmapToBase64(insertBitmap);
|
|
378
|
uploadPic(base64);
|
366
|
379
|
}
|
367
|
380
|
|
368
|
381
|
@Override
|
|
@ -382,4 +395,180 @@ public class CarOwnerCertificateActivity extends AppCompatActivity implements Vi
|
382
|
395
|
}
|
383
|
396
|
});
|
384
|
397
|
}
|
|
398
|
|
|
399
|
private String bitmapToBase64(Bitmap bitmap) {
|
|
400
|
String result = null;
|
|
401
|
ByteArrayOutputStream baos = null;
|
|
402
|
try {
|
|
403
|
if (bitmap != null) {
|
|
404
|
baos = new ByteArrayOutputStream();
|
|
405
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
|
|
406
|
baos.flush();
|
|
407
|
baos.close();
|
|
408
|
byte[] bitmapBytes = baos.toByteArray();
|
|
409
|
result = Base64.encodeToString(bitmapBytes, Base64.NO_WRAP);
|
|
410
|
}
|
|
411
|
} catch (IOException e) {
|
|
412
|
e.printStackTrace();
|
|
413
|
} finally {
|
|
414
|
try {
|
|
415
|
if (baos != null) {
|
|
416
|
baos.flush();
|
|
417
|
baos.close();
|
|
418
|
}
|
|
419
|
} catch (IOException e) {
|
|
420
|
e.printStackTrace();
|
|
421
|
}
|
|
422
|
}
|
|
423
|
return result;
|
|
424
|
}
|
|
425
|
|
|
426
|
private void uploadPic(final String base64) {
|
|
427
|
driving_license_info.setVisibility(View.VISIBLE);
|
|
428
|
if (base64 == null) {
|
|
429
|
return;
|
|
430
|
}
|
|
431
|
drivingLicenseBase64Data = "data:image/png;base64," + base64;
|
|
432
|
insertDialog.setMessage("正在识别行驶证");
|
|
433
|
insertDialog.show();
|
|
434
|
long appTime = System.currentTimeMillis() / 1000;
|
|
435
|
long updateTime = appTime - MainMapActivity.cha - 1;
|
|
436
|
String token = null;
|
|
437
|
try {
|
|
438
|
token = URLEncoder.encode(DES3.encode(String.valueOf(updateTime)));
|
|
439
|
} catch (Exception e) {
|
|
440
|
e.printStackTrace();
|
|
441
|
}
|
|
442
|
|
|
443
|
String url = MainApplication.url + "/zhannew/basic/web/index.php/car/ocr";
|
|
444
|
OkHttpUtils.post().url(url).addParams("Base64Data", drivingLicenseBase64Data).addParams("Category", "driving").addParams("token", token)
|
|
445
|
.build().execute(new StringCallback() {
|
|
446
|
@Override
|
|
447
|
public void onError(Call call, Exception e) {
|
|
448
|
insertDialog.dismiss();
|
|
449
|
e.printStackTrace();
|
|
450
|
ToastUtil.showToast(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT);
|
|
451
|
}
|
|
452
|
|
|
453
|
@Override
|
|
454
|
public void onResponse(String response) {
|
|
455
|
insertDialog.dismiss();
|
|
456
|
// {"Code":0,"Message":"成功","RequestId":"F84FF659-1D65-48E1-8C12-B253CEFCC4F8","Data":{"plate_num":"京Q52DR5","vehicle_type":"小型轿车","owner":"北京一度用车信息科技有限公司","address":"北京市海淀区中关村东路18号1号楼C日609-1","useCharacter":"葙赁","model":"北京牌BJ7000B3D5-BEV","vin":"LNBSCB3F4HD101254","engine_num":"AD33DH03040031","register_date":"20170525","issueDate":"00170525"}}
|
|
457
|
String code = JsonUtils.getKeyResult(response, "Code");
|
|
458
|
if ("0".equals(code)) {
|
|
459
|
String data = JsonUtils.getKeyResult(response, "Data");
|
|
460
|
String platNum = JsonUtils.getKeyResult(data, "plate_num");
|
|
461
|
String engineNum = JsonUtils.getKeyResult(data, "engine_num");
|
|
462
|
String registerDate = JsonUtils.getKeyResult(data, "register_date");
|
|
463
|
plate_num.setText(platNum);
|
|
464
|
engine_num.setText(engineNum);
|
|
465
|
register_date.setText(registerDate);
|
|
466
|
} else {
|
|
467
|
String message = JsonUtils.getKeyResult(response, "Message");
|
|
468
|
ToastUtil.showToast(getApplicationContext(), message, Toast.LENGTH_SHORT);
|
|
469
|
}
|
|
470
|
}
|
|
471
|
});
|
|
472
|
}
|
|
473
|
|
|
474
|
private void addCarOwnerCertification() {
|
|
475
|
if (carSeriesEntity == null) {
|
|
476
|
ToastUtil.showToast(this, "请添加车型", Toast.LENGTH_SHORT);
|
|
477
|
return;
|
|
478
|
}
|
|
479
|
|
|
480
|
// if (drivingLicenseBase64Data == null) {
|
|
481
|
// ToastUtil.showToast(this, "请上传行驶证首页" + drivingLicenseType, Toast.LENGTH_SHORT);
|
|
482
|
// return;
|
|
483
|
// }
|
|
484
|
|
|
485
|
insertDialog.setMessage("数据提交中");
|
|
486
|
insertDialog.show();
|
|
487
|
|
|
488
|
String url = MainApplication.url + "/zhannew/basic/web/index.php/car/add";
|
|
489
|
Map<String, String> map = new HashMap<>();
|
|
490
|
map.put("brand_id", carSeriesEntity.getBrandId());
|
|
491
|
map.put("brand_name", carSeriesEntity.getBrandName());
|
|
492
|
map.put("company_id", carSeriesEntity.getCompanyId());
|
|
493
|
map.put("icon", carSeriesEntity.getIcon());
|
|
494
|
map.put("series_id", carSeriesEntity.getSeriesId());
|
|
495
|
map.put("chexing", carSeriesEntity.getSeriesName());
|
|
496
|
if (drivingLicenseBase64Data != null) {
|
|
497
|
map.put("license_img1", drivingLicenseBase64Data);
|
|
498
|
map.put("plate_number", plate_num.getText().toString().trim());
|
|
499
|
map.put("engine_number", engine_num.getText().toString().trim());
|
|
500
|
map.put("regdate", register_date.getText().toString().trim());
|
|
501
|
}
|
|
502
|
map.put("cartype",drivingLicenseType);
|
|
503
|
map.put("userid", MainApplication.userId);
|
|
504
|
OkHttpUtils.postString().url(url).content(new Gson().toJson(map)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
|
|
505
|
@Override
|
|
506
|
public void onError(Call call, Exception e) {
|
|
507
|
insertDialog.dismiss();
|
|
508
|
e.printStackTrace();
|
|
509
|
ToastUtil.showToast(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT);
|
|
510
|
}
|
|
511
|
|
|
512
|
@Override
|
|
513
|
public void onResponse(String response) {
|
|
514
|
insertDialog.dismiss();
|
|
515
|
// {"Code":0,"Message":"成功","RequestId":"F84FF659-1D65-48E1-8C12-B253CEFCC4F8","Data":{"plate_num":"京Q52DR5","vehicle_type":"小型轿车","owner":"北京一度用车信息科技有限公司","address":"北京市海淀区中关村东路18号1号楼C日609-1","useCharacter":"葙赁","model":"北京牌BJ7000B3D5-BEV","vin":"LNBSCB3F4HD101254","engine_num":"AD33DH03040031","register_date":"20170525","issueDate":"00170525"}}
|
|
516
|
String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
|
|
517
|
if ("01".equals(rtnCode)) {
|
|
518
|
ToastUtil.showToast(getApplicationContext(), "数据提交成功", Toast.LENGTH_SHORT);
|
|
519
|
finish();
|
|
520
|
} else {
|
|
521
|
String message = JsonUtils.getKeyResult(response, "Message");
|
|
522
|
ToastUtil.showToast(getApplicationContext(), message, Toast.LENGTH_SHORT);
|
|
523
|
}
|
|
524
|
}
|
|
525
|
});
|
|
526
|
}
|
|
527
|
|
|
528
|
@Override
|
|
529
|
public void onPermissionsGranted(int requestCode, List<String> perms) {
|
|
530
|
|
|
531
|
}
|
|
532
|
|
|
533
|
@Override
|
|
534
|
public void onPermissionsDenied(int requestCode, List<String> perms) {
|
|
535
|
|
|
536
|
}
|
|
537
|
|
|
538
|
@Override
|
|
539
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
540
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
541
|
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
|
|
542
|
}
|
|
543
|
|
|
544
|
@AfterPermissionGranted(RC_ALBUM_PERM)
|
|
545
|
public void permissionTask() {
|
|
546
|
if (isPermissionOK()) {
|
|
547
|
Matisse.from(CarOwnerCertificateActivity.this)
|
|
548
|
.choose(MimeType.of(MimeType.JPEG, MimeType.PNG))
|
|
549
|
.showSingleMediaType(true)
|
|
550
|
.countable(true)
|
|
551
|
.maxSelectable(1)
|
|
552
|
.capture(true)
|
|
553
|
.captureStrategy(new CaptureStrategy(true, "com.electric.chargingpile.provider"))
|
|
554
|
.imageEngine(new GlideEngine())
|
|
555
|
.forResult(REQUEST_CODE_CHOOSE);
|
|
556
|
} else {
|
|
557
|
EasyPermissions.requestPermissions(
|
|
558
|
this, "充电桩想要获取您的图片读取权限,是否允许?",
|
|
559
|
RC_ALBUM_PERM,
|
|
560
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
561
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
562
|
Manifest.permission.CAMERA
|
|
563
|
);
|
|
564
|
}
|
|
565
|
}
|
|
566
|
|
|
567
|
private boolean isPermissionOK() {
|
|
568
|
return EasyPermissions.hasPermissions(this,
|
|
569
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
570
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
571
|
Manifest.permission.CAMERA
|
|
572
|
);
|
|
573
|
}
|
385
|
574
|
}
|