1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Make R class fields non-final

This commit is contained in:
José Rebelo 2024-06-30 20:27:12 +01:00
parent 39708e5fb6
commit d7242c1f12
31 changed files with 433 additions and 459 deletions

View File

@ -217,11 +217,11 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -72,12 +72,12 @@ public abstract class AbstractSettingsActivityV2 extends AbstractGBActivity impl
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Simulate a back press, so that we don't actually exit the activity when
// in a nested PreferenceScreen
this.onBackPressed();
return true;
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// Simulate a back press, so that we don't actually exit the activity when
// in a nested PreferenceScreen
this.onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);

View File

@ -125,22 +125,21 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean processed = false;
switch (item.getItemId()) {
case android.R.id.home:
// back button, close drawer if open, otherwise exit
finish();
return true;
case R.id.activity_action_manage_timestamp:
resetFetchTimestampToChosenDate();
processed = true;
break;
case R.id.activity_action_filter:
runFilterActivity();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button, close drawer if open, otherwise exit
finish();
return true;
} else if (itemId == R.id.activity_action_manage_timestamp) {
resetFetchTimestampToChosenDate();
return true;
} else if (itemId == R.id.activity_action_filter) {
runFilterActivity();
return true;
}
return processed;
return false;
}
@Override
@ -229,77 +228,72 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) {
boolean processed = false;
SparseBooleanArray checked = getItemListView().getCheckedItemPositions();
switch (menuItem.getItemId()) {
case R.id.activity_action_delete:
final List<BaseActivitySummary> toDelete = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
toDelete.add(getItemAdapter().getItem(checked.keyAt(i)));
}
final SparseBooleanArray checked = getItemListView().getCheckedItemPositions();
final int itemId = menuItem.getItemId();
if (itemId == R.id.activity_action_delete) {
final List<BaseActivitySummary> toDelete = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
toDelete.add(getItemAdapter().getItem(checked.keyAt(i)));
}
}
new MaterialAlertDialogBuilder(ActivitySummariesActivity.this)
.setTitle(ActivitySummariesActivity.this.getString(R.string.sports_activity_confirm_delete_title, toDelete.size()))
.setMessage(ActivitySummariesActivity.this.getString(R.string.sports_activity_confirm_delete_description, toDelete.size()))
.setIcon(R.drawable.ic_delete_forever)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
deleteItems(toDelete);
}
})
.setNegativeButton(android.R.string.no, null)
.show();
new MaterialAlertDialogBuilder(ActivitySummariesActivity.this)
.setTitle(ActivitySummariesActivity.this.getString(R.string.sports_activity_confirm_delete_title, toDelete.size()))
.setMessage(ActivitySummariesActivity.this.getString(R.string.sports_activity_confirm_delete_description, toDelete.size()))
.setIcon(R.drawable.ic_delete_forever)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
deleteItems(toDelete);
}
})
.setNegativeButton(android.R.string.no, null)
.show();
processed = true;
break;
case R.id.activity_action_export:
List<String> paths = new ArrayList<>();
processed = true;
} else if (itemId == R.id.activity_action_export) {
final List<String> paths = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
BaseActivitySummary item = getItemAdapter().getItem(checked.keyAt(i));
if (item != null) {
ActivitySummary summary = item;
BaseActivitySummary item = getItemAdapter().getItem(checked.keyAt(i));
if (item != null) {
ActivitySummary summary = item;
String gpxTrack = summary.getGpxTrack();
if (gpxTrack != null) {
paths.add(gpxTrack);
}
String gpxTrack = summary.getGpxTrack();
if (gpxTrack != null) {
paths.add(gpxTrack);
}
}
}
shareMultiple(paths);
processed = true;
break;
case R.id.activity_action_select_all:
for (int i = 0; i < getItemListView().getCount(); i++) {
getItemListView().setItemChecked(i, true);
}
return true; //don't finish actionmode in this case!
case R.id.activity_action_addto_filter:
List<Long> toFilter = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
BaseActivitySummary item = getItemAdapter().getItem(checked.keyAt(i));
if (item != null && item.getId() != null) {
ActivitySummary summary = item;
Long id = summary.getId();
toFilter.add(id);
}
}
shareMultiple(paths);
processed = true;
} else if (itemId == R.id.activity_action_select_all) {
for (int i = 0; i < getItemListView().getCount(); i++) {
getItemListView().setItemChecked(i, true);
}
return true; //don't finish actionmode in this case!
} else if (itemId == R.id.activity_action_addto_filter) {
final List<Long> toFilter = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
BaseActivitySummary item = getItemAdapter().getItem(checked.keyAt(i));
if (item != null && item.getId() != null) {
ActivitySummary summary = item;
Long id = summary.getId();
toFilter.add(id);
}
}
itemsFilter = toFilter;
setItemsFilter(itemsFilter);
refresh();
}
itemsFilter = toFilter;
setItemsFilter(itemsFilter);
refresh();
processed = true;
break;
default:
break;
processed = true;
}
actionMode.finish();
return processed;

View File

@ -236,12 +236,12 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -563,27 +563,27 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
case R.id.activity_action_take_screenshot:
take_share_screenshot(ActivitySummaryDetail.this);
return true;
case R.id.activity_action_show_gpx:
viewGpxTrack(ActivitySummaryDetail.this);
return true;
case R.id.activity_action_share_gpx:
shareGpxTrack(ActivitySummaryDetail.this, currentItem);
return true;
case R.id.activity_action_dev_share_raw_summary:
shareRawSummary(ActivitySummaryDetail.this, currentItem);
return true;
case R.id.activity_action_dev_share_raw_details:
shareRawDetails(ActivitySummaryDetail.this, currentItem);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
} else if (itemId == R.id.activity_action_take_screenshot) {
take_share_screenshot(ActivitySummaryDetail.this);
return true;
} else if (itemId == R.id.activity_action_show_gpx) {
viewGpxTrack(ActivitySummaryDetail.this);
return true;
} else if (itemId == R.id.activity_action_share_gpx) {
shareGpxTrack(ActivitySummaryDetail.this, currentItem);
return true;
} else if (itemId == R.id.activity_action_dev_share_raw_summary) {
shareRawSummary(ActivitySummaryDetail.this, currentItem);
return true;
} else if (itemId == R.id.activity_action_dev_share_raw_details) {
shareRawDetails(ActivitySummaryDetail.this, currentItem);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -260,12 +260,12 @@ public class AlarmDetails extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -22,9 +22,6 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import androidx.appcompat.widget.SearchView;
import androidx.core.app.NavUtils;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -34,32 +31,30 @@ import nodomain.freeyourgadget.gadgetbridge.adapter.AppBlacklistAdapter;
public class AppBlacklistActivity extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(AppBlacklistActivity.class);
private AppBlacklistAdapter appBlacklistAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appblacklist);
RecyclerView appListView = (RecyclerView) findViewById(R.id.appListView);
final RecyclerView appListView = (RecyclerView) findViewById(R.id.appListView);
appListView.setLayoutManager(new LinearLayoutManager(this));
appBlacklistAdapter = new AppBlacklistAdapter(R.layout.item_app_blacklist, this);
appListView.setAdapter(appBlacklistAdapter);
SearchView searchView = (SearchView) findViewById(R.id.appListViewSearch);
final SearchView searchView = findViewById(R.id.appListViewSearch);
searchView.setIconifiedByDefault(false);
searchView.setIconified(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
public boolean onQueryTextSubmit(final String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
public boolean onQueryTextChange(final String newText) {
appBlacklistAdapter.getFilter().filter(newText);
return true;
}
@ -67,24 +62,24 @@ public class AppBlacklistActivity extends AbstractGBActivity {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
public boolean onCreateOptionsMenu(final Menu menu) {
final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.app_blacklist_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.check_all_applications:
appBlacklistAdapter.checkAllApplications();
return true;
case R.id.uncheck_all_applications:
appBlacklistAdapter.uncheckAllApplications();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
} else if (itemId == R.id.check_all_applications) {
appBlacklistAdapter.checkAllApplications();
return true;
} else if (itemId == R.id.uncheck_all_applications) {
appBlacklistAdapter.uncheckAllApplications();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -103,11 +103,11 @@ public class CalBlacklistActivity extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -151,12 +151,12 @@ public class ConfigureAlarms extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -142,12 +142,12 @@ public class ConfigureContacts extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -174,12 +174,12 @@ public class ConfigureReminders extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -189,12 +189,12 @@ public class ConfigureWorldClocks extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -120,12 +120,12 @@ public class ContactDetails extends AbstractGBActivity {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
// TODO confirm when exiting without saving
finish();
return true;
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
// TODO confirm when exiting without saving
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -200,13 +200,11 @@ public class ControlCenterv2 extends AppCompatActivity
navigationView.setVisibility(View.GONE);
}
navigationView.setOnItemSelectedListener(menuItem -> {
switch (menuItem.getItemId()) {
case R.id.bottom_nav_dashboard:
viewPager.setCurrentItem(0, true);
break;
case R.id.bottom_nav_devices:
viewPager.setCurrentItem(1, true);
break;
final int itemId = menuItem.getItemId();
if (itemId == R.id.bottom_nav_dashboard) {
viewPager.setCurrentItem(0, true);
} else if (itemId == R.id.bottom_nav_devices) {
viewPager.setCurrentItem(1, true);
}
return true;
});
@ -386,58 +384,57 @@ public class ControlCenterv2 extends AppCompatActivity
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
switch (item.getItemId()) {
case R.id.action_settings:
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivityForResult(settingsIntent, MENU_REFRESH_CODE);
return false; //we do not want the drawer menu item to get selected
case R.id.action_debug:
Intent debugIntent = new Intent(this, DebugActivity.class);
startActivity(debugIntent);
return false;
case R.id.action_data_management:
Intent dbIntent = new Intent(this, DataManagementActivity.class);
startActivity(dbIntent);
return false;
case R.id.action_notification_management:
Intent blIntent = new Intent(this, NotificationManagementActivity.class);
startActivity(blIntent);
return false;
case R.id.device_action_discover:
launchDiscoveryActivity();
return false;
case R.id.action_quit:
GBApplication.quit();
return false;
case R.id.donation_link:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://liberapay.com/Gadgetbridge")); //TODO: centralize if ever used somewhere else
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return false;
case R.id.external_changelog:
GBChangeLog cl = createChangeLog();
try {
if (cl.hasChanges(false)) {
cl.getMaterialLogDialog().show();
} else {
cl.getMaterialFullLogDialog().show();
}
} catch (Exception ignored) {
GB.toast(getBaseContext(), getString(R.string.error_showing_changelog), Toast.LENGTH_LONG, GB.ERROR);
final int itemId = item.getItemId();
if (itemId == R.id.action_settings) {
final Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivityForResult(settingsIntent, MENU_REFRESH_CODE);
return false;
} else if (itemId == R.id.action_debug) {
final Intent debugIntent = new Intent(this, DebugActivity.class);
startActivity(debugIntent);
return false;
} else if (itemId == R.id.action_data_management) {
final Intent dbIntent = new Intent(this, DataManagementActivity.class);
startActivity(dbIntent);
return false;
} else if (itemId == R.id.action_notification_management) {
final Intent blIntent = new Intent(this, NotificationManagementActivity.class);
startActivity(blIntent);
return false;
} else if (itemId == R.id.device_action_discover) {
launchDiscoveryActivity();
return false;
} else if (itemId == R.id.action_quit) {
GBApplication.quit();
return false;
} else if (itemId == R.id.donation_link) {
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://liberapay.com/Gadgetbridge")); //TODO: centralize if ever used somewhere else
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return false;
} else if (itemId == R.id.external_changelog) {
final GBChangeLog cl = createChangeLog();
try {
if (cl.hasChanges(false)) {
cl.getMaterialLogDialog().show();
} else {
cl.getMaterialFullLogDialog().show();
}
return false;
case R.id.about:
Intent aboutIntent = new Intent(this, AboutActivity.class);
startActivity(aboutIntent);
return false;
} catch (Exception ignored) {
GB.toast(getBaseContext(), getString(R.string.error_showing_changelog), Toast.LENGTH_LONG, GB.ERROR);
}
return false;
} else if (itemId == R.id.about) {
final Intent aboutIntent = new Intent(this, AboutActivity.class);
startActivity(aboutIntent);
return false;
}
return false;
return false; // we do not want the drawer menu item to get selected
}
private GBChangeLog createChangeLog() {

View File

@ -175,13 +175,13 @@ public class DashboardFragment extends Fragment {
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.dashboard_show_calendar:
Intent intent = new Intent(requireActivity(), DashboardCalendarActivity.class);
intent.putExtra(DashboardCalendarActivity.EXTRA_TIMESTAMP, day.getTimeInMillis());
startActivityForResult(intent, 0);
return false;
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == R.id.dashboard_show_calendar) {
final Intent intent = new Intent(requireActivity(), DashboardCalendarActivity.class);
intent.putExtra(DashboardCalendarActivity.EXTRA_TIMESTAMP, day.getTimeInMillis());
startActivityForResult(intent, 0);
return false;
}
return super.onOptionsItemSelected(item);
}

View File

@ -1014,11 +1014,11 @@ public class DebugActivity extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -227,11 +227,11 @@ public class ExternalPebbleJSActivity extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -289,11 +289,11 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -33,12 +33,11 @@ import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@ -51,12 +50,9 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.entities.Reminder;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class ReminderDetails extends AbstractGBActivity implements TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
private static final Logger LOG = LoggerFactory.getLogger(ReminderDetails.class);
private Reminder reminder;
private GBDevice device;
@ -168,13 +164,13 @@ public class ReminderDetails extends AbstractGBActivity implements TimePickerDia
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
// TODO confirm when exiting without saving
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
// TODO confirm when exiting without saving
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@ -184,13 +180,13 @@ public class ReminderDetails extends AbstractGBActivity implements TimePickerDia
}
@Override
protected void onSaveInstanceState(Bundle state) {
protected void onSaveInstanceState(@NonNull final Bundle state) {
super.onSaveInstanceState(state);
state.putSerializable("reminder", reminder);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
reminder = (Reminder) savedInstanceState.getSerializable("reminder");
updateUiFromReminder();

View File

@ -81,27 +81,20 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.alarm1:
setAlarm(5);
break;
case R.id.alarm2:
setAlarm(10);
break;
case R.id.alarm3:
setAlarm(20);
break;
case R.id.alarm4:
setAlarm(60);
break;
case R.id.alarm5:
setAlarm(0);
break;
default:
break;
public void onClick(final View v) {
final int viewId = v.getId();
if (viewId == R.id.alarm1) {
setAlarm(5);
} else if (viewId == R.id.alarm2) {
setAlarm(10);
} else if (viewId == R.id.alarm3) {
setAlarm(20);
} else if (viewId == R.id.alarm4) {
setAlarm(60);
} else if (viewId == R.id.alarm5) {
setAlarm(0);
}
//this is to prevent screen flashing during closing
new Handler().postDelayed(new Runnable() {
@Override

View File

@ -29,12 +29,11 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.TimeZone;
import nodomain.freeyourgadget.gadgetbridge.R;
@ -42,13 +41,10 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.entities.WorldClock;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
public class WorldClockDetails extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(WorldClockDetails.class);
private WorldClock worldClock;
private GBDevice device;
@ -80,6 +76,12 @@ public class WorldClockDetails extends AbstractGBActivity {
worldClockCode = findViewById(R.id.world_clock_code);
device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
if (device == null) {
GB.toast("No device provided to WorldClockDetails Activity", Toast.LENGTH_LONG, GB.ERROR);
finish();
return;
}
final DeviceCoordinator coordinator = device.getDeviceCoordinator();
final String[] timezoneIDs = TimeZone.getAvailableIDs();
@ -153,13 +155,13 @@ public class WorldClockDetails extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
// TODO confirm when exiting without saving
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
// TODO confirm when exiting without saving
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@ -169,13 +171,13 @@ public class WorldClockDetails extends AbstractGBActivity {
}
@Override
protected void onSaveInstanceState(Bundle state) {
protected void onSaveInstanceState(@NonNull final Bundle state) {
super.onSaveInstanceState(state);
state.putSerializable("worldClock", worldClock);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
worldClock = (WorldClock) savedInstanceState.getSerializable("worldClock");
updateUiFromWorldClock();

View File

@ -577,94 +577,91 @@ public abstract class AbstractAppManagerFragment extends Fragment {
return true;
}
private boolean onContextItemSelected(MenuItem item, GBDeviceApp selectedApp) {
File appCacheDir;
private boolean onContextItemSelected(final MenuItem item, final GBDeviceApp selectedApp) {
final File appCacheDir;
try {
appCacheDir = mCoordinator.getAppCacheDir();
} catch (IOException e) {
} catch (final IOException e) {
LOG.warn("could not get external dir while trying to access app cache.");
return true;
}
switch (item.getItemId()) {
case R.id.appmanager_app_delete_cache:
deleteAppConfirm(selectedApp, true);
final int itemId = item.getItemId();
if (itemId == R.id.appmanager_app_delete_cache) {
deleteAppConfirm(selectedApp, true);
return true;
} else if (itemId == R.id.appmanager_app_delete) {
deleteAppConfirm(selectedApp, false);
return true;
} else if (itemId == R.id.appmanager_app_start || itemId == R.id.appmanager_watchface_activate) {
GBApplication.deviceService(mGBDevice).onAppStart(selectedApp.getUUID(), true);
return true;
} else if (itemId == R.id.appmanager_app_download) {
GBApplication.deviceService(mGBDevice).onAppDownload(selectedApp.getUUID());
GB.toast(requireContext().getString(R.string.appmanager_download_started), Toast.LENGTH_LONG, GB.INFO);
return true;
} else if (itemId == R.id.appmanager_app_reinstall) {
final File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.fromFile(cachePath));
return true;
} else if (itemId == R.id.appmanager_app_share) {
final File origFilePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
final File appTempDir = new File(appCacheDir, "temp_sharing");
final File sharedAppFile = new File(appTempDir, selectedApp.getName() + mCoordinator.getAppFileExtension());
try {
appTempDir.mkdirs();
FileUtils.copyFile(origFilePath, sharedAppFile);
} catch (final IOException e) {
return true;
case R.id.appmanager_app_delete:
deleteAppConfirm(selectedApp, false);
return true;
case R.id.appmanager_app_start:
case R.id.appmanager_watchface_activate:
GBApplication.deviceService(mGBDevice).onAppStart(selectedApp.getUUID(), true);
return true;
case R.id.appmanager_app_download:
GBApplication.deviceService(mGBDevice).onAppDownload(selectedApp.getUUID());
GB.toast(getContext().getString(R.string.appmanager_download_started), Toast.LENGTH_LONG, GB.INFO);
return true;
case R.id.appmanager_app_reinstall:
File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.fromFile(cachePath));
return true;
case R.id.appmanager_app_share:
File origFilePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
File appTempDir = new File(appCacheDir, "temp_sharing");
File sharedAppFile = new File(appTempDir, selectedApp.getName() + mCoordinator.getAppFileExtension());
try {
appTempDir.mkdirs();
FileUtils.copyFile(origFilePath, sharedAppFile);
} catch (IOException e) {
return true;
}
Uri contentUri = FileProvider.getUriForFile(getContext(),getContext().getApplicationContext().getPackageName() + ".screenshot_provider", sharedAppFile);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.setType("*/*");
try {
startActivity(Intent.createChooser(shareIntent, null));
} catch (ActivityNotFoundException e) {
LOG.warn("Sharing watchface failed", e);
}
return true;
case R.id.appmanager_health_activate:
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://health"));
return true;
case R.id.appmanager_hrm_activate:
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://hrm"));
return true;
case R.id.appmanager_weather_activate:
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://weather"));
return true;
case R.id.appmanager_health_deactivate:
case R.id.appmanager_hrm_deactivate:
case R.id.appmanager_weather_deactivate:
GBApplication.deviceService(mGBDevice).onAppDelete(selectedApp.getUUID());
return true;
case R.id.appmanager_weather_install_provider:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/app/ru.gelin.android.weather.notification")));
return true;
case R.id.appmanager_app_configure:
GBApplication.deviceService(mGBDevice).onAppStart(selectedApp.getUUID(), true);
}
final Uri contentUri = FileProvider.getUriForFile(requireContext(), requireContext().getApplicationContext().getPackageName() + ".screenshot_provider", sharedAppFile);
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.setType("*/*");
try {
startActivity(Intent.createChooser(shareIntent, null));
} catch (ActivityNotFoundException e) {
LOG.warn("Sharing watchface failed", e);
}
return true;
} else if (itemId == R.id.appmanager_health_activate) {
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://health"));
return true;
} else if (itemId == R.id.appmanager_hrm_activate) {
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://hrm"));
return true;
} else if (itemId == R.id.appmanager_weather_activate) {
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://weather"));
return true;
} else if (itemId == R.id.appmanager_health_deactivate || itemId == R.id.appmanager_hrm_deactivate || itemId == R.id.appmanager_weather_deactivate) {
GBApplication.deviceService(mGBDevice).onAppDelete(selectedApp.getUUID());
return true;
} else if (itemId == R.id.appmanager_weather_install_provider) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/app/ru.gelin.android.weather.notification")));
return true;
} else if (itemId == R.id.appmanager_app_configure) {
GBApplication.deviceService(mGBDevice).onAppStart(selectedApp.getUUID(), true);
Intent startIntent = new Intent(getContext().getApplicationContext(), ExternalPebbleJSActivity.class);
startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
startIntent.putExtra(ExternalPebbleJSActivity.SHOW_CONFIG, true);
startActivity(startIntent);
return true;
case R.id.appmanager_app_openinstore:
String url = "https://apps.rebble.io/en_US/search/" + ((selectedApp.getType() == GBDeviceApp.Type.WATCHFACE) ? "watchfaces" : "watchapps") + "/1/?native=true&?query=" + Uri.encode(selectedApp.getName());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
case R.id.appmanager_app_edit:
Intent editWatchfaceIntent = new Intent(getContext(), watchfaceDesignerActivity);
editWatchfaceIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
editWatchfaceIntent.putExtra(GBDevice.EXTRA_UUID, selectedApp.getUUID().toString());
startActivityForResult(editWatchfaceIntent, CHILD_ACTIVITY_WATCHFACE_EDITOR);
return true;
default:
return super.onContextItemSelected(item);
final Intent startIntent = new Intent(getContext().getApplicationContext(), ExternalPebbleJSActivity.class);
startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
startIntent.putExtra(ExternalPebbleJSActivity.SHOW_CONFIG, true);
startActivity(startIntent);
return true;
} else if (itemId == R.id.appmanager_app_openinstore) {
final String url = "https://apps.rebble.io/en_US/search/" + ((selectedApp.getType() == GBDeviceApp.Type.WATCHFACE) ? "watchfaces" : "watchapps") + "/1/?native=true&?query=" + Uri.encode(selectedApp.getName());
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
} else if (itemId == R.id.appmanager_app_edit) {
final Intent editWatchfaceIntent = new Intent(getContext(), watchfaceDesignerActivity);
editWatchfaceIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
editWatchfaceIntent.putExtra(GBDevice.EXTRA_UUID, selectedApp.getUUID().toString());
startActivityForResult(editWatchfaceIntent, CHILD_ACTIVITY_WATCHFACE_EDITOR);
return true;
}
return super.onContextItemSelected(item);
}
private void deleteAppConfirm(final GBDeviceApp selectedApp, final boolean deleteFromCache) {

View File

@ -162,11 +162,11 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -142,12 +142,12 @@ public class WidgetScreenDetailsActivity extends AbstractGBActivity {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
// TODO confirm when exiting without saving
finish();
return true;
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
// TODO confirm when exiting without saving
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -139,12 +139,12 @@ public class WidgetScreensListActivity extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -857,54 +857,55 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.controlcenter_device_submenu_connect:
if (device.getState() != GBDevice.State.CONNECTED) {
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
handleDeviceConnect(device);
}
return true;
case R.id.controlcenter_device_submenu_disconnect:
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
GBApplication.deviceService(device).disconnect();
}
removeFromLastDeviceAddressesPref(device);
return true;
case R.id.controlcenter_device_submenu_set_alias:
showSetAliasDialog(device);
return true;
case R.id.controlcenter_device_submenu_remove:
showRemoveDeviceDialog(device);
return true;
case R.id.controlcenter_device_submenu_show_details:
final String previouslyExpandedDeviceAddress = expandedDeviceAddress;
expandedDeviceAddress = detailsShown ? "" : device.getAddress();
public boolean onMenuItemClick(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == R.id.controlcenter_device_submenu_connect) {
if (device.getState() != GBDevice.State.CONNECTED) {
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
handleDeviceConnect(device);
}
return true;
} else if (itemId == R.id.controlcenter_device_submenu_disconnect) {
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
GBApplication.deviceService(device).disconnect();
}
removeFromLastDeviceAddressesPref(device);
return true;
} else if (itemId == R.id.controlcenter_device_submenu_set_alias) {
showSetAliasDialog(device);
return true;
} else if (itemId == R.id.controlcenter_device_submenu_remove) {
showRemoveDeviceDialog(device);
return true;
} else if (itemId == R.id.controlcenter_device_submenu_show_details) {
final String previouslyExpandedDeviceAddress = expandedDeviceAddress;
expandedDeviceAddress = detailsShown ? "" : device.getAddress();
if (!previouslyExpandedDeviceAddress.isEmpty()) {
// Notify the previously expanded device for a change (collapsing it)
for (int i = 0; i < devicesListWithFolders.size(); i++) {
final GBDevice gbDevice = devicesListWithFolders.get(i);
if (gbDevice.getAddress().equals(previouslyExpandedDeviceAddress)) {
notifyItemChanged(devicesListWithFolders.indexOf(gbDevice));
break;
}
if (!previouslyExpandedDeviceAddress.isEmpty()) {
// Notify the previously expanded device for a change (collapsing it)
for (int i = 0; i < devicesListWithFolders.size(); i++) {
final GBDevice gbDevice = devicesListWithFolders.get(i);
if (gbDevice.getAddress().equals(previouslyExpandedDeviceAddress)) {
notifyItemChanged(devicesListWithFolders.indexOf(gbDevice));
break;
}
}
}
// Update the current one
notifyItemChanged(devicesListWithFolders.indexOf(device));
return true;
case R.id.controlcenter_device_submenu_set_parent_folder:
showSetParentFolderDialog(device);
return true;
case R.id.controlcenter_device_submenu_installer:
Intent openFwIntent = new Intent(context, OpenFwAppInstallerActivity.class);
openFwIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
context.startActivity(openFwIntent);
return false;
// Update the current one
notifyItemChanged(devicesListWithFolders.indexOf(device));
return true;
} else if (itemId == R.id.controlcenter_device_submenu_set_parent_folder) {
showSetParentFolderDialog(device);
return true;
} else if (itemId == R.id.controlcenter_device_submenu_installer) {
Intent openFwIntent = new Intent(context, OpenFwAppInstallerActivity.class);
openFwIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
context.startActivity(openFwIntent);
return false;
}
return false;
}
});

View File

@ -21,6 +21,7 @@ import android.os.Bundle;
import android.text.InputType;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
@ -68,7 +69,7 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivityV
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
if (item.getItemId() == android.R.id.home) {
// Action bar back button
Intent output = new Intent();

View File

@ -21,6 +21,7 @@ import android.os.Bundle;
import android.text.InputType;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
@ -84,7 +85,7 @@ public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivityV2
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
if (item.getItemId() == android.R.id.home) {
// Action bar back button
Intent output = new Intent();

View File

@ -550,10 +550,10 @@ public class QHybridConfigActivity extends AbstractGBActivity {
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.onBackPressed();
return true;
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
this.onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);

View File

@ -42,8 +42,8 @@ public class WithingsCalibrationActivity extends AbstractGBActivity {
MINUTES((short)0),
ACTIVITY_TARGET((short)2);
private short code;
private Hands(short code) {
private final short code;
Hands(short code) {
this.code = code;
}
@ -51,8 +51,8 @@ public class WithingsCalibrationActivity extends AbstractGBActivity {
private GBDevice device;
private LocalBroadcastManager localBroadcastManager;
private String[] calibrationAdvices = new String[3];
private Hands[] hands = new Hands[]{Hands.HOURS, Hands.MINUTES, Hands.ACTIVITY_TARGET};
private final String[] calibrationAdvices = new String[3];
private final Hands[] hands = new Hands[]{Hands.HOURS, Hands.MINUTES, Hands.ACTIVITY_TARGET};
private short handIndex = 0;
private Button previousButton;
private Button nextButton;
@ -141,11 +141,11 @@ public class WithingsCalibrationActivity extends AbstractGBActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);

View File

@ -20,8 +20,5 @@ org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF
android.useAndroidX=true
android.enableJetifier=true
# FIXME: Migrate all switches to if statements
android.nonFinalResIds=false
# FIXME: This optimizes away some classes it should not - see #3853
android.enableR8.fullMode=false