Compare resourceIds via if rather than switch.

As of ADT 14 as well as Gradle Plugin 5.0 those are not final anymore.
Fixes #544.
This commit is contained in:
Dennis Guse
2020-12-11 18:44:01 +01:00
parent 397e056f6f
commit 1862e38a20
5 changed files with 153 additions and 131 deletions
@@ -227,16 +227,17 @@ public class MarkerEditActivity extends AbstractActivity {
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { if (item.getItemId() == R.id.marker_edit_insert_photo) {
case R.id.marker_edit_insert_photo:
createMarkerWithPicture(); createMarkerWithPicture();
return true; return true;
case R.id.marker_edit_insert_gallery_img: }
if (item.getItemId() == R.id.marker_edit_insert_gallery_img) {
createMarkerWithGalleryImage(); createMarkerWithGalleryImage();
return true; return true;
default:
return super.onOptionsItemSelected(item);
} }
return super.onOptionsItemSelected(item);
} }
@Override @Override
@@ -261,7 +262,7 @@ public class MarkerEditActivity extends AbstractActivity {
photoUri = FileUtils.getUriForFile(this, dstFile); photoUri = FileUtils.getUriForFile(this, dstFile);
setMarkerImageView(photoUri); setMarkerImageView(photoUri);
} catch(Exception e) { } catch (Exception e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, e.getMessage());
Toast.makeText(this, R.string.marker_add_canceled, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.marker_add_canceled, Toast.LENGTH_LONG).show();
return; return;
@@ -273,7 +274,7 @@ public class MarkerEditActivity extends AbstractActivity {
/** /**
* Checks and hide/shows all buttons/options about marker photo options. * Checks and hide/shows all buttons/options about marker photo options.
* * <p>
* If a photo is set then one's options are shown, otherwise another ones are shown. * If a photo is set then one's options are shown, otherwise another ones are shown.
*/ */
private void hideAndShowOptions() { private void hideAndShowOptions() {
@@ -320,13 +320,10 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
Intent intent; if (item.getItemId() == R.id.track_list_start_gps) {
switch (item.getItemId()) {
case R.id.track_list_start_gps:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (locationManager != null && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
startActivity(intent);
} else { } else {
// Invoke trackRecordingService // Invoke trackRecordingService
if (!isGpsStarted()) { if (!isGpsStarted()) {
@@ -343,20 +340,25 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
// Update menu after starting or stopping gps // Update menu after starting or stopping gps
this.invalidateOptionsMenu(); this.invalidateOptionsMenu();
} }
return true;
case R.id.track_list_aggregated_stats:
intent = IntentUtils.newIntent(this, AggregatedStatisticsActivity.class);
startActivity(intent);
return true;
case R.id.track_list_markers:
intent = IntentUtils.newIntent(this, MarkerListActivity.class);
startActivity(intent);
return true;
case R.id.track_list_settings:
intent = IntentUtils.newIntent(this, SettingsActivity.class);
startActivity(intent);
return true; return true;
} }
if (item.getItemId() == R.id.track_list_aggregated_stats) {
startActivity(IntentUtils.newIntent(this, AggregatedStatisticsActivity.class));
return true;
}
if (item.getItemId() == R.id.track_list_markers) {
startActivity(IntentUtils.newIntent(this, MarkerListActivity.class));
return true;
}
if (item.getItemId() == R.id.track_list_settings) {
startActivity(IntentUtils.newIntent(this, SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@@ -22,7 +22,6 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewParent;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@@ -147,43 +146,51 @@ public class TrackRecordedActivity extends AbstractListActivity implements Confi
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
Intent intent; if (item.getItemId() == R.id.track_detail_share) {
switch (item.getItemId()) { Intent intent = Intent.createChooser(IntentUtils.newShareFileIntent(this, trackId), null);
case R.id.track_detail_share:
intent = IntentUtils.newShareFileIntent(this, trackId);
intent = Intent.createChooser(intent, null);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.track_detail_menu_show_on_map: }
if (item.getItemId() == R.id.track_detail_menu_show_on_map) {
IntentDashboardUtils.startDashboard(this, false, trackId); IntentDashboardUtils.startDashboard(this, false, trackId);
return true; return true;
case R.id.track_detail_markers: }
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
if (item.getItemId() == R.id.track_detail_markers) {
Intent intent = IntentUtils.newIntent(this, MarkerListActivity.class)
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId); .putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.track_detail_edit: }
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
if (item.getItemId() == R.id.track_detail_edit) {
Intent intent = IntentUtils.newIntent(this, TrackEditActivity.class)
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.track_detail_delete: }
if (item.getItemId() == R.id.track_detail_delete) {
deleteTracks(trackId); deleteTracks(trackId);
return true; return true;
case R.id.track_detail_resume_track: }
if (item.getItemId() == R.id.track_detail_resume_track) {
Intent newIntent = IntentUtils.newIntent(TrackRecordedActivity.this, TrackRecordingActivity.class) Intent newIntent = IntentUtils.newIntent(TrackRecordedActivity.this, TrackRecordingActivity.class)
.putExtra(TrackRecordingActivity.EXTRA_TRACK_ID, trackId); .putExtra(TrackRecordingActivity.EXTRA_TRACK_ID, trackId);
startActivity(newIntent); startActivity(newIntent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish(); finish();
return true; return true;
case R.id.track_detail_settings:
intent = IntentUtils.newIntent(this, SettingsActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
} }
if (item.getItemId() == R.id.track_detail_settings) {
startActivity(IntentUtils.newIntent(this, SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
} }
@Override @Override
@@ -278,34 +278,41 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
Intent intent; if (item.getItemId() == R.id.track_detail_insert_marker) {
switch (item.getItemId()) { Intent intent = IntentUtils
case R.id.track_detail_insert_marker:
intent = IntentUtils
.newIntent(this, MarkerEditActivity.class) .newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId); .putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.track_detail_menu_show_on_map: }
if (item.getItemId() == R.id.track_detail_menu_show_on_map) {
IntentDashboardUtils.startDashboard(this, true, trackId); IntentDashboardUtils.startDashboard(this, true, trackId);
return true; return true;
case R.id.track_detail_markers: }
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
if (item.getItemId() == R.id.track_detail_markers) {
Intent intent = IntentUtils.newIntent(this, MarkerListActivity.class)
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId); .putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.track_detail_edit:
intent = IntentUtils.newIntent(this, TrackEditActivity.class) }
if (item.getItemId() == R.id.track_detail_edit) {
Intent intent = IntentUtils.newIntent(this, TrackEditActivity.class)
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.track_detail_settings: }
intent = IntentUtils.newIntent(this, SettingsActivity.class);
if (item.getItemId() == R.id.track_detail_settings) {
Intent intent = IntentUtils.newIntent(this, SettingsActivity.class);
startActivity(intent); startActivity(intent);
return true; return true;
default:
return super.onOptionsItemSelected(item);
} }
return super.onOptionsItemSelected(item);
} }
/** /**
@@ -184,29 +184,34 @@ public class MarkerDetailFragment extends Fragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
Marker.Id markerId = getArguments().getParcelable(KEY_MARKER_ID); //TODO Should only happen in onCreate? Marker.Id markerId = getArguments().getParcelable(KEY_MARKER_ID); //TODO Should only happen in onCreate?
FragmentActivity fragmentActivity = getActivity(); FragmentActivity fragmentActivity = getActivity();
Intent intent;
switch (item.getItemId()) { if (item.getItemId() == R.id.marker_detail_show_on_map) {
case R.id.marker_detail_show_on_map:
IntentUtils.showCoordinateOnMap(getContext(), marker); IntentUtils.showCoordinateOnMap(getContext(), marker);
return true; return true;
case R.id.marker_detail_edit: }
intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class)
if (item.getItemId() == R.id.marker_detail_edit) {
Intent intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId); .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.marker_detail_share: }
if (item.getItemId() == R.id.marker_detail_share) {
if (marker.hasPhoto()) { if (marker.hasPhoto()) {
intent = IntentUtils.newShareImageIntent(getContext(), marker.getPhotoURI()); Intent intent = IntentUtils.newShareImageIntent(getContext(), marker.getPhotoURI());
intent = Intent.createChooser(intent, null); intent = Intent.createChooser(intent, null);
startActivity(intent); startActivity(intent);
} }
return true; return true;
case R.id.marker_detail_delete: }
if (item.getItemId() == R.id.marker_detail_delete) {
DeleteMarkerDialogFragment.showDialog(getChildFragmentManager(), markerId); DeleteMarkerDialogFragment.showDialog(getChildFragmentManager(), markerId);
return true; return true;
default:
return super.onOptionsItemSelected(item);
} }
return super.onOptionsItemSelected(item);
} }
private void updateMarker(boolean refresh) { private void updateMarker(boolean refresh) {