diff options
author | Kunhung Li <kunhungli@google.com> | 2019-03-20 18:19:14 +0800 |
---|---|---|
committer | Kunhung Li <kunhungli@google.com> | 2019-04-12 06:57:16 +0000 |
commit | 3712a0cfa01170bfcb7807a191727d57bb3652fe (patch) | |
tree | ff25ff3afde82a05219638e1370aae1fe8f2e573 | |
parent | d2cc826dc61035c9e22fcda5b4263ac150d8525f (diff) | |
download | android_packages_wallpapers_LivePicker-3712a0cfa01170bfcb7807a191727d57bb3652fe.tar.gz android_packages_wallpapers_LivePicker-3712a0cfa01170bfcb7807a191727d57bb3652fe.tar.bz2 android_packages_wallpapers_LivePicker-3712a0cfa01170bfcb7807a191727d57bb3652fe.zip |
Keep "Set wallpaper" button the same position in different tabs.
1. Consider both (info > setting) page and (info < setting) page cases,
add extra space to let "Set wallpaper" button can align bottom.
2. Add extra height in info page top area if info page has
enough empty space.
3. Refine info and setting layouts in portrait and landscape.
4. Correct dummy data can't show title.
Bug: 128393998
Test: Manual test
Change-Id: I29a3dc8309fa879d1b93c5db81630f6e0cbd36d8
-rw-r--r-- | res/layout/page_info.xml | 29 | ||||
-rw-r--r-- | res/layout/page_settings.xml | 7 | ||||
-rw-r--r-- | res/values-land/dimensions.xml | 20 | ||||
-rw-r--r-- | res/values/dimensions.xml | 11 | ||||
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java | 1 | ||||
-rw-r--r-- | src/com/android/wallpaper/livepicker/widget/ConstraintViewPager.java | 27 |
6 files changed, 83 insertions, 12 deletions
diff --git a/res/layout/page_info.xml b/res/layout/page_info.xml index 7187b56..f7baad0 100644 --- a/res/layout/page_info.xml +++ b/res/layout/page_info.xml @@ -15,29 +15,35 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/page_info" android:orientation="vertical" - android:paddingHorizontal="@dimen/preview_attribution_pane_horizontal_padding" - android:paddingVertical="@dimen/preview_attribution_pane_vertical_padding"> + android:paddingHorizontal="@dimen/preview_attribution_pane_horizontal_padding"> + + <Space + android:id="@+id/preview_attribution_pane_title_spacer" + android:layout_width="0dp" + android:layout_height="@dimen/preview_attribution_pane_inner_spacer_height"/> <TextView android:id="@+id/preview_attribution_pane_title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="start" + android:minHeight="@dimen/preview_attribution_pane_title_height" android:ellipsize="end" android:forceHasOverlappingRendering="false" - android:gravity="center_horizontal" + android:gravity="center" android:singleLine="true" - android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Title" + android:textAppearance="@*android:style/TextAppearance.DeviceDefault.SearchResult.Title" android:visibility="gone"/> <TextView android:id="@+id/preview_attribution_pane_author" android:layout_width="match_parent" android:layout_height="wrap_content" + android:minHeight="@dimen/preview_attribution_pane_author_height" android:layout_marginTop="@dimen/preview_attribution_pane_author_top_margin" android:forceHasOverlappingRendering="false" - android:gravity="center_horizontal" + android:gravity="center" android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead" android:visibility="gone"/> @@ -45,17 +51,24 @@ android:id="@+id/preview_attribution_pane_description" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/preview_attribution_pane_description_top_margin" + android:minHeight="@dimen/preview_attribution_pane_description_height" android:forceHasOverlappingRendering="false" android:gravity="center_horizontal" android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Caption" android:visibility="gone"/> + <Space + android:id="@+id/preview_attribution_pane_spacer" + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_marginTop="@dimen/preview_attribution_pane_inner_spacer_height" + android:layout_weight="1"/> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" - android:layout_marginTop="@dimen/preview_attribution_pane_explore_top_margin" + android:layout_marginBottom="@dimen/preview_attribution_pane_button_bottom_margin" android:orientation="horizontal"> <com.google.android.material.button.MaterialButton diff --git a/res/layout/page_settings.xml b/res/layout/page_settings.xml index 25b4aec..5729aa3 100644 --- a/res/layout/page_settings.xml +++ b/res/layout/page_settings.xml @@ -24,10 +24,17 @@ android:layout_width="match_parent" android:layout_height="wrap_content"/> + <Space + android:id="@+id/preview_attribution_pane_spacer" + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_weight="1"/> + <com.google.android.material.button.MaterialButton android:id="@+id/preview_attribution_pane_set_wallpaper_button" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/preview_attribution_pane_button_bottom_margin" style="@style/ButtonStyle" android:text="@string/set_live_wallpaper"/> diff --git a/res/values-land/dimensions.xml b/res/values-land/dimensions.xml new file mode 100644 index 0000000..e2d5ffe --- /dev/null +++ b/res/values-land/dimensions.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 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. +--> +<resources> + <!-- Dimensions for the preview attribution pane. --> + <dimen name="preview_attribution_pane_author_top_margin">8dp</dimen> + <dimen name="preview_attribution_pane_button_bottom_margin">14dp</dimen> +</resources> diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml index 5066ca3..9e92df7 100644 --- a/res/values/dimensions.xml +++ b/res/values/dimensions.xml @@ -34,10 +34,13 @@ <!-- Dimensions for the preview attribution pane. --> <dimen name="preview_attribution_pane_horizontal_padding">24dp</dimen> - <dimen name="preview_attribution_pane_vertical_padding">13dp</dimen> - <dimen name="preview_attribution_pane_author_top_margin">12dp</dimen> - <dimen name="preview_attribution_pane_description_top_margin">2dp</dimen> - <dimen name="preview_attribution_pane_explore_top_margin">12dp</dimen> + <dimen name="preview_attribution_pane_extra_spacer_height">16dp</dimen> + <dimen name="preview_attribution_pane_inner_spacer_height">14dp</dimen> + <dimen name="preview_attribution_pane_title_height">48dp</dimen> + <dimen name="preview_attribution_pane_author_height">24dp</dimen> + <dimen name="preview_attribution_pane_author_top_margin">0dp</dimen> + <dimen name="preview_attribution_pane_description_height">34dp</dimen> + <dimen name="preview_attribution_pane_button_bottom_margin">8dp</dimen> <!-- Dimensions for the ConstraintViewPager on preview activity. --> <dimen name="preview_viewpager_round_radius">12dp</dimen> diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java index 095c8e1..9cd50c3 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java @@ -176,6 +176,7 @@ public class LiveWallpaperPreview extends Activity { if (SHOW_DUMMY_DATA) { attributionTitle.setText("Diorama, Yosemite"); + attributionTitle.setVisibility(View.VISIBLE); attributionAuthor.setText("Live Earth Collection - Android Earth"); attributionAuthor.setVisibility(View.VISIBLE); attributionDescription.setText("Lorem ipsum dolor sit amet, consectetur adipiscing" diff --git a/src/com/android/wallpaper/livepicker/widget/ConstraintViewPager.java b/src/com/android/wallpaper/livepicker/widget/ConstraintViewPager.java index c4dcf09..985cad6 100644 --- a/src/com/android/wallpaper/livepicker/widget/ConstraintViewPager.java +++ b/src/com/android/wallpaper/livepicker/widget/ConstraintViewPager.java @@ -24,36 +24,63 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.viewpager.widget.ViewPager; +import com.android.wallpaper.livepicker.R; + /** * When ConstraintViewPager is being measured, it will get all height of pages and makes itself * height as the same as the maximum height. */ public class ConstraintViewPager extends ViewPager { + private final int mExtraSpacerHeight; + public ConstraintViewPager(@NonNull Context context) { this(context, null /* attrs */); } public ConstraintViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); + mExtraSpacerHeight = context.getResources().getDimensionPixelSize( + R.dimen.preview_attribution_pane_extra_spacer_height); } /** * Visit all child views first and then determine the maximum height for ViewPager. + * Info page will add extra height in top area determined by empty space. */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int maxChildHeight = 0; + int infoChildHeight = 0; + int infoTopPadding = 0; + View infoPage = null; for (int i = 0; i < getChildCount(); i++) { View view = getChildAt(i); view.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0 /* size */, MeasureSpec.UNSPECIFIED)); int childHeight = view.getMeasuredHeight(); + // Get info page height and top padding. + if (view.getId() == R.id.page_info) { + infoPage = view; + infoChildHeight = childHeight; + infoTopPadding = view.getPaddingTop(); + } if (childHeight > maxChildHeight) { maxChildHeight = childHeight; } } + // Add extra padding in info page top area if info page has enough empty space to + // accommodate above and below extra height. + // 1. "infoChildHeight - infoTopPadding" means info page height without extra padding. + // 2. "mExtraSpacerHeight * 2" means above and below extra height. + if (maxChildHeight > (infoChildHeight - infoTopPadding + mExtraSpacerHeight * 2)) { + if (infoPage != null && infoTopPadding != mExtraSpacerHeight) { + infoPage.setPadding(infoPage.getPaddingLeft(), mExtraSpacerHeight, + infoPage.getPaddingRight(), infoPage.getPaddingBottom()); + } + } + if (maxChildHeight != 0) { heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxChildHeight, MeasureSpec.EXACTLY); } |