chore(main): clean warnings

This commit is contained in:
ZCShou 2024-03-30 16:09:12 +08:00
parent dcb41a51b8
commit 9aff736220
No known key found for this signature in database
GPG Key ID: 40F856243C184EAB
2 changed files with 87 additions and 81 deletions

View File

@ -28,6 +28,8 @@ public class GoApplication extends Application {
public void onCreate() {
super.onCreate();
initXlog();
// 百度地图 7.5 开始要求必须同意隐私政策默认为false
SDKInitializer.setAgreePrivacy(this, true);
// 百度定位 7.5 开始要求必须同意隐私政策默认为false(官方说可以统一为以上接口但实际测试并不行定位还是需要单独设置)
@ -38,10 +40,8 @@ public class GoApplication extends Application {
SDKInitializer.initialize(this);
SDKInitializer.setCoordType(CoordType.BD09LL);
} catch (BaiduMapSDKException e) {
e.printStackTrace();
XLog.e("ERROR init baidu sdk");
}
initXlog();
}
/**
@ -49,12 +49,13 @@ public class GoApplication extends Application {
*/
private void initXlog() {
File logPath = getExternalFilesDir("Logs");
LogConfiguration config = new LogConfiguration.Builder()
.logLevel(LogLevel.ALL)
.tag(APP_NAME) // 指定 TAG默认为 "X-LOG"
.enableThreadInfo() // 允许打印线程信息默认禁止
.enableStackTrace(2) // 允许打印深度为 2 的调用栈信息默认禁止
.enableBorder() // 允许打印日志边框默认禁止
if (logPath != null) {
LogConfiguration config = new LogConfiguration.Builder()
.logLevel(LogLevel.ALL)
.tag(APP_NAME) // 指定 TAG默认为 "X-LOG"
.enableThreadInfo() // 允许打印线程信息默认禁止
.enableStackTrace(2) // 允许打印深度为 2 的调用栈信息默认禁止
.enableBorder() // 允许打印日志边框默认禁止
// .jsonFormatter(new MyJsonFormatter()) // 指定 JSON 格式化器默认为 DefaultJsonFormatter
// .xmlFormatter(new MyXmlFormatter()) // 指定 XML 格式化器默认为 DefaultXmlFormatter
// .throwableFormatter(new MyThrowableFormatter()) // 指定可抛出异常格式化器默认为 DefaultThrowableFormatter
@ -66,16 +67,16 @@ public class GoApplication extends Application {
// .addInterceptor(new BlacklistTagsFilterInterceptor( // 添加黑名单 TAG 过滤器
// "blacklist1", "blacklist2", "blacklist3"))
// .addInterceptor(new MyInterceptor()) // 添加一个日志拦截器
.build();
.build();
// Printer androidPrinter = new AndroidPrinter(true); // 通过 android.util.Log 打印日志的打印器
Printer consolePrinter = new ConsolePrinter(); // 通过 System.out 打印日志到控制台的打印器
Printer filePrinter = new FilePrinter // 打印日志到文件的打印器
.Builder(logPath.getPath()) // 指定保存日志文件的路径
.fileNameGenerator(new ChangelessFileNameGenerator(LOG_FILE_NAME)) // 指定日志文件名生成器默认为 ChangelessFileNameGenerator("log")
.backupStrategy(new NeverBackupStrategy()) // 指定日志文件备份策略默认为 FileSizeBackupStrategy(1024 * 1024)
.cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME)) // 指定日志文件清除策略默认为 NeverCleanStrategy()
.build();
XLog.init(config, consolePrinter, filePrinter);
Printer consolePrinter = new ConsolePrinter(); // 通过 System.out 打印日志到控制台的打印器
Printer filePrinter = new FilePrinter // 打印日志到文件的打印器
.Builder(logPath.getPath()) // 指定保存日志文件的路径
.fileNameGenerator(new ChangelessFileNameGenerator(LOG_FILE_NAME)) // 指定日志文件名生成器默认为 ChangelessFileNameGenerator("log")
.backupStrategy(new NeverBackupStrategy()) // 指定日志文件备份策略默认为 FileSizeBackupStrategy(1024 * 1024)
.cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME)) // 指定日志文件清除策略默认为 NeverCleanStrategy()
.build();
XLog.init(config, consolePrinter, filePrinter);
}
}
}

View File

@ -78,6 +78,7 @@ import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.baidu.mapapi.search.sug.SuggestionResult;
import com.baidu.mapapi.search.sug.SuggestionSearch;
import com.baidu.mapapi.search.sug.SuggestionSearchOption;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -298,7 +299,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
//展示搜索历史
List<Map<String, Object>> data = getSearchHistory();
if (data.size() > 0) {
if (!data.isEmpty()) {
SimpleAdapter simAdapt = new SimpleAdapter(
MainActivity.this,
data,
@ -349,7 +350,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
} catch (Exception e) {
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.app_error_search));
XLog.d(getResources().getString(R.string.app_error_search));
e.printStackTrace();
}
return true;
@ -361,7 +361,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
//搜索历史置为不可见
mHistoryLayout.setVisibility(View.INVISIBLE);
if (newText != null && newText.length() > 0) {
if (newText != null && !newText.isEmpty()) {
try {
mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
.keyword(newText)
@ -370,7 +370,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
} catch (Exception e) {
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.app_error_search));
XLog.d(getResources().getString(R.string.app_error_search));
e.printStackTrace();
}
}
@ -432,7 +431,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
startActivity(intent);
} catch (Exception e) {
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_dev));
e.printStackTrace();
}
} else if (id == R.id.nav_update) {
checkUpdateVersion(true);
@ -514,7 +512,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
mReg.put("UserName", s.toString());
mRegReq.setText(mReg.toString());
} catch (JSONException e) {
e.printStackTrace();
XLog.e("ERROR: username");
}
}
}
@ -531,7 +529,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
mReg.put("DateTime", 1111);
mRegReq.setText(mReg.toString());
} catch (JSONException e) {
e.printStackTrace();
XLog.e("ERROR: DateTime");
}
});
@ -564,7 +562,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
mReg.put("ReqResp", regResp.toString());
} catch (JSONException e) {
e.printStackTrace();
XLog.e("ERROR: reg req");
}
alertDialog.cancel();
@ -762,7 +760,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
}
/**
* 错误的状态码
* <a>http://lbsyun.baidu.com/index.php?title=android-locsdk/guide/addition-func/error-code</a>
* <a><a href="http://lbsyun.baidu.com/index.php?title=android-locsdk/guide/addition-func/error-code">...</a></a>
* <p>
* 回调定位诊断信息开发者可以根据相关信息解决定位遇到的一些问题
*
@ -775,41 +773,47 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
XLog.i("Baidu ERROR: " + locType + "-" + diagnosticType + "-" + diagnosticMessage);
}
});
LocationClientOption locationOption = new LocationClientOption();
//可选默认高精度设置定位模式高精度低功耗仅设备
locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
//可选默认gcj02设置返回的定位结果坐标系如果配合百度地图使用建议设置为bd09ll;
locationOption.setCoorType("bd09ll");
//可选默认0即仅定位一次设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
locationOption.setScanSpan(1000);
//可选设置是否需要地址信息默认不需要
locationOption.setIsNeedAddress(true);
//可选设置是否需要设备方向结果
locationOption.setNeedDeviceDirect(false);
//可选默认false设置是否当gps有效时按照1S1次频率输出GPS结果
locationOption.setLocationNotify(true);
//可选默认true定位SDK内部是一个SERVICE并放到了独立进程设置是否在stop的时候杀死这个进程默认不杀死
locationOption.setIgnoreKillProcess(true);
//可选默认false设置是否需要位置语义化结果可以在BDLocation.getLocationDescribe里得到结果类似于在北京天安门附近
locationOption.setIsNeedLocationDescribe(false);
//可选默认false设置是否需要POI结果可以在BDLocation.getPoiList里得到
locationOption.setIsNeedLocationPoiList(false);
//可选默认false设置是否收集CRASH信息默认收集
locationOption.SetIgnoreCacheException(true);
//可选默认false设置是否开启Gps定位
//locationOption.setOpenGps(true);
locationOption.setOpenGnss(true);
//可选默认false设置定位时是否需要海拔信息默认不需要除基础定位版本都可用
locationOption.setIsNeedAltitude(false);
LocationClientOption locationOption = getLocationClientOption();
//需将配置好的LocationClientOption对象通过setLocOption方法传递给LocationClient对象使用
mLocClient.setLocOption(locationOption);
//开始定位
mLocClient.start();
} catch (Exception e) {
e.printStackTrace();
XLog.e("ERROR: initMapLocation");
}
}
@NonNull
private static LocationClientOption getLocationClientOption() {
LocationClientOption locationOption = new LocationClientOption();
//可选默认高精度设置定位模式高精度低功耗仅设备
locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
//可选默认gcj02设置返回的定位结果坐标系如果配合百度地图使用建议设置为bd09ll;
locationOption.setCoorType("bd09ll");
//可选默认0即仅定位一次设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
locationOption.setScanSpan(1000);
//可选设置是否需要地址信息默认不需要
locationOption.setIsNeedAddress(true);
//可选设置是否需要设备方向结果
locationOption.setNeedDeviceDirect(false);
//可选默认false设置是否当gps有效时按照1S1次频率输出GPS结果
locationOption.setLocationNotify(true);
//可选默认true定位SDK内部是一个SERVICE并放到了独立进程设置是否在stop的时候杀死这个进程默认不杀死
locationOption.setIgnoreKillProcess(true);
//可选默认false设置是否需要位置语义化结果可以在BDLocation.getLocationDescribe里得到结果类似于在北京天安门附近
locationOption.setIsNeedLocationDescribe(false);
//可选默认false设置是否需要POI结果可以在BDLocation.getPoiList里得到
locationOption.setIsNeedLocationPoiList(false);
//可选默认false设置是否收集CRASH信息默认收集
locationOption.SetIgnoreCacheException(true);
//可选默认false设置是否开启Gps定位
//locationOption.setOpenGps(true);
locationOption.setOpenGnss(true);
//可选默认false设置定位时是否需要海拔信息默认不需要除基础定位版本都可用
locationOption.setIsNeedAltitude(false);
return locationOption;
}
//地图上各按键的监听
private void initMapButton() {
RadioGroup mGroupMapType = this.findViewById(R.id.RadioGroupMapType);
@ -994,7 +998,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
} catch (Exception e) {
ret = false;
XLog.e("ERROR: showHistoryLocation");
e.printStackTrace();
}
return ret;
@ -1126,14 +1129,13 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_DESCRIPTION, cursor.getString(2));
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_TIMESTAMP, "" + cursor.getInt(3));
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_IS_LOCATION, "" + cursor.getInt(4));
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_LONGITUDE_CUSTOM, "" + cursor.getString(7));
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_LATITUDE_CUSTOM, "" + cursor.getString(8));
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_LONGITUDE_CUSTOM, cursor.getString(7));
searchHistoryItem.put(DataBaseHistorySearch.DB_COLUMN_LATITUDE_CUSTOM, cursor.getString(8));
data.add(searchHistoryItem);
}
cursor.close();
} catch (Exception e) {
XLog.e("ERROR: query error");
e.printStackTrace();
XLog.e("ERROR: getSearchHistory");
}
return data;
@ -1213,7 +1215,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
contentValues.put(DataBaseHistoryLocation.DB_COLUMN_LATITUDE_CUSTOM, Double.toString(lat));
DataBaseHistoryLocation.saveHistoryLocation(mLocationHistoryDB, contentValues);
e.printStackTrace();
}
}
}
@ -1297,7 +1298,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
} catch (Exception e) {
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_search));
XLog.e(getResources().getString(R.string.app_error_search));
e.printStackTrace();
}
} else {
XLog.e(getResources().getString(R.string.app_error_param));
@ -1316,7 +1316,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
//展示搜索历史
List<Map<String, Object>> data = getSearchHistory();
if (data.size() > 0) {
if (!data.isEmpty()) {
SimpleAdapter simAdapt = new SimpleAdapter(
MainActivity.this,
data,
@ -1347,22 +1347,8 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
mSuggestionSearch.setOnGetSuggestionResultListener(suggestionResult -> {
if (suggestionResult == null || suggestionResult.getAllSuggestions() == null) {
GoUtils.DisplayToast(this,getResources().getString(R.string.app_search_null));
} else { //获取在线建议检索结果
List<Map<String, Object>> data = new ArrayList<>();
int retCnt = suggestionResult.getAllSuggestions().size();
for (int i = 0; i < retCnt; i++) {
if (suggestionResult.getAllSuggestions().get(i).pt == null) {
continue;
}
Map<String, Object> poiItem = new HashMap<>();
poiItem.put(POI_NAME, suggestionResult.getAllSuggestions().get(i).key);
poiItem.put(POI_ADDRESS, suggestionResult.getAllSuggestions().get(i).city + " " + suggestionResult.getAllSuggestions().get(i).district);
poiItem.put(POI_LONGITUDE, "" + suggestionResult.getAllSuggestions().get(i).pt.longitude);
poiItem.put(POI_LATITUDE, "" + suggestionResult.getAllSuggestions().get(i).pt.latitude);
data.add(poiItem);
}
} else {
List<Map<String, Object>> data = getMapList(suggestionResult);
SimpleAdapter simAdapt = new SimpleAdapter(
MainActivity.this,
@ -1377,6 +1363,26 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
});
}
@NonNull
private static List<Map<String, Object>> getMapList(SuggestionResult suggestionResult) {
List<Map<String, Object>> data = new ArrayList<>();
int retCnt = suggestionResult.getAllSuggestions().size();
for (int i = 0; i < retCnt; i++) {
if (suggestionResult.getAllSuggestions().get(i).pt == null) {
continue;
}
Map<String, Object> poiItem = new HashMap<>();
poiItem.put(POI_NAME, suggestionResult.getAllSuggestions().get(i).key);
poiItem.put(POI_ADDRESS, suggestionResult.getAllSuggestions().get(i).city + " " + suggestionResult.getAllSuggestions().get(i).district);
poiItem.put(POI_LONGITUDE, "" + suggestionResult.getAllSuggestions().get(i).pt.longitude);
poiItem.put(POI_LATITUDE, "" + suggestionResult.getAllSuggestions().get(i).pt.latitude);
data.add(poiItem);
}
return data;
}
/*============================== 更新 相关 ==============================*/
private void initUpdateVersion() {
mDownloadManager =(DownloadManager) MainActivity.this.getSystemService(DOWNLOAD_SERVICE);
@ -1459,8 +1465,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
}
}
} catch (JSONException e) {
XLog.e("ERROR: resolve json");
e.printStackTrace();
XLog.e("ERROR: resolve json");
}
});
}