Replace listeners and runnables with lambdas.

This commit is contained in:
Andreas Schildbach 2019-10-26 11:04:04 +02:00
parent d08464cb7f
commit 34b1104020
35 changed files with 803 additions and 1340 deletions

View file

@ -190,29 +190,25 @@ public class MyActionBar extends LinearLayout {
public void startProgress() { public void startProgress() {
if (progressCount++ == 0) { if (progressCount++ == 0) {
handler.removeCallbacksAndMessages(null); handler.removeCallbacksAndMessages(null);
handler.post(new Runnable() { handler.post(() -> {
public void run() {
progressView.setVisibility(View.VISIBLE); progressView.setVisibility(View.VISIBLE);
if (progressAnimation == null) { if (progressAnimation == null) {
progressAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate); progressAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate);
progressImage.startAnimation(progressAnimation); progressImage.startAnimation(progressAnimation);
} }
}
}); });
} }
} }
public void stopProgress() { public void stopProgress() {
if (--progressCount <= 0) { if (--progressCount <= 0) {
handler.postDelayed(new Runnable() { handler.postDelayed(() -> {
public void run() {
if (progressAnimation != null) { if (progressAnimation != null) {
progressImage.clearAnimation(); progressImage.clearAnimation();
progressAnimation = null; progressAnimation = null;
} }
if (!progressAlwaysVisible) if (!progressAlwaysVisible)
progressView.setVisibility(View.GONE); progressView.setVisibility(View.GONE);
}
}, 200); }, 200);
} }
} }
@ -224,13 +220,11 @@ public class MyActionBar extends LinearLayout {
public void overflow(final int menuResId, final PopupMenu.OnMenuItemClickListener menuItemClickListener) { public void overflow(final int menuResId, final PopupMenu.OnMenuItemClickListener menuItemClickListener) {
final View overflowButton = findViewById(R.id.action_bar_overflow_button); final View overflowButton = findViewById(R.id.action_bar_overflow_button);
overflowButton.setVisibility(View.VISIBLE); overflowButton.setVisibility(View.VISIBLE);
overflowButton.setOnClickListener(new View.OnClickListener() { overflowButton.setOnClickListener(v -> {
public void onClick(final View v) {
final PopupMenu overflowMenu = new PopupMenu(context, v); final PopupMenu overflowMenu = new PopupMenu(context, v);
overflowMenu.inflate(menuResId); overflowMenu.inflate(menuResId);
overflowMenu.setOnMenuItemClickListener(menuItemClickListener); overflowMenu.setOnMenuItemClickListener(menuItemClickListener);
overflowMenu.show(); overflowMenu.show();
}
}); });
} }
} }

View file

@ -187,12 +187,10 @@ public abstract class OeffiMainActivity extends OeffiActivity {
final MyActionBar actionBar = getMyActionBar(); final MyActionBar actionBar = getMyActionBar();
final NavigationMenuAdapter menuAdapter = new NavigationMenuAdapter(this, final NavigationMenuAdapter menuAdapter = new NavigationMenuAdapter(this,
new MenuItem.OnMenuItemClickListener() { item -> {
public boolean onMenuItemClick(final MenuItem item) {
onOptionsItemSelected(item); onOptionsItemSelected(item);
navigationDrawerLayout.closeDrawers(); navigationDrawerLayout.closeDrawers();
return false; return false;
}
}); });
final Menu menu = menuAdapter.getMenu(); final Menu menu = menuAdapter.getMenu();
onCreateOptionsMenu(menu); onCreateOptionsMenu(menu);
@ -206,11 +204,7 @@ public abstract class OeffiMainActivity extends OeffiActivity {
navigationDrawerLayout.setDrawerShadow(R.drawable.view_shadow_right, Gravity.LEFT); navigationDrawerLayout.setDrawerShadow(R.drawable.view_shadow_right, Gravity.LEFT);
navigationDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { navigationDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
public void onDrawerOpened(final View drawerView) { public void onDrawerOpened(final View drawerView) {
handler.postDelayed(new Runnable() { handler.postDelayed(() -> heartbeat.start(), 2000);
public void run() {
heartbeat.start();
}
}, 2000);
} }
public void onDrawerClosed(final View drawerView) { public void onDrawerClosed(final View drawerView) {
@ -223,18 +217,12 @@ public abstract class OeffiMainActivity extends OeffiActivity {
} }
}); });
navigationDrawerFooterView.setOnClickListener(new View.OnClickListener() { navigationDrawerFooterView.setOnClickListener(v -> {
public void onClick(final View v) {
handler.removeCallbacksAndMessages(null); handler.removeCallbacksAndMessages(null);
heartbeat.start(); heartbeat.start();
}
}); });
actionBar.setDrawer(new OnClickListener() { actionBar.setDrawer(v -> toggleNavigation());
public void onClick(final View v) {
toggleNavigation();
}
});
updateNavigation(); updateNavigation();
} }
@ -581,8 +569,7 @@ public abstract class OeffiMainActivity extends OeffiActivity {
} }
} }
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
if (isFinishing()) if (isFinishing())
return; return;
@ -592,7 +579,6 @@ public abstract class OeffiMainActivity extends OeffiActivity {
messagesPrefs.edit().putLong(id, now).commit(); messagesPrefs.edit().putLong(id, now).commit();
if ("info".equals(action)) if ("info".equals(action))
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).commit(); prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).commit();
}
}); });
} else { } else {
log.info("Got '{}: {}' when fetching message from: '{}'", response.code(), log.info("Got '{}: {}' when fetching message from: '{}'", response.code(),

View file

@ -495,17 +495,13 @@ public class OeffiMapView extends MapView {
public void setZoomControls(final ZoomControls zoomControls) { public void setZoomControls(final ZoomControls zoomControls) {
this.zoomControls = zoomControls; this.zoomControls = zoomControls;
zoomControls.setOnZoomInClickListener(new OnClickListener() { zoomControls.setOnZoomInClickListener(v -> {
public void onClick(final View v) {
showZoomControls(); showZoomControls();
getController().zoomIn(); getController().zoomIn();
}
}); });
zoomControls.setOnZoomOutClickListener(new OnClickListener() { zoomControls.setOnZoomOutClickListener(v -> {
public void onClick(final View v) {
showZoomControls(); showZoomControls();
getController().zoomOut(); getController().zoomOut();
}
}); });
} }

View file

@ -272,31 +272,20 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final MyActionBar actionBar = getMyActionBar(); final MyActionBar actionBar = getMyActionBar();
setPrimaryColor(R.color.action_bar_background_directions); setPrimaryColor(R.color.action_bar_background_directions);
actionBar.setPrimaryTitle(R.string.directions_activity_title); actionBar.setPrimaryTitle(R.string.directions_activity_title);
actionBar.setTitlesOnClickListener(new OnClickListener() { actionBar.setTitlesOnClickListener(v -> NetworkPickerActivity.start(DirectionsActivity.this));
public void onClick(final View v) {
NetworkPickerActivity.start(DirectionsActivity.this);
}
});
buttonExpand = actionBar.addToggleButton(R.drawable.ic_expand_white_24dp, buttonExpand = actionBar.addToggleButton(R.drawable.ic_expand_white_24dp,
R.string.directions_action_expand_title); R.string.directions_action_expand_title);
buttonExpand.setOnCheckedChangeListener(new OnCheckedChangeListener() { buttonExpand.setOnCheckedChangeListener((buttonView, isChecked) -> {
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
if (isChecked) if (isChecked)
expandForm(); expandForm();
else else
collapseForm(); collapseForm();
updateMap(); updateMap();
}
}); });
actionBar.addButton(R.drawable.ic_shuffle_white_24dp, R.string.directions_action_return_trip_title) actionBar.addButton(R.drawable.ic_shuffle_white_24dp, R.string.directions_action_return_trip_title)
.setOnClickListener(new OnClickListener() { .setOnClickListener(v -> viewToLocation.exchangeWith(viewFromLocation));
public void onClick(final View v) { actionBar.overflow(R.menu.directions_options, item -> {
viewToLocation.exchangeWith(viewFromLocation);
}
});
actionBar.overflow(R.menu.directions_options, new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem item) {
if (item.getItemId() == R.id.directions_options_clear_history) { if (item.getItemId() == R.id.directions_options_clear_history) {
if (network != null) if (network != null)
showDialog(DIALOG_CLEAR_HISTORY); showDialog(DIALOG_CLEAR_HISTORY);
@ -304,29 +293,22 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
} else { } else {
return false; return false;
} }
}
}); });
initNavigation(); initNavigation();
((Button) findViewById(R.id.directions_network_missing_capability_button)) ((Button) findViewById(R.id.directions_network_missing_capability_button))
.setOnClickListener(new OnClickListener() { .setOnClickListener((OnClickListener) v -> NetworkPickerActivity.start(DirectionsActivity.this));
public void onClick(final View v) {
NetworkPickerActivity.start(DirectionsActivity.this);
}
});
connectivityWarningView = (TextView) findViewById(R.id.directions_connectivity_warning_box); connectivityWarningView = (TextView) findViewById(R.id.directions_connectivity_warning_box);
initLayoutTransitions(); initLayoutTransitions();
final AutoCompleteLocationAdapter autoCompleteAdapter = new AutoCompleteLocationAdapter(); final AutoCompleteLocationAdapter autoCompleteAdapter = new AutoCompleteLocationAdapter();
final LocationView.Listener locationChangeListener = new LocationView.Listener() { final LocationView.Listener locationChangeListener = () -> {
public void changed() {
updateMap(); updateMap();
queryHistoryListAdapter.clearSelectedEntry(); queryHistoryListAdapter.clearSelectedEntry();
requestFocusFirst(); requestFocusFirst();
}
}; };
viewFromLocation = (LocationView) findViewById(R.id.directions_from); viewFromLocation = (LocationView) findViewById(R.id.directions_from);
@ -344,8 +326,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
viewToLocation = (LocationView) findViewById(R.id.directions_to); viewToLocation = (LocationView) findViewById(R.id.directions_to);
viewToLocation.setAdapter(autoCompleteAdapter); viewToLocation.setAdapter(autoCompleteAdapter);
viewToLocation.setListener(locationChangeListener); viewToLocation.setListener(locationChangeListener);
viewToLocation.setOnEditorActionListener(new TextView.OnEditorActionListener() { viewToLocation.setOnEditorActionListener((v, actionId, event) -> {
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) { if (actionId == EditorInfo.IME_ACTION_GO) {
viewGo.performClick(); viewGo.performClick();
return true; return true;
@ -355,7 +336,6 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
} else { } else {
return false; return false;
} }
}
}); });
viewToLocation.setContextMenuItemClickListener(new LocationContextMenuItemClickListener(viewToLocation, viewToLocation.setContextMenuItemClickListener(new LocationContextMenuItemClickListener(viewToLocation,
REQUEST_CODE_LOCATION_PERMISSION_TO, REQUEST_CODE_PICK_CONTACT_TO, REQUEST_CODE_PICK_STATION_TO)); REQUEST_CODE_LOCATION_PERMISSION_TO, REQUEST_CODE_PICK_CONTACT_TO, REQUEST_CODE_PICK_STATION_TO));
@ -372,12 +352,10 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
viewProductToggles.add((ToggleImageButton) findViewById(R.id.directions_products_c)); viewProductToggles.add((ToggleImageButton) findViewById(R.id.directions_products_c));
initProductToggles(); initProductToggles();
final OnLongClickListener productLongClickListener = new OnLongClickListener() { final OnLongClickListener productLongClickListener = v -> {
public boolean onLongClick(final View v) {
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this); final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
builder.setTitle(R.string.directions_products_prompt); builder.setTitle(R.string.directions_products_prompt);
builder.setItems(R.array.directions_products, new DialogInterface.OnClickListener() { builder.setItems(R.array.directions_products, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
for (final ToggleImageButton view : viewProductToggles) { for (final ToggleImageButton view : viewProductToggles) {
if (which == 0) if (which == 0)
view.setChecked(view.equals(v)); view.setChecked(view.equals(v));
@ -388,11 +366,9 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
if (which == 3) if (which == 3)
view.setChecked("SUTBP".contains((String) view.getTag())); view.setChecked("SUTBP".contains((String) view.getTag()));
} }
}
}); });
builder.show(); builder.show();
return true; return true;
}
}; };
for (final View view : viewProductToggles) for (final View view : viewProductToggles)
view.setOnLongClickListener(productLongClickListener); view.setOnLongClickListener(productLongClickListener);
@ -400,12 +376,10 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
viewBike = (CheckBox) findViewById(R.id.directions_option_bike); viewBike = (CheckBox) findViewById(R.id.directions_option_bike);
viewTimeDepArr = (Button) findViewById(R.id.directions_time_dep_arr); viewTimeDepArr = (Button) findViewById(R.id.directions_time_dep_arr);
viewTimeDepArr.setOnClickListener(new OnClickListener() { viewTimeDepArr.setOnClickListener(v -> {
public void onClick(final View v) {
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this); final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
builder.setTitle(R.string.directions_set_time_prompt); builder.setTitle(R.string.directions_set_time_prompt);
builder.setItems(R.array.directions_set_time, new DialogInterface.OnClickListener() { builder.setItems(R.array.directions_set_time, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
final String[] parts = getResources().getStringArray(R.array.directions_set_time_values)[which] final String[] parts = getResources().getStringArray(R.array.directions_set_time_values)[which]
.split("_"); .split("_");
final DepArr depArr = DepArr.valueOf(parts[0]); final DepArr depArr = DepArr.valueOf(parts[0]);
@ -423,21 +397,15 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
throw new IllegalStateException(parts[1]); throw new IllegalStateException(parts[1]);
} }
updateGUI(); updateGUI();
}
}); });
builder.show(); builder.show();
}
}); });
viewTime1 = (Button) findViewById(R.id.directions_time_1); viewTime1 = (Button) findViewById(R.id.directions_time_1);
viewTime2 = (Button) findViewById(R.id.directions_time_2); viewTime2 = (Button) findViewById(R.id.directions_time_2);
viewGo = (Button) findViewById(R.id.directions_go); viewGo = (Button) findViewById(R.id.directions_go);
viewGo.setOnClickListener(new OnClickListener() { viewGo.setOnClickListener(v -> handleGo());
public void onClick(final View v) {
handleGo();
}
});
viewQueryHistoryList = (RecyclerView) findViewById(android.R.id.list); viewQueryHistoryList = (RecyclerView) findViewById(android.R.id.list);
viewQueryHistoryList.setLayoutManager(new LinearLayoutManager(this)); viewQueryHistoryList.setLayoutManager(new LinearLayoutManager(this));
@ -453,10 +421,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
quickReturnView.getLayoutParams().width, quickReturnView.getLayoutParams().height); quickReturnView.getLayoutParams().width, quickReturnView.getLayoutParams().height);
layoutParams.setBehavior(new QuickReturnBehavior()); layoutParams.setBehavior(new QuickReturnBehavior());
quickReturnView.setLayoutParams(layoutParams); quickReturnView.setLayoutParams(layoutParams);
quickReturnView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { quickReturnView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
@Override
public void onLayoutChange(final View v, final int left, final int top, final int right, final int bottom,
final int oldLeft, final int oldTop, final int oldRight, final int oldBottom) {
final int height = bottom - top; final int height = bottom - top;
viewQueryHistoryList.setPadding(viewQueryHistoryList.getPaddingLeft(), height, viewQueryHistoryList.setPadding(viewQueryHistoryList.getPaddingLeft(), height,
viewQueryHistoryList.getPaddingRight(), viewQueryHistoryList.getPaddingBottom()); viewQueryHistoryList.getPaddingRight(), viewQueryHistoryList.getPaddingBottom());
@ -464,7 +429,6 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
viewQueryHistoryEmpty.getPaddingRight(), viewQueryHistoryEmpty.getPaddingBottom()); viewQueryHistoryEmpty.getPaddingRight(), viewQueryHistoryEmpty.getPaddingBottom());
viewQueryMissingCapability.setPadding(viewQueryMissingCapability.getPaddingLeft(), height, viewQueryMissingCapability.setPadding(viewQueryMissingCapability.getPaddingLeft(), height,
viewQueryMissingCapability.getPaddingRight(), viewQueryMissingCapability.getPaddingBottom()); viewQueryMissingCapability.getPaddingRight(), viewQueryMissingCapability.getPaddingBottom());
}
}); });
mapView = (OeffiMapView) findViewById(R.id.directions_map); mapView = (OeffiMapView) findViewById(R.id.directions_map);
@ -493,17 +457,13 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final LocationTextView locationView = (LocationTextView) view final LocationTextView locationView = (LocationTextView) view
.findViewById(R.id.directions_map_pin_location); .findViewById(R.id.directions_map_pin_location);
final View buttonGroup = view.findViewById(R.id.directions_map_pin_buttons); final View buttonGroup = view.findViewById(R.id.directions_map_pin_buttons);
buttonGroup.findViewById(R.id.directions_map_pin_button_from).setOnClickListener(new OnClickListener() { buttonGroup.findViewById(R.id.directions_map_pin_button_from).setOnClickListener(v -> {
public void onClick(final View v) {
viewFromLocation.setLocation(pinLocation); viewFromLocation.setLocation(pinLocation);
mapView.removeAllViews(); mapView.removeAllViews();
}
}); });
buttonGroup.findViewById(R.id.directions_map_pin_button_to).setOnClickListener(new OnClickListener() { buttonGroup.findViewById(R.id.directions_map_pin_button_to).setOnClickListener(v -> {
public void onClick(final View v) {
viewToLocation.setLocation(pinLocation); viewToLocation.setLocation(pinLocation);
mapView.removeAllViews(); mapView.removeAllViews();
}
}); });
locationView.setLocation(pinLocation); locationView.setLocation(pinLocation);
locationView.setShowLocationType(false); locationView.setShowLocationType(false);
@ -744,49 +704,37 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
} }
} }
private final OnClickListener dateClickListener = new OnClickListener() { private final OnClickListener dateClickListener = v -> {
public void onClick(final View v) {
final Calendar calendar = new GregorianCalendar(); final Calendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs); calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs);
final int year = calendar.get(Calendar.YEAR); final int year = calendar.get(Calendar.YEAR);
final int month = calendar.get(Calendar.MONTH); final int month = calendar.get(Calendar.MONTH);
final int day = calendar.get(Calendar.DAY_OF_MONTH); final int day = calendar.get(Calendar.DAY_OF_MONTH);
new DatePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, new OnDateSetListener() { new DatePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, (view, year1, month1, day1) -> {
public void onDateSet(final DatePicker view, final int year, final int month, final int day) { calendar.set(Calendar.YEAR, year1);
calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month1);
calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day1);
calendar.set(Calendar.DAY_OF_MONTH, day);
time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis()); time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis());
updateGUI(); updateGUI();
}
}, year, month, day).show(); }, year, month, day).show();
}
}; };
private final OnClickListener timeClickListener = new OnClickListener() { private final OnClickListener timeClickListener = v -> {
public void onClick(final View v) {
final Calendar calendar = new GregorianCalendar(); final Calendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs); calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs);
final int hour = calendar.get(Calendar.HOUR_OF_DAY); final int hour = calendar.get(Calendar.HOUR_OF_DAY);
final int minute = calendar.get(Calendar.MINUTE); final int minute = calendar.get(Calendar.MINUTE);
new TimePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, new OnTimeSetListener() { new TimePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, (view, hour1, minute1) -> {
public void onTimeSet(final TimePicker view, final int hour, final int minute) { calendar.set(Calendar.HOUR_OF_DAY, hour1);
calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute1);
calendar.set(Calendar.MINUTE, minute);
time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis()); time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis());
updateGUI(); updateGUI();
}
}, hour, minute, DateFormat.is24HourFormat(DirectionsActivity.this)).show(); }, hour, minute, DateFormat.is24HourFormat(DirectionsActivity.this)).show();
}
}; };
private final OnClickListener diffClickListener = new OnClickListener() { private final OnClickListener diffClickListener = v -> handleDiffClick();
public void onClick(final View v) {
handleDiffClick();
}
};
private void handleDiffClick() { private void handleDiffClick() {
final int[] relativeTimeValues = getResources().getIntArray(R.array.directions_set_time_relative); final int[] relativeTimeValues = getResources().getIntArray(R.array.directions_set_time_relative);
@ -801,8 +749,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
} }
final DialogBuilder builder = DialogBuilder.get(this); final DialogBuilder builder = DialogBuilder.get(this);
builder.setTitle(R.string.directions_set_time_relative_prompt); builder.setTitle(R.string.directions_set_time_relative_prompt);
builder.setItems(relativeTimeStrings, new DialogInterface.OnClickListener() { builder.setItems(relativeTimeStrings, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
if (which < relativeTimeValues.length) { if (which < relativeTimeValues.length) {
final int mins = relativeTimeValues[which]; final int mins = relativeTimeValues[which];
time = new TimeSpec.Relative(mins * DateUtils.MINUTE_IN_MILLIS); time = new TimeSpec.Relative(mins * DateUtils.MINUTE_IN_MILLIS);
@ -810,7 +757,6 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
time = new TimeSpec.Absolute(DepArr.DEPART, time.timeInMillis()); time = new TimeSpec.Absolute(DepArr.DEPART, time.timeInMillis());
} }
updateGUI(); updateGUI();
}
}); });
builder.show(); builder.show();
} }
@ -1009,11 +955,9 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
} }
final ProgressDialog progressDialog = ProgressDialog.show(DirectionsActivity.this, null, final ProgressDialog progressDialog = ProgressDialog.show(DirectionsActivity.this, null,
getString(R.string.directions_query_progress), true, true, new DialogInterface.OnCancelListener() { getString(R.string.directions_query_progress), true, true, dialog -> {
public void onCancel(final DialogInterface dialog) {
if (queryTripsRunnable != null) if (queryTripsRunnable != null)
queryTripsRunnable.cancel(); queryTripsRunnable.cancel();
}
}); });
progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCanceledOnTouchOutside(false);
@ -1070,14 +1014,12 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this); final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
builder.setTitle(getString(R.string.ambiguous_address_title)); builder.setTitle(getString(R.string.ambiguous_address_title));
builder.setAdapter(new AmbiguousLocationAdapter(DirectionsActivity.this, autocompletes), builder.setAdapter(new AmbiguousLocationAdapter(DirectionsActivity.this, autocompletes),
new DialogInterface.OnClickListener() { (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
final LocationView locationView = result.ambiguousFrom != null final LocationView locationView = result.ambiguousFrom != null
? viewFromLocation ? viewFromLocation
: (result.ambiguousVia != null ? viewViaLocation : viewToLocation); : (result.ambiguousVia != null ? viewViaLocation : viewToLocation);
locationView.setLocation(autocompletes.get(which)); locationView.setLocation(autocompletes.get(which));
viewGo.performClick(); viewGo.performClick();
}
}); });
builder.create().show(); builder.create().show();
} else { } else {
@ -1092,11 +1034,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
R.string.directions_alert_redirect_title); R.string.directions_alert_redirect_title);
builder.setMessage(getString(R.string.directions_alert_redirect_message, url.host())); builder.setMessage(getString(R.string.directions_alert_redirect_message, url.host()));
builder.setPositiveButton(R.string.directions_alert_redirect_button_follow, builder.setPositiveButton(R.string.directions_alert_redirect_button_follow,
new DialogInterface.OnClickListener() { (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()))));
public void onClick(final DialogInterface dialog, final int which) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
}
});
builder.setNegativeButton(R.string.directions_alert_redirect_button_dismiss, null); builder.setNegativeButton(R.string.directions_alert_redirect_button_dismiss, null);
builder.show(); builder.show();
} }
@ -1107,11 +1045,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
R.string.directions_alert_blocked_title); R.string.directions_alert_blocked_title);
builder.setMessage(getString(R.string.directions_alert_blocked_message, url.host())); builder.setMessage(getString(R.string.directions_alert_blocked_message, url.host()));
builder.setPositiveButton(R.string.directions_alert_blocked_button_retry, builder.setPositiveButton(R.string.directions_alert_blocked_button_retry,
new DialogInterface.OnClickListener() { (dialog, which) -> viewGo.performClick());
public void onClick(final DialogInterface dialog, final int which) {
viewGo.performClick();
}
});
builder.setNegativeButton(R.string.directions_alert_blocked_button_dismiss, null); builder.setNegativeButton(R.string.directions_alert_blocked_button_dismiss, null);
builder.show(); builder.show();
} }
@ -1122,11 +1056,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
R.string.directions_alert_internal_error_title); R.string.directions_alert_internal_error_title);
builder.setMessage(getString(R.string.directions_alert_internal_error_message, url.host())); builder.setMessage(getString(R.string.directions_alert_internal_error_message, url.host()));
builder.setPositiveButton(R.string.directions_alert_internal_error_button_retry, builder.setPositiveButton(R.string.directions_alert_internal_error_button_retry,
new DialogInterface.OnClickListener() { (dialog, which) -> viewGo.performClick());
public void onClick(final DialogInterface dialog, final int which) {
viewGo.performClick();
}
});
builder.setNegativeButton(R.string.directions_alert_internal_error_button_dismiss, null); builder.setNegativeButton(R.string.directions_alert_internal_error_button_dismiss, null);
builder.show(); builder.show();
} }
@ -1145,17 +1075,11 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final DialogBuilder builder = DialogBuilder.warn(DirectionsActivity.this, final DialogBuilder builder = DialogBuilder.warn(DirectionsActivity.this,
R.string.alert_network_problem_title); R.string.alert_network_problem_title);
builder.setMessage(R.string.alert_network_problem_message); builder.setMessage(R.string.alert_network_problem_message);
builder.setPositiveButton(R.string.alert_network_problem_retry, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.alert_network_problem_retry, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
dialog.dismiss(); dialog.dismiss();
viewGo.performClick(); viewGo.performClick();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
dialog.dismiss();
}
}); });
builder.setOnCancelListener(dialog -> dialog.dismiss());
builder.show(); builder.show();
} }
}; };
@ -1172,13 +1096,11 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final DialogBuilder builder = DialogBuilder.get(this); final DialogBuilder builder = DialogBuilder.get(this);
builder.setMessage(R.string.directions_query_history_clear_confirm_message); builder.setMessage(R.string.directions_query_history_clear_confirm_message);
builder.setPositiveButton(R.string.directions_query_history_clear_confirm_button_clear, builder.setPositiveButton(R.string.directions_query_history_clear_confirm_button_clear,
new Dialog.OnClickListener() { (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
queryHistoryListAdapter.removeAllEntries(); queryHistoryListAdapter.removeAllEntries();
viewFromLocation.reset(); viewFromLocation.reset();
viewViaLocation.reset(); viewViaLocation.reset();
viewToLocation.reset(); viewToLocation.reset();
}
}); });
builder.setNegativeButton(R.string.directions_query_history_clear_confirm_button_dismiss, null); builder.setNegativeButton(R.string.directions_query_history_clear_confirm_button_dismiss, null);
return builder.create(); return builder.create();

View file

@ -143,15 +143,13 @@ public class DirectionsShortcutActivity extends OeffiActivity
public void onLocationStart(final String provider) { public void onLocationStart(final String provider) {
progressDialog = ProgressDialog.show(DirectionsShortcutActivity.this, null, progressDialog = ProgressDialog.show(DirectionsShortcutActivity.this, null,
getString(R.string.acquire_location_start, provider), true, true, new OnCancelListener() { getString(R.string.acquire_location_start, provider), true, true, dialog -> {
public void onCancel(final DialogInterface dialog) {
locationHelper.stop(); locationHelper.stop();
if (queryTripsRunnable != null) if (queryTripsRunnable != null)
queryTripsRunnable.cancel(); queryTripsRunnable.cancel();
finish(); finish();
}
}); });
progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCanceledOnTouchOutside(false);
} }
@ -264,23 +262,13 @@ public class DirectionsShortcutActivity extends OeffiActivity
R.string.directions_alert_redirect_title); R.string.directions_alert_redirect_title);
builder.setMessage(getString(R.string.directions_alert_redirect_message, url.host())); builder.setMessage(getString(R.string.directions_alert_redirect_message, url.host()));
builder.setPositiveButton(R.string.directions_alert_redirect_button_follow, builder.setPositiveButton(R.string.directions_alert_redirect_button_follow,
new DialogInterface.OnClickListener() { (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()))); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
finish(); finish();
}
}); });
builder.setNegativeButton(R.string.directions_alert_redirect_button_dismiss, builder.setNegativeButton(R.string.directions_alert_redirect_button_dismiss,
new DialogInterface.OnClickListener() { (dialog, which) -> finish());
public void onClick(final DialogInterface dialog, final int which) { builder.setOnCancelListener(dialog -> finish());
finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
finish();
}
});
builder.show(); builder.show();
} }
@ -290,16 +278,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
R.string.directions_alert_blocked_title); R.string.directions_alert_blocked_title);
builder.setMessage(getString(R.string.directions_alert_blocked_message, url.host())); builder.setMessage(getString(R.string.directions_alert_blocked_message, url.host()));
builder.setNeutralButton(R.string.directions_alert_blocked_button_dismiss, builder.setNeutralButton(R.string.directions_alert_blocked_button_dismiss,
new DialogInterface.OnClickListener() { (dialog, which) -> finish());
public void onClick(final DialogInterface dialog, final int which) { builder.setOnCancelListener(dialog -> finish());
finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
finish();
}
});
builder.show(); builder.show();
} }
@ -309,16 +289,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
R.string.directions_alert_internal_error_title); R.string.directions_alert_internal_error_title);
builder.setMessage(getString(R.string.directions_alert_internal_error_message, url.host())); builder.setMessage(getString(R.string.directions_alert_internal_error_message, url.host()));
builder.setNeutralButton(R.string.directions_alert_internal_error_button_dismiss, builder.setNeutralButton(R.string.directions_alert_internal_error_button_dismiss,
new DialogInterface.OnClickListener() { (dialog, which) -> finish());
public void onClick(final DialogInterface dialog, final int which) { builder.setOnCancelListener(dialog -> finish());
finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
finish();
}
});
builder.show(); builder.show();
} }
@ -329,16 +301,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
builder.setMessage(getString(R.string.directions_alert_ssl_exception_message, builder.setMessage(getString(R.string.directions_alert_ssl_exception_message,
Throwables.getRootCause(x).toString())); Throwables.getRootCause(x).toString()));
builder.setNeutralButton(R.string.directions_alert_ssl_exception_button_dismiss, builder.setNeutralButton(R.string.directions_alert_ssl_exception_button_dismiss,
new DialogInterface.OnClickListener() { (dialog, which) -> finish());
public void onClick(final DialogInterface dialog, final int which) { builder.setOnCancelListener(dialog -> finish());
finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
finish();
}
});
builder.show(); builder.show();
} }
}; };
@ -351,16 +315,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
private void errorDialog(final int resId) { private void errorDialog(final int resId) {
final DialogBuilder builder = DialogBuilder.warn(this, R.string.directions_shortcut_error_title); final DialogBuilder builder = DialogBuilder.warn(this, R.string.directions_shortcut_error_title);
builder.setMessage(resId); builder.setMessage(resId);
builder.setPositiveButton("Ok", new OnClickListener() { builder.setPositiveButton("Ok", (dialog, which) -> finish());
public void onClick(final DialogInterface dialog, final int which) { builder.setOnCancelListener(dialog -> finish());
finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
finish();
}
});
builder.show(); builder.show();
} }

View file

@ -144,11 +144,7 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback
@Override @Override
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
handler.post(new Runnable() { handler.post(() -> chooseView.requestLayout());
public void run() {
chooseView.requestLayout();
}
});
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
} }
@ -164,8 +160,7 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback
final int paddingCram = res.getDimensionPixelSize(R.dimen.list_entry_padding_horizontal_cram); final int paddingCram = res.getDimensionPixelSize(R.dimen.list_entry_padding_horizontal_cram);
final int paddingLax = res.getDimensionPixelSize(R.dimen.list_entry_padding_horizontal_lax); final int paddingLax = res.getDimensionPixelSize(R.dimen.list_entry_padding_horizontal_lax);
textView.setPadding(paddingLax, paddingCram, paddingLax, paddingCram); textView.setPadding(paddingLax, paddingCram, paddingLax, paddingCram);
textView.setOnItemClickListener(new OnItemClickListener() { textView.setOnItemClickListener((parent, view, position, id) -> {
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
// workaround for NPE // workaround for NPE
if (parent == null) if (parent == null)
return; return;
@ -180,7 +175,6 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback
afterLocationViewInput(); afterLocationViewInput();
fireChanged(); fireChanged();
}
}); });
leftDrawable = new MultiDrawable(context); leftDrawable = new MultiDrawable(context);

View file

@ -157,8 +157,7 @@ public abstract class QueryTripsRunnable implements Runnable {
} }
private void postOnPreExecute() { private void postOnPreExecute() {
handler.post(new Runnable() { handler.post(() -> {
public void run() {
final boolean hasOptimize = options.optimize != null; final boolean hasOptimize = options.optimize != null;
final boolean hasWalkSpeed = options.walkSpeed != null && options.walkSpeed != WalkSpeed.NORMAL; final boolean hasWalkSpeed = options.walkSpeed != null && options.walkSpeed != WalkSpeed.NORMAL;
final boolean hasAccessibility = options.accessibility != null final boolean hasAccessibility = options.accessibility != null
@ -204,7 +203,6 @@ public abstract class QueryTripsRunnable implements Runnable {
dialog.setMessage(progressMessage); dialog.setMessage(progressMessage);
onPreExecute(); onPreExecute();
}
}); });
} }
@ -212,65 +210,41 @@ public abstract class QueryTripsRunnable implements Runnable {
} }
private void postOnPostExecute() { private void postOnPostExecute() {
handler.post(new Runnable() { handler.post(() -> onPostExecute());
public void run() {
onPostExecute();
}
});
} }
protected void onPostExecute() { protected void onPostExecute() {
} }
private void postOnResult(final QueryTripsResult result) { private void postOnResult(final QueryTripsResult result) {
handler.post(new Runnable() { handler.post(() -> onResult(result));
public void run() {
onResult(result);
}
});
} }
protected abstract void onResult(QueryTripsResult result); protected abstract void onResult(QueryTripsResult result);
private void postOnRedirect(final HttpUrl url) { private void postOnRedirect(final HttpUrl url) {
handler.post(new Runnable() { handler.post(() -> onRedirect(url));
public void run() {
onRedirect(url);
}
});
} }
protected void onRedirect(final HttpUrl url) { protected void onRedirect(final HttpUrl url) {
} }
private void postOnBlocked(final HttpUrl url) { private void postOnBlocked(final HttpUrl url) {
handler.post(new Runnable() { handler.post(() -> onBlocked(url));
public void run() {
onBlocked(url);
}
});
} }
protected void onBlocked(final HttpUrl url) { protected void onBlocked(final HttpUrl url) {
} }
private void postOnInternalError(final HttpUrl url) { private void postOnInternalError(final HttpUrl url) {
handler.post(new Runnable() { handler.post(() -> onInternalError(url));
public void run() {
onInternalError(url);
}
});
} }
protected void onInternalError(final HttpUrl url) { protected void onInternalError(final HttpUrl url) {
} }
private void postOnSSLException(final SSLException x) { private void postOnSSLException(final SSLException x) {
handler.post(new Runnable() { handler.post(() -> onSSLException(x));
public void run() {
onSSLException(x);
}
});
} }
protected void onSSLException(final SSLException x) { protected void onSSLException(final SSLException x) {
@ -279,11 +253,7 @@ public abstract class QueryTripsRunnable implements Runnable {
public void cancel() { public void cancel() {
cancelled.set(true); cancelled.set(true);
handler.post(new Runnable() { handler.post(() -> onCancelled());
public void run() {
onCancelled();
}
});
} }
protected void onCancelled() { protected void onCancelled() {

View file

@ -198,11 +198,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
final MyActionBar actionBar = getMyActionBar(); final MyActionBar actionBar = getMyActionBar();
setPrimaryColor(R.color.action_bar_background_directions); setPrimaryColor(R.color.action_bar_background_directions);
actionBar.setPrimaryTitle(getTitle()); actionBar.setPrimaryTitle(getTitle());
actionBar.setBack(new OnClickListener() { actionBar.setBack(v -> finish());
public void onClick(final View v) {
finish();
}
});
// action bar secondary title // action bar secondary title
final StringBuilder secondaryTitle = new StringBuilder(); final StringBuilder secondaryTitle = new StringBuilder();
@ -223,8 +219,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
trackButton = actionBar.addToggleButton(R.drawable.ic_location_white_24dp, trackButton = actionBar.addToggleButton(R.drawable.ic_location_white_24dp,
R.string.directions_trip_details_action_track_title); R.string.directions_trip_details_action_track_title);
trackButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { trackButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
if (isChecked) { if (isChecked) {
final String provider = requestLocationUpdates(); final String provider = requestLocationUpdates();
if (provider != null) { if (provider != null) {
@ -246,16 +241,13 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
mapView.zoomToAll(); mapView.zoomToAll();
updateGUI(); updateGUI();
}
}); });
} }
actionBar.addButton(R.drawable.ic_share_white_24dp, R.string.directions_trip_details_action_share_title) actionBar.addButton(R.drawable.ic_share_white_24dp, R.string.directions_trip_details_action_share_title)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(v -> {
public void onClick(final View v) {
final PopupMenu popupMenu = new PopupMenu(TripDetailsActivity.this, v); final PopupMenu popupMenu = new PopupMenu(TripDetailsActivity.this, v);
popupMenu.inflate(R.menu.directions_trip_details_action_share); popupMenu.inflate(R.menu.directions_trip_details_action_share);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
if (item.getItemId() == R.id.directions_trip_details_action_share_short) { if (item.getItemId() == R.id.directions_trip_details_action_share_short) {
shareTripShort(); shareTripShort();
return true; return true;
@ -265,18 +257,12 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
} else { } else {
return false; return false;
} }
}
}); });
popupMenu.show(); popupMenu.show();
}
}); });
if (getPackageManager().resolveActivity(scheduleTripIntent, 0) != null) { if (getPackageManager().resolveActivity(scheduleTripIntent, 0) != null) {
actionBar.addButton(R.drawable.ic_today_white_24dp, R.string.directions_trip_details_action_calendar_title) actionBar.addButton(R.drawable.ic_today_white_24dp, R.string.directions_trip_details_action_calendar_title)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(v -> startActivity(scheduleTripIntent));
public void onClick(final View v) {
startActivity(scheduleTripIntent);
}
});
} }
legsGroup = (ViewGroup) findViewById(R.id.directions_trip_details_legs_group); legsGroup = (ViewGroup) findViewById(R.id.directions_trip_details_legs_group);
@ -626,11 +612,9 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
expandButton expandButton
.setVisibility(intermediateStops != null && !intermediateStops.isEmpty() ? View.VISIBLE : View.GONE); .setVisibility(intermediateStops != null && !intermediateStops.isEmpty() ? View.VISIBLE : View.GONE);
expandButton.setChecked(checked != null ? checked : false); expandButton.setChecked(checked != null ? checked : false);
expandButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { expandButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
legExpandStates.put(leg, isChecked); legExpandStates.put(leg, isChecked);
updateGUI(); updateGUI();
}
}); });
final TableLayout stopsView = (TableLayout) row.findViewById(R.id.directions_trip_details_public_entry_stops); final TableLayout stopsView = (TableLayout) row.findViewById(R.id.directions_trip_details_public_entry_stops);
@ -664,11 +648,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
final View collapsedIntermediateStopsRow = collapsedIntermediateStopsRow(numIntermediateStops, final View collapsedIntermediateStopsRow = collapsedIntermediateStopsRow(numIntermediateStops,
leg.line.style); leg.line.style);
stopsView.addView(collapsedIntermediateStopsRow); stopsView.addView(collapsedIntermediateStopsRow);
collapsedIntermediateStopsRow.setOnClickListener(new OnClickListener() { collapsedIntermediateStopsRow.setOnClickListener(v -> expandButton.setChecked(true));
public void onClick(final View v) {
expandButton.setChecked(true);
}
});
} }
} }
} }
@ -898,15 +878,13 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
public void onClick(final View v) { public void onClick(final View v) {
final PopupMenu contextMenu = new StationContextMenu(TripDetailsActivity.this, v, network, location, null, final PopupMenu contextMenu = new StationContextMenu(TripDetailsActivity.this, v, network, location, null,
false, false, true, false, false); false, false, true, false, false);
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
if (item.getItemId() == R.id.station_context_details) { if (item.getItemId() == R.id.station_context_details) {
StationDetailsActivity.start(TripDetailsActivity.this, network, location); StationDetailsActivity.start(TripDetailsActivity.this, network, location);
return true; return true;
} else { } else {
return false; return false;
} }
}
}); });
contextMenu.show(); contextMenu.show();
} }
@ -922,8 +900,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
public void onClick(final View v) { public void onClick(final View v) {
final PopupMenu contextMenu = new StationContextMenu(TripDetailsActivity.this, v, network, stop.location, final PopupMenu contextMenu = new StationContextMenu(TripDetailsActivity.this, v, network, stop.location,
null, false, false, true, true, false); null, false, false, true, true, false);
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
if (item.getItemId() == R.id.station_context_details) { if (item.getItemId() == R.id.station_context_details) {
StationDetailsActivity.start(TripDetailsActivity.this, network, stop.location); StationDetailsActivity.start(TripDetailsActivity.this, network, stop.location);
return true; return true;
@ -944,7 +921,6 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
} else { } else {
return false; return false;
} }
}
}); });
contextMenu.show(); contextMenu.show();
} }

View file

@ -101,8 +101,7 @@ public class TripsOverviewActivity extends OeffiActivity {
private @Nullable QueryTripsContext context; private @Nullable QueryTripsContext context;
private TripsGallery barView; private TripsGallery barView;
private final NavigableSet<Trip> trips = new TreeSet<>(new Comparator<Trip>() { private final NavigableSet<Trip> trips = new TreeSet<>((trip1, trip2) -> {
public int compare(final Trip trip1, final Trip trip2) {
if (trip1.equals(trip2)) if (trip1.equals(trip2))
return 0; return 0;
else else
@ -111,7 +110,6 @@ public class TripsOverviewActivity extends OeffiActivity {
.compare(trip1.getLastArrivalTime(), trip2.getLastArrivalTime()) // .compare(trip1.getLastArrivalTime(), trip2.getLastArrivalTime()) //
.compare(trip1.numChanges, trip2.numChanges, Ordering.natural().nullsLast()) // .compare(trip1.numChanges, trip2.numChanges, Ordering.natural().nullsLast()) //
.result(); .result();
}
}); });
private boolean queryMoreTripsRunning = false; private boolean queryMoreTripsRunning = false;
@ -142,21 +140,12 @@ public class TripsOverviewActivity extends OeffiActivity {
setContentView(R.layout.directions_trip_overview_content); setContentView(R.layout.directions_trip_overview_content);
final MyActionBar actionBar = getMyActionBar(); final MyActionBar actionBar = getMyActionBar();
setPrimaryColor(R.color.action_bar_background_directions_dark); setPrimaryColor(R.color.action_bar_background_directions_dark);
actionBar.setBack(new OnClickListener() { actionBar.setBack(v -> finish());
public void onClick(final View v) {
finish();
}
});
actionBar.setCustomTitles(R.layout.directions_trip_overview_custom_title); actionBar.setCustomTitles(R.layout.directions_trip_overview_custom_title);
actionBar.addProgressButton().setOnClickListener(new OnClickListener() { actionBar.addProgressButton().setOnClickListener(v -> handler.post(checkMoreRunnable));
public void onClick(final View v) {
handler.post(checkMoreRunnable);
}
});
barView = (TripsGallery) findViewById(R.id.trips_bar_view); barView = (TripsGallery) findViewById(R.id.trips_bar_view);
barView.setOnItemClickListener(new OnItemClickListener() { barView.setOnItemClickListener((parent, v, position, id) -> {
public void onItemClick(final AdapterView<?> parent, final View v, final int position, final long id) {
final Trip trip = (Trip) barView.getAdapter().getItem(position); final Trip trip = (Trip) barView.getAdapter().getItem(position);
if (trip != null && trip.legs != null) { if (trip != null && trip.legs != null) {
@ -174,13 +163,8 @@ public class TripsOverviewActivity extends OeffiActivity {
getContentResolver().update(historyUri, values, null, null); getContentResolver().update(historyUri, values, null, null);
} }
} }
}
});
barView.setOnScrollListener(new OnScrollListener() {
public void onScroll() {
handler.post(checkMoreRunnable);
}
}); });
barView.setOnScrollListener(() -> handler.post(checkMoreRunnable));
processResult(result, dep); processResult(result, dep);
} }
@ -259,21 +243,15 @@ public class TripsOverviewActivity extends OeffiActivity {
} }
public void run() { public void run() {
runOnUiThread(new Runnable() { runOnUiThread(() -> actionBar.startProgress());
public void run() {
actionBar.startProgress();
}
});
try { try {
doRequest(); doRequest();
} finally { } finally {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
queryMoreTripsRunning = false; queryMoreTripsRunning = false;
actionBar.stopProgress(); actionBar.stopProgress();
}
}); });
} }
} }
@ -288,8 +266,7 @@ public class TripsOverviewActivity extends OeffiActivity {
final NetworkProvider networkProvider = NetworkProviderFactory.provider(network); final NetworkProvider networkProvider = NetworkProviderFactory.provider(network);
final QueryTripsResult result = networkProvider.queryMoreTrips(context, later); final QueryTripsResult result = networkProvider.queryMoreTrips(context, later);
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
log.debug("Got {} ({})", result.toShortString(), later ? "later" : "earlier"); log.debug("Got {} ({})", result.toShortString(), later ? "later" : "earlier");
if (result.status == QueryTripsResult.Status.OK) { if (result.status == QueryTripsResult.Status.OK) {
processResult(result, later); processResult(result, later);
@ -301,21 +278,12 @@ public class TripsOverviewActivity extends OeffiActivity {
} else { } else {
new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem); new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem);
} }
}
}); });
} catch (final SessionExpiredException | NotFoundException x) { } catch (final SessionExpiredException | NotFoundException x) {
runOnUiThread(new Runnable() { runOnUiThread(() -> new Toast(TripsOverviewActivity.this).longToast(R.string.toast_session_expired));
public void run() {
new Toast(TripsOverviewActivity.this).longToast(R.string.toast_session_expired);
}
});
} catch (final InvalidDataException x) { } catch (final InvalidDataException x) {
runOnUiThread(new Runnable() { runOnUiThread(() -> new Toast(TripsOverviewActivity.this).longToast(R.string.toast_invalid_data,
public void run() { x.getMessage()));
new Toast(TripsOverviewActivity.this).longToast(R.string.toast_invalid_data,
x.getMessage());
}
});
} catch (final IOException x) { } catch (final IOException x) {
final String message = "IO problem while processing " + context + " on " + network + " (try " final String message = "IO problem while processing " + context + " on " + network + " (try "
+ tries + ")"; + tries + ")";
@ -323,18 +291,10 @@ public class TripsOverviewActivity extends OeffiActivity {
if (tries >= Constants.MAX_TRIES_ON_IO_PROBLEM) { if (tries >= Constants.MAX_TRIES_ON_IO_PROBLEM) {
if (x instanceof SocketTimeoutException || x instanceof UnknownHostException if (x instanceof SocketTimeoutException || x instanceof UnknownHostException
|| x instanceof SocketException || x instanceof SSLException) { || x instanceof SocketException || x instanceof SSLException) {
runOnUiThread(new Runnable() { runOnUiThread(() -> new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem));
public void run() {
new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem);
}
});
} else if (x instanceof InternalErrorException) { } else if (x instanceof InternalErrorException) {
runOnUiThread(new Runnable() { runOnUiThread(() -> new Toast(TripsOverviewActivity.this).toast(R.string.toast_internal_error,
public void run() { ((InternalErrorException) x).getUrl().host()));
new Toast(TripsOverviewActivity.this).toast(R.string.toast_internal_error,
((InternalErrorException) x).getUrl().host());
}
});
} else { } else {
throw new RuntimeException(message, x); throw new RuntimeException(message, x);
} }

View file

@ -65,12 +65,10 @@ public class QueryHistoryViewHolder extends RecyclerView.ViewHolder {
final QueryHistoryContextMenuItemListener contextMenuItemListener) { final QueryHistoryContextMenuItemListener contextMenuItemListener) {
final boolean selected = rowId == selectedRowId; final boolean selected = rowId == selectedRowId;
itemView.setActivated(selected); itemView.setActivated(selected);
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(v -> {
public void onClick(final View v) {
final int position = getAdapterPosition(); final int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
clickListener.onEntryClick(position, from, to); clickListener.onEntryClick(position, from, to);
}
}); });
fromView.setLocation(from); fromView.setLocation(from);
@ -84,20 +82,17 @@ public class QueryHistoryViewHolder extends RecyclerView.ViewHolder {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
tripView.setText(Formats.formatDate(context, now, savedTripDepartureTime) + "\n" tripView.setText(Formats.formatDate(context, now, savedTripDepartureTime) + "\n"
+ Formats.formatTime(context, savedTripDepartureTime)); + Formats.formatTime(context, savedTripDepartureTime));
tripView.setOnClickListener(new OnClickListener() { tripView.setOnClickListener(v -> {
public void onClick(View v) {
final int position = getAdapterPosition(); final int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
clickListener.onSavedTripClick(position, serializedSavedTrip); clickListener.onSavedTripClick(position, serializedSavedTrip);
}
}); });
} else { } else {
tripView.setVisibility(View.GONE); tripView.setVisibility(View.GONE);
} }
contextButton.setVisibility(selected ? View.VISIBLE : View.GONE); contextButton.setVisibility(selected ? View.VISIBLE : View.GONE);
contextButton.setOnClickListener(new View.OnClickListener() { contextButton.setOnClickListener(v -> {
public void onClick(final View v) {
final PopupMenu contextMenu = new PopupMenu(context, v); final PopupMenu contextMenu = new PopupMenu(context, v);
final MenuInflater inflater = contextMenu.getMenuInflater(); final MenuInflater inflater = contextMenu.getMenuInflater();
final Menu menu = contextMenu.getMenu(); final Menu menu = contextMenu.getMenu();
@ -136,8 +131,7 @@ public class QueryHistoryViewHolder extends RecyclerView.ViewHolder {
} else { } else {
toMenu = null; toMenu = null;
} }
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
final int position = getAdapterPosition(); final int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
if (fromMenu != null && item == fromMenu.findItem(item.getItemId())) if (fromMenu != null && item == fromMenu.findItem(item.getItemId()))
@ -152,10 +146,8 @@ public class QueryHistoryViewHolder extends RecyclerView.ViewHolder {
} else { } else {
return false; return false;
} }
}
}); });
contextMenu.show(); contextMenu.show();
}
}); });
} }
} }

View file

@ -86,11 +86,7 @@ public abstract class GetAreaRunnable implements Runnable {
} }
private void postOnResult(final Point[] area) { private void postOnResult(final Point[] area) {
handler.post(new Runnable() { handler.post(() -> onResult(area));
public void run() {
onResult(area);
}
});
} }
protected abstract void onResult(final Point[] area); protected abstract void onResult(final Point[] area);

View file

@ -144,11 +144,7 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
((FrameLayout) findViewById(R.id.network_picker_firsttime_message_shadow)).setForeground(null); ((FrameLayout) findViewById(R.id.network_picker_firsttime_message_shadow)).setForeground(null);
} else { } else {
findViewById(R.id.network_picker_firsttime_message).setVisibility(View.GONE); findViewById(R.id.network_picker_firsttime_message).setVisibility(View.GONE);
actionBar.setBack(new View.OnClickListener() { actionBar.setBack(v -> finish());
public void onClick(final View v) {
finish();
}
});
final NetworkId networkId = prefsGetNetworkId(); final NetworkId networkId = prefsGetNetworkId();
if (networkId != null) { if (networkId != null) {
backgroundHandler.post(new GetAreaRunnable(NetworkProviderFactory.provider(networkId), handler) { backgroundHandler.post(new GetAreaRunnable(NetworkProviderFactory.provider(networkId), handler) {

View file

@ -68,11 +68,7 @@ public class NetworkViewHolder extends RecyclerView.ViewHolder {
@Nullable final NetworkContextMenuItemListener contextMenuItemListener) { @Nullable final NetworkContextMenuItemListener contextMenuItemListener) {
itemView.setFocusable(isEnabled); itemView.setFocusable(isEnabled);
if (clickListener != null) { if (clickListener != null) {
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(v -> clickListener.onNetworkClick(entry));
public void onClick(final View v) {
clickListener.onNetworkClick(entry);
}
});
} else { } else {
itemView.setOnClickListener(null); itemView.setOnClickListener(null);
} }
@ -114,17 +110,11 @@ public class NetworkViewHolder extends RecyclerView.ViewHolder {
if (contextMenuItemListener != null) { if (contextMenuItemListener != null) {
contextButton.setVisibility(View.VISIBLE); contextButton.setVisibility(View.VISIBLE);
contextButtonSpace.setVisibility(View.VISIBLE); contextButtonSpace.setVisibility(View.VISIBLE);
contextButton.setOnClickListener(new View.OnClickListener() { contextButton.setOnClickListener(v -> {
public void onClick(final View v) {
final PopupMenu contextMenu = new PopupMenu(context, v); final PopupMenu contextMenu = new PopupMenu(context, v);
contextMenu.inflate(R.menu.network_picker_context); contextMenu.inflate(R.menu.network_picker_context);
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> contextMenuItemListener.onNetworkContextMenuItemClick(entry, item.getItemId()));
public boolean onMenuItemClick(final MenuItem item) {
return contextMenuItemListener.onNetworkContextMenuItemClick(entry, item.getItemId());
}
});
contextMenu.show(); contextMenu.show();
}
}); });
} else { } else {
contextButton.setVisibility(View.GONE); contextButton.setVisibility(View.GONE);

View file

@ -137,35 +137,29 @@ public class PlanActivity extends Activity {
viewAnimator = (ViewAnimator) findViewById(R.id.plans_layout); viewAnimator = (ViewAnimator) findViewById(R.id.plans_layout);
plan = (ScrollImageView) findViewById(R.id.plans_plan); plan = (ScrollImageView) findViewById(R.id.plans_plan);
plan.setOnMoveListener(new OnMoveListener() { plan.setOnMoveListener(() -> {
public void onMove() {
updateBubble(); updateBubble();
updateScale(); updateScale();
zoom.clearAnimation(); zoom.clearAnimation();
zoom.startAnimation(zoomControlsAnimation); zoom.startAnimation(zoomControlsAnimation);
}
}); });
bubble = findViewById(R.id.plans_bubble); bubble = findViewById(R.id.plans_bubble);
bubble.setVisibility(View.GONE); bubble.setVisibility(View.GONE);
bubble.setOnClickListener(new OnClickListener() { bubble.setOnClickListener(v -> {
public void onClick(final View v) {
final Station selection = checkNotNull(PlanActivity.this.selection); final Station selection = checkNotNull(PlanActivity.this.selection);
final PopupMenu contextMenu = new StationContextMenu(PlanActivity.this, v, selection.network, final PopupMenu contextMenu = new StationContextMenu(PlanActivity.this, v, selection.network,
selection.location, null, false, false, false, false, false); selection.location, null, false, false, false, false, false);
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
if (item.getItemId() == R.id.station_context_details) { if (item.getItemId() == R.id.station_context_details) {
StationDetailsActivity.start(PlanActivity.this, selection.network, selection.location); StationDetailsActivity.start(PlanActivity.this, selection.network, selection.location);
return true; return true;
} else { } else {
return false; return false;
} }
}
}); });
contextMenu.show(); contextMenu.show();
}
}); });
bubbleName = (TextView) findViewById(R.id.plans_bubble_name); bubbleName = (TextView) findViewById(R.id.plans_bubble_name);
@ -173,17 +167,13 @@ public class PlanActivity extends Activity {
bubbleLinesView = (LineView) findViewById(R.id.plans_bubble_lines); bubbleLinesView = (LineView) findViewById(R.id.plans_bubble_lines);
zoom = (ZoomControls) findViewById(R.id.plans_zoom); zoom = (ZoomControls) findViewById(R.id.plans_zoom);
zoom.setOnZoomInClickListener(new OnClickListener() { zoom.setOnZoomInClickListener(v -> {
public void onClick(final View v) {
plan.animateScaleStepIn(); plan.animateScaleStepIn();
updateScale(); updateScale();
}
}); });
zoom.setOnZoomOutClickListener(new OnClickListener() { zoom.setOnZoomOutClickListener(v -> {
public void onClick(final View v) {
plan.animateScaleStepOut(); plan.animateScaleStepOut();
updateScale(); updateScale();
}
}); });
final String planId = checkNotNull(getIntent().getExtras().getString(INTENT_EXTRA_PLAN_ID), final String planId = checkNotNull(getIntent().getExtras().getString(INTENT_EXTRA_PLAN_ID),
@ -408,11 +398,7 @@ public class PlanActivity extends Activity {
for (final Station station : stations) { for (final Station station : stations) {
if (selectedId.equals(station.location.id)) { if (selectedId.equals(station.location.id)) {
// delay until after layout finished // delay until after layout finished
handler.postDelayed(new Runnable() { handler.postDelayed(() -> selectStation(station), 500);
public void run() {
selectStation(station);
}
}, 500);
break; break;
} }

View file

@ -113,11 +113,7 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
setPrimaryColor(R.color.action_bar_background); setPrimaryColor(R.color.action_bar_background);
actionBar.setPrimaryTitle(R.string.plans_activity_title); actionBar.setPrimaryTitle(R.string.plans_activity_title);
actionBar.addButton(R.drawable.ic_search_white_24dp, R.string.plans_picker_action_search_title) actionBar.addButton(R.drawable.ic_search_white_24dp, R.string.plans_picker_action_search_title)
.setOnClickListener(new OnClickListener() { .setOnClickListener(v -> onSearchRequested());
public void onClick(final View v) {
onSearchRequested();
}
});
initNavigation(); initNavigation();
@ -132,11 +128,7 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
connectivityWarningView = (TextView) findViewById(R.id.plans_picker_connectivity_warning_box); connectivityWarningView = (TextView) findViewById(R.id.plans_picker_connectivity_warning_box);
filterBox = findViewById(R.id.plans_picker_filter_box); filterBox = findViewById(R.id.plans_picker_filter_box);
findViewById(R.id.plans_picker_filter_clear).setOnClickListener(new OnClickListener() { findViewById(R.id.plans_picker_filter_clear).setOnClickListener(v -> clearListFilter());
public void onClick(final View v) {
clearListFilter();
}
});
connectivityReceiver = new ConnectivityBroadcastReceiver(connectivityManager) { connectivityReceiver = new ConnectivityBroadcastReceiver(connectivityManager) {
@Override @Override
@ -308,10 +300,7 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
final HttpUrl remoteUrl = plan.url != null ? plan.url final HttpUrl remoteUrl = plan.url != null ? plan.url
: Constants.PLANS_BASE_URL.newBuilder().addEncodedPathSegment(planFilename).build(); : Constants.PLANS_BASE_URL.newBuilder().addEncodedPathSegment(planFilename).build();
final ListenableFuture<Integer> download = downloader.download(remoteUrl, planFile, false, final ListenableFuture<Integer> download = downloader.download(remoteUrl, planFile, false,
new Downloader.ProgressCallback() { (contentRead, contentLength) -> runOnUiThread(() -> {
public void progress(final long contentRead, final long contentLength) {
runOnUiThread(new Runnable() {
public void run() {
final RecyclerView.ViewHolder holder = listView.findViewHolderForItemId(plan.rowId); final RecyclerView.ViewHolder holder = listView.findViewHolderForItemId(plan.rowId);
if (holder != null) { if (holder != null) {
final int position = holder.getAdapterPosition(); final int position = holder.getAdapterPosition();
@ -319,10 +308,7 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
listAdapter.setProgressPermille(position, listAdapter.setProgressPermille(position,
(int) (contentRead * 1000 / contentLength)); (int) (contentRead * 1000 / contentLength));
} }
} }));
});
}
});
actionBar.startProgress(); actionBar.startProgress();
Futures.addCallback(download, new FutureCallback<Integer>() { Futures.addCallback(download, new FutureCallback<Integer>() {
public void onSuccess(final @Nullable Integer status) { public void onSuccess(final @Nullable Integer status) {

View file

@ -71,11 +71,7 @@ public class PlanViewHolder extends RecyclerView.ViewHolder {
public void bind(final PlansAdapter.Plan plan, final PlanClickListener clickListener, public void bind(final PlansAdapter.Plan plan, final PlanClickListener clickListener,
final PlanContextMenuItemListener contextMenuItemListener) { final PlanContextMenuItemListener contextMenuItemListener) {
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(v -> clickListener.onPlanClick(plan));
public void onClick(final View v) {
clickListener.onPlanClick(plan);
}
});
thumbView.setImageDrawable(null); thumbView.setImageDrawable(null);
@ -101,18 +97,13 @@ public class PlanViewHolder extends RecyclerView.ViewHolder {
networkLogoView.setVisibility(View.GONE); networkLogoView.setVisibility(View.GONE);
} }
contextButton.setOnClickListener(new View.OnClickListener() { contextButton.setOnClickListener(v -> {
public void onClick(final View v) {
final PopupMenu contextMenu = new PopupMenu(context, v); final PopupMenu contextMenu = new PopupMenu(context, v);
contextMenu.inflate(R.menu.plans_picker_context); contextMenu.inflate(R.menu.plans_picker_context);
contextMenu.getMenu().findItem(R.id.plans_picker_context_remove).setVisible(plan.localFile.exists()); contextMenu.getMenu().findItem(R.id.plans_picker_context_remove).setVisible(plan.localFile.exists());
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> contextMenuItemListener.onPlanContextMenuItemClick(plan,
public boolean onMenuItemClick(final MenuItem item) { item.getItemId()));
return contextMenuItemListener.onPlanContextMenuItemClick(plan, item.getItemId());
}
});
contextMenu.show(); contextMenu.show();
}
}); });
} }

View file

@ -154,24 +154,18 @@ public class PlansAdapter extends RecyclerView.Adapter<PlanViewHolder> {
else else
thumb = res.getDrawable(R.drawable.ic_oeffi_plans_grey300_72dp).mutate(); thumb = res.getDrawable(R.drawable.ic_oeffi_plans_grey300_72dp).mutate();
if (!call.isCanceled()) { if (!call.isCanceled()) {
handler.post(new Runnable() { handler.post(() -> {
public void run() {
holder.setCall(null); holder.setCall(null);
final int position = holder.getAdapterPosition(); final int position1 = holder.getAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position1 != RecyclerView.NO_POSITION)
notifyItemChanged(position, thumb); notifyItemChanged(position1, thumb);
}
}); });
} }
} }
} }
public void onFailure(final Call call, final IOException e) { public void onFailure(final Call call, final IOException e) {
handler.post(new Runnable() { handler.post(() -> holder.setCall(null));
public void run() {
holder.setCall(null);
}
});
} }
}); });
} }

View file

@ -53,13 +53,10 @@ public class AboutFragment extends PreferenceFragment {
final Uri marketUri = Uri.parse(String.format(Constants.MARKET_APP_URL, application.getPackageName())); final Uri marketUri = Uri.parse(String.format(Constants.MARKET_APP_URL, application.getPackageName()));
findPreference(KEY_ABOUT_MARKET_APP).setSummary(marketUri.toString()); findPreference(KEY_ABOUT_MARKET_APP).setSummary(marketUri.toString());
findPreference(KEY_ABOUT_MARKET_APP).setIntent(new Intent(Intent.ACTION_VIEW, marketUri)); findPreference(KEY_ABOUT_MARKET_APP).setIntent(new Intent(Intent.ACTION_VIEW, marketUri));
findPreference(KEY_ABOUT_CHANGELOG).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { findPreference(KEY_ABOUT_CHANGELOG).setOnPreferenceClickListener(preference -> {
@Override
public boolean onPreferenceClick(Preference preference) {
ChangelogDialogBuilder.get(activity, Application.versionCode(application), null, ChangelogDialogBuilder.get(activity, Application.versionCode(application), null,
Application.versionFlavor(application), 0, null).show(); Application.versionFlavor(application), 0, null).show();
return true; return true;
}
}); });
} }
} }

View file

@ -33,12 +33,9 @@ public class DonateFragment extends PreferenceFragment {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_donate); addPreferencesFromResource(R.xml.preference_donate);
findPreference(KEY_ABOUT_DONATE_BITCOIN).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { findPreference(KEY_ABOUT_DONATE_BITCOIN).setOnPreferenceClickListener(preference -> {
@Override
public boolean onPreferenceClick(Preference preference) {
BitcoinIntegration.request(getActivity(), Constants.BITCOIN_ADDRESS); BitcoinIntegration.request(getActivity(), Constants.BITCOIN_ADDRESS);
return true; return true;
}
}); });
} }
} }

View file

@ -61,11 +61,7 @@ public class DecodeForeignActivity extends Activity {
final Matcher m = Pattern.compile("/t/d(\\d+)").matcher(path); final Matcher m = Pattern.compile("/t/d(\\d+)").matcher(path);
if (m.matches()) { if (m.matches()) {
final ProgressDialog progressDialog = ProgressDialog.show(DecodeForeignActivity.this, null, final ProgressDialog progressDialog = ProgressDialog.show(DecodeForeignActivity.this, null,
getString(R.string.stations_decode_foreign_progress), true, true, new OnCancelListener() { getString(R.string.stations_decode_foreign_progress), true, true, dialog -> finish());
public void onCancel(final DialogInterface dialog) {
finish();
}
});
progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCanceledOnTouchOutside(false);
final Request.Builder request = new Request.Builder(); final Request.Builder request = new Request.Builder();
@ -79,8 +75,7 @@ public class DecodeForeignActivity extends Activity {
if (mRefresh.find()) { if (mRefresh.find()) {
final Uri refreshUri = Uri.parse(mRefresh.group(1)); final Uri refreshUri = Uri.parse(mRefresh.group(1));
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
progressDialog.dismiss(); progressDialog.dismiss();
if ("mobil.rmv.de".equals(refreshUri.getHost()) if ("mobil.rmv.de".equals(refreshUri.getHost())
&& "/mobile".equals(refreshUri.getPath())) { && "/mobile".equals(refreshUri.getPath())) {
@ -91,7 +86,6 @@ public class DecodeForeignActivity extends Activity {
} else { } else {
errorDialog(R.string.stations_decode_foreign_failed); errorDialog(R.string.stations_decode_foreign_failed);
} }
}
}); });
} else { } else {
onFail(); onFail();
@ -107,11 +101,9 @@ public class DecodeForeignActivity extends Activity {
} }
private void onFail() { private void onFail() {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
progressDialog.dismiss(); progressDialog.dismiss();
errorDialog(R.string.stations_decode_foreign_failed); errorDialog(R.string.stations_decode_foreign_failed);
}
}); });
} }
}); });
@ -127,16 +119,8 @@ public class DecodeForeignActivity extends Activity {
private void errorDialog(final int resId) { private void errorDialog(final int resId) {
final DialogBuilder builder = DialogBuilder.warn(this, 0); final DialogBuilder builder = DialogBuilder.warn(this, 0);
builder.setMessage(resId); builder.setMessage(resId);
builder.setPositiveButton("Ok", new OnClickListener() { builder.setPositiveButton("Ok", (dialog, which) -> finish());
public void onClick(final DialogInterface dialog, final int which) { builder.setOnCancelListener(dialog -> finish());
finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
public void onCancel(final DialogInterface dialog) {
finish();
}
});
builder.show(); builder.show();
} }
} }

View file

@ -77,11 +77,7 @@ public class FavoriteStationsActivity extends OeffiActivity
final MyActionBar actionBar = getMyActionBar(); final MyActionBar actionBar = getMyActionBar();
setPrimaryColor(R.color.action_bar_background_stations); setPrimaryColor(R.color.action_bar_background_stations);
actionBar.setPrimaryTitle(getTitle()); actionBar.setPrimaryTitle(getTitle());
actionBar.setBack(new OnClickListener() { actionBar.setBack(v -> finish());
public void onClick(final View v) {
finish();
}
});
viewAnimator = (ViewAnimator) findViewById(R.id.favorites_layout); viewAnimator = (ViewAnimator) findViewById(R.id.favorites_layout);

View file

@ -121,11 +121,7 @@ public class LineView extends TextView {
// sort by count // sort by count
final List<Entry<Product, Integer>> sortedEntries = new ArrayList<>(productCounts.entrySet()); final List<Entry<Product, Integer>> sortedEntries = new ArrayList<>(productCounts.entrySet());
Collections.sort(sortedEntries, new Comparator<Entry<Product, Integer>>() { Collections.sort(sortedEntries, (entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue()));
public int compare(final Entry<Product, Integer> entry1, final Entry<Product, Integer> entry2) {
return entry2.getValue().compareTo(entry1.getValue());
}
});
// condense // condense
for (final Map.Entry<Product, Integer> entry : sortedEntries) { for (final Map.Entry<Product, Integer> entry : sortedEntries) {

View file

@ -122,43 +122,27 @@ public abstract class QueryDeparturesRunnable implements Runnable {
} }
private void postOnPreExecute() { private void postOnPreExecute() {
handler.post(new Runnable() { handler.post(() -> onPreExecute());
public void run() {
onPreExecute();
}
});
} }
protected void onPreExecute() { protected void onPreExecute() {
} }
private void postOnPostExecute() { private void postOnPostExecute() {
handler.post(new Runnable() { handler.post(() -> onPostExecute());
public void run() {
onPostExecute();
}
});
} }
protected void onPostExecute() { protected void onPostExecute() {
} }
private void postOnResult(final QueryDeparturesResult result) { private void postOnResult(final QueryDeparturesResult result) {
handler.post(new Runnable() { handler.post(() -> onResult(result));
public void run() {
onResult(result);
}
});
} }
protected abstract void onResult(QueryDeparturesResult result); protected abstract void onResult(QueryDeparturesResult result);
private void postOnRedirect(final HttpUrl url) { private void postOnRedirect(final HttpUrl url) {
handler.post(new Runnable() { handler.post(() -> onRedirect(url));
public void run() {
onRedirect(url);
}
});
} }
protected void onRedirect(final HttpUrl url) { protected void onRedirect(final HttpUrl url) {
@ -166,11 +150,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
} }
private void postOnBlocked(final HttpUrl url) { private void postOnBlocked(final HttpUrl url) {
handler.post(new Runnable() { handler.post(() -> onBlocked(url));
public void run() {
onBlocked(url);
}
});
} }
protected void onBlocked(final HttpUrl url) { protected void onBlocked(final HttpUrl url) {
@ -178,11 +158,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
} }
private void postOnInternalError(final HttpUrl url) { private void postOnInternalError(final HttpUrl url) {
handler.post(new Runnable() { handler.post(() -> onInternalError(url));
public void run() {
onInternalError(url);
}
});
} }
protected void onInternalError(final HttpUrl url) { protected void onInternalError(final HttpUrl url) {
@ -190,11 +166,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
} }
private void postOnParserException(final String message) { private void postOnParserException(final String message) {
handler.post(new Runnable() { handler.post(() -> onParserException(message));
public void run() {
onParserException(message);
}
});
} }
protected void onParserException(final String message) { protected void onParserException(final String message) {
@ -202,11 +174,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
} }
private void postOnInputOutputError(final IOException x) { private void postOnInputOutputError(final IOException x) {
handler.post(new Runnable() { handler.post(() -> onInputOutputError(x));
public void run() {
onInputOutputError(x);
}
});
} }
protected void onInputOutputError(final IOException x) { protected void onInputOutputError(final IOException x) {

View file

@ -85,8 +85,7 @@ public class StationContextMenu extends PopupMenu {
builder.setTitle(R.string.station_context_launcher_shortcut_title); builder.setTitle(R.string.station_context_launcher_shortcut_title);
builder.setView(view); builder.setView(view);
builder.setPositiveButton(R.string.create_launcher_shortcut_dialog_button_ok, builder.setPositiveButton(R.string.create_launcher_shortcut_dialog_button_ok,
new DialogInterface.OnClickListener() { (DialogInterface.OnClickListener) (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
final EditText nameView = (EditText) view final EditText nameView = (EditText) view
.findViewById(R.id.create_launcher_shortcut_dialog_name); .findViewById(R.id.create_launcher_shortcut_dialog_name);
final String shortcutName = nameView.getText().toString(); final String shortcutName = nameView.getText().toString();
@ -117,7 +116,6 @@ public class StationContextMenu extends PopupMenu {
R.mipmap.ic_oeffi_directions_color_48dp)) R.mipmap.ic_oeffi_directions_color_48dp))
.setIntent(shortcutIntent).build(), .setIntent(shortcutIntent).build(),
null); null);
}
}); });
builder.setNegativeButton(R.string.button_cancel, null); builder.setNegativeButton(R.string.button_cancel, null);
return builder.create(); return builder.create();
@ -189,11 +187,9 @@ public class StationContextMenu extends PopupMenu {
final String planName = plansCursor final String planName = plansCursor
.getString(plansCursor.getColumnIndexOrThrow(PlanContentProvider.KEY_PLAN_NAME)); .getString(plansCursor.getColumnIndexOrThrow(PlanContentProvider.KEY_PLAN_NAME));
plansCursor.close(); plansCursor.close();
menu.add(planName).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { menu.add(planName).setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
PlanActivity.start(context, planId, location.id); PlanActivity.start(context, planId, location.id);
return true; return true;
}
}); });
} }
stationsCursor.close(); stationsCursor.close();
@ -203,11 +199,9 @@ public class StationContextMenu extends PopupMenu {
private static void prepareMapMenuItem(final Context context, final MenuItem item, final Intent intent) { private static void prepareMapMenuItem(final Context context, final MenuItem item, final Intent intent) {
final PackageManager pm = context.getPackageManager(); final PackageManager pm = context.getPackageManager();
item.setVisible(pm.resolveActivity(intent, 0) != null); item.setVisible(pm.resolveActivity(intent, 0) != null);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(item1 -> {
public boolean onMenuItemClick(final MenuItem item) {
context.startActivity(intent); context.startActivity(intent);
return true; return true;
}
}); });
} }
} }

View file

@ -152,21 +152,12 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
setContentView(R.layout.stations_station_details_content); setContentView(R.layout.stations_station_details_content);
actionBar = getMyActionBar(); actionBar = getMyActionBar();
setPrimaryColor(R.color.action_bar_background_stations); setPrimaryColor(R.color.action_bar_background_stations);
actionBar.setBack(new OnClickListener() { actionBar.setBack(v -> finish());
public void onClick(final View v) {
finish();
}
});
actionBar.swapTitles(); actionBar.swapTitles();
actionBar.addProgressButton().setOnClickListener(new OnClickListener() { actionBar.addProgressButton().setOnClickListener(v -> load());
public void onClick(final View v) {
load();
}
});
favoriteButton = actionBar.addToggleButton(R.drawable.ic_star_24dp, favoriteButton = actionBar.addToggleButton(R.drawable.ic_star_24dp,
R.string.stations_station_details_action_favorite_title); R.string.stations_station_details_action_favorite_title);
favoriteButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { favoriteButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
if (isChecked) { if (isChecked) {
final Uri rowUri = FavoriteUtils.persist(getContentResolver(), final Uri rowUri = FavoriteUtils.persist(getContentResolver(),
FavoriteStationsProvider.TYPE_FAVORITE, selectedNetwork, selectedStation); FavoriteStationsProvider.TYPE_FAVORITE, selectedNetwork, selectedStation);
@ -181,7 +172,6 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
FavoriteUtils.notifyFavoritesChanged(StationDetailsActivity.this); FavoriteUtils.notifyFavoritesChanged(StationDetailsActivity.this);
} }
} }
}
}); });
viewAnimator = (ViewAnimator) findViewById(R.id.stations_station_details_list_layout); viewAnimator = (ViewAnimator) findViewById(R.id.stations_station_details_list_layout);
@ -800,11 +790,7 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
final Location destination = departure.destination; final Location destination = departure.destination;
if (destination != null) { if (destination != null) {
destinationView.setText(Constants.DESTINATION_ARROW_PREFIX + destination.uniqueShortName()); destinationView.setText(Constants.DESTINATION_ARROW_PREFIX + destination.uniqueShortName());
itemView.setOnClickListener(destination.id != null ? new OnClickListener() { itemView.setOnClickListener(destination.id != null ? (OnClickListener) v -> start(context, network, destination) : null);
public void onClick(final View v) {
start(context, network, destination);
}
} : null);
} else { } else {
destinationView.setText(null); destinationView.setText(null);
itemView.setOnClickListener(null); itemView.setOnClickListener(null);

View file

@ -195,30 +195,18 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
actionBar = getMyActionBar(); actionBar = getMyActionBar();
setPrimaryColor(R.color.action_bar_background_stations); setPrimaryColor(R.color.action_bar_background_stations);
actionBar.setPrimaryTitle(R.string.stations_activity_title); actionBar.setPrimaryTitle(R.string.stations_activity_title);
actionBar.setTitlesOnClickListener(new OnClickListener() { actionBar.setTitlesOnClickListener(v -> NetworkPickerActivity.start(StationsActivity.this));
public void onClick(final View v) { actionBar.addProgressButton().setOnClickListener(v -> {
NetworkPickerActivity.start(StationsActivity.this);
}
});
actionBar.addProgressButton().setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
for (final Station station : stations) for (final Station station : stations)
station.requestedAt = null; station.requestedAt = null;
handler.post(initStationsRunnable); handler.post(initStationsRunnable);
}
}); });
actionBar.addButton(R.drawable.ic_search_white_24dp, R.string.stations_action_search_title) actionBar.addButton(R.drawable.ic_search_white_24dp, R.string.stations_action_search_title)
.setOnClickListener(new OnClickListener() { .setOnClickListener(v -> onSearchRequested());
public void onClick(final View v) {
onSearchRequested();
}
});
filterActionButton = actionBar.addButton(R.drawable.ic_filter_list_24dp, R.string.stations_filter_title); filterActionButton = actionBar.addButton(R.drawable.ic_filter_list_24dp, R.string.stations_filter_title);
filterActionButton.setOnClickListener(new OnClickListener() { filterActionButton.setOnClickListener(v -> {
public void onClick(final View v) {
final StationsFilterPopup popup = new StationsFilterPopup(StationsActivity.this, products, final StationsFilterPopup popup = new StationsFilterPopup(StationsActivity.this, products,
new StationsFilterPopup.Listener() { filter -> {
public void filterChanged(final Set<Product> filter) {
final Set<Product> added = new HashSet<>(filter); final Set<Product> added = new HashSet<>(filter);
added.removeAll(products); added.removeAll(products);
@ -233,7 +221,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
} }
if (!removed.isEmpty()) { if (!removed.isEmpty()) {
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) { for (final Iterator<Station> i = stations.iterator(); i.hasNext(); ) {
final Station station = i.next(); final Station station = i.next();
if (!filter(station, products)) { if (!filter(station, products)) {
i.remove(); i.remove();
@ -246,20 +234,16 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
} }
updateGUI(); updateGUI();
}
}); });
popup.showAsDropDown(v); popup.showAsDropDown(v);
}
}); });
actionBar.overflow(R.menu.stations_options, new PopupMenu.OnMenuItemClickListener() { actionBar.overflow(R.menu.stations_options, item -> {
public boolean onMenuItemClick(final MenuItem item) {
if (item.getItemId() == R.id.stations_options_favorites) { if (item.getItemId() == R.id.stations_options_favorites) {
FavoriteStationsActivity.start(StationsActivity.this); FavoriteStationsActivity.start(StationsActivity.this);
return true; return true;
} else { } else {
return false; return false;
} }
}
}); });
initNavigation(); initNavigation();
@ -268,26 +252,14 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
final Button locationPermissionRequestButton = (Button) findViewById( final Button locationPermissionRequestButton = (Button) findViewById(
R.id.stations_location_permission_request_button); R.id.stations_location_permission_request_button);
locationPermissionRequestButton.setOnClickListener(new OnClickListener() { locationPermissionRequestButton.setOnClickListener(v -> ActivityCompat.requestPermissions(StationsActivity.this,
public void onClick(final View v) {
ActivityCompat.requestPermissions(StationsActivity.this,
new String[] { Manifest.permission.ACCESS_FINE_LOCATION, new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION }, 0); Manifest.permission.ACCESS_BACKGROUND_LOCATION }, 0));
}
});
final Button locationSettingsButton = (Button) findViewById(R.id.stations_list_location_settings); final Button locationSettingsButton = (Button) findViewById(R.id.stations_list_location_settings);
locationSettingsButton.setOnClickListener(new OnClickListener() { locationSettingsButton.setOnClickListener(v -> startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)));
public void onClick(final View v) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
});
final OnClickListener selectNetworkListener = new OnClickListener() { final OnClickListener selectNetworkListener = v -> NetworkPickerActivity.start(StationsActivity.this);
public void onClick(final View v) {
NetworkPickerActivity.start(StationsActivity.this);
}
};
final Button networkSettingsButton = (Button) findViewById(R.id.stations_list_empty_network_settings); final Button networkSettingsButton = (Button) findViewById(R.id.stations_list_empty_network_settings);
networkSettingsButton.setOnClickListener(selectNetworkListener); networkSettingsButton.setOnClickListener(selectNetworkListener);
final Button missingCapabilityButton = (Button) findViewById(R.id.stations_network_missing_capability_button); final Button missingCapabilityButton = (Button) findViewById(R.id.stations_network_missing_capability_button);
@ -597,8 +569,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
if (fixedLocation != null && fixedLocation.hasCoord()) if (fixedLocation != null && fixedLocation.hasCoord())
mapView.animateToLocation(fixedLocation.getLatAsDouble(), fixedLocation.getLonAsDouble()); mapView.animateToLocation(fixedLocation.getLatAsDouble(), fixedLocation.getLonAsDouble());
findViewById(R.id.stations_location_clear).setOnClickListener(new OnClickListener() { findViewById(R.id.stations_location_clear).setOnClickListener(v -> {
public void onClick(final View v) {
fixedLocation = null; fixedLocation = null;
if (deviceLocation != null) { if (deviceLocation != null) {
@ -626,7 +597,6 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
handler.post(initStationsRunnable); handler.post(initStationsRunnable);
updateGUI(); updateGUI();
}
}); });
handler.post(initStationsRunnable); handler.post(initStationsRunnable);
@ -652,11 +622,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
private void setListFilter(final String filter) { private void setListFilter(final String filter) {
searchQuery = filter; searchQuery = filter;
findViewById(R.id.stations_search_clear).setOnClickListener(new OnClickListener() { findViewById(R.id.stations_search_clear).setOnClickListener(v -> clearListFilter());
public void onClick(final View v) {
clearListFilter();
}
});
stations.clear(); stations.clear();
stationsMap.clear(); stationsMap.clear();
@ -777,17 +743,11 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
final DialogBuilder builder = DialogBuilder.warn(this, R.string.stations_nearby_stations_error_title); final DialogBuilder builder = DialogBuilder.warn(this, R.string.stations_nearby_stations_error_title);
builder.setMessage(getString(R.string.stations_nearby_stations_error_message)); builder.setMessage(getString(R.string.stations_nearby_stations_error_message));
builder.setPositiveButton(getString(R.string.stations_nearby_stations_error_continue), builder.setPositiveButton(getString(R.string.stations_nearby_stations_error_continue),
new DialogInterface.OnClickListener() { (dialog, _id) -> dialog.dismiss());
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setNegativeButton(getString(R.string.stations_nearby_stations_error_exit), builder.setNegativeButton(getString(R.string.stations_nearby_stations_error_exit),
new DialogInterface.OnClickListener() { (dialog, _id) -> {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss(); dialog.dismiss();
finish(); finish();
}
}); });
return builder.create(); return builder.create();
} }
@ -825,14 +785,11 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
if (favoriteIds.length() != 0) if (favoriteIds.length() != 0)
favoriteIds.setLength(favoriteIds.length() - 1); favoriteIds.setLength(favoriteIds.length() - 1);
backgroundHandler.post(new Runnable() { backgroundHandler.post(() -> {
public void run() { runOnUiThread(() -> {
runOnUiThread(new Runnable() {
public void run() {
actionBar.startProgress(); actionBar.startProgress();
loading = true; loading = true;
updateGUI(); updateGUI();
}
}); });
final Builder uriBuilder = NetworkContentProvider.CONTENT_URI.buildUpon(); final Builder uriBuilder = NetworkContentProvider.CONTENT_URI.buildUpon();
@ -883,7 +840,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
products = Product.fromCodes(cursor.getString(productsColumnIndex).toCharArray()); products = Product.fromCodes(cursor.getString(productsColumnIndex).toCharArray());
else else
products = null; products = null;
final Station station = new Station(network, new de.schildbach.pte.dto.Location( final Station station = new Station(network, new Location(
LocationType.STATION, id, coord, place, name, products), lineDestinations); LocationType.STATION, id, coord, place, name, products), lineDestinations);
if (deviceLocation != null) { if (deviceLocation != null) {
android.location.Location.distanceBetween(referenceLocation.getLatAsDouble(), android.location.Location.distanceBetween(referenceLocation.getLatAsDouble(),
@ -896,21 +853,14 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
cursor.close(); cursor.close();
runOnUiThread(new Runnable() { runOnUiThread(() -> mergeIntoStations(freshStations, true));
public void run() {
mergeIntoStations(freshStations, true);
}
});
} }
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
actionBar.stopProgress(); actionBar.stopProgress();
loading = false; loading = false;
updateGUI(); updateGUI();
}
}); });
}
}); });
} }
@ -1032,11 +982,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
} }
if (added) { if (added) {
handler.postDelayed(new Runnable() { handler.postDelayed(() -> mapView.zoomToStations(stations), 500);
public void run() {
mapView.zoomToStations(stations);
}
}, 500);
} }
updateGUI(); updateGUI();
@ -1065,8 +1011,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
} }
private static void sortStations(final List<Station> stations) { private static void sortStations(final List<Station> stations) {
Collections.sort(stations, new Comparator<Station>() { Collections.sort(stations, (station1, station2) -> {
public int compare(final Station station1, final Station station2) {
ComparisonChain chain = ComparisonChain.start(); ComparisonChain chain = ComparisonChain.start();
// order by distance // order by distance
@ -1091,7 +1036,6 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
} }
return chain.result(); return chain.result();
}
}); });
} }
@ -1183,58 +1127,40 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
protected void onRedirect(final HttpUrl url) { protected void onRedirect(final HttpUrl url) {
log.info("Redirect while querying departures on {}", requestedStationId); log.info("Redirect while querying departures on {}", requestedStationId);
handler.post(new Runnable() { handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_network_problem));
public void run() {
new Toast(StationsActivity.this).toast(R.string.toast_network_problem);
}
});
}; };
@Override @Override
protected void onBlocked(final HttpUrl url) { protected void onBlocked(final HttpUrl url) {
log.info("Blocked querying departures on {}", requestedStationId); log.info("Blocked querying departures on {}", requestedStationId);
handler.post(new Runnable() { handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_network_blocked,
public void run() { url.host()));
new Toast(StationsActivity.this).toast(R.string.toast_network_blocked,
url.host());
}
});
} }
@Override @Override
protected void onInternalError(final HttpUrl url) { protected void onInternalError(final HttpUrl url) {
log.info("Internal error querying departures on {}", requestedStationId); log.info("Internal error querying departures on {}", requestedStationId);
handler.post(new Runnable() { handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_internal_error,
public void run() { url.host()));
new Toast(StationsActivity.this).toast(R.string.toast_internal_error,
url.host());
}
});
} }
@Override @Override
protected void onParserException(final String message) { protected void onParserException(final String message) {
log.info("Cannot parse departures on {}: {}", requestedStationId, message); log.info("Cannot parse departures on {}: {}", requestedStationId, message);
handler.post(new Runnable() { handler.post(() -> {
public void run() {
final String limitedMessage = message != null final String limitedMessage = message != null
? message.substring(0, Math.min(100, message.length())) : null; ? message.substring(0, Math.min(100, message.length())) : null;
new Toast(StationsActivity.this).toast(R.string.toast_invalid_data, new Toast(StationsActivity.this).toast(R.string.toast_invalid_data,
limitedMessage); limitedMessage);
}
}); });
} }
@Override @Override
protected void onInputOutputError(final IOException x) { protected void onInputOutputError(final IOException x) {
handler.post(new Runnable() { handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_network_problem));
public void run() {
new Toast(StationsActivity.this).toast(R.string.toast_network_problem);
}
});
} }
}); });
} }
@ -1571,8 +1497,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
lastTime = System.currentTimeMillis(); lastTime = System.currentTimeMillis();
runOnUiThread(new Runnable() { runOnUiThread(() -> {
public void run() {
deviceBearing = azimuth; deviceBearing = azimuth;
stationListAdapter.setDeviceBearing(azimuth, faceDown); stationListAdapter.setDeviceBearing(azimuth, faceDown);
@ -1584,7 +1509,6 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
if (bearingView != null) if (bearingView != null)
bearingView.invalidate(); bearingView.invalidate();
} }
}
}); });
} }

View file

@ -60,12 +60,10 @@ public class FavoriteStationViewHolder extends RecyclerView.ViewHolder {
final long selectedRowId) { final long selectedRowId) {
final boolean selected = rowId == selectedRowId; final boolean selected = rowId == selectedRowId;
itemView.setActivated(selected); itemView.setActivated(selected);
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(v -> {
public void onClick(final View v) {
final int position = getAdapterPosition(); final int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
clickListener.onStationClick(position, network, station); clickListener.onStationClick(position, network, station);
}
}); });
if (showNetwork) { if (showNetwork) {
@ -84,22 +82,18 @@ public class FavoriteStationViewHolder extends RecyclerView.ViewHolder {
if (contextMenuItemListener != null) { if (contextMenuItemListener != null) {
contextButton.setVisibility(View.VISIBLE); contextButton.setVisibility(View.VISIBLE);
contextButton.setOnClickListener(new View.OnClickListener() { contextButton.setOnClickListener(v -> {
public void onClick(final View v) {
final PopupMenu contextMenu = new StationContextMenu(context, v, network, station, final PopupMenu contextMenu = new StationContextMenu(context, v, network, station,
FavoriteStationsProvider.TYPE_FAVORITE, true, false, true, false, false); FavoriteStationsProvider.TYPE_FAVORITE, true, false, true, false, false);
contextMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
final int position = getAdapterPosition(); final int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
return contextMenuItemListener.onStationContextMenuItemClick(position, network, station, return contextMenuItemListener.onStationContextMenuItemClick(position, network, station,
null, item.getItemId()); null, item.getItemId());
else else
return false; return false;
}
}); });
contextMenu.show(); contextMenu.show();
}
}); });
} else { } else {
contextButton.setVisibility(View.GONE); contextButton.setVisibility(View.GONE);

View file

@ -185,22 +185,18 @@ public class StationViewHolder extends RecyclerView.ViewHolder {
// context button // context button
contextButton.setVisibility(itemView.isActivated() ? View.VISIBLE : View.GONE); contextButton.setVisibility(itemView.isActivated() ? View.VISIBLE : View.GONE);
contextButtonSpace.setVisibility(itemView.isActivated() ? View.VISIBLE : View.GONE); contextButtonSpace.setVisibility(itemView.isActivated() ? View.VISIBLE : View.GONE);
contextButton.setOnClickListener(itemView.isActivated() ? new View.OnClickListener() { contextButton.setOnClickListener(itemView.isActivated() ? (View.OnClickListener) v -> {
public void onClick(final View v) {
final PopupMenu contextMenu = new StationContextMenu(context, v, station.network, station.location, final PopupMenu contextMenu = new StationContextMenu(context, v, station.network, station.location,
favState, true, true, true, true, true); favState, true, true, true, true, true);
contextMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { contextMenu.setOnMenuItemClickListener(item -> {
public boolean onMenuItemClick(final MenuItem item) {
final int position = getAdapterPosition(); final int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
return contextMenuItemListener.onStationContextMenuItemClick(position, station.network, return contextMenuItemListener.onStationContextMenuItemClick(position, station.network,
station.location, station.departures, item.getItemId()); station.location, station.departures, item.getItemId());
else else
return false; return false;
}
}); });
contextMenu.show(); contextMenu.show();
}
} : null); } : null);
// departures // departures

View file

@ -104,12 +104,9 @@ public class StationsAdapter extends RecyclerView.Adapter<StationViewHolder> imp
// select stations // select stations
holder.itemView.setActivated(stationsAware.isSelectedStation(station.location.id)); holder.itemView.setActivated(stationsAware.isSelectedStation(station.location.id));
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(v -> {
@Override
public void onClick(final View v) {
final boolean isSelected = stationsAware.isSelectedStation(station.location.id); final boolean isSelected = stationsAware.isSelectedStation(station.location.id);
stationsAware.selectStation(isSelected ? null : station); stationsAware.selectStation(isSelected ? null : station);
}
}); });
// populate view // populate view

View file

@ -77,10 +77,6 @@ public class ChangelogDialogBuilder extends AlertDialog.Builder {
: "") + context.getString(R.string.changelog_dialog_title)); : "") + context.getString(R.string.changelog_dialog_title));
setView(view); setView(view);
setPositiveButton(context.getString(R.string.changelog_dialog_button_dismiss), setPositiveButton(context.getString(R.string.changelog_dialog_button_dismiss),
new DialogInterface.OnClickListener() { (dialog, id) -> dialog.dismiss());
public void onClick(final DialogInterface dialog, final int id) {
dialog.dismiss();
}
});
} }
} }

View file

@ -50,12 +50,7 @@ public class CheatSheet {
* The view to add a cheat sheet for. * The view to add a cheat sheet for.
*/ */
public static void setup(View view) { public static void setup(View view) {
view.setOnLongClickListener(new View.OnLongClickListener() { view.setOnLongClickListener(v -> showCheatSheet(v, v.getContentDescription()));
@Override
public boolean onLongClick(View view) {
return showCheatSheet(view, view.getContentDescription());
}
});
} }
/** /**
@ -69,12 +64,7 @@ public class CheatSheet {
* The string resource containing the text to show on long-press. * The string resource containing the text to show on long-press.
*/ */
public static void setup(View view, final int textResId) { public static void setup(View view, final int textResId) {
view.setOnLongClickListener(new View.OnLongClickListener() { view.setOnLongClickListener(v -> showCheatSheet(v, v.getContext().getString(textResId)));
@Override
public boolean onLongClick(View view) {
return showCheatSheet(view, view.getContext().getString(textResId));
}
});
} }
/** /**
@ -88,12 +78,7 @@ public class CheatSheet {
* The text to show on long-press. * The text to show on long-press.
*/ */
public static void setup(View view, final CharSequence text) { public static void setup(View view, final CharSequence text) {
view.setOnLongClickListener(new View.OnLongClickListener() { view.setOnLongClickListener(v -> showCheatSheet(v, text));
@Override
public boolean onLongClick(View view) {
return showCheatSheet(view, text);
}
});
} }
/** /**

View file

@ -356,11 +356,7 @@ public class ErrorReporter implements Thread.UncaughtExceptionHandler {
} }
private void callback(final String newVersion) { private void callback(final String newVersion) {
callbackHandler.post(new Runnable() { callbackHandler.post(() -> dialog(context, newVersion));
public void run() {
dialog(context, newVersion);
}
});
} }
}); });
} }
@ -369,39 +365,25 @@ public class ErrorReporter implements Thread.UncaughtExceptionHandler {
final DialogBuilder builder = DialogBuilder.warn(context, R.string.alert_crash_report_title); final DialogBuilder builder = DialogBuilder.warn(context, R.string.alert_crash_report_title);
builder.setMessage(newVersion != null ? context.getString(R.string.alert_crash_report_new_version, newVersion) builder.setMessage(newVersion != null ? context.getString(R.string.alert_crash_report_new_version, newVersion)
: context.getString(R.string.alert_crash_report_message)); : context.getString(R.string.alert_crash_report_message));
builder.setNegativeButton(R.string.alert_crash_report_negative, new OnClickListener() { builder.setNegativeButton(R.string.alert_crash_report_negative, (dialog, which) -> stackTraceFile.delete());
public void onClick(final DialogInterface dialog, final int which) {
stackTraceFile.delete();
}
});
if (newVersion != null) { if (newVersion != null) {
builder.setNeutralButton(R.string.alert_crash_report_update, new OnClickListener() { builder.setNeutralButton(R.string.alert_crash_report_update, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
stackTraceFile.delete(); stackTraceFile.delete();
context.startActivity(new Intent(Intent.ACTION_VIEW, context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + context.getPackageName()))); Uri.parse("market://details?id=" + context.getPackageName())));
}
}); });
builder.setPositiveButton(R.string.alert_crash_report_download, new OnClickListener() { builder.setPositiveButton(R.string.alert_crash_report_download, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
stackTraceFile.delete(); stackTraceFile.delete();
context.startActivity( context.startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.OEFFI_BASE_URL + "download.html"))); new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.OEFFI_BASE_URL + "download.html")));
}
}); });
} else { } else {
builder.setPositiveButton(R.string.alert_crash_report_positive, new OnClickListener() { builder.setPositiveButton(R.string.alert_crash_report_positive, (dialog, which) -> {
public void onClick(final DialogInterface dialog, final int which) {
sendError(context); sendError(context);
stackTraceFile.delete(); stackTraceFile.delete();
}
}); });
} }
builder.setOnCancelListener(new OnCancelListener() { builder.setOnCancelListener(dialog -> stackTraceFile.delete());
public void onCancel(final DialogInterface dialog) {
stackTraceFile.delete();
}
});
try { try {
builder.show(); builder.show();

View file

@ -98,21 +98,13 @@ public class GeocoderThread extends Thread {
private void onResult(final Address address) { private void onResult(final Address address) {
log.info("Geocoder took {} ms, returned {}", System.currentTimeMillis() - startTime, address); log.info("Geocoder took {} ms, returned {}", System.currentTimeMillis() - startTime, address);
callbackHandler.post(new Runnable() { callbackHandler.post(() -> callback.onGeocoderResult(address));
public void run() {
callback.onGeocoderResult(address);
}
});
} }
private void onFail(final Exception exception) { private void onFail(final Exception exception) {
log.info("Geocoder failed: {}", exception.getMessage()); log.info("Geocoder failed: {}", exception.getMessage());
callbackHandler.post(new Runnable() { callbackHandler.post(() -> callback.onGeocoderFail(exception));
public void run() {
callback.onGeocoderFail(exception);
}
});
} }
public static Location addressToLocation(final Address address) { public static Location addressToLocation(final Address address) {

View file

@ -105,11 +105,9 @@ public final class LocationHelper {
manager.requestLocationUpdates(provider, 0, 0, listener); manager.requestLocationUpdates(provider, 0, 0, listener);
if (timeout > 0) { if (timeout > 0) {
handler.postDelayed(new Runnable() { handler.postDelayed(() -> {
public void run() {
log.info("LocationHelper timed out"); log.info("LocationHelper timed out");
stop(true); stop(true);
}
}, timeout); }, timeout);
} }
} else { } else {

View file

@ -114,11 +114,7 @@ public class NavigationMenuAdapter extends RecyclerView.Adapter<NavigationMenuAd
itemView.setActivated(item.isChecked()); itemView.setActivated(item.isChecked());
itemView.setFocusable(item.isEnabled()); itemView.setFocusable(item.isEnabled());
if (item.isEnabled()) { if (item.isEnabled()) {
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(v -> menuClickListener.onMenuItemClick(item));
public void onClick(final View v) {
menuClickListener.onMenuItemClick(item);
}
});
} }
final boolean primaryItem = item.getTitleCondensed() != null; final boolean primaryItem = item.getTitleCondensed() != null;