fix(ui): support foldables and large screens instead of running in compat mode

This commit is contained in:
n0tst3v3
2026-08-19 03:32:34 -06:00
parent 340a32c301
commit feb32c9cd1
6 changed files with 80 additions and 4 deletions
+4 -3
View File
@@ -10,9 +10,10 @@
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity>
<activity android:name=".LiveRangeFinderActivity" android:label="Live Find"/><activity android:name=".DeviceManagerActivity" android:label="Bluetooth Items"/><activity android:name=".MapActivity" android:label="Last Seen Map"/>
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" android:resizeable="true"/>
<application android:resizeableActivity="true" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|density|uiMode"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity>
<activity android:name=".LiveRangeFinderActivity" android:label="Live Find" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|density|uiMode"/><activity android:name=".DeviceManagerActivity" android:label="Bluetooth Items" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|density|uiMode"/><activity android:name=".MapActivity" android:label="Last Seen Map" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|density|uiMode"/>
<service android:name=".BluetoothTrackingService" android:enabled="true"/>
</application>
</manifest>
@@ -239,6 +239,7 @@ public class DeviceManagerActivity extends Activity {
root.addView(pairedList, new LinearLayout.LayoutParams(-1, 0, 1));
pairedHeader.setVisibility(View.GONE); pairedList.setVisibility(View.GONE);
setContentView(root);
LargeScreenLayout.constrain(this);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_FOUND);
@@ -0,0 +1,72 @@
package com.wytehat.btlogger;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
/**
* Keeps the phone-sized UI readable on tablets and unfolded foldables.
*
* The screens are laid out for a ~360dp phone. Stretched across a 670dp+
* inner display every row spans the full width, which leaves controls
* marooned at opposite edges. Centering the content in a phone-width column
* keeps the proportions the layouts were designed for.
*/
final class LargeScreenLayout {
/** Below this the layout is already phone-shaped; leave it alone. */
private static final int WIDE_THRESHOLD_DP = 640;
/** Column width used once the screen is wider than the threshold. */
private static final int CONTENT_WIDTH_DP = 600;
private LargeScreenLayout() {
}
/**
* Call after setContentView. No-op on phones and on folded screens.
*/
static void constrain(Activity activity) {
float density =
activity.getResources().getDisplayMetrics().density;
int widthDp = (int)
(activity.getResources().getDisplayMetrics().widthPixels / density);
if (widthDp < WIDE_THRESHOLD_DP) {
return;
}
View content =
activity.findViewById(android.R.id.content);
if (!(content instanceof ViewGroup)) {
return;
}
ViewGroup holder = (ViewGroup) content;
if (holder.getChildCount() == 0) {
return;
}
View root = holder.getChildAt(0);
ViewGroup.LayoutParams existing =
root.getLayoutParams();
if (!(existing instanceof FrameLayout.LayoutParams)) {
return;
}
FrameLayout.LayoutParams params =
(FrameLayout.LayoutParams) existing;
params.width = (int) (CONTENT_WIDTH_DP * density + 0.5f);
params.gravity = android.view.Gravity.CENTER_HORIZONTAL;
root.setLayoutParams(params);
}
}
@@ -169,6 +169,7 @@ public class LiveRangeFinderActivity extends Activity implements LocationListene
root.addView(map, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
setContentView(root);
LargeScreenLayout.constrain(this);
startButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) { startSearch(); }
@@ -32,6 +32,7 @@ public class MainActivity extends Activity implements ItemActionListener {
protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
LargeScreenLayout.constrain(this);
LinearLayout nav = (LinearLayout) findViewById(R.id.navigation_container);
nav.addView(NavigationHelper.createBar(this, 0, "My Tracked Items"));
db = new TrackerDatabase(this);
+1 -1
View File
@@ -11,5 +11,5 @@
<Button android:id="@+id/sort_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Newest first" android:textSize="10sp" android:layout_marginRight="8dp"/>
</LinearLayout>
<ListView android:id="@+id/device_list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:dividerHeight="10dp" android:padding="8dp"/>
<TextView android:id="@+id/empty_view" android:text="No tracked items yet. Use ADD / PAIR to choose an item." android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent"/>
<TextView android:id="@+id/empty_view" android:text="No tracked items yet. Use ADD / PAIR to choose an item." android:gravity="center" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/>
</LinearLayout>