From d7242c1f121db9430f69c591f1cad9b25e54c32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 30 Jun 2024 20:27:12 +0100 Subject: [PATCH] Make R class fields non-final --- .../activities/AbstractSettingsActivity.java | 10 +- .../AbstractSettingsActivityV2.java | 12 +- .../activities/ActivitySummariesActivity.java | 140 ++++++++-------- .../activities/ActivitySummariesFilter.java | 12 +- .../activities/ActivitySummaryDetail.java | 42 ++--- .../gadgetbridge/activities/AlarmDetails.java | 12 +- .../activities/AppBlacklistActivity.java | 41 ++--- .../activities/CalBlacklistActivity.java | 10 +- .../activities/ConfigureAlarms.java | 12 +- .../activities/ConfigureContacts.java | 12 +- .../activities/ConfigureReminders.java | 12 +- .../activities/ConfigureWorldClocks.java | 12 +- .../activities/ContactDetails.java | 12 +- .../activities/ControlCenterv2.java | 105 ++++++------ .../activities/DashboardFragment.java | 14 +- .../activities/DebugActivity.java | 10 +- .../activities/ExternalPebbleJSActivity.java | 10 +- .../activities/FwAppInstallerActivity.java | 10 +- .../activities/ReminderDetails.java | 26 ++- .../activities/WidgetAlarmsActivity.java | 33 ++-- .../activities/WorldClockDetails.java | 32 ++-- .../AbstractAppManagerFragment.java | 157 +++++++++--------- .../appmanager/AppManagerActivity.java | 10 +- .../widgets/WidgetScreenDetailsActivity.java | 12 +- .../widgets/WidgetScreensListActivity.java | 12 +- .../adapter/GBDeviceAdapterv2.java | 87 +++++----- .../HybridHRWatchfaceSettingsActivity.java | 3 +- .../HybridHRWatchfaceWidgetActivity.java | 3 +- .../qhybrid/QHybridConfigActivity.java | 8 +- .../WithingsCalibrationActivity.java | 18 +- gradle.properties | 3 - 31 files changed, 433 insertions(+), 459 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivity.java index 827d9377a..ec7d123b4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java index a33e7c608..5ea4b9d42 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractSettingsActivityV2.java @@ -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); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java index 170617b40..bd001f9d0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java @@ -125,22 +125,21 @@ public class ActivitySummariesActivity extends AbstractListActivity 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 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 paths = new ArrayList<>(); + processed = true; + } else if (itemId == R.id.activity_action_export) { + final List 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 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 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; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java index 2906aecbe..552b46c67 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java index e50185a13..b1c91702d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java index 4696e7171..276c1200f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AlarmDetails.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java index d4e4b6af3..a7ba373a5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/CalBlacklistActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/CalBlacklistActivity.java index 6684e5a99..6c849b459 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/CalBlacklistActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/CalBlacklistActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java index b0954b7a1..014a4806b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureContacts.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureContacts.java index f004f63d6..c083e6c00 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureContacts.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureContacts.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java index 55b8dbc41..08702fbcb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureWorldClocks.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureWorldClocks.java index 04a646c64..dbb55c2ca 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureWorldClocks.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureWorldClocks.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ContactDetails.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ContactDetails.java index be8a75379..df13be65d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ContactDetails.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ContactDetails.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index 9bad04260..e6911455f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -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() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java index 7329f3eab..d5b7af412 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 2cf7a1e57..a02d56fa3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index 54897692e..a9a97b356 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java index 78e57958b..530c281f8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java index e45448f73..007ebe91d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java @@ -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(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WidgetAlarmsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WidgetAlarmsActivity.java index ecc04aa32..8d56e9e9d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WidgetAlarmsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WidgetAlarmsActivity.java @@ -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 diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WorldClockDetails.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WorldClockDetails.java index d04641911..9d48ac3c0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WorldClockDetails.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WorldClockDetails.java @@ -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(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index 5bc47aadb..3ddd57e18 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -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) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java index 9647d1aaa..2398e9168 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java index 086337705..f3783a7b5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreensListActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreensListActivity.java index 8c3987b5a..eb4f3ebc6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreensListActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreensListActivity.java @@ -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); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java index eee67de01..fbdec3cbf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java @@ -857,54 +857,55 @@ public class GBDeviceAdapterv2 extends ListAdapter