From 03596ac0fbd4a499e9c235f63ce2ca5df125c7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 28 Sep 2024 22:49:59 +0100 Subject: [PATCH] Discovery Activity: Improve layout on limited space --- .../discovery/DiscoveryActivityV2.java | 43 +++++++++++-------- .../activities/files/FileManagerActivity.java | 1 + .../main/res/layout/activity_discovery.xml | 38 ++-------------- app/src/main/res/menu/menu_discovery.xml | 11 +++++ 4 files changed, 42 insertions(+), 51 deletions(-) create mode 100644 app/src/main/res/menu/menu_discovery.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java index ae2c2114d..9d1fc01f6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java @@ -47,6 +47,9 @@ import android.os.Parcelable; import android.provider.Settings; import android.text.TextUtils; import android.util.Pair; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -64,6 +67,7 @@ import androidx.annotation.RequiresApi; import androidx.annotation.RequiresPermission; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import androidx.core.view.MenuProvider; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -100,7 +104,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, BondingInterface, - GBScanEventProcessor.Callback { + GBScanEventProcessor.Callback, + MenuProvider { private static final Logger LOG = LoggerFactory.getLogger(DiscoveryActivityV2.class); private final Handler handler = new Handler(); @@ -112,7 +117,6 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi private final ScanCallback bleScanCallback = new BleScanCallback(); private ProgressBar bluetoothProgress; - private ProgressBar bluetoothLEProgress; private DeviceCandidateAdapter deviceCandidateAdapter; private GBDeviceCandidate deviceTarget; @@ -160,25 +164,16 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi setContentView(R.layout.activity_discovery); + addMenuProvider(this); + startButton = findViewById(R.id.discovery_start); startButton.setOnClickListener(v -> toggleDiscovery()); - final Button settingsButton = findViewById(R.id.discovery_preferences); - settingsButton.setOnClickListener(v -> { - final Intent enableIntent = new Intent(DiscoveryActivityV2.this, DiscoveryPairingPreferenceActivity.class); - startActivity(enableIntent); - }); - bluetoothProgress = findViewById(R.id.discovery_progressbar); bluetoothProgress.setProgress(0); bluetoothProgress.setIndeterminate(true); bluetoothProgress.setVisibility(View.GONE); - bluetoothLEProgress = findViewById(R.id.discovery_ble_progressbar); - bluetoothLEProgress.setProgress(0); - bluetoothLEProgress.setIndeterminate(true); - bluetoothLEProgress.setVisibility(View.GONE); - deviceCandidateAdapter = new DeviceCandidateAdapter(this, deviceCandidates); final ListView deviceCandidatesView = findViewById(R.id.discovery_device_candidates_list); @@ -315,6 +310,8 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi startBTLEDiscovery(); } startBTDiscovery(); + + bluetoothProgress.setVisibility(View.VISIBLE); } catch (final SecurityException e) { LOG.error("SecurityException on startDiscovery"); deviceFoundProcessor.stop(); @@ -349,7 +346,6 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi } else { startButton.setText(getString(R.string.discovery_start_scanning)); bluetoothProgress.setVisibility(View.GONE); - bluetoothLEProgress.setVisibility(View.GONE); } } @@ -366,7 +362,6 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi adapter.getBluetoothLeScanner().startScan(null, getScanSettings(), bleScanCallback); LOG.debug("Bluetooth LE discovery started successfully"); - bluetoothLEProgress.setVisibility(View.VISIBLE); } @RequiresPermission("android.permission.BLUETOOTH_SCAN") @@ -413,7 +408,6 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi if (adapter.startDiscovery()) { LOG.debug("Discovery started successfully"); - bluetoothProgress.setVisibility(View.VISIBLE); } else { LOG.error("Discovery starting failed"); } @@ -434,7 +428,6 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi this.adapter = null; startButton.setEnabled(false); bluetoothProgress.setVisibility(View.GONE); - bluetoothLEProgress.setVisibility(View.GONE); } } @@ -836,6 +829,22 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi refreshDeviceList(true); } + @Override + public void onCreateMenu(@NonNull final Menu menu, @NonNull final MenuInflater menuInflater) { + menuInflater.inflate(R.menu.menu_discovery, menu); + } + + @Override + public boolean onMenuItemSelected(@NonNull final MenuItem menuItem) { + final int itemId = menuItem.getItemId(); + if (itemId == R.id.prefs_discovery_pairing) { + final Intent intent = new Intent(DiscoveryActivityV2.this, DiscoveryPairingPreferenceActivity.class); + startActivity(intent); + return true; + } + return false; + } + private final class BluetoothReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/files/FileManagerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/files/FileManagerActivity.java index 037966e96..517dfd325 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/files/FileManagerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/files/FileManagerActivity.java @@ -119,6 +119,7 @@ public class FileManagerActivity extends AbstractGBActivity implements MenuProvi searchView.requestFocus(); searchView.setIconified(true); searchView.setIconified(false); + return true; } return false; } diff --git a/app/src/main/res/layout/activity_discovery.xml b/app/src/main/res/layout/activity_discovery.xml index 100c4fb96..cf7177f6a 100644 --- a/app/src/main/res/layout/activity_discovery.xml +++ b/app/src/main/res/layout/activity_discovery.xml @@ -24,16 +24,13 @@ - - - - - - - - - - + android:layout_weight="1" /> - -