Skip to content

Commit

Permalink
DemManagementActivit(ies) add ProgressBar spinner for long operations…
Browse files Browse the repository at this point in the history
… and improve error text
  • Loading branch information
mkrupczak3 committed May 3, 2024
1 parent 3da7edb commit cc788aa
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 8 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/openathena/DemDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ public void run()
}
}
}
catch (java.net.UnknownHostException uhe) {
if (consumer != null) {
consumer.accept("Could not connect to" + " portal.opentopography.org.\n " + "Is your device connected to the Internet?");
}
}
catch (java.net.SocketException se) {
if (consumer != null) {
consumer.accept("Internet connection was interrupted during download operation. Please try again.");
}
}
catch (Exception e) {
if (consumer != null) {
consumer.accept(e.toString());
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/openathena/DemManagementActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -17,6 +19,10 @@ public abstract class DemManagementActivity extends AthenaActivity {
protected LocationManager locationManager;
protected LocationListener locationListener;

protected ProgressBar progressBar;
// semaphore value will be > 0 if a long process is currently running
protected int showProgressBarSemaphore = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -30,6 +36,10 @@ protected LocationListener createLocationListener() {
public void onLocationChanged(Location location) {
updateLatLonText(location);
locationManager.removeUpdates(this);
showProgressBarSemaphore--;
if (showProgressBarSemaphore<=0) {
progressBar.setVisibility(View.GONE);
}
}

@Override
Expand Down Expand Up @@ -65,6 +75,9 @@ protected boolean hasAccessCoarseLocation() {
}

protected void onClickGetPosGPS() {
showProgressBarSemaphore++;
progressBar.setVisibility(View.VISIBLE);

boolean hasGPSAccess = requestPermissionGPS();
if (hasGPSAccess) {
try {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/openathena/ManageDemsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
Expand Down Expand Up @@ -72,6 +73,9 @@ protected void onCreate(Bundle savedInstanceState)
lookupButton = (Button)findViewById(R.id.lookupButton);
resultsButton = (Button)findViewById(R.id.lookupResultsButton);

progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);

manageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
41 changes: 34 additions & 7 deletions app/src/main/java/com/openathena/NewElevationMapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -67,15 +68,17 @@
public class NewElevationMapActivity extends DemManagementActivity
{
public static String TAG = NewElevationMapActivity.class.getSimpleName();

private TextView instructionsLabel;
private ImageButton getPosGPSButton;
private EditText latLonText;
private EditText metersText;
private ImageButton getPosGPSButton;
private Button downloadButton;
private TextView resultsLabel;
private TextView instructionsLabel;
private Button importButton;
private ActivityResultLauncher<String> importLauncher;


private TextView resultsLabel;
private ActivityResultLauncher<String> importLauncher;
private LocationManager locationManager;
private LocationListener locationListener;

Expand All @@ -87,14 +90,19 @@ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_dem);

instructionsLabel = (TextView)findViewById(R.id.new_dem_label);
getPosGPSButton = (ImageButton) findViewById(R.id.get_pos_gps_button);
latLonText = (EditText)findViewById(R.id.new_dem_latlon);
metersText = (EditText)findViewById(R.id.new_dem_meters);
getPosGPSButton = (ImageButton) findViewById(R.id.get_pos_gps_button);
downloadButton = (Button)findViewById(R.id.new_dem_downloadbutton);
resultsLabel = (TextView)findViewById(R.id.new_dem_results);
instructionsLabel = (TextView)findViewById(R.id.new_dem_label);
importButton = (Button)findViewById(R.id.new_dem_importbutton);

progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
showProgressBarSemaphore = 0;

resultsLabel = (TextView)findViewById(R.id.new_dem_results);

getPosGPSButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { onClickGetPosGPS(); }
Expand Down Expand Up @@ -166,11 +174,18 @@ protected void updateLatLonText(Location location) {
// handle a download
private void onClickDownload()
{
showProgressBarSemaphore++;
progressBar.setVisibility(View.VISIBLE);

String latlon = latLonText.getText().toString();
latlon = latlon.trim();
Log.d(TAG, "latlon is: " + latlon);
if (latlon.equals("")) {
postResults(getString(R.string.button_lookup_please_enter));
showProgressBarSemaphore--;
if (showProgressBarSemaphore<=0) {
progressBar.setVisibility(View.GONE);
}
return;
}

Expand Down Expand Up @@ -211,13 +226,21 @@ private void onClickDownload()
lon = latLonPair[1];
} catch (java.text.ParseException pe) {
postResults(getString(R.string.button_lookup_please_enter));
showProgressBarSemaphore--;
if (showProgressBarSemaphore<=0) {
progressBar.setVisibility(View.GONE);
}
return;
}

Log.d(TAG,"NewDemActivity going to fetch elevation map from the InterWebs");

if (lat == 0 && lon == 0) {
postResults("No elevation data for the middle of the ocean!");
showProgressBarSemaphore--;
if (showProgressBarSemaphore<=0) {
progressBar.setVisibility(View.GONE);
}
return;
}

Expand All @@ -232,6 +255,10 @@ public void accept(String s) {
runOnUiThread(new Runnable() {
@Override
public void run() {
showProgressBarSemaphore--;
if (showProgressBarSemaphore<=0) {
progressBar.setVisibility(View.GONE);
}
Toast t = Toast.makeText(NewElevationMapActivity.this,s,Toast.LENGTH_SHORT);
t.setGravity(Gravity.CENTER,0,0);
t.show();
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/res/layout/activity_manage_dems.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,28 @@
android:gravity="center"
android:layout_marginTop="8dp" />

</LinearLayout>
<!-- Spacer view to push everything else down -->
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:indeterminate="true"
android:indeterminateBehavior="cycle"
android:indeterminateOnly="true"
android:visibility="gone" />

<!-- Spacer view to push progressBar back up a little -->
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

</LinearLayout>

16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_new_dem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>


<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/new_dem_importbutton"
android:layout_above="@id/new_dem_results"
android:layout_centerHorizontal="true"
android:gravity="bottom"
android:indeterminate="true"
android:indeterminateBehavior="cycle"
android:indeterminateOnly="true"
android:visibility="gone" />


<TextView
android:id="@+id/new_dem_results"
android:layout_width="wrap_content"
Expand Down

0 comments on commit cc788aa

Please sign in to comment.