summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael W <baddaemon87@gmail.com>2023-01-01 17:03:03 +0100
committerMichael W <baddaemon87@gmail.com>2023-01-22 11:54:01 +0100
commit1a55360838f5bd45dbd4ee99dd741e703c97b515 (patch)
tree191e669161555481b8aafa52ea7e0a38b24d0a55
parenta4c8487f880897da754dea053f8468f9c0582b78 (diff)
DeskClock: Get rid of percentlayout
* Use ConstraintLayout instead * The change to DataModel is required because otherwise AS refuses to render stopwatch_fragment.xml due to a NPE Change-Id: I67c8b88e7789b16db57cf699c22abecb1afc9012
-rw-r--r--Android.bp1
-rw-r--r--res/layout/stopwatch_fragment.xml74
-rw-r--r--src/com/android/deskclock/data/DataModel.java3
3 files changed, 51 insertions, 27 deletions
diff --git a/Android.bp b/Android.bp
index 9313aa70a..ffafc993a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -23,7 +23,6 @@ android_app {
"androidx.lifecycle_lifecycle-common",
"com.google.android.material_material",
"androidx.lifecycle_lifecycle-runtime",
- "androidx.percentlayout_percentlayout",
"androidx.transition_transition",
"androidx.core_core",
"androidx.media_media",
diff --git a/res/layout/stopwatch_fragment.xml b/res/layout/stopwatch_fragment.xml
index 5c72bc727..4c9bb2888 100644
--- a/res/layout/stopwatch_fragment.xml
+++ b/res/layout/stopwatch_fragment.xml
@@ -14,48 +14,72 @@
limitations under the License.
-->
-<LinearLayout
+<androidx.constraintlayout.widget.ConstraintLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical">
- <androidx.percentlayout.widget.PercentFrameLayout
- android:layout_width="match_parent"
+ <androidx.constraintlayout.widget.Guideline
+ android:id="@+id/left_guideline"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center">
+ android:orientation="vertical"
+ app:layout_constraintGuide_percent=".1" />
- <com.android.deskclock.TimerCircleFrameLayout
- android:id="@+id/stopwatch_time_wrapper"
- android:layout_gravity="center"
- app:layout_aspectRatio="100%"
- android:layout_height="0dp"
- android:layout_width="0dp"
- app:layout_heightPercent="@fraction/timer_circle_height_percent"
- app:layout_widthPercent="@fraction/timer_circle_width_percent">
+ <androidx.constraintlayout.widget.Guideline
+ android:id="@+id/right_guideline"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ app:layout_constraintGuide_percent=".9" />
- <include layout="@layout/stopwatch_time" />
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/stopwatch_time_wrapper"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toTopOf="@id/laps_list"
+ app:layout_constraintStart_toStartOf="@id/left_guideline"
+ app:layout_constraintEnd_toStartOf="@id/right_guideline"
+ app:layout_constraintDimensionRatio="1:1"
+ app:layout_constraintHeight_max="@dimen/max_timer_circle_size">
- <!-- Sufficient space exists to include the bounding stopwatch circle. -->
- <com.android.deskclock.stopwatch.StopwatchCircleView
- android:id="@+id/stopwatch_circle"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ <!-- Sufficient space exists to include the bounding stopwatch circle. -->
+ <include
+ layout="@layout/stopwatch_time"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
- </com.android.deskclock.TimerCircleFrameLayout>
+ <com.android.deskclock.stopwatch.StopwatchCircleView
+ android:id="@+id/stopwatch_circle"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
- </androidx.percentlayout.widget.PercentFrameLayout>
+ </androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/laps_list"
- android:layout_width="match_parent"
+ android:layout_width="0dp"
android:layout_height="0dp"
- android:layout_weight="1"
- android:layout_gravity="center"
android:clipToPadding="false"
- android:paddingBottom="@dimen/fab_height" />
+ android:paddingBottom="@dimen/fab_container_height"
+ app:layout_constraintTop_toBottomOf="@id/stopwatch_time_wrapper"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ tools:visibility="visible"/>
-</LinearLayout> \ No newline at end of file
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/src/com/android/deskclock/data/DataModel.java b/src/com/android/deskclock/data/DataModel.java
index 19c65b4df..2e5330668 100644
--- a/src/com/android/deskclock/data/DataModel.java
+++ b/src/com/android/deskclock/data/DataModel.java
@@ -46,6 +46,7 @@ import com.android.deskclock.timer.TimerService;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -770,7 +771,7 @@ public final class DataModel {
*/
public List<Lap> getLaps() {
enforceMainLooper();
- return mStopwatchModel.getLaps();
+ return (mStopwatchModel != null) ? mStopwatchModel.getLaps() : new ArrayList<Lap>();
}
/**