Skip to content

Commit b760c89

Browse files
cibgoglin
authored andcommitted
contrib/android: fix case expressions must be constants expressions
Recent Android changed the definition of R.id, convert switch/case to if/else. Signed-off-by: Brice Goglin <[email protected]>
1 parent 02ca260 commit b760c89

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

contrib/android/AndroidApp/lstopo/src/main/java/com/hwloc/lstopo/MainActivity.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
207207
*/
208208
@Override
209209
public boolean onOptionsItemSelected(MenuItem item) {
210-
switch (item.getItemId()) {
211-
case R.id.share:
210+
if (item.getItemId() == R.id.share) {
212211
share();
213212
return true;
214-
default:
213+
} else {
215214
return super.onOptionsItemSelected(item);
216215
}
217216
}
@@ -225,8 +224,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
225224
menuItems.setCheckedItems(item);
226225
zoomView.resetZoom();
227226

228-
switch (id){
229-
case R.id.activity_main_drawer_draw :
227+
if (id == R.id.activity_main_drawer_draw) {
230228
if(topology.equals("phone") && !menuItems.isInputPhoneSelected())
231229
menuItems.setPhoneInput();
232230

@@ -238,8 +236,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
238236
else
239237
startWithInput(lstopo, 1, "", topology, options);
240238
setMode("draw");
241-
break;
242-
case R.id.activity_main_drawer_text:
239+
} else if (id == R.id.activity_main_drawer_text) {
243240
if(topology.equals("phone") && !menuItems.isInputPhoneSelected())
244241
menuItems.setPhoneInput();
245242

@@ -255,12 +252,10 @@ public boolean onNavigationItemSelected(MenuItem item) {
255252
setMode("txt");
256253
String lstopoText = readFile(txtFile);
257254
lstopo.text(lstopoText, 0, 0, 0, 0, 0, -1);
258-
break;
259255
} catch (IOException e) {
260256
e.printStackTrace();
261-
break;
262257
}
263-
case R.id.activity_main_drawer_xml:
258+
} else if (id == R.id.activity_main_drawer_xml) {
264259
if(topology.equals("phone") && !menuItems.isInputPhoneSelected())
265260
menuItems.setPhoneInput();
266261

@@ -276,46 +271,36 @@ public boolean onNavigationItemSelected(MenuItem item) {
276271
setMode("xml");
277272
String lstopoText = readFile(xmlFile);
278273
lstopo.text(lstopoText, 0, 0, 0, 0, 0, -1);
279-
break;
280274
} catch (IOException e) {
281275
e.printStackTrace();
282-
break;
283276
}
284-
case R.id.activity_main_drawer_MyPhone:
277+
} else if (id == R.id.activity_main_drawer_MyPhone) {
285278
topology = "phone";
286279
layout.removeAllViews();
287280

288281
start(lstopo, 1, "", options);
289282
menuItems.setDrawFormat();
290283
mode = "draw";
291-
break;
292-
case R.id.activity_main_drawer_database:
284+
} else if (id == R.id.activity_main_drawer_database) {
293285
/* menuItems.setDrawFormat();
294286
downloadTopology(); */
295287
Uri uriDatabase = Uri.parse("https://hwloc.gitlabpages.inria.fr/xmls/");
296288
Intent intentDatabase = new Intent(Intent.ACTION_VIEW, uriDatabase);
297289
startActivity(intentDatabase);
298-
break;
299-
case R.id.activity_main_drawer_LocalXML:
290+
} else if (id == R.id.activity_main_drawer_LocalXML) {
300291
file_picker();
301-
break;
302-
case R.id.activity_main_drawer_Synthetic_Topology:
292+
} else if (id == R.id.activity_main_drawer_Synthetic_Topology) {
303293
createSyntheticLayout();
304-
break;
305-
case R.id.activity_main_drawer_debug:
294+
} else if (id == R.id.activity_main_drawer_debug) {
306295
final Uri data = FileProvider.getUriForFile(this, "com.hwloc.lstopo.fileprovider", debugFile);
307296
this.grantUriPermission(this.getPackageName(), data, Intent.FLAG_GRANT_READ_URI_PERMISSION);
308297
final Intent intent = new Intent(Intent.ACTION_VIEW)
309298
.setDataAndType(data, "text/plain")
310299
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
311300
this.startActivity(intent);
312-
break;
313-
case R.id.activity_main_drawer_about:
301+
} else if (id == R.id.activity_main_drawer_about) {
314302
Intent intentAbout = new Intent(MainActivity.this, About.class);
315303
startActivityForResult(intentAbout, 5);
316-
break;
317-
default:
318-
break;
319304
}
320305

321306
this.drawerLayout.closeDrawer(GravityCompat.START);

0 commit comments

Comments
 (0)