Skip to content

Commit 2d93219

Browse files
committed
Improve tablet layout
1 parent 9c29d63 commit 2d93219

File tree

3 files changed

+66
-21
lines changed

3 files changed

+66
-21
lines changed

app/src/main/kotlin/com/heisenberg/lux/MainActivity.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ class MainActivity : AppCompatActivity() {
6464

6565
prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
6666

67-
// Load saved values (default to disabled on first run for safety)
67+
// On first run, detect and save default camera (but keep sensitivity at 0 for safety)
68+
val isFirstRun = !prefs.contains(KEY_CAMERA_SELECTION)
69+
if (isFirstRun) {
70+
val defaultCamera = getDefaultCamera()
71+
prefs.edit().putInt(KEY_CAMERA_SELECTION, defaultCamera).apply()
72+
Log.i(TAG, "First run: detected default camera = $defaultCamera")
73+
}
74+
75+
// Load saved values
6876
val cameraSelection = prefs.getInt(KEY_CAMERA_SELECTION, CAMERA_NONE)
6977
val cameraSensitivity = prefs.getInt(KEY_CAMERA_SENSITIVITY, 0)
7078
val lightSensitivity = prefs.getInt(KEY_LIGHT_SENSITIVITY, 0)
@@ -188,10 +196,19 @@ class MainActivity : AppCompatActivity() {
188196
}
189197
}
190198

191-
// Hide light sensor card if no sensor is detected
199+
// Disable light sensor controls if no sensor is detected
192200
val sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
193201
val lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT)
194-
binding.lightCard.visibility = if (lightSensor != null) View.VISIBLE else View.GONE
202+
if (lightSensor == null) {
203+
// Sensor not available - disable controls and show message
204+
binding.lightSeekBar.isEnabled = false
205+
binding.lightSeekBar.alpha = 0.5f
206+
binding.lightValue.text = getString(R.string.sensor_not_available)
207+
binding.lightValue.alpha = 0.5f
208+
binding.lightLiveReading.text = getString(R.string.sensor_not_available_message)
209+
binding.lightLiveReading.visibility = View.VISIBLE
210+
Log.i(TAG, "Light sensor not detected on this device")
211+
}
195212

196213
// Request camera permission if needed
197214
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

app/src/main/res/layout-sw600dp/activity_main.xml

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,25 @@
1515
<androidx.constraintlayout.widget.ConstraintLayout
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content"
18-
android:padding="32dp">
18+
android:paddingStart="32dp"
19+
android:paddingEnd="32dp"
20+
android:paddingTop="32dp"
21+
android:paddingBottom="32dp">
22+
23+
<!-- Content Container with Max Width -->
24+
<androidx.constraintlayout.widget.Guideline
25+
android:id="@+id/guidelineStart"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:orientation="vertical"
29+
app:layout_constraintGuide_percent="0.1" />
30+
31+
<androidx.constraintlayout.widget.Guideline
32+
android:id="@+id/guidelineEnd"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:orientation="vertical"
36+
app:layout_constraintGuide_percent="0.9" />
1937

2038
<!-- App Title with Whimsical Style -->
2139
<TextView
@@ -37,8 +55,8 @@
3755
android:shadowRadius="4"
3856
android:rotation="-2"
3957
app:layout_constraintTop_toTopOf="parent"
40-
app:layout_constraintStart_toStartOf="parent"
41-
app:layout_constraintEnd_toEndOf="parent" />
58+
app:layout_constraintStart_toStartOf="@id/guidelineStart"
59+
app:layout_constraintEnd_toEndOf="@id/guidelineEnd" />
4260

4361
<!-- App Subtitle -->
4462
<TextView
@@ -48,28 +66,36 @@
4866
android:text="@string/app_subtitle"
4967
android:textSize="16sp"
5068
android:textColor="?android:attr/textColorSecondary"
51-
android:layout_marginBottom="32dp"
69+
android:layout_marginBottom="0dp"
5270
android:gravity="center"
5371
android:fontFamily="sans-serif"
5472
app:layout_constraintTop_toBottomOf="@id/appTitle"
55-
app:layout_constraintStart_toStartOf="parent"
56-
app:layout_constraintEnd_toEndOf="parent" />
73+
app:layout_constraintStart_toStartOf="@id/guidelineStart"
74+
app:layout_constraintEnd_toEndOf="@id/guidelineEnd" />
75+
76+
<!-- Vertical guideline at center for two-column layout -->
77+
<androidx.constraintlayout.widget.Guideline
78+
android:id="@+id/guidelineCenter"
79+
android:layout_width="wrap_content"
80+
android:layout_height="wrap_content"
81+
android:orientation="vertical"
82+
app:layout_constraintGuide_percent="0.5" />
5783

5884
<!-- Left Column: Motion Detection Card -->
5985
<com.google.android.material.card.MaterialCardView
6086
android:id="@+id/motionCard"
6187
android:layout_width="0dp"
6288
android:layout_height="wrap_content"
63-
android:layout_marginEnd="16dp"
89+
android:layout_marginTop="32dp"
90+
android:layout_marginEnd="8dp"
6491
app:cardElevation="4dp"
6592
app:cardCornerRadius="20dp"
6693
app:contentPadding="24dp"
6794
app:strokeWidth="0dp"
6895
app:cardBackgroundColor="@color/card_motion"
6996
app:layout_constraintTop_toBottomOf="@id/appSubtitle"
70-
app:layout_constraintStart_toStartOf="parent"
71-
app:layout_constraintEnd_toStartOf="@id/lightCard"
72-
app:layout_constraintWidth_percent="0.5">
97+
app:layout_constraintStart_toStartOf="@id/guidelineStart"
98+
app:layout_constraintEnd_toEndOf="@id/guidelineCenter">
7399

74100
<LinearLayout
75101
android:layout_width="match_parent"
@@ -141,7 +167,7 @@
141167

142168
<TextView
143169
android:id="@+id/cameraValue"
144-
android:layout_width="80dp"
170+
android:layout_width="110dp"
145171
android:layout_height="wrap_content"
146172
android:text="50"
147173
android:textSize="15sp"
@@ -168,16 +194,16 @@
168194
android:id="@+id/lightCard"
169195
android:layout_width="0dp"
170196
android:layout_height="wrap_content"
171-
android:layout_marginStart="16dp"
197+
android:layout_marginTop="32dp"
198+
android:layout_marginStart="8dp"
172199
app:cardElevation="4dp"
173200
app:cardCornerRadius="20dp"
174201
app:contentPadding="24dp"
175202
app:strokeWidth="0dp"
176203
app:cardBackgroundColor="@color/card_light"
177204
app:layout_constraintTop_toBottomOf="@id/appSubtitle"
178-
app:layout_constraintStart_toEndOf="@id/motionCard"
179-
app:layout_constraintEnd_toEndOf="parent"
180-
app:layout_constraintWidth_percent="0.5">
205+
app:layout_constraintStart_toStartOf="@id/guidelineCenter"
206+
app:layout_constraintEnd_toEndOf="@id/guidelineEnd">
181207

182208
<LinearLayout
183209
android:layout_width="match_parent"
@@ -227,7 +253,7 @@
227253

228254
<TextView
229255
android:id="@+id/lightValue"
230-
android:layout_width="80dp"
256+
android:layout_width="110dp"
231257
android:layout_height="wrap_content"
232258
android:text="0"
233259
android:textSize="15sp"
@@ -260,8 +286,8 @@
260286
app:strokeWidth="0dp"
261287
app:cardBackgroundColor="@color/card_settings"
262288
app:layout_constraintTop_toBottomOf="@id/motionCard"
263-
app:layout_constraintStart_toStartOf="parent"
264-
app:layout_constraintEnd_toEndOf="parent">
289+
app:layout_constraintStart_toStartOf="@id/guidelineStart"
290+
app:layout_constraintEnd_toEndOf="@id/guidelineEnd">
265291

266292
<LinearLayout
267293
android:layout_width="match_parent"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@
2828
<string name="camera_rear_option">Rear Camera</string>
2929
<string name="camera_front_option">Front Camera</string>
3030
<string name="start_at_boot">Start at boot</string>
31+
<string name="sensor_not_available">N/A</string>
32+
<string name="sensor_not_available_message">This device does not have an ambient light sensor</string>
3133
</resources>

0 commit comments

Comments
 (0)