summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/customization/picker/BasePreviewAdapter.java2
-rw-r--r--src/com/android/customization/picker/clock/ClockFragment.java2
-rw-r--r--src/com/android/customization/picker/grid/GridFragment.java2
-rw-r--r--src/com/android/customization/picker/theme/ThemeFragment.java2
-rw-r--r--src/com/android/customization/widget/PageIndicator.java295
-rw-r--r--src/com/android/customization/widget/PreviewPager.java246
6 files changed, 4 insertions, 545 deletions
diff --git a/src/com/android/customization/picker/BasePreviewAdapter.java b/src/com/android/customization/picker/BasePreviewAdapter.java
index 53f750a1..dab923af 100644
--- a/src/com/android/customization/picker/BasePreviewAdapter.java
+++ b/src/com/android/customization/picker/BasePreviewAdapter.java
@@ -29,7 +29,7 @@ import androidx.core.view.ViewCompat;
import androidx.viewpager.widget.PagerAdapter;
import com.android.customization.picker.BasePreviewAdapter.PreviewPage;
-import com.android.customization.widget.PreviewPager;
+import com.android.wallpaper.widget.PreviewPager;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/com/android/customization/picker/clock/ClockFragment.java b/src/com/android/customization/picker/clock/ClockFragment.java
index 5191a9e2..48b4c0db 100644
--- a/src/com/android/customization/picker/clock/ClockFragment.java
+++ b/src/com/android/customization/picker/clock/ClockFragment.java
@@ -40,11 +40,11 @@ import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.picker.BasePreviewAdapter;
import com.android.customization.picker.BasePreviewAdapter.PreviewPage;
import com.android.customization.widget.OptionSelectorController;
-import com.android.customization.widget.PreviewPager;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
+import com.android.wallpaper.widget.PreviewPager;
import java.util.List;
diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java
index 9947acab..49a3771f 100644
--- a/src/com/android/customization/picker/grid/GridFragment.java
+++ b/src/com/android/customization/picker/grid/GridFragment.java
@@ -45,7 +45,6 @@ import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.picker.BasePreviewAdapter;
import com.android.customization.picker.BasePreviewAdapter.PreviewPage;
import com.android.customization.widget.OptionSelectorController;
-import com.android.customization.widget.PreviewPager;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.ContentUriAsset;
@@ -53,6 +52,7 @@ import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
+import com.android.wallpaper.widget.PreviewPager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
diff --git a/src/com/android/customization/picker/theme/ThemeFragment.java b/src/com/android/customization/picker/theme/ThemeFragment.java
index b7a39b32..b5c68e53 100644
--- a/src/com/android/customization/picker/theme/ThemeFragment.java
+++ b/src/com/android/customization/picker/theme/ThemeFragment.java
@@ -60,7 +60,6 @@ import com.android.customization.picker.TimeTicker;
import com.android.customization.picker.theme.ThemePreviewPage.ThemeCoverPage;
import com.android.customization.picker.theme.ThemePreviewPage.TimeContainer;
import com.android.customization.widget.OptionSelectorController;
-import com.android.customization.widget.PreviewPager;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.Asset.CenterCropBitmapTask;
@@ -68,6 +67,7 @@ import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
+import com.android.wallpaper.widget.PreviewPager;
import java.util.List;
diff --git a/src/com/android/customization/widget/PageIndicator.java b/src/com/android/customization/widget/PageIndicator.java
deleted file mode 100644
index dd636ad9..00000000
--- a/src/com/android/customization/widget/PageIndicator.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-package com.android.customization.widget;
-
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Animatable2;
-import android.graphics.drawable.AnimatedVectorDrawable;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-
-import com.android.wallpaper.R;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-
-/**
- * Page indicator widget, based on QS's page indicator:
- *
- * Based on QS PageIndicator
- * Path: frameworks/base/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java
- */
-public class PageIndicator extends ViewGroup {
-
- private static final String TAG = "PageIndicator";
- private static final boolean DEBUG = false;
-
- // The size of a single dot in relation to the whole animation.
- private static final float SINGLE_SCALE = .4f;
-
- static final float MINOR_ALPHA = .42f;
-
- private final ArrayList<Integer> mQueuedPositions = new ArrayList<>();
-
- private final int mPageIndicatorWidth;
- private final int mPageIndicatorHeight;
- private final int mPageDotWidth;
-
- private int mPosition = -1;
- private boolean mAnimating;
-
- private static Method sMethodForceAnimationOnUI = null;
- private final Animatable2.AnimationCallback mAnimationCallback =
- new Animatable2.AnimationCallback() {
-
- @Override
- public void onAnimationEnd(Drawable drawable) {
- super.onAnimationEnd(drawable);
- if (drawable instanceof AnimatedVectorDrawable) {
- ((AnimatedVectorDrawable) drawable).unregisterAnimationCallback(
- mAnimationCallback);
- }
- if (DEBUG) {
- Log.d(TAG, "onAnimationEnd - queued: " + mQueuedPositions.size());
- }
- mAnimating = false;
- if (mQueuedPositions.size() != 0) {
- setPosition(mQueuedPositions.remove(0));
- }
- }
- };
-
-
- public PageIndicator(Context context, AttributeSet attrs) {
- super(context, attrs);
- mPageIndicatorWidth =
- (int) context.getResources().getDimension(R.dimen.preview_indicator_width);
- mPageIndicatorHeight =
- (int) context.getResources().getDimension(R.dimen.preview_indicator_height);
- mPageDotWidth = (int) (mPageIndicatorWidth * SINGLE_SCALE);
- }
-
- public void setNumPages(int numPages) {
- setVisibility(numPages > 1 ? View.VISIBLE : View.INVISIBLE);
- if (mAnimating) {
- Log.w(TAG, "setNumPages during animation");
- }
- while (numPages < getChildCount()) {
- removeViewAt(getChildCount() - 1);
- }
- TypedArray array = getContext().obtainStyledAttributes(
- new int[]{android.R.attr.colorControlActivated});
- int color = array.getColor(0, 0);
- array.recycle();
- while (numPages > getChildCount()) {
- ImageView v = new ImageView(getContext());
- v.setImageResource(R.drawable.minor_a_b);
- v.setImageTintList(ColorStateList.valueOf(color));
- addView(v, new LayoutParams(mPageIndicatorWidth, mPageIndicatorHeight));
- }
- // Refresh state.
- setIndex(mPosition >> 1);
- }
-
- public void setLocation(float location) {
- int index = (int) location;
- setContentDescription(getContext().getString(R.string.accessibility_preview_pager,
- (index + 1), getChildCount()));
- int position = index << 1 | ((location != index) ? 1 : 0);
- if (DEBUG) {
- Log.d(TAG, "setLocation " + location + " " + index + " " + position);
- }
-
- int lastPosition = mPosition;
- if (mQueuedPositions.size() != 0) {
- lastPosition = mQueuedPositions.get(mQueuedPositions.size() - 1);
- }
- if (DEBUG) {
- Log.d(TAG, position + " " + lastPosition);
- }
- if (position == lastPosition) return;
- if (mAnimating) {
- if (DEBUG) {
- Log.d(TAG, "Queueing transition to " + Integer.toHexString(position));
- }
- mQueuedPositions.add(position);
- return;
- }
-
- setPosition(position);
- }
-
- private void setPosition(int position) {
- if (mPosition >= 0 && Math.abs(mPosition - position) == 1) {
- animate(mPosition, position);
- } else {
- if (DEBUG) {
- Log.d(TAG, "Skipping animation " + mPosition
- + " " + position);
- }
- setIndex(position >> 1);
- }
- mPosition = position;
- }
-
- private void setIndex(int index) {
- final int N = getChildCount();
- for (int i = 0; i < N; i++) {
- ImageView v = (ImageView) getChildAt(i);
- // Clear out any animation positioning.
- v.setTranslationX(0);
- v.setImageResource(R.drawable.major_a_b);
- v.setAlpha(getAlpha(i == index));
- }
- }
-
- private void animate(int from, int to) {
- if (DEBUG) {
- Log.d(TAG, "Animating from " + Integer.toHexString(from) + " to "
- + Integer.toHexString(to));
- }
- int fromIndex = from >> 1;
- int toIndex = to >> 1;
-
- // Set the position of everything, then we will manually control the two views involved
- // in the animation.
- setIndex(fromIndex);
-
- boolean fromTransition = (from & 1) != 0;
- boolean isAState = fromTransition ? from > to : from < to;
- int firstIndex = Math.min(fromIndex, toIndex);
- int secondIndex = Math.max(fromIndex, toIndex);
- if (secondIndex == firstIndex) {
- secondIndex++;
- }
- ImageView first = (ImageView) getChildAt(firstIndex);
- ImageView second = (ImageView) getChildAt(secondIndex);
- if (first == null || second == null) {
- // may happen during reInflation or other weird cases
- return;
- }
- // Lay the two views on top of each other.
- second.setTranslationX(first.getX() - second.getX());
-
- playAnimation(first, getTransition(fromTransition, isAState, false));
- first.setAlpha(getAlpha(false));
-
- playAnimation(second, getTransition(fromTransition, isAState, true));
- second.setAlpha(getAlpha(true));
-
- mAnimating = true;
- }
-
- private float getAlpha(boolean isMajor) {
- return isMajor ? 1 : MINOR_ALPHA;
- }
-
- private void playAnimation(ImageView imageView, int res) {
- Drawable drawable = getContext().getDrawable(res);
- if (!(drawable instanceof AnimatedVectorDrawable)) {
- return;
- }
- final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) drawable;
- imageView.setImageDrawable(avd);
- try {
- forceAnimationOnUI(avd);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- Log.e(TAG, "Catch an exception in playAnimation", e);
- }
- avd.registerAnimationCallback(mAnimationCallback);
- avd.start();
- }
-
- private void forceAnimationOnUI(AnimatedVectorDrawable avd)
- throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- if (sMethodForceAnimationOnUI == null) {
- sMethodForceAnimationOnUI = AnimatedVectorDrawable.class.getMethod(
- "forceAnimationOnUI");
- }
- if (sMethodForceAnimationOnUI != null) {
- sMethodForceAnimationOnUI.invoke(avd);
- }
- }
-
- private int getTransition(boolean fromB, boolean isMajorAState, boolean isMajor) {
- if (isMajor) {
- if (fromB) {
- if (isMajorAState) {
- return R.drawable.major_b_a_animation;
- } else {
- return R.drawable.major_b_c_animation;
- }
- } else {
- if (isMajorAState) {
- return R.drawable.major_a_b_animation;
- } else {
- return R.drawable.major_c_b_animation;
- }
- }
- } else {
- if (fromB) {
- if (isMajorAState) {
- return R.drawable.minor_b_c_animation;
- } else {
- return R.drawable.minor_b_a_animation;
- }
- } else {
- if (isMajorAState) {
- return R.drawable.minor_c_b_animation;
- } else {
- return R.drawable.minor_a_b_animation;
- }
- }
- }
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- final int N = getChildCount();
- if (N == 0) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- return;
- }
- final int widthChildSpec = MeasureSpec.makeMeasureSpec(mPageIndicatorWidth,
- MeasureSpec.EXACTLY);
- final int heightChildSpec = MeasureSpec.makeMeasureSpec(mPageIndicatorHeight,
- MeasureSpec.EXACTLY);
- for (int i = 0; i < N; i++) {
- getChildAt(i).measure(widthChildSpec, heightChildSpec);
- }
- int width = (mPageIndicatorWidth - mPageDotWidth) * (N - 1) + mPageDotWidth;
- setMeasuredDimension(width, mPageIndicatorHeight);
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- final int N = getChildCount();
- if (N == 0) {
- return;
- }
- for (int i = 0; i < N; i++) {
- int left = (mPageIndicatorWidth - mPageDotWidth) * i;
- getChildAt(i).layout(left, 0, mPageIndicatorWidth + left, mPageIndicatorHeight);
- }
- }
-}
diff --git a/src/com/android/customization/widget/PreviewPager.java b/src/com/android/customization/widget/PreviewPager.java
deleted file mode 100644
index 73a55549..00000000
--- a/src/com/android/customization/widget/PreviewPager.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-package com.android.customization.widget;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.database.DataSetObserver;
-import android.util.AttributeSet;
-import android.util.DisplayMetrics;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.LinearLayout;
-
-import androidx.annotation.Nullable;
-import androidx.core.text.TextUtilsCompat;
-import androidx.core.view.ViewCompat;
-import androidx.viewpager.widget.PagerAdapter;
-import androidx.viewpager.widget.ViewPager;
-import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
-
-import com.android.wallpaper.R;
-
-import java.util.Locale;
-
-/**
- * A Widget consisting of a ViewPager linked to a PageIndicator and previous/next arrows that can be
- * used to page over that ViewPager.
- * To use it, set a {@link PagerAdapter} using {@link #setAdapter(PagerAdapter)}, and optionally use
- * a {@link #setOnPageChangeListener(OnPageChangeListener)} to listen for page changes.
- */
-public class PreviewPager extends LinearLayout {
-
- private static final int STYLE_PEEKING = 0;
- private static final int STYLE_ASPECT_RATIO = 1;
-
- private final ViewPager mViewPager;
- private final PageIndicator mPageIndicator;
- private final View mPreviousArrow;
- private final View mNextArrow;
- private final ViewPager.OnPageChangeListener mPageListener;
- private int mPageStyle;
-
- private PagerAdapter mAdapter;
- private ViewPager.OnPageChangeListener mExternalPageListener;
- private float mScreenAspectRatio;
-
- public PreviewPager(Context context) {
- this(context, null);
- }
-
- public PreviewPager(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public PreviewPager(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- LayoutInflater.from(context).inflate(R.layout.preview_pager, this);
- Resources res = context.getResources();
- TypedArray a = context.obtainStyledAttributes(attrs,
- R.styleable.PreviewPager, defStyleAttr, 0);
-
- mPageStyle = a.getInteger(R.styleable.PreviewPager_card_style, STYLE_PEEKING);
-
- a.recycle();
-
- mViewPager = findViewById(R.id.preview_viewpager);
- mViewPager.setPageMargin(res.getDimensionPixelOffset(R.dimen.preview_page_gap));
- mViewPager.setClipToPadding(false);
- if (mPageStyle == STYLE_PEEKING) {
- int screenWidth = mViewPager.getResources().getDisplayMetrics().widthPixels;
- int hMargin = res.getDimensionPixelOffset(R.dimen.preview_page_horizontal_margin);
- hMargin = Math.max(hMargin, screenWidth/8);
- mViewPager.setPadding(
- hMargin,
- res.getDimensionPixelOffset(R.dimen.preview_page_top_margin),
- hMargin,
- res.getDimensionPixelOffset(R.dimen.preview_page_bottom_margin));
- } else if (mPageStyle == STYLE_ASPECT_RATIO) {
- DisplayMetrics dm = res.getDisplayMetrics();
- mScreenAspectRatio = dm.heightPixels > dm.widthPixels
- ? (float) dm.heightPixels / dm.widthPixels
- : (float) dm.widthPixels / dm.heightPixels;
- mViewPager.setPadding(
- 0,
- res.getDimensionPixelOffset(R.dimen.preview_page_top_margin),
- 0,
- res.getDimensionPixelOffset(R.dimen.preview_page_bottom_margin));
- }
- mPageIndicator = findViewById(R.id.page_indicator);
- mPreviousArrow = findViewById(R.id.arrow_previous);
- mPreviousArrow.setOnClickListener(v -> {
- final int previousPos = mViewPager.getCurrentItem() - 1;
- mViewPager.setCurrentItem(previousPos, true);
- });
- mNextArrow = findViewById(R.id.arrow_next);
- mNextArrow.setOnClickListener(v -> {
- final int NextPos = mViewPager.getCurrentItem() + 1;
- mViewPager.setCurrentItem(NextPos, true);
- });
- mPageListener = createPageListener();
- mViewPager.addOnPageChangeListener(mPageListener);
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- if (mPageStyle == STYLE_ASPECT_RATIO) {
- int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
- int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
- int indicatorHeight = mPageIndicator.getVisibility() == VISIBLE
- ? ((View) mPageIndicator.getParent()).getLayoutParams().height
- : 0;
- int pagerHeight = availableHeight - indicatorHeight;
- if (availableWidth > 0) {
- int absoluteCardWidth = (int) ((pagerHeight - mViewPager.getPaddingBottom()
- - mViewPager.getPaddingTop())/ mScreenAspectRatio);
- int hPadding = (availableWidth / 2) - (absoluteCardWidth / 2);
- mViewPager.setPaddingRelative(
- hPadding,
- mViewPager.getPaddingTop(),
- hPadding,
- mViewPager.getPaddingBottom());
- }
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
-
- public void forceCardWidth(int widthPixels) {
- mViewPager.addOnLayoutChangeListener(new OnLayoutChangeListener() {
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom,
- int oldLeft, int oldTop, int oldRight, int oldBottom) {
- int hPadding = (mViewPager.getWidth() - widthPixels) / 2;
- mViewPager.setPadding(hPadding, mViewPager.getPaddingTop(),
- hPadding, mViewPager.getPaddingBottom());
- mViewPager.removeOnLayoutChangeListener(this);
- }
- });
- mViewPager.invalidate();
- }
-
- /**
- * Call this method to set the {@link PagerAdapter} backing the {@link ViewPager} in this
- * widget.
- */
- public void setAdapter(PagerAdapter adapter) {
- int initialPage = 0;
- if (mViewPager.getAdapter() != null) {
- initialPage = isRtl() ? mAdapter.getCount() - 1 - mViewPager.getCurrentItem()
- : mViewPager.getCurrentItem();
- }
- mAdapter = adapter;
- mViewPager.setAdapter(adapter);
- mViewPager.setCurrentItem(isRtl() ? mAdapter.getCount() - 1 - initialPage : initialPage);
- mAdapter.registerDataSetObserver(new DataSetObserver() {
- @Override
- public void onChanged() {
- initIndicator();
- }
- });
- initIndicator();
- updateIndicator(mViewPager.getCurrentItem());
- }
-
- private boolean isRtl() {
- if (ViewCompat.isLayoutDirectionResolved(mViewPager)) {
- return ViewCompat.getLayoutDirection(mViewPager) == ViewCompat.LAYOUT_DIRECTION_RTL;
- }
- return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
- == ViewCompat.LAYOUT_DIRECTION_RTL;
- }
-
- /**
- * Set a {@link OnPageChangeListener} to be notified when the ViewPager's page state changes
- */
- public void setOnPageChangeListener(@Nullable ViewPager.OnPageChangeListener listener) {
- mExternalPageListener = listener;
- }
-
- private void initIndicator() {
- mPageIndicator.setNumPages(mAdapter.getCount());
- mPageIndicator.setLocation(mViewPager.getCurrentItem());
- }
-
- private ViewPager.OnPageChangeListener createPageListener() {
- return new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(
- int position, float positionOffset, int positionOffsetPixels) {
- // For certain sizes, positionOffset never makes it to 1, so round it as we don't
- // need that much precision
- float location = (float) Math.round((position + positionOffset) * 100) / 100;
- mPageIndicator.setLocation(location);
- if (mExternalPageListener != null) {
- mExternalPageListener.onPageScrolled(position, positionOffset,
- positionOffsetPixels);
- }
- }
-
- @Override
- public void onPageSelected(int position) {
- int adapterCount = mAdapter.getCount();
- if (position < 0 || position >= adapterCount) {
- return;
- }
-
- updateIndicator(position);
- if (mExternalPageListener != null) {
- mExternalPageListener.onPageSelected(position);
- }
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
- if (mExternalPageListener != null) {
- mExternalPageListener.onPageScrollStateChanged(state);
- }
- }
- };
- }
-
- private void updateIndicator(int position) {
- int adapterCount = mAdapter.getCount();
- if (adapterCount > 1) {
- mPreviousArrow.setVisibility(position != 0 ? View.VISIBLE : View.GONE);
- mNextArrow.setVisibility(position != (adapterCount - 1) ? View.VISIBLE : View.GONE);
- } else {
- mPageIndicator.setVisibility(View.GONE);
- mPreviousArrow.setVisibility(View.GONE);
- mNextArrow.setVisibility(View.GONE);
- }
- }
-}