mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-09 03:37:03 +01:00
Discovery Activity: Improve layout on limited space
This commit is contained in:
parent
56c8901ba1
commit
03596ac0fb
@ -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) {
|
||||
|
@ -119,6 +119,7 @@ public class FileManagerActivity extends AbstractGBActivity implements MenuProvi
|
||||
searchView.requestFocus();
|
||||
searchView.setIconified(true);
|
||||
searchView.setIconified(false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -24,16 +24,13 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/discovery_bluetooth_scan" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/discovery_progressbar"
|
||||
android:layout_width="wrap_content"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:indeterminate="true"
|
||||
@ -42,33 +39,12 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/discovery_bluetooth_le_scan" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/discovery_ble_progressbar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:indeterminate="true"
|
||||
android:indeterminateOnly="true"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<ListView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:id="@+id/discovery_device_candidates_list"
|
||||
android:layout_gravity="bottom|top"
|
||||
android:layout_weight="0.83" />
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
@ -88,11 +64,5 @@
|
||||
android:id="@+id/discovery_hint"
|
||||
android:textColor="@color/secondarytext"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/discovery_preferences"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/activity_prefs_discovery_pairing" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
11
app/src/main/res/menu/menu_discovery.xml
Normal file
11
app/src/main/res/menu/menu_discovery.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryActivityV2">
|
||||
<item
|
||||
android:id="@+id/prefs_discovery_pairing"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="@string/activity_prefs_discovery_pairing"
|
||||
app:iconTint="?attr/actionmenu_icon_color"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
Loading…
Reference in New Issue
Block a user