Skip to content

Commit

Permalink
Merge pull request #532 from afischerdev/app-online-check
Browse files Browse the repository at this point in the history
App changes, online check
  • Loading branch information
afischerdev committed Apr 22, 2023
2 parents 60de94f + 4559f17 commit e176679
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 42 deletions.
1 change: 1 addition & 0 deletions brouter-routing-app/src/main/AndroidManifest.xml
Expand Up @@ -18,6 +18,7 @@
android:label="@string/app_name"
android:preserveLegacyExternalStorage="true"
android:hasFragileUserData="true"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.App">
<activity
Expand Down
Binary file modified brouter-routing-app/src/main/assets/modes.zip
Binary file not shown.
Expand Up @@ -33,7 +33,6 @@
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;
import androidx.work.WorkRequest;

import com.google.android.material.progressindicator.LinearProgressIndicator;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -92,8 +91,7 @@ public void onCreate(Bundle savedInstanceState) {
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.POST_NOTIFICATIONS)
== PackageManager.PERMISSION_GRANTED) {
// nothing to do
}
if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
} else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
//
} else {
// You can directly ask for the permission.
Expand Down Expand Up @@ -222,14 +220,14 @@ public void downloadAll(ArrayList<Integer> downloadList, int all) {
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();

WorkRequest downloadWorkRequest =
OneTimeWorkRequest downloadWorkRequest =
new OneTimeWorkRequest.Builder(DownloadWorker.class)
.setInputData(inputData)
.setConstraints(constraints)
.build();

WorkManager workManager = WorkManager.getInstance(getApplicationContext());
workManager.enqueueUniqueWork(DownloadWorker.WORKER_NAME, ExistingWorkPolicy.KEEP, (OneTimeWorkRequest) downloadWorkRequest);
workManager.enqueueUniqueWork(DownloadWorker.WORKER_NAME, ExistingWorkPolicy.KEEP, downloadWorkRequest);

try {
WorkInfo wi = WorkManager.getInstance(getApplicationContext()).getWorkInfoById(downloadWorkRequest.getId()).get();
Expand All @@ -256,7 +254,6 @@ public void downloadAll(ArrayList<Integer> downloadList, int all) {
private void startObserver(WorkInfo workInfo) {
if (workInfo != null) {
if (workInfo.getState() == WorkInfo.State.ENQUEUED || workInfo.getState() == WorkInfo.State.BLOCKED) {
Log.d("worker", "cancel " + workInfo.getState());
//WorkManager.getInstance(getApplicationContext()).cancelWorkById(downloadWorkRequest.getId());
}

Expand All @@ -265,6 +262,9 @@ private void startObserver(WorkInfo workInfo) {
mProgressIndicator.hide();
mProgressIndicator.setIndeterminate(true);
mProgressIndicator.show();

mButtonDownload.setText(getString(R.string.action_cancel));
mButtonDownload.setEnabled(true);
}

if (workInfo.getState() == WorkInfo.State.RUNNING) {
Expand Down Expand Up @@ -310,12 +310,17 @@ private void startObserver(WorkInfo workInfo) {
}
}

if (error != null && error.startsWith("error new app")) {
if (error != null && error.startsWith("Version new app")) {
showAppUpdate();
} else if (error != null && error.startsWith("Version error")) {
showConfirmNextSteps();
} else if (error != null && error.startsWith("Version diffs")) {
showConfirmGetDiffs();
} else if (error != null) {
stopDownload();
mBInstallerView.setOnSelectListener(onSelectListener);
mBInstallerView.clearAllTilesStatus(MASK_SELECTED_RD5);
scanExistingFiles();
} else {
mBInstallerView.setOnSelectListener(onSelectListener);
mBInstallerView.clearAllTilesStatus(MASK_SELECTED_RD5);
Expand Down
Expand Up @@ -29,7 +29,6 @@ public class BRouterService extends Service {

@Override
public IBinder onBind(Intent arg0) {
Log.d(getClass().getSimpleName(), "onBind()");
return myBRouterServiceStub;
}

Expand Down Expand Up @@ -277,13 +276,11 @@ private void logBundle(Bundle params) {
@Override
public void onCreate() {
super.onCreate();
Log.d(getClass().getSimpleName(), "onCreate()");
}

@Override
public void onDestroy() {
super.onDestroy();
Log.d(getClass().getSimpleName(), "onDestroy()");
}

// This is the old onStart method that will be called on the pre-2.0
Expand Down
Expand Up @@ -266,7 +266,7 @@ private boolean downloadLookup() throws IOException, InterruptedException {
}
if (newappversion != -1 && newappversion > appversion) {
if (DEBUG) Log.d(LOG_TAG, "app version old " + appversion + " new " + newappversion);
errorCode = "error new app";
errorCode = "Version new app";
return false;
}
if (changed && downloadAll == VALUE_SEGMENT_PARTS) {
Expand Down Expand Up @@ -375,36 +375,42 @@ private boolean httpFileExists(URL downloadUrl) throws IOException {
connection.setConnectTimeout(5000);
connection.setRequestMethod("HEAD");
connection.setDoInput(false);
connection.connect();
try {
connection.connect();
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
} finally {
connection.disconnect();
}

return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
}

private boolean downloadFile(URL downloadUrl, File outputFile, int fileSize, boolean limitDownloadSpeed, DownloadType type) throws IOException, InterruptedException {
if (DEBUG) Log.d(LOG_TAG, "download " + outputFile.getAbsolutePath());
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
connection.setConnectTimeout(5000);
connection.connect();
connection.setDefaultUseCaches(false);

if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("HTTP Request failed: " + downloadUrl + " returned " + connection.getResponseCode());
}
int dataLength = connection.getContentLength();
// no need of download when size equal
// file size not the best coice but easy to handle, date is not available
switch (type) {
case LOOKUP:
if (fileSize == dataLength) return false;
break;
case PROFILE:
if (fileSize == dataLength) return false;
break;
default:
break;
}
InputStream input = null;
OutputStream output = null;
try {
connection.connect();

if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("HTTP Request failed: " + downloadUrl + " returned " + connection.getResponseCode());
}
int dataLength = connection.getContentLength();
// no need of download when size equal
// file size not the best coice but easy to handle, date is not available
switch (type) {
case LOOKUP:
if (fileSize == dataLength) return false;
break;
case PROFILE:
if (fileSize == dataLength) return false;
break;
default:
break;
}
input = connection.getInputStream();
output = new FileOutputStream(outputFile);

Expand Down
2 changes: 1 addition & 1 deletion docs/features/elevation.md
Expand Up @@ -21,7 +21,7 @@ elevation-enabled routing tools. However, the routing algorithm is able to
extract the information on real ascends and descends and ignores the noise.

For latitudes above 60 degree in northern Europe, BRouter uses Lidar data, that
were [compiled and resampled by Sonny](https://data.opendataportal.at/dataset/dtm-europe)
were [compiled and resampled by Sonny](https://sonny.4lima.de/)

On the reporting side, BRouter uses a similar concept to compute the *filtered
ascend*, which is the ascend without the noise and the small hills and which
Expand Down
26 changes: 15 additions & 11 deletions misc/profiles2/hiking-mountain.brf
Expand Up @@ -10,24 +10,22 @@

---context:global

assign consider_elevation 1 # 0 as default, otherwise less interesting flat roads are chosen.
assign shortest_way 0 # 0 as default, duplicate shortest standard profile, SAC access limit ignored for now
assign consider_elevation true # %consider_elevation% | Set to false, otherwise less interesting flat roads are chosen | boolean

assign turnInstructionMode = 1 # %turnInstructionMode% | Mode for the generated turn instructions | [0=none, 1=auto-choose, 2=locus-style, 3=osmand-style, 4=comment-style, 5=gpsies-style, 6=orux-style, 7=locus-old-style]
assign turnInstructionCatchingRange 20 # V1.8.5 / default=40, but foot paths may be more distingushed, especially in cities.
assign shortest_way 0 # 0 as default, duplicate shortest standard profile, SAC access limit ignored for now

assign iswet 0 # 0 as default, 1 tries to prevent muddy boots and wet buttocks
assign hiking_routes_preference 0.20 # 0.10 as default, Increases cost of non hiking routes by multiplier 1 + hiking_routes_preference
assign iswet 0 # %iswet% | tries to prevent muddy boots and wet buttocks | boolean
assign hiking_routes_preference 0.20 # %hiking_routes_preference% | Increases cost of non hiking routes by multiplier 1 + hiking_routes_preference (0.10 to 2.0) | number

assign Offroad_factor 0.0 # default 0.0, see ****), see also https://github.com/poutnikl/Brouter-profiles/wiki/Trekking-MTB-Profiles---legend

assign path_preference 0.0 # 0.0 as default, try 20.0 to penalize nonpath ways a/o paved ways

#SAC - mountain hiking - see http://wiki.openstreetmap.org/wiki/Key:sac_scale

assign SAC_scale_limit 3 # 0..6, 0 to avoid any SAC paths, 1 for T1 as maximum, 6 for T6 as maximum
# all paths with sac_scale higher than SAC_scale_limit are forbidden.
assign SAC_scale_preferred 1 # The same, but the preferred SAC scale level. Level below are slightly, above strongly penalized
assign SAC_scale_limit 3 # %SAC_scale_limit% | all paths with sac_scale higher than SAC_scale_limit are forbidden | [0=avoid any SAC paths, 1=SAC T1, 2=SAC T2, 3=SAC T3, 4=SAC T4, 5=SAC T5, 6=SAC T6]
assign SAC_scale_preferred 1 # %SAC_scale_preferred% | The same, but the preferred SAC scale level. Level below are slightly, above strongly penalized | [0=avoid any SAC paths, 1=SAC T1, 2=SAC T2, 3=SAC T3, 4=SAC T4, 5=SAC T5, 6=SAC T6]

assign SAC_access_penalty 9000 # costfactor 9999 means the most horrible but allowed road.,
# 100000=forbidden. This makes difference if forbidden way is the only option.
assign SAC_K1 0.05 # Penalizing of SAC levels below preferred
Expand All @@ -38,14 +36,20 @@ assign turncost_value 0 # not used now
assign initialcost_value 0 # not used now

#less frequently changed flags
assign allow_steps 1 # 1 as default
assign allow_ferries 1 # 1 as default
assign allow_steps true # %allow_steps% | Set to false to disallow steps | boolean
assign allow_ferries true # %allow_ferries% | set to false to disallow ferries | boolean

assign cost_of_unknown 2 # 2 as default

#
assign elevationpenaltybuffer 5 # 5 as default
assign elevationmaxbuffer 10 # 10 as default
assign elevationbufferreduce 1.0 # 0.0 as default

assign turnInstructionMode = 1 # %turnInstructionMode% | Mode for the generated turn instructions | [0=none, 1=auto-choose, 2=locus-style, 3=osmand-style, 4=comment-style, 5=gpsies-style, 6=orux-style, 7=locus-old-style]
assign turnInstructionCatchingRange 20 # V1.8.5 / default=40, but foot paths may be more distingushed, especially in cities.


# as initial point, considered flat speed 4 km/h, climbing speed 600 m /h
assign uphillcostvalue 7
assign uphillcutoffvalue 3
Expand Down

0 comments on commit e176679

Please sign in to comment.