Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:

# https://github.com/marketplace/actions/gh-release
- name: Release APK
uses: softprops/action-gh-release@v2.2.0
uses: softprops/action-gh-release@v2.2.1
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ github.token }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
swap-size-gb: 10
- name: Initialize CodeQL
uses: github/codeql-action/init@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9
uses: github/codeql-action/init@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9
with:
languages: ${{ matrix.language }}
- name: Set up JDK 17
Expand All @@ -63,4 +63,4 @@ jobs:
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > "$HOME/.gradle/gradle.properties"
./gradlew assembleDebug
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9
uses: github/codeql-action/analyze@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
apply plugin: 'com.android.application'

def getGitCommitHash() {
return providers.exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
}.standardOutput.asText.get().trim()
}

android {
signingConfigs {
debug {
Expand All @@ -24,7 +30,7 @@ android {
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 32
versionCode 1121
versionName '1.12.1' // https://semver.org/lang/zh-CN/
versionName '1.12.1-' + getGitCommitHash()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs 'zh', 'zh-rCN', 'en', 'en-rUS'
ndk {
Expand Down
50 changes: 9 additions & 41 deletions app/src/main/java/com/zcshou/gogogo/HistoryActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zcshou.gogogo;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
Expand Down Expand Up @@ -28,8 +30,6 @@
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import java.util.Locale;
import java.util.List;
import java.util.Map;

Expand All @@ -48,7 +48,6 @@ public class HistoryActivity extends BaseActivity {
private LinearLayout mSearchLayout;
private SQLiteDatabase mHistoryLocationDB;
private List<Map<String, Object>> mAllRecord;
private SharedPreferences sharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -68,8 +67,6 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

initLocationDataBase();

initSearchView();
Expand Down Expand Up @@ -175,6 +172,7 @@ private List<Map<String, Object>> fetchAllRecord() {
private void recordArchive() {
double limits;
try {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
limits = Double.parseDouble(sharedPreferences.getString("setting_pos_history", getResources().getString(R.string.history_expiration)));
} catch (NumberFormatException e) { // GOOD: The exception is caught.
limits = 7;
Expand Down Expand Up @@ -295,50 +293,20 @@ private void showInputDialog(String locID, String name) {
builder.show();
}

private String[] randomOffset(String longitude, String latitude) {
String max_offset_default = getResources().getString(R.string.setting_random_offset_default);
double lon_max_offset = Double.parseDouble(Objects.requireNonNull(sharedPreferences.getString("setting_lon_max_offset", max_offset_default)));
double lat_max_offset = Double.parseDouble(Objects.requireNonNull(sharedPreferences.getString("setting_lat_max_offset", max_offset_default)));
double lon = Double.parseDouble(longitude);
double lat = Double.parseDouble(latitude);

double randomLonOffset = (Math.random() * 2 - 1) * lon_max_offset; // Longitude offset (meters)
double randomLatOffset = (Math.random() * 2 - 1) * lat_max_offset; // Latitude offset (meters)

lon += randomLonOffset / 111320; // (meters -> longitude)
lat += randomLatOffset / 110574; // (meters -> latitude)

String offsetMessage = String.format(Locale.US, "经度偏移: %.2f米\n纬度偏移: %.2f米", randomLonOffset, randomLatOffset);
GoUtils.DisplayToast(this, offsetMessage);

return new String[]{String.valueOf(lon), String.valueOf(lat)};
}

private void initRecordListView() {
noRecordText = findViewById(R.id.record_no_textview);
mSearchLayout = findViewById(R.id.search_linear);
mRecordListView = findViewById(R.id.record_list_view);
mRecordListView.setOnItemClickListener((adapterView, view, i, l) -> {
String bd09Longitude;
String bd09Latitude;
String name;
name = (String) ((TextView) view.findViewById(R.id.LocationText)).getText();
String bd09LatLng = (String) ((TextView) view.findViewById(R.id.BDLatLngText)).getText();
bd09LatLng = bd09LatLng.substring(bd09LatLng.indexOf('[') + 1, bd09LatLng.indexOf(']'));
String[] latLngStr = bd09LatLng.split(" ");
bd09Longitude = latLngStr[0].substring(latLngStr[0].indexOf(':') + 1);
bd09Latitude = latLngStr[1].substring(latLngStr[1].indexOf(':') + 1);

// Random offset
if(sharedPreferences.getBoolean("setting_random_offset", false)) {
String[] offsetResult = randomOffset(bd09Longitude, bd09Latitude);
bd09Longitude = offsetResult[0];
bd09Latitude = offsetResult[1];
}

if (!MainActivity.showLocation(name, bd09Longitude, bd09Latitude)) {
GoUtils.DisplayToast(this, getResources().getString(R.string.history_error_location));
}
String bd09Longitude = latLngStr[0].substring(latLngStr[0].indexOf(':') + 1);
String bd09Latitude = latLngStr[1].substring(latLngStr[1].indexOf(':') + 1);
Intent resultIntent = new Intent();
resultIntent.putExtra("bd09_lon", bd09Longitude);
resultIntent.putExtra("bd09_lat", bd09Latitude);
setResult(Activity.RESULT_OK, resultIntent);
this.finish();
});

Expand Down
Loading
Loading