1、代码优化

main
shisaiqun 2 years ago
parent 58cb445923
commit 40294e429a
  1. 87
      app/src/main/java/cn/org/landcloud/survey/data/DataRepositories.java
  2. 40
      app/src/main/java/cn/org/landcloud/survey/util/Utils.java
  3. 18
      build.gradle
  4. 4
      gradle/wrapper/gradle-wrapper.properties
  5. 7
      ssl/build.gradle

@ -3,40 +3,30 @@ package cn.org.landcloud.survey.data;
import static cn.org.landcloud.survey.util.Constants.CERT_ORG_CODE;
import static cn.org.landcloud.survey.util.Constants.TEST_CER;
import static cn.org.landcloud.survey.util.Constants.TEST_CERT_ORG_PUBLICKEY;
import static cn.org.landcloud.survey.util.Constants.TEST_PUBLICKEY;
import android.content.Context;
import android.os.Environment;
import android.util.Base64;
import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;
import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.NumberFormat;
import java.util.HashMap;
import cn.org.landcloud.security.Util;
import cn.org.landcloud.security.sm2.SM2SignVO;
import cn.org.landcloud.security.sm2.SM2SignVerUtils;
import cn.org.landcloud.security.sm3.SM3Utils;
import cn.org.landcloud.survey.util.Constants;
import cn.org.landcloud.survey.util.FileIOUtils;
import cn.org.landcloud.survey.util.TimeUtils;
import cn.org.landcloud.survey.util.Utils;
import cn.org.landcloud.survey.data.bean.DBInfo;
import cn.org.landcloud.survey.data.bean.DCHSXX;
import cn.org.landcloud.survey.data.bean.FJ;
import cn.org.landcloud.survey.data.bean.JMXX;
import cn.org.landcloud.survey.data.bean.KZXXYSJ;
import cn.org.landcloud.survey.data.bean.TBJBXX;
import cn.org.landcloud.survey.util.Constants;
import cn.org.landcloud.survey.util.FileIOUtils;
import cn.org.landcloud.survey.util.TimeUtils;
import cn.org.landcloud.survey.util.Utils;
public class DataRepositories {
@ -181,15 +171,9 @@ public class DataRepositories {
fj_phone_normal.setPSTZ("J");
File file = new File(Environment.getExternalStorageDirectory(),RELATIVE_FJ_DIR+"phone_1.jpg");
ExifInterface exifInterface;
fj_phone_normal.setFJ(FileIOUtils.readFile2BytesByChannel(file));
try {
fj_phone_normal.setFJHXZ(SM3Utils.sm3(file));
exifInterface = new ExifInterface(file);
exifInterface.setAttribute(ExifInterface.TAG_ARTIST, Base64Encode("test"));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, decimalToDMS(119.9854736));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, decimalToDMS(30.2776146));
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
@ -220,9 +204,9 @@ public class DataRepositories {
content.append(fj_phone_normal.getPSSJ()).append(",");
content.append(Utils.doubleFormat(fj_phone_normal.getLongitude())).append(",");
content.append(Utils.doubleFormat(fj_phone_normal.getLatitude())).append(",");
content.append(Utils.doubleFormat(fj_phone_normal.getPSFYJ())).append(",");
content.append(Utils.doubleFormat(fj_phone_normal.getPSJD())).append(",");
content.append(Utils.doubleFormat(fj_phone_normal.getPSHGJ())).append(",");
content.append(fj_phone_normal.getPSFYJ()).append(",");
content.append(fj_phone_normal.getPSJD()).append(",");
content.append(fj_phone_normal.getPSHGJ()).append(",");
content.append(fj_phone_normal.getPSRY()).append(",");
content.append(fj_phone_normal.getZSDM());
String jym = Utils.makeJYM(content.toString(),Constants.TEST_PRIVATEKEY);
@ -248,11 +232,6 @@ public class DataRepositories {
fj_phone_panoramic.setFJ(FileIOUtils.readFile2BytesByChannel(file));
try {
fj_phone_panoramic.setFJHXZ(SM3Utils.sm3(file));
exifInterface = new ExifInterface(file);
exifInterface.setAttribute(ExifInterface.TAG_ARTIST, Base64Encode("test"));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, decimalToDMS(119.9854813));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, decimalToDMS(30.2775860));
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
@ -282,9 +261,9 @@ public class DataRepositories {
content.append(fj_phone_panoramic.getPSSJ()).append(",");
content.append(Utils.doubleFormat(fj_phone_panoramic.getLongitude())).append(",");
content.append(Utils.doubleFormat(fj_phone_panoramic.getLatitude())).append(",");
content.append(Utils.doubleFormat(fj_phone_panoramic.getPSFYJ())).append(",");
content.append(Utils.doubleFormat(fj_phone_panoramic.getPSJD())).append(",");
content.append(Utils.doubleFormat(fj_phone_panoramic.getPSHGJ())).append(",");
content.append(fj_phone_panoramic.getPSFYJ()).append(",");
content.append(fj_phone_panoramic.getPSJD()).append(",");
content.append(fj_phone_panoramic.getPSHGJ()).append(",");
content.append(fj_phone_panoramic.getPSRY()).append(",");
content.append(fj_phone_panoramic.getZSDM());
fj_phone_panoramic.setJYM(Utils.makeJYM(content.toString(),Constants.TEST_PRIVATEKEY));
@ -303,11 +282,6 @@ public class DataRepositories {
fj_uav_normal.setFJ(FileIOUtils.readFile2BytesByChannel(file));
try {
fj_uav_normal.setFJHXZ(SM3Utils.sm3(file));
exifInterface = new ExifInterface(file);
exifInterface.setAttribute(ExifInterface.TAG_ARTIST, Base64Encode("kmap"));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, decimalToDMS(119.9855061));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, decimalToDMS(30.2774821));
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
@ -337,9 +311,9 @@ public class DataRepositories {
content.append(fj_uav_normal.getPSSJ()).append(",");
content.append(Utils.doubleFormat(fj_uav_normal.getLongitude())).append(",");
content.append(Utils.doubleFormat(fj_uav_normal.getLatitude())).append(",");
content.append(Utils.doubleFormat(fj_uav_normal.getPSFYJ())).append(",");
content.append(Utils.doubleFormat(fj_uav_normal.getPSJD())).append(",");
content.append(Utils.doubleFormat(fj_uav_normal.getPSHGJ())).append(",");
content.append(fj_uav_normal.getPSFYJ()).append(",");
content.append(fj_uav_normal.getPSJD()).append(",");
content.append(fj_uav_normal.getPSHGJ()).append(",");
content.append(fj_uav_normal.getPSRY()).append(",");
content.append(fj_uav_normal.getZSDM());
fj_uav_normal.setJYM(Utils.makeJYM(content.toString(),Constants.TEST_PRIVATEKEY));
@ -359,11 +333,6 @@ public class DataRepositories {
fj_uav_panoramic.setFJ(FileIOUtils.readFile2BytesByChannel(file));
try {
fj_uav_panoramic.setFJHXZ(SM3Utils.sm3(file));
exifInterface = new ExifInterface(file);
exifInterface.setAttribute(ExifInterface.TAG_ARTIST, Base64Encode("kmap"));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, decimalToDMS(119.9855061));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, decimalToDMS(30.2774821));
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
@ -393,9 +362,9 @@ public class DataRepositories {
content.append(fj_uav_panoramic.getPSSJ()).append(",");
content.append(Utils.doubleFormat(fj_uav_panoramic.getLongitude())).append(",");
content.append(Utils.doubleFormat(fj_uav_panoramic.getLatitude())).append(",");
content.append(Utils.doubleFormat(fj_uav_panoramic.getPSFYJ())).append(",");
content.append(Utils.doubleFormat(fj_uav_panoramic.getPSJD())).append(",");
content.append(Utils.doubleFormat(fj_uav_panoramic.getPSHGJ())).append(",");
content.append(fj_uav_panoramic.getPSFYJ()).append(",");
content.append(fj_uav_panoramic.getPSJD()).append(",");
content.append(fj_uav_panoramic.getPSHGJ()).append(",");
content.append(fj_uav_panoramic.getPSRY()).append(",");
content.append(fj_uav_panoramic.getZSDM());
fj_uav_panoramic.setJYM(Utils.makeJYM(content.toString(),Constants.TEST_PRIVATEKEY));
@ -442,9 +411,9 @@ public class DataRepositories {
content.append(fj_video.getPSSJ()).append(",");
content.append(Utils.doubleFormat(fj_video.getLongitude())).append(",");
content.append(Utils.doubleFormat(fj_video.getLatitude())).append(",");
content.append(Utils.doubleFormat(fj_video.getPSFYJ())).append(",");
content.append(Utils.doubleFormat(fj_video.getPSJD())).append(",");
content.append(Utils.doubleFormat(fj_video.getPSHGJ())).append(",");
content.append(fj_video.getPSFYJ()).append(",");
content.append(fj_video.getPSJD()).append(",");
content.append(fj_video.getPSHGJ()).append(",");
content.append(fj_video.getPSRY()).append(",");
content.append(fj_video.getZSDM());
fj_video.setJYM(Utils.makeJYM(content.toString(),Constants.TEST_PRIVATEKEY));
@ -500,22 +469,4 @@ public class DataRepositories {
}
}
private String Base64Encode(String s) {
return Base64.encodeToString(s.getBytes(), Base64.DEFAULT);
}
/**
* 经纬度 度分秒
*
* @param value - latitude or longitude
* @return
*/
private String decimalToDMS(double value) {
int num1 = (int) Math.floor(value);
int num2 = (int) Math.floor((value - num1) * 60);
double num3 = (value - ((double) num1 + ((double) num2 / 60))) * 360000000;
return num1 + "/1," + num2 + "/1," + num3 + "/100000";
}
}

@ -1,12 +1,15 @@
package cn.org.landcloud.survey.util;
import androidx.exifinterface.media.ExifInterface;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import cn.org.landcloud.security.Util;
import cn.org.landcloud.security.sm2.SM2;
import cn.org.landcloud.security.sm2.SM2EncDecUtils;
import cn.org.landcloud.security.sm2.SM2SignVO;
import cn.org.landcloud.security.sm2.SM2SignVerUtils;
import cn.org.landcloud.security.sm3.SM3Utils;
@ -35,4 +38,35 @@ public class Utils {
DecimalFormat df = new DecimalFormat("##########.#########");
return df.format(value);
}
/**
* 经纬度 度分秒
*
* @param value - latitude or longitude
* @return
*/
public static String decimalToDMS(double value) {
int num1 = (int) Math.floor(value);
int num2 = (int) Math.floor((value - num1) * 60);
double num3 = (value - ((double) num1 + ((double) num2 / 60))) * 360000000;
return num1 + "/1," + num2 + "/1," + num3 + "/100000";
}
/**
* 照片属性写入类
* @param file
* @param attributes
*/
public static void writeExifAttributes(File file, HashMap<String,String> attributes) {
ExifInterface exifInterface;
try {
exifInterface = new ExifInterface(file);
for(Map.Entry<String,String> entry:attributes.entrySet()) {
exifInterface.setAttribute(entry.getKey(), entry.getValue());
}
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -1,5 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

@ -1,6 +1,6 @@
#Wed Oct 12 10:45:05 CST 2022
#Fri Oct 21 08:48:54 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

@ -6,13 +6,6 @@ java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
/* task makeJar(type: jar) {
delete 'ssl.jar'
from file('src/main/java/')
destinationDir = file('build/libs')
archiveName = 'ssl.jar'
}
makeJar.dependsOn(build)*/
}
dependencies {

Loading…
Cancel
Save