Avoided switch usage for Resource IDs

(because of a warning that Resource IDs will be/are non-final)
pull/15/head
Olga Miller 2021-07-25 13:57:50 +02:00
rodzic 817d8cb73f
commit 556a392816
2 zmienionych plików z 42 dodań i 47 usunięć

Wyświetl plik

@ -200,21 +200,18 @@ public class EditTextActivity extends AppCompatActivity
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.edit_text_size:
mLabel.setTextSize(positionToTextSize(position));
break;
case R.id.edit_outline_size:
mLabel.setOutlineSize(positionToOutlineSize(position));
break;
case R.id.edit_font_family:
String displayName = mFontFamilyNameList.get(position);
mSelectedFontFamily = mFontFamilySet.getFontFamilyFromDisplayName(displayName);
mLabel.setFamilyName(mSelectedFontFamily.name);
updateBoldAndItalic();
break;
default:
break;
int parentId = parent.getId();
if (parentId == R.id.edit_text_size) {
mLabel.setTextSize(positionToTextSize(position));
}
else if (parentId == R.id.edit_outline_size) {
mLabel.setOutlineSize(positionToOutlineSize(position));
}
else if (parentId == R.id.edit_font_family) {
String displayName = mFontFamilyNameList.get(position);
mSelectedFontFamily = mFontFamilySet.getFontFamilyFromDisplayName(displayName);
mLabel.setFamilyName(mSelectedFontFamily.name);
updateBoldAndItalic();
}
}
@ -258,10 +255,10 @@ public class EditTextActivity extends AppCompatActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_done:
done();
return true;
int id = item.getItemId();
if (id == R.id.action_done) {
done();
return true;
}
return super.onOptionsItemSelected(item);
}

Wyświetl plik

@ -325,35 +325,33 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_pick_picture:
dispatchPickPictureIntent();
return true;
case R.id.action_take_picture:
takePicture();
return true;
case R.id.action_save_wave:
if (needsRequestWritePermission())
requestWritePermission(REQUEST_SAVE_WAVE_PERMISSION);
else
save();
return true;
case R.id.action_play:
play();
return true;
case R.id.action_stop:
mEncoder.stop();
return true;
case R.id.action_rotate:
mCropView.rotateImage(90);
return true;
case R.id.action_modes:
return true;
default:
String className = item.getIntent().getStringExtra(CLASS_NAME);
setMode(className);
return true;
int id = item.getItemId();
if (id == R.id.action_pick_picture) {
dispatchPickPictureIntent();
}
else if (id == R.id.action_take_picture) {
takePicture();
}
else if (id == R.id.action_save_wave) {
if (needsRequestWritePermission())
requestWritePermission(REQUEST_SAVE_WAVE_PERMISSION);
else
save();
}
else if (id == R.id.action_play) {
play();
}
else if (id == R.id.action_stop) {
mEncoder.stop();
}
else if (id == R.id.action_rotate) {
mCropView.rotateImage(90);
}
else if (id != R.id.action_modes) {
String className = item.getIntent().getStringExtra(CLASS_NAME);
setMode(className);
}
return true;
}
private void setMode(String modeClassName) {