diff options
author | Kunhung Li <kunhungli@google.com> | 2019-05-01 21:24:11 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-05-01 21:24:11 -0700 |
commit | 308dcbc79fba9114062594ed36a8d5eed02a3e47 (patch) | |
tree | a1938fea9bd94b62a2a87971dad960d65dda02c3 | |
parent | ecbe70007c06d97cc06d8c2df3143947470911f7 (diff) | |
parent | faf0af1fe4855ad05f1c7c24db8206d3e0ab420d (diff) | |
download | android_packages_wallpapers_LivePicker-308dcbc79fba9114062594ed36a8d5eed02a3e47.tar.gz android_packages_wallpapers_LivePicker-308dcbc79fba9114062594ed36a8d5eed02a3e47.tar.bz2 android_packages_wallpapers_LivePicker-308dcbc79fba9114062594ed36a8d5eed02a3e47.zip |
Add preview checkbox for LivePicker
am: faf0af1fe4
Change-Id: I6e14aa1c7cf98698ad98ef8a8d77e8a901808a5b
-rw-r--r-- | res/layout/live_wallpaper_preview.xml | 34 | ||||
-rw-r--r-- | res/layout/preview_action.xml | 24 | ||||
-rw-r--r-- | res/layout/set_wallpaper_action.xml | 24 | ||||
-rw-r--r-- | res/menu/menu_preview.xml | 5 | ||||
-rw-r--r-- | res/values/dimensions.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 10 | ||||
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java | 90 |
7 files changed, 140 insertions, 48 deletions
diff --git a/res/layout/live_wallpaper_preview.xml b/res/layout/live_wallpaper_preview.xml index 0c35b68..b6bbd7c 100644 --- a/res/layout/live_wallpaper_preview.xml +++ b/res/layout/live_wallpaper_preview.xml @@ -46,29 +46,37 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - <LinearLayout - android:id="@+id/bottom_pane" + <androidx.coordinatorlayout.widget.CoordinatorLayout + android:id="@+id/coordinator_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:background="@color/translucent_black" android:orientation="vertical"> - <com.google.android.material.tabs.TabLayout - android:id="@+id/tablayout" + <LinearLayout + android:id="@+id/bottom_pane" android:layout_width="match_parent" android:layout_height="wrap_content" - style="@style/TabLayoutStyle" - android:visibility="gone" /> + android:background="@color/translucent_black" + android:orientation="vertical" + app:behavior_peekHeight="@dimen/preview_attribution_pane_collapsed_height" + app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> - <com.android.wallpaper.livepicker.widget.ConstraintViewPager - android:id="@+id/viewpager" - android:layout_width="match_parent" - android:layout_height="wrap_content"> + <com.google.android.material.tabs.TabLayout + android:id="@+id/tablayout" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="@style/TabLayoutStyle" + android:visibility="gone"/> + + <com.android.wallpaper.livepicker.widget.ConstraintViewPager + android:id="@+id/viewpager" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> - </com.android.wallpaper.livepicker.widget.ConstraintViewPager> + </LinearLayout> - </LinearLayout> + </androidx.coordinatorlayout.widget.CoordinatorLayout> <android.widget.Toolbar android:id="@+id/toolbar" diff --git a/res/layout/preview_action.xml b/res/layout/preview_action.xml new file mode 100644 index 0000000..89a3c9e --- /dev/null +++ b/res/layout/preview_action.xml @@ -0,0 +1,24 @@ +<!-- 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. +--> + +<CheckBox + xmlns:android="http://schemas.android.com/apk/res/android" + style="?android:attr/checkboxStyle" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:text="@string/preview" + android:textAllCaps="false" + android:textAppearance="?android:attr/actionMenuTextAppearance" + android:background="?android:attr/selectableItemBackgroundBorderless"/> diff --git a/res/layout/set_wallpaper_action.xml b/res/layout/set_wallpaper_action.xml deleted file mode 100644 index 02f4fcd..0000000 --- a/res/layout/set_wallpaper_action.xml +++ /dev/null @@ -1,24 +0,0 @@ -<!-- - ~ Copyright (C) 2016 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 - --> - -<Button - xmlns:android="http://schemas.android.com/apk/res/android" - style="?android:attr/actionButtonStyle" - android:layout_width="wrap_content" - android:layout_height="match_parent" - android:text="@string/set_live_wallpaper" - android:textAppearance="?android:attr/actionMenuTextAppearance" - android:background="?android:attr/selectableItemBackgroundBorderless"/>
\ No newline at end of file diff --git a/res/menu/menu_preview.xml b/res/menu/menu_preview.xml index c8d450a..183ffd4 100644 --- a/res/menu/menu_preview.xml +++ b/res/menu/menu_preview.xml @@ -16,6 +16,11 @@ --> <menu xmlns:android="http://schemas.android.com/apk/res/android" > + <item android:id="@+id/preview" + android:checkable="true" + android:showAsAction="ifRoom" + android:actionLayout="@layout/preview_action"/> + <item android:id="@+id/configure" android:icon="@drawable/ic_settings" diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml index 85ce7db..a1ccd3f 100644 --- a/res/values/dimensions.xml +++ b/res/values/dimensions.xml @@ -33,6 +33,7 @@ <dimen name="preview_gradient_background_height">256dp</dimen> <!-- Dimensions for the preview attribution pane. --> + <dimen name="preview_attribution_pane_collapsed_height">0dp</dimen> <dimen name="preview_attribution_pane_horizontal_padding">24dp</dimen> <dimen name="preview_attribution_pane_extra_spacer_height">16dp</dimen> <dimen name="preview_attribution_pane_inner_spacer_height">14dp</dimen> diff --git a/res/values/strings.xml b/res/values/strings.xml index 824c23b..4ade992 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -33,6 +33,8 @@ <string name="configure_wallpaper">Settingsā¦</string> <!-- List item for deleting the current wallpaper --> <string name="delete_live_wallpaper">Delete</string> + <!-- List item for showing the current wallpaper by hiding bottom panel. --> + <string name="preview">Preview</string> <!-- Button label on Wallpaper Gallery screen; user selects this button to set a specific wallpaper --> <string name="wallpaper_instructions">Set wallpaper</string> <!-- Warning message, no live wallpapers available. --> @@ -61,4 +63,12 @@ <!-- Confirmation dialog. Shown after user selects to delete one wallpaper. [CHAR LIMIT=NONE] --> <string name="delete_wallpaper_confirmation">Delete this wallpaper from your phone?</string> + + <!-- Content description for a checkbox letting the user collapse a visual panel showing info + about the wallpaper being previewed. [CHAR LIMIT=none] --> + <string name="collapse_attribution_panel">Collapse wallpaper info panel</string> + + <!-- Content description for a checkbox letting the user expand a visual panel showing info + about the wallpaper being previewed. [CHAR LIMIT=none] --> + <string name="expand_attribution_panel">Expand wallpaper info panel</string> </resources> diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java index 7cfdb4d..65e0e6c 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java @@ -43,7 +43,6 @@ import android.service.wallpaper.IWallpaperEngine; import android.service.wallpaper.IWallpaperService; import android.service.wallpaper.WallpaperService; import android.service.wallpaper.WallpaperSettingsActivity; -import com.google.android.material.tabs.TabLayout; import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -58,6 +57,7 @@ import android.view.WindowManager.LayoutParams; import android.view.animation.AnimationUtils; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toolbar; @@ -71,6 +71,10 @@ import androidx.slice.widget.SliceView; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; +import com.google.android.material.bottomsheet.BottomSheetBehavior; +import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback; +import com.google.android.material.tabs.TabLayout; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -90,6 +94,11 @@ public class LiveWallpaperPreview extends Activity { private Intent mDeleteIntent; private View mLoading; + private View mViewBottomPane; + private BottomSheetBehavior mBottomSheetBehavior; + private ViewPager mViewPager; + private TabLayout mTabLayout; + private CheckBox mPreview; protected final List<Pair<String, View>> mPages = new ArrayList<>(); private SliceView mSliceViewSettings; @@ -282,9 +291,12 @@ public class LiveWallpaperPreview extends Activity { } private void populateBottomPane() { - final View viewBottomPane = findViewById(R.id.bottom_pane); - final ViewPager viewPager = findViewById(R.id.viewpager); - final TabLayout tabLayout = findViewById(R.id.tablayout); + mViewBottomPane = findViewById(R.id.bottom_pane); + mViewPager = findViewById(R.id.viewpager); + mTabLayout = findViewById(R.id.tablayout); + + mBottomSheetBehavior = BottomSheetBehavior.from(mViewBottomPane); + mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); // Create PagerAdapter final PagerAdapter pagerAdapter = new PagerAdapter() { @@ -325,24 +337,24 @@ public class LiveWallpaperPreview extends Activity { }; // Add OnPageChangeListener to re-measure ViewPager's height - viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { - viewPager.requestLayout(); + mViewPager.requestLayout(); } }); // Set PagerAdapter - viewPager.setAdapter(pagerAdapter); + mViewPager.setAdapter(pagerAdapter); // Make TabLayout visible if there are more than one page if (mPages.size() > 1) { - tabLayout.setVisibility(View.VISIBLE); - tabLayout.setupWithViewPager(viewPager); + mTabLayout.setVisibility(View.VISIBLE); + mTabLayout.setupWithViewPager(mViewPager); } // Initializes a rounded rectangle outline and clips the upper corners to be rounded. - viewBottomPane.setOutlineProvider(new ViewOutlineProvider() { + mViewBottomPane.setOutlineProvider(new ViewOutlineProvider() { private final int radius = getResources().getDimensionPixelSize( R.dimen.preview_viewpager_round_radius); @@ -352,17 +364,73 @@ public class LiveWallpaperPreview extends Activity { view.getHeight() + radius, radius); } }); - viewBottomPane.setClipToOutline(true); + mViewBottomPane.setClipToOutline(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_preview, menu); + setupPreviewMenu(menu); menu.findItem(R.id.configure).setVisible(mSettingsIntent != null); menu.findItem(R.id.delete_wallpaper).setVisible(mDeleteIntent != null); return super.onCreateOptionsMenu(menu); } + private void setupPreviewMenu(Menu menu) { + mPreview = (CheckBox) menu.findItem(R.id.preview).getActionView(); + mPreview.setOnClickListener(this::setPreviewBehavior); + + BottomSheetCallback callback = new BottomSheetCallback() { + @Override + public void onStateChanged(View bottomSheet, int newState) { + switch (newState) { + case BottomSheetBehavior.STATE_COLLAPSED: + setPreviewChecked(true /* checked */); + break; + case BottomSheetBehavior.STATE_EXPANDED: + setPreviewChecked(false /* checked */); + break; + } + } + + @Override + public void onSlide(View bottomSheet, float slideOffset) { + mTabLayout.setAlpha(slideOffset); + mViewPager.setAlpha(slideOffset); + } + }; + mBottomSheetBehavior.setBottomSheetCallback(callback); + + int state = mBottomSheetBehavior.getState(); + callback.onStateChanged(mViewBottomPane, state); + switch (state) { + case BottomSheetBehavior.STATE_COLLAPSED: + callback.onSlide(mViewBottomPane, 0f); + break; + case BottomSheetBehavior.STATE_EXPANDED: + callback.onSlide(mViewBottomPane, 1f); + break; + } + } + + private void setPreviewChecked(boolean checked) { + if (mPreview != null) { + mPreview.setChecked(checked); + int resId = checked ? R.string.expand_attribution_panel + : R.string.collapse_attribution_panel; + mPreview.setContentDescription(getResources().getString(resId)); + } + } + + private void setPreviewBehavior(final View v) { + CheckBox checkbox = (CheckBox) v; + if (checkbox.isChecked()) { + mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + } else { + mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); + } + } + public void setLiveWallpaper(final View v) { if (mWallpaperManager.getWallpaperInfo() != null && mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK) < 0) { |