ADD week 5
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
package com.google.android.material.tabs;
|
||||
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import com.google.android.material.animation.AnimationUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class ElasticTabIndicatorInterpolator extends TabIndicatorInterpolator {
|
||||
ElasticTabIndicatorInterpolator() {
|
||||
}
|
||||
|
||||
private static float decInterp(float f) {
|
||||
return (float) Math.sin((f * 3.141592653589793d) / 2.0d);
|
||||
}
|
||||
|
||||
private static float accInterp(float f) {
|
||||
return (float) (1.0d - Math.cos((f * 3.141592653589793d) / 2.0d));
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.tabs.TabIndicatorInterpolator
|
||||
void updateIndicatorForOffset(TabLayout tabLayout, View view, View view2, float f, Drawable drawable) {
|
||||
float decInterp;
|
||||
float accInterp;
|
||||
RectF calculateIndicatorWidthForTab = calculateIndicatorWidthForTab(tabLayout, view);
|
||||
RectF calculateIndicatorWidthForTab2 = calculateIndicatorWidthForTab(tabLayout, view2);
|
||||
if (calculateIndicatorWidthForTab.left < calculateIndicatorWidthForTab2.left) {
|
||||
decInterp = accInterp(f);
|
||||
accInterp = decInterp(f);
|
||||
} else {
|
||||
decInterp = decInterp(f);
|
||||
accInterp = accInterp(f);
|
||||
}
|
||||
drawable.setBounds(AnimationUtils.lerp((int) calculateIndicatorWidthForTab.left, (int) calculateIndicatorWidthForTab2.left, decInterp), drawable.getBounds().top, AnimationUtils.lerp((int) calculateIndicatorWidthForTab.right, (int) calculateIndicatorWidthForTab2.right, accInterp), drawable.getBounds().bottom);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.google.android.material.tabs;
|
||||
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import com.google.android.material.animation.AnimationUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class FadeTabIndicatorInterpolator extends TabIndicatorInterpolator {
|
||||
private static final float FADE_THRESHOLD = 0.5f;
|
||||
|
||||
FadeTabIndicatorInterpolator() {
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.tabs.TabIndicatorInterpolator
|
||||
void updateIndicatorForOffset(TabLayout tabLayout, View view, View view2, float f, Drawable drawable) {
|
||||
float lerp;
|
||||
if (f >= 0.5f) {
|
||||
view = view2;
|
||||
}
|
||||
RectF calculateIndicatorWidthForTab = calculateIndicatorWidthForTab(tabLayout, view);
|
||||
if (f < 0.5f) {
|
||||
lerp = AnimationUtils.lerp(1.0f, 0.0f, 0.0f, 0.5f, f);
|
||||
} else {
|
||||
lerp = AnimationUtils.lerp(0.0f, 1.0f, 0.5f, 1.0f, f);
|
||||
}
|
||||
drawable.setBounds((int) calculateIndicatorWidthForTab.left, drawable.getBounds().top, (int) calculateIndicatorWidthForTab.right, drawable.getBounds().bottom);
|
||||
drawable.setAlpha((int) (lerp * 255.0f));
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.google.android.material.tabs;
|
||||
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import com.google.android.material.animation.AnimationUtils;
|
||||
import com.google.android.material.internal.ViewUtils;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class TabIndicatorInterpolator {
|
||||
private static final int MIN_INDICATOR_WIDTH = 24;
|
||||
|
||||
TabIndicatorInterpolator() {
|
||||
}
|
||||
|
||||
static RectF calculateTabViewContentBounds(TabLayout.TabView tabView, int i) {
|
||||
int contentWidth = tabView.getContentWidth();
|
||||
int contentHeight = tabView.getContentHeight();
|
||||
int dpToPx = (int) ViewUtils.dpToPx(tabView.getContext(), i);
|
||||
if (contentWidth < dpToPx) {
|
||||
contentWidth = dpToPx;
|
||||
}
|
||||
int left = (tabView.getLeft() + tabView.getRight()) / 2;
|
||||
int top = (tabView.getTop() + tabView.getBottom()) / 2;
|
||||
int i2 = contentWidth / 2;
|
||||
return new RectF(left - i2, top - (contentHeight / 2), i2 + left, top + (left / 2));
|
||||
}
|
||||
|
||||
static RectF calculateIndicatorWidthForTab(TabLayout tabLayout, View view) {
|
||||
if (view == null) {
|
||||
return new RectF();
|
||||
}
|
||||
if (!tabLayout.isTabIndicatorFullWidth() && (view instanceof TabLayout.TabView)) {
|
||||
return calculateTabViewContentBounds((TabLayout.TabView) view, 24);
|
||||
}
|
||||
return new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
|
||||
}
|
||||
|
||||
void setIndicatorBoundsForTab(TabLayout tabLayout, View view, Drawable drawable) {
|
||||
RectF calculateIndicatorWidthForTab = calculateIndicatorWidthForTab(tabLayout, view);
|
||||
drawable.setBounds((int) calculateIndicatorWidthForTab.left, drawable.getBounds().top, (int) calculateIndicatorWidthForTab.right, drawable.getBounds().bottom);
|
||||
}
|
||||
|
||||
void updateIndicatorForOffset(TabLayout tabLayout, View view, View view2, float f, Drawable drawable) {
|
||||
RectF calculateIndicatorWidthForTab = calculateIndicatorWidthForTab(tabLayout, view);
|
||||
RectF calculateIndicatorWidthForTab2 = calculateIndicatorWidthForTab(tabLayout, view2);
|
||||
drawable.setBounds(AnimationUtils.lerp((int) calculateIndicatorWidthForTab.left, (int) calculateIndicatorWidthForTab2.left, f), drawable.getBounds().top, AnimationUtils.lerp((int) calculateIndicatorWidthForTab.right, (int) calculateIndicatorWidthForTab2.right, f), drawable.getBounds().bottom);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.google.android.material.tabs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import androidx.appcompat.widget.TintTypedArray;
|
||||
import com.google.android.material.R;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class TabItem extends View {
|
||||
public final int customLayout;
|
||||
public final Drawable icon;
|
||||
public final CharSequence text;
|
||||
|
||||
public TabItem(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public TabItem(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, attributeSet, R.styleable.TabItem);
|
||||
this.text = obtainStyledAttributes.getText(R.styleable.TabItem_android_text);
|
||||
this.icon = obtainStyledAttributes.getDrawable(R.styleable.TabItem_android_icon);
|
||||
this.customLayout = obtainStyledAttributes.getResourceId(R.styleable.TabItem_android_layout, 0);
|
||||
obtainStyledAttributes.recycle();
|
||||
}
|
||||
}
|
2145
02-Easy5/E5/sources/com/google/android/material/tabs/TabLayout.java
Normal file
2145
02-Easy5/E5/sources/com/google/android/material/tabs/TabLayout.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,206 @@
|
||||
package com.google.android.material.tabs;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class TabLayoutMediator {
|
||||
private RecyclerView.Adapter<?> adapter;
|
||||
private boolean attached;
|
||||
private final boolean autoRefresh;
|
||||
private TabLayoutOnPageChangeCallback onPageChangeCallback;
|
||||
private TabLayout.OnTabSelectedListener onTabSelectedListener;
|
||||
private RecyclerView.AdapterDataObserver pagerAdapterObserver;
|
||||
private final boolean smoothScroll;
|
||||
private final TabConfigurationStrategy tabConfigurationStrategy;
|
||||
private final TabLayout tabLayout;
|
||||
private final ViewPager2 viewPager;
|
||||
|
||||
public interface TabConfigurationStrategy {
|
||||
void onConfigureTab(TabLayout.Tab tab, int i);
|
||||
}
|
||||
|
||||
public boolean isAttached() {
|
||||
return this.attached;
|
||||
}
|
||||
|
||||
public TabLayoutMediator(TabLayout tabLayout, ViewPager2 viewPager2, TabConfigurationStrategy tabConfigurationStrategy) {
|
||||
this(tabLayout, viewPager2, true, tabConfigurationStrategy);
|
||||
}
|
||||
|
||||
public TabLayoutMediator(TabLayout tabLayout, ViewPager2 viewPager2, boolean z, TabConfigurationStrategy tabConfigurationStrategy) {
|
||||
this(tabLayout, viewPager2, z, true, tabConfigurationStrategy);
|
||||
}
|
||||
|
||||
public TabLayoutMediator(TabLayout tabLayout, ViewPager2 viewPager2, boolean z, boolean z2, TabConfigurationStrategy tabConfigurationStrategy) {
|
||||
this.tabLayout = tabLayout;
|
||||
this.viewPager = viewPager2;
|
||||
this.autoRefresh = z;
|
||||
this.smoothScroll = z2;
|
||||
this.tabConfigurationStrategy = tabConfigurationStrategy;
|
||||
}
|
||||
|
||||
public void attach() {
|
||||
if (this.attached) {
|
||||
throw new IllegalStateException("TabLayoutMediator is already attached");
|
||||
}
|
||||
RecyclerView.Adapter<?> adapter = this.viewPager.getAdapter();
|
||||
this.adapter = adapter;
|
||||
if (adapter == null) {
|
||||
throw new IllegalStateException("TabLayoutMediator attached before ViewPager2 has an adapter");
|
||||
}
|
||||
this.attached = true;
|
||||
TabLayoutOnPageChangeCallback tabLayoutOnPageChangeCallback = new TabLayoutOnPageChangeCallback(this.tabLayout);
|
||||
this.onPageChangeCallback = tabLayoutOnPageChangeCallback;
|
||||
this.viewPager.registerOnPageChangeCallback(tabLayoutOnPageChangeCallback);
|
||||
ViewPagerOnTabSelectedListener viewPagerOnTabSelectedListener = new ViewPagerOnTabSelectedListener(this.viewPager, this.smoothScroll);
|
||||
this.onTabSelectedListener = viewPagerOnTabSelectedListener;
|
||||
this.tabLayout.addOnTabSelectedListener((TabLayout.OnTabSelectedListener) viewPagerOnTabSelectedListener);
|
||||
if (this.autoRefresh) {
|
||||
PagerAdapterObserver pagerAdapterObserver = new PagerAdapterObserver();
|
||||
this.pagerAdapterObserver = pagerAdapterObserver;
|
||||
this.adapter.registerAdapterDataObserver(pagerAdapterObserver);
|
||||
}
|
||||
populateTabsFromPagerAdapter();
|
||||
this.tabLayout.setScrollPosition(this.viewPager.getCurrentItem(), 0.0f, true);
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
RecyclerView.Adapter<?> adapter;
|
||||
if (this.autoRefresh && (adapter = this.adapter) != null) {
|
||||
adapter.unregisterAdapterDataObserver(this.pagerAdapterObserver);
|
||||
this.pagerAdapterObserver = null;
|
||||
}
|
||||
this.tabLayout.removeOnTabSelectedListener(this.onTabSelectedListener);
|
||||
this.viewPager.unregisterOnPageChangeCallback(this.onPageChangeCallback);
|
||||
this.onTabSelectedListener = null;
|
||||
this.onPageChangeCallback = null;
|
||||
this.adapter = null;
|
||||
this.attached = false;
|
||||
}
|
||||
|
||||
void populateTabsFromPagerAdapter() {
|
||||
this.tabLayout.removeAllTabs();
|
||||
RecyclerView.Adapter<?> adapter = this.adapter;
|
||||
if (adapter != null) {
|
||||
int itemCount = adapter.getItemCount();
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
TabLayout.Tab newTab = this.tabLayout.newTab();
|
||||
this.tabConfigurationStrategy.onConfigureTab(newTab, i);
|
||||
this.tabLayout.addTab(newTab, false);
|
||||
}
|
||||
if (itemCount > 0) {
|
||||
int min = Math.min(this.viewPager.getCurrentItem(), this.tabLayout.getTabCount() - 1);
|
||||
if (min != this.tabLayout.getSelectedTabPosition()) {
|
||||
TabLayout tabLayout = this.tabLayout;
|
||||
tabLayout.selectTab(tabLayout.getTabAt(min));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class TabLayoutOnPageChangeCallback extends ViewPager2.OnPageChangeCallback {
|
||||
private int previousScrollState;
|
||||
private int scrollState;
|
||||
private final WeakReference<TabLayout> tabLayoutRef;
|
||||
|
||||
void reset() {
|
||||
this.scrollState = 0;
|
||||
this.previousScrollState = 0;
|
||||
}
|
||||
|
||||
TabLayoutOnPageChangeCallback(TabLayout tabLayout) {
|
||||
this.tabLayoutRef = new WeakReference<>(tabLayout);
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override // androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
this.previousScrollState = this.scrollState;
|
||||
this.scrollState = i;
|
||||
TabLayout tabLayout = this.tabLayoutRef.get();
|
||||
if (tabLayout != null) {
|
||||
tabLayout.updateViewPagerScrollState(this.scrollState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
public void onPageScrolled(int i, float f, int i2) {
|
||||
TabLayout tabLayout = this.tabLayoutRef.get();
|
||||
if (tabLayout != null) {
|
||||
int i3 = this.scrollState;
|
||||
tabLayout.setScrollPosition(i, f, i3 != 2 || this.previousScrollState == 1, (i3 == 2 && this.previousScrollState == 0) ? false : true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
public void onPageSelected(int i) {
|
||||
TabLayout tabLayout = this.tabLayoutRef.get();
|
||||
if (tabLayout == null || tabLayout.getSelectedTabPosition() == i || i >= tabLayout.getTabCount()) {
|
||||
return;
|
||||
}
|
||||
int i2 = this.scrollState;
|
||||
tabLayout.selectTab(tabLayout.getTabAt(i), i2 == 0 || (i2 == 2 && this.previousScrollState == 0));
|
||||
}
|
||||
}
|
||||
|
||||
private static class ViewPagerOnTabSelectedListener implements TabLayout.OnTabSelectedListener {
|
||||
private final boolean smoothScroll;
|
||||
private final ViewPager2 viewPager;
|
||||
|
||||
@Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
}
|
||||
|
||||
ViewPagerOnTabSelectedListener(ViewPager2 viewPager2, boolean z) {
|
||||
this.viewPager = viewPager2;
|
||||
this.smoothScroll = z;
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
this.viewPager.setCurrentItem(tab.getPosition(), this.smoothScroll);
|
||||
}
|
||||
}
|
||||
|
||||
private class PagerAdapterObserver extends RecyclerView.AdapterDataObserver {
|
||||
PagerAdapterObserver() {
|
||||
}
|
||||
|
||||
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
public void onChanged() {
|
||||
TabLayoutMediator.this.populateTabsFromPagerAdapter();
|
||||
}
|
||||
|
||||
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
public void onItemRangeChanged(int i, int i2) {
|
||||
TabLayoutMediator.this.populateTabsFromPagerAdapter();
|
||||
}
|
||||
|
||||
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
public void onItemRangeChanged(int i, int i2, Object obj) {
|
||||
TabLayoutMediator.this.populateTabsFromPagerAdapter();
|
||||
}
|
||||
|
||||
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
public void onItemRangeInserted(int i, int i2) {
|
||||
TabLayoutMediator.this.populateTabsFromPagerAdapter();
|
||||
}
|
||||
|
||||
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
public void onItemRangeRemoved(int i, int i2) {
|
||||
TabLayoutMediator.this.populateTabsFromPagerAdapter();
|
||||
}
|
||||
|
||||
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
public void onItemRangeMoved(int i, int i2, int i3) {
|
||||
TabLayoutMediator.this.populateTabsFromPagerAdapter();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user