Skip to content

Commit

Permalink
Merge branch 'main' into cc
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob authored Dec 3, 2023
2 parents be3ef30 + 9a5243b commit 4e381a9
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.os.AsyncTask;

import net.twisterrob.java.io.MailSender;

public class MailSenderAsyncTask extends AsyncTask<String, Void, Boolean> {
@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
public class MailSenderAsyncTask extends android.os.AsyncTask<String, Void, Boolean> {
private static final Logger LOG = LoggerFactory.getLogger(MailSenderAsyncTask.class);

private final MailSender m = new MailSender();
Expand Down
6 changes: 4 additions & 2 deletions Android/src/main/java/net/twisterrob/blt/android/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public App() {

@Override protected Object createDatabase() {
DataBaseHelper db = new DataBaseHelper(this);
new BackgroundExecution(new Runnable() {
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new BackgroundExecution(new Runnable() {
@Override public void run() {
db().openDB();
}
Expand All @@ -77,7 +78,8 @@ public AndroidStaticData getStaticData() {
}

public static void sendMail(String body) {
new MailSenderAsyncTask("Better London Travel",
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new MailSenderAsyncTask("Better London Travel",
"[email protected]", "[email protected]") {
@Override protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import org.slf4j.*;
import org.xml.sax.SAXException;

import android.os.AsyncTask;

import net.twisterrob.android.utils.concurrent.AsyncTaskResult;
import net.twisterrob.blt.android.App;
import net.twisterrob.blt.io.feeds.*;
import net.twisterrob.java.io.IOTools;

public class DownloadFeedTask<T extends BaseFeed<T>> extends AsyncTask<Feed, Integer, AsyncTaskResult<Feed, T>> {
@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
public class DownloadFeedTask<T extends BaseFeed<T>> extends android.os.AsyncTask<Feed, Integer, AsyncTaskResult<Feed, T>> {
protected final Logger LOG = LoggerFactory.getLogger(getClass());

private Map<String, ?> m_args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

import org.xml.sax.SAXException;

import android.os.AsyncTask;

import net.twisterrob.android.utils.concurrent.AsyncTaskResult;
import net.twisterrob.blt.io.feeds.facilities.*;
import net.twisterrob.java.io.IOTools;

class DownloadFilesTask extends AsyncTask<URL, Integer, AsyncTaskResult<URL, FacilitiesFeed>> {
@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
class DownloadFilesTask extends android.os.AsyncTask<URL, Integer, AsyncTaskResult<URL, FacilitiesFeed>> {
@SuppressWarnings("resource")
@Override protected AsyncTaskResult<URL, FacilitiesFeed> doInBackground(URL... urls) {
if (urls.length != 1 || urls[0] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ public class PostCodesActivity extends FragmentActivity {
map.setMyLocationEnabled(true);
LatLng cityOfLondon = new LatLng(51.512161, -0.090981);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(cityOfLondon, 13));
new LoadPostCodesTask().execute((Void[])null);
new LoadPostCodesTask().execute();
}
});
}

@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
private class LoadPostCodesTask extends AsyncTask<Void, Void, Map<String, List<AreaHullPoint>>> {
public void execute() {
execute((Void[])null);
}
@Override protected Map<String, List<AreaHullPoint>> doInBackground(Void... params) {
return App.db().getAreas();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import android.widget.ExpandableListView.*;

import net.twisterrob.android.utils.concurrent.AsyncTaskResult;
import net.twisterrob.android.utils.tools.BundleTools;
import net.twisterrob.android.utils.tools.IntentTools;
import net.twisterrob.blt.android.R;
import net.twisterrob.blt.android.io.feeds.DownloadFeedTask;
import net.twisterrob.blt.android.ui.ListViewHandler;
Expand Down Expand Up @@ -75,7 +77,7 @@ public class PredictionSummaryActivity extends BaseActivity implements

// gather params
Intent intent = getIntent();
m_line = (Line)intent.getSerializableExtra(EXTRA_LINE);
m_line = IntentTools.getSerializableExtra(intent, EXTRA_LINE, Line.class);
getSupportActionBar().setSubtitle(m_line.getTitle());
}

Expand Down Expand Up @@ -127,7 +129,7 @@ protected void restoreInstanceState(Bundle state) {
}

m_directionsEnabled.clear();
PlatformDirection[] dirs = (PlatformDirection[])state.getSerializable("dirs");
PlatformDirection[] dirs = BundleTools.getSerializable(state, "dirs", PlatformDirection[].class);
if (dirs != null) {
m_directionsEnabled.addAll(Arrays.asList(dirs));
}
Expand All @@ -142,8 +144,8 @@ private void startLoadingData() {
private void delayedGetRoot() {
Map<String, Object> args = new HashMap<>();
args.put("line", m_line);
@SuppressWarnings("unused")
@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new DownloadFeedTask<PredictionSummaryFeed>(args) {
@Override protected void onPostExecute(AsyncTaskResult<Feed, PredictionSummaryFeed> result) {
if (result.getError() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RangeMapActivity extends MapActivity {
private List<Marker> markers = new LinkedList<>();
private RangeMapGeneratorConfig genConfig = new RangeMapGeneratorConfig();
private RangeMapDrawerConfig drawConfig = new RangeMapDrawerConfig();
private BottomSheetBehavior behavior;
private BottomSheetBehavior<?> behavior;
private RangeNearestFragment nearestFragment;
private RangeOptionsFragment optionsFragment;
private ClickThroughDrawerLayout drawers;
Expand All @@ -67,12 +67,11 @@ public class RangeMapActivity extends MapActivity {
private SupportPlaceAutocompleteFragment searchFragment;

@Override protected void onCreate(Bundle savedInstanceState) {
int statusBarColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(this, R.color.accent), 0x66);
AndroidTools.setTranslucentStatusBar(getWindow(), statusBarColor);
setTranslucentStatusBar();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_range_map);

AndroidTools.accountForStatusBar(findViewById(R.id.view__range__toolbar_container));
accountForStatusBar();
Toolbar toolbar = (Toolbar)findViewById(R.id.view__range__toolbar);
setSupportActionBar(toolbar);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down Expand Up @@ -114,8 +113,8 @@ public class RangeMapActivity extends MapActivity {
setupSearch(fm.findFragmentById(R.id.view__range__search));

updateToolbarVisibility();
@SuppressWarnings("unused")
@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new AsyncTask<Void, Void, Set<NetworkNode>>() {
@Override protected Set<NetworkNode> doInBackground(Void... params) {
return App.db().getTubeNetwork();
Expand All @@ -127,6 +126,17 @@ public class RangeMapActivity extends MapActivity {
}.execute((Void[])null);
}

@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/12
private void setTranslucentStatusBar() {
int statusBarColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(this, R.color.accent), 0x66);
AndroidTools.setTranslucentStatusBar(getWindow(), statusBarColor);
}

@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/12
private void accountForStatusBar() {
AndroidTools.accountForStatusBar(findViewById(R.id.view__range__toolbar_container));
}

@SuppressWarnings("deprecation")
private void setupSearch(Fragment searchFragment) {
this.searchFragment = (SupportPlaceAutocompleteFragment)searchFragment;
Expand Down Expand Up @@ -190,7 +200,7 @@ class MapInteractorListener

private void zoomFullLondon() {
LatLngBounds fullLondon = new LatLngBounds(new LatLng(51.342889, -0.611361), new LatLng(51.705232, 0.251388));
Point screen = AndroidTools.getScreenSize(getWindowManager().getDefaultDisplay());
Point screen = AndroidTools.getScreenSize(ContextCompat.getDisplayOrDefault(this));
map.moveCamera(CameraUpdateFactory.newLatLngBounds(fullLondon, screen.x, screen.y, dipInt(this, -160)));
// TODO below doesn't work, even with latest GMS, negative padding above is a workaround
// map.moveCamera(CameraUpdateFactory.zoomIn());
Expand All @@ -214,7 +224,9 @@ public void updateToolbarVisibility() {
if (bottomMostTopView.getVisibility() != View.GONE) {
topMargin = bottomMostTopView.getBottom() + ViewTools.getBottomMargin(bottomMostTopView);
} else {
topMargin = AndroidTools.getStatusBarHeight(RangeMapActivity.this);
@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/12
int height = AndroidTools.getStatusBarHeight(RangeMapActivity.this);
topMargin = height;
}
}
int bottomMargin = 0;
Expand Down Expand Up @@ -254,7 +266,7 @@ public void updateToolbarVisibility() {
}
private void killTask() {
if (drawTask != null) {
drawTask.cancel(true);
drawTask.cancel();
drawTask = null;
}
}
Expand Down Expand Up @@ -388,7 +400,8 @@ private void addMarkers(Iterable<NetworkNode> nodes) {
}
}

@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
private final class DrawAsyncTask extends SimpleAsyncTask<LatLng, DrawAsyncTask.Result, DrawAsyncTask.Result> {
private final Set<NetworkNode> nodes;
private final RangeMapGeneratorConfig config;
Expand Down Expand Up @@ -429,6 +442,10 @@ public DrawAsyncTask(Set<NetworkNode> nodes,
updateMap(result.overlay, result.startNodes);
}

public void cancel() {
super.cancel(true);
}

class Result {
Collection<NetworkNode> startNodes = Collections.emptyList();
Bitmap overlay = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class RangeNearestFragment extends Fragment {
@Override public void onDestroyView() {
super.onDestroyView();
if (m_geocoderTask != null) {
m_geocoderTask.cancel(true);
m_geocoderTask.cancel();
m_geocoderTask = null;
}
}
Expand All @@ -65,7 +65,7 @@ public void updateLocation(@NonNull LatLng latlng, @Nullable Address address) {
latlng, addressString, StringerTools.toString(m_geocoderTask));
if (address == null) {
if (m_geocoderTask != null) {
m_geocoderTask.cancel(true);
m_geocoderTask.cancel();
m_geocoderTask = null;
}
m_geocoderTask = new GeocoderTask(getContext());
Expand Down Expand Up @@ -150,7 +150,7 @@ private Collection<StationWithDistance> toStations(Collection<NetworkNode> nodes
return result;
}

@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
private final class GeocoderTask extends SimpleSafeAsyncTask<LatLng, Void, Address> {
private final Geocoder geocoder;
private GeocoderTask(Context context) {
Expand All @@ -175,6 +175,7 @@ private Geocoder createGeocoder(Context context) {

@Override protected @Nullable Address doInBackground(LatLng latlng) throws Exception {
if (geocoder != null) {
@SuppressWarnings("deprecation") // We're already in background. TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
List<Address> location = geocoder.getFromLocation(latlng.latitude, latlng.longitude, 1);
if (location != null && !location.isEmpty()) {
return location.get(0);
Expand All @@ -189,6 +190,11 @@ private Geocoder createGeocoder(Context context) {
LOG.warn("Cannot determine location for {}", latlng, ex);
updateLocationInternal(latlng, null);
}

@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
public void cancel() {
super.cancel(true);
}
}

private static class StationWithDistance extends Station {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface ConfigsUpdatedListener {
return onOptionsItemSelected(item);
}
});
AndroidTools.accountForStatusBar(nav.getHeaderView(0));
accountForStatusBar();
Toolbar toolbar = (Toolbar)nav.getHeaderView(0).findViewById(R.id.view__range__parameters_toolbar);
toolbar.inflateMenu(R.menu.range_options_header);
toolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
Expand Down Expand Up @@ -222,6 +222,11 @@ interface ConfigsUpdatedListener {
});
}

@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/12
private void accountForStatusBar() {
AndroidTools.accountForStatusBar(nav.getHeaderView(0));
}

@SuppressWarnings("unchecked")
private <T extends View> T getAction(@IdRes int menuItemId) {
MenuItem switchItem = nav.getMenu().findItem(menuItemId);
Expand Down Expand Up @@ -250,6 +255,7 @@ private ColorPickerWidget color(@IdRes int menuItemId,
return picker;
}

@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/21
@Override public boolean onOptionsItemSelected(MenuItem item) {
if (item.getGroupId() == R.id.group__range__config__generator
|| item.getGroupId() == R.id.group__range__config__draw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.ExpandableListView.*;

import net.twisterrob.android.utils.concurrent.AsyncTaskResult;
import net.twisterrob.android.utils.tools.IntentTools;
import net.twisterrob.blt.android.*;
import net.twisterrob.blt.android.R;
import net.twisterrob.blt.android.io.feeds.DownloadFeedTask;
Expand Down Expand Up @@ -73,7 +74,7 @@ public int compare(Station lhs, Station rhs) {

// gather params
Intent intent = getIntent();
String name = (String)intent.getSerializableExtra(EXTRA_STATION_NAME);
String name = IntentTools.getSerializableExtra(intent, EXTRA_STATION_NAME, String.class);
m_station = App.db().getStation(name);

getSupportActionBar().setSubtitle(name);
Expand All @@ -97,8 +98,8 @@ private void delayedGetRoot() {
Map<String, Object> args = new HashMap<>();
args.put("line", line);
args.put("station", m_station.getTrackerNetCode(line));
@SuppressWarnings("unused")
@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new DownloadFeedTask<PredictionSummaryFeed>(args) {
@Override protected void onPostExecute(AsyncTaskResult<Feed, PredictionSummaryFeed> result) {
if (result.getError() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
});

@SuppressWarnings("unused")
@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new AsyncTask<Void, Void, List<Station>>() {
@Override protected List<Station> doInBackground(Void... params) {
return App.db().getStations();
Expand All @@ -70,7 +70,7 @@ private void handleIntent(Intent intent) {
String query = intent.getStringExtra(SearchManager.QUERY);
filter(query);
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
SpannableString querySpan = (SpannableString)intent.getExtras().get(SearchManager.USER_QUERY);
SpannableString querySpan = (SpannableString)intent.getCharSequenceExtra(SearchManager.USER_QUERY);
String query = querySpan.toString();
filter(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ public class StationMapsActivity extends FragmentActivity {
map.setMyLocationEnabled(true);
LatLng cityOfLondon = new LatLng(51.512161, -0.090981);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(cityOfLondon, 13));
new LoadStationsTask().execute((Void[])null);
new LoadStationsTask().execute();
}
});
}

@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings("deprecation") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
private class LoadStationsTask extends AsyncTask<Void, Void, List<Station>> {
public void execute() {
execute((Void[])null);
}
@Override protected List<Station> doInBackground(Void... params) {
return App.db().getStations();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private void startLoadingData() {
}

private void delayedGetRoot() {
@SuppressWarnings("unused")
@SuppressLint("StaticFieldLeak") // https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressLint("StaticFieldLeak") // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
@SuppressWarnings({"unused", "deprecation"}) // TODO https://github.com/TWiStErRob/net.twisterrob.travel/issues/15
Object task = new DownloadFeedTask<LineStatusFeed>() {
@Override protected void onPostExecute(AsyncTaskResult<Feed, LineStatusFeed> result) {
if (result.getError() != null) {
Expand Down
Loading

0 comments on commit 4e381a9

Please sign in to comment.