diff --git a/res/layout-land/stopwatch_fragment.xml b/res/layout-land/stopwatch_fragment.xml index f5bc8ad0aa4680930ee810c7c27eae01d24540a2..7744eb9dcb501f482a19026f1e1d60324a3d5f3f 100644 --- a/res/layout-land/stopwatch_fragment.xml +++ b/res/layout-land/stopwatch_fragment.xml @@ -51,13 +51,12 @@ <ListView android:id="@+id/laps_list" - android:layout_marginTop="32dip" - android:layout_marginBottom="48dip" - android:layout_marginStart="@dimen/stopwatch_list_margin_start" - android:layout_marginEnd="16dip" - android:layout_gravity="center" - android:layout_width="wrap_content" - android:layout_height="wrap_content" /> + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="2" + android:layout_marginTop="8dip" + android:layout_marginBottom="8dip" + android:layout_gravity="center" /> <Space android:id="@+id/end_space" diff --git a/res/layout/lap_view.xml b/res/layout/lap_view.xml index bc1b0542e2f10991fc966ff66c878f928ed57f37..5130c115e9fbdbea651166057189af535eef8ac8 100644 --- a/res/layout/lap_view.xml +++ b/res/layout/lap_view.xml @@ -16,32 +16,32 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_marginTop="4dip" - android:layout_marginBottom="4dip" - android:gravity="center" + android:layout_width="match_parent" + android:layout_height="match_parent" android:layoutDirection="ltr" android:paddingTop="@dimen/body_font_padding" android:paddingBottom="@dimen/body_font_padding" - android:layout_width="match_parent" - android:layout_height="match_parent" > + android:gravity="center" + android:orientation="horizontal"> + <TextView android:id="@+id/lap_number" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="@dimen/sw_item_space" android:layout_marginEnd="@dimen/sw_item_space" android:gravity="start" android:textAllCaps="false" android:textAppearance="@style/SecondaryLabelTextAppearance" /> + <TextView android:id="@+id/lap_time" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="@dimen/sw_item_space" android:layout_marginEnd="@dimen/sw_item_space" android:gravity="end" android:textAllCaps="false" android:textAppearance="@style/PrimaryLabelTextAppearance" /> + <TextView android:id="@+id/lap_total" android:layout_height="wrap_content" @@ -49,5 +49,5 @@ android:gravity="end" android:textAllCaps="false" android:textAppearance="@style/PrimaryLabelTextAppearance" /> -</LinearLayout> +</LinearLayout> diff --git a/res/layout/stopwatch_fragment.xml b/res/layout/stopwatch_fragment.xml index 6310ea20eafa438bbf4e0f34da765ec0ba8efc75..ceb0e8ca377bc57d8cefb663f7e552a116a58075 100644 --- a/res/layout/stopwatch_fragment.xml +++ b/res/layout/stopwatch_fragment.xml @@ -61,9 +61,4 @@ android:layout_width="match_parent" android:layout_height="0dip" /> - <Space - android:layout_width="match_parent" - android:layout_height="@dimen/footer_button_size" - android:layout_margin="@dimen/footer_button_layout_margin" /> - </LinearLayout> diff --git a/res/layout/stopwatch_spacer.xml b/res/layout/stopwatch_spacer.xml new file mode 100644 index 0000000000000000000000000000000000000000..31b648b93f75bdb49c28e53946b45b35c511202e --- /dev/null +++ b/res/layout/stopwatch_spacer.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<Space + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="@dimen/stopwatch_list_bottom_spacing" /> diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml index fa002232b425c1c567fd2010d8e3ccf89ba9b79b..7b21dd7f95104b64da13329e0fbc012b8c73399f 100644 --- a/res/values-land/dimens.xml +++ b/res/values-land/dimens.xml @@ -51,6 +51,7 @@ <dimen name="medium_font_size">48sp</dimen> <dimen name="circle_size">232dip</dimen> + <dimen name="stopwatch_list_bottom_spacing">0dip</dimen> <dimen name="world_clock_margin">8dp</dimen> <dimen name="sw_padding_end">8dp</dimen> diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml index a25493f85056647bcd58e39a4d2076582ed5d217..d02f3f5f84e260b9cb9d0d08b7f5a1a8bb7f5717 100644 --- a/res/values-sw600dp-land/dimens.xml +++ b/res/values-sw600dp-land/dimens.xml @@ -43,7 +43,7 @@ <dimen name="timer_circle_margin">48dp</dimen> <dimen name="circle_size">360dip</dimen> - <dimen name="stopwatch_list_margin_start">128dip</dimen> + <dimen name="stopwatch_list_bottom_spacing">0dip</dimen> <dimen name="world_clock_margin">48dp</dimen> <dimen name="sw_padding_end">48dp</dimen> diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml index 72a6d2553ab94ed7ef450ad8e7277bad76d0aeca..470e18de5c8e2351fe0a36e08fe02ce411917485 100644 --- a/res/values-sw600dp/dimens.xml +++ b/res/values-sw600dp/dimens.xml @@ -76,6 +76,8 @@ <dimen name="timer_circle_margin">96dp</dimen> <dimen name="circle_size">400dp</dimen> + <!-- stopwatch_list_bottom_spacing = footer_button_size + footer_button_layout_margin --> + <dimen name="stopwatch_list_bottom_spacing">96dip</dimen> <!-- Width of the clock, for use with alarm buttons. --> <dimen name="alarm_alert_display_width">550dip</dimen> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 613df11136fed40629223e85852e45e843735747..2d9e86c62d4ca2e0593da17aceccbc55c411b4e3 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -117,7 +117,8 @@ <dimen name="timer_circle_margin">32dp</dimen> <dimen name="circle_size">280dp</dimen> - <dimen name="stopwatch_list_margin_start">64dip</dimen> + <!-- stopwatch_list_bottom_spacing = footer_button_size + footer_button_layout_margin --> + <dimen name="stopwatch_list_bottom_spacing">72dip</dimen> <dimen name="sw_padding_end">32dp</dimen> diff --git a/src/com/android/deskclock/stopwatch/StopwatchFragment.java b/src/com/android/deskclock/stopwatch/StopwatchFragment.java index b7402966d461346352cce33798af4e2b8f348b5a..4abf41f361338df79210e1ee17efe2afe73e625c 100644 --- a/src/com/android/deskclock/stopwatch/StopwatchFragment.java +++ b/src/com/android/deskclock/stopwatch/StopwatchFragment.java @@ -82,6 +82,10 @@ public class StopwatchFragment extends DeskClockFragment // Adapter for the ListView that shows the lap times. class LapsListAdapter extends BaseAdapter { + private static final int VIEW_TYPE_LAP = 0; + private static final int VIEW_TYPE_SPACE = 1; + private static final int VIEW_TYPE_COUNT = 2; + ArrayList<Lap> mLaps = new ArrayList<Lap>(); private final LayoutInflater mInflater; private final String[] mFormats; @@ -110,20 +114,34 @@ public class StopwatchFragment extends DeskClockFragment return position; } + @Override + public int getItemViewType(int position) { + return position < mLaps.size() ? VIEW_TYPE_LAP : VIEW_TYPE_SPACE; + } + + @Override + public int getViewTypeCount() { + return VIEW_TYPE_COUNT; + } + @Override public View getView(int position, View convertView, ViewGroup parent) { - if (mLaps.size() == 0 || position >= mLaps.size()) { + if (getCount() == 0) { return null; } - Lap lap = getItem(position); - View lapInfo; - if (convertView != null) { - lapInfo = convertView; - } else { - lapInfo = mInflater.inflate(R.layout.lap_view, parent, false); + + // Handle request for the Spacer at the end + if (getItemViewType(position) == VIEW_TYPE_SPACE) { + return convertView != null ? convertView + : mInflater.inflate(R.layout.stopwatch_spacer, parent, false); } + + final View lapInfo = convertView != null ? convertView + : mInflater.inflate(R.layout.lap_view, parent, false); + Lap lap = getItem(position); lapInfo.setTag(lap); - TextView count = (TextView)lapInfo.findViewById(R.id.lap_number); + + TextView count = (TextView) lapInfo.findViewById(R.id.lap_number); count.setText(String.format(mLapFormat, mLaps.size() - position).toUpperCase()); setTimeText(lapInfo, lap); @@ -139,12 +157,13 @@ public class StopwatchFragment extends DeskClockFragment @Override public int getCount() { - return mLaps.size(); + // Add 1 for the spacer if list is not empty + return mLaps.isEmpty() ? 0 : mLaps.size() + 1; } @Override public Lap getItem(int position) { - if (mLaps.size() == 0 || position >= mLaps.size()) { + if (position >= mLaps.size()) { return null; } return mLaps.get(position);