Commit bafecd11 by konghaorui

升级动态模块

parent db858acd
......@@ -53,7 +53,7 @@ ext {
"m-tests" : "0.0.15.3",
"m-course" : "0.0.34.4",
"m-im" : "0.0.3.7",
"m-dynamic" : "0.0.1.3",
"m-dynamic" : "0.0.1.5",
//-------------- 业务模块 API 层 --------------
......
......@@ -88,7 +88,6 @@ dependencies {
implementation 'com.github.ksoichiro:android-observablescrollview:1.6.0'
implementation 'com.pnikosis:materialish-progress:1.7'
implementation 'com.daimajia.numberprogressbar:library:1.4@aar'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'com.github.faruktoptas:FancyShowCaseView:0.1.1'
kapt rootProject.ext.dependencies["butterknife-compiler"]
api rootProject.ext.dependencies["butterknife"]
......
package com.yidianling.dynamic.trendsDetail;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.os.Build;
import android.support.annotation.AnimatorRes;
import android.support.annotation.DrawableRes;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import com.yidianling.dynamic.R;
/**
* Created by haorui on 2019-12-23.
* Des:
*/
public class CircleIndicator extends LinearLayout {
private final static int DEFAULT_INDICATOR_WIDTH = 5;
private ViewPager mViewpager;
private int mIndicatorMargin = -1;
private int mIndicatorWidth = -1;
private int mIndicatorHeight = -1;
private int mAnimatorResId = R.animator.scale_with_alpha;
private int mAnimatorReverseResId = 0;
private int mIndicatorBackgroundResId = R.drawable.white_radius;
private int mIndicatorUnselectedBackgroundResId = R.drawable.white_radius;
private Animator mAnimatorOut;
private Animator mAnimatorIn;
private Animator mImmediateAnimatorOut;
private Animator mImmediateAnimatorIn;
private int mLastPosition = -1;
public CircleIndicator(Context context) {
super(context);
init(context, null);
}
public CircleIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public CircleIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CircleIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
handleTypedArray(context, attrs);
checkIndicatorConfig(context);
}
private void handleTypedArray(Context context, AttributeSet attrs) {
if (attrs == null) {
return;
}
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator);
mIndicatorWidth =
typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_width, -1);
mIndicatorHeight =
typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_height, -1);
mIndicatorMargin =
typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_margin, -1);
mAnimatorResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_animator,
R.animator.scale_with_alpha);
mAnimatorReverseResId =
typedArray.getResourceId(R.styleable.CircleIndicator_ci_animator_reverse, 0);
mIndicatorBackgroundResId =
typedArray.getResourceId(R.styleable.CircleIndicator_ci_drawable,
R.drawable.white_radius);
mIndicatorUnselectedBackgroundResId =
typedArray.getResourceId(R.styleable.CircleIndicator_ci_drawable_unselected,
mIndicatorBackgroundResId);
int orientation = typedArray.getInt(R.styleable.CircleIndicator_ci_orientation, -1);
setOrientation(orientation == VERTICAL ? VERTICAL : HORIZONTAL);
int gravity = typedArray.getInt(R.styleable.CircleIndicator_ci_gravity, -1);
setGravity(gravity >= 0 ? gravity : Gravity.CENTER);
typedArray.recycle();
}
/**
* Create and configure Indicator in Java code.
*/
public void configureIndicator(int indicatorWidth, int indicatorHeight, int indicatorMargin) {
configureIndicator(indicatorWidth, indicatorHeight, indicatorMargin,
R.animator.scale_with_alpha, 0, R.drawable.white_radius, R.drawable.white_radius);
}
public void configureIndicator(int indicatorWidth, int indicatorHeight, int indicatorMargin,
@AnimatorRes int animatorId, @AnimatorRes int animatorReverseId,
@DrawableRes int indicatorBackgroundId,
@DrawableRes int indicatorUnselectedBackgroundId) {
mIndicatorWidth = indicatorWidth;
mIndicatorHeight = indicatorHeight;
mIndicatorMargin = indicatorMargin;
mAnimatorResId = animatorId;
mAnimatorReverseResId = animatorReverseId;
mIndicatorBackgroundResId = indicatorBackgroundId;
mIndicatorUnselectedBackgroundResId = indicatorUnselectedBackgroundId;
checkIndicatorConfig(getContext());
}
private void checkIndicatorConfig(Context context) {
mIndicatorWidth = (mIndicatorWidth < 0) ? dip2px(DEFAULT_INDICATOR_WIDTH) : mIndicatorWidth;
mIndicatorHeight =
(mIndicatorHeight < 0) ? dip2px(DEFAULT_INDICATOR_WIDTH) : mIndicatorHeight;
mIndicatorMargin =
(mIndicatorMargin < 0) ? dip2px(DEFAULT_INDICATOR_WIDTH) : mIndicatorMargin;
mAnimatorResId = (mAnimatorResId == 0) ? R.animator.scale_with_alpha : mAnimatorResId;
mAnimatorOut = createAnimatorOut(context);
mImmediateAnimatorOut = createAnimatorOut(context);
mImmediateAnimatorOut.setDuration(0);
mAnimatorIn = createAnimatorIn(context);
mImmediateAnimatorIn = createAnimatorIn(context);
mImmediateAnimatorIn.setDuration(0);
mIndicatorBackgroundResId = (mIndicatorBackgroundResId == 0) ? R.drawable.white_radius
: mIndicatorBackgroundResId;
mIndicatorUnselectedBackgroundResId =
(mIndicatorUnselectedBackgroundResId == 0) ? mIndicatorBackgroundResId
: mIndicatorUnselectedBackgroundResId;
}
private Animator createAnimatorOut(Context context) {
return AnimatorInflater.loadAnimator(context, mAnimatorResId);
}
private Animator createAnimatorIn(Context context) {
Animator animatorIn;
if (mAnimatorReverseResId == 0) {
animatorIn = AnimatorInflater.loadAnimator(context, mAnimatorResId);
animatorIn.setInterpolator(new CircleIndicator.ReverseInterpolator());
} else {
animatorIn = AnimatorInflater.loadAnimator(context, mAnimatorReverseResId);
}
return animatorIn;
}
public void setViewPager(ViewPager viewPager) {
mViewpager = viewPager;
if (mViewpager != null && mViewpager.getAdapter() != null) {
mLastPosition = -1;
createIndicators();
mViewpager.removeOnPageChangeListener(mInternalPageChangeListener);
mViewpager.addOnPageChangeListener(mInternalPageChangeListener);
mInternalPageChangeListener.onPageSelected(mViewpager.getCurrentItem());
}
}
private final ViewPager.OnPageChangeListener mInternalPageChangeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override public void onPageSelected(int position) {
if (mViewpager.getAdapter() == null || mViewpager.getAdapter().getCount() <= 0) {
return;
}
if (mAnimatorIn.isRunning()) {
mAnimatorIn.end();
mAnimatorIn.cancel();
}
if (mAnimatorOut.isRunning()) {
mAnimatorOut.end();
mAnimatorOut.cancel();
}
View currentIndicator;
if (mLastPosition >= 0 && (currentIndicator = getChildAt(mLastPosition)) != null) {
currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);
mAnimatorIn.setTarget(currentIndicator);
mAnimatorIn.start();
}
View selectedIndicator = getChildAt(position);
if (selectedIndicator != null) {
selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId);
mAnimatorOut.setTarget(selectedIndicator);
mAnimatorOut.start();
}
mLastPosition = position;
}
@Override public void onPageScrollStateChanged(int state) {
}
};
public DataSetObserver getDataSetObserver() {
return mInternalDataSetObserver;
}
private DataSetObserver mInternalDataSetObserver = new DataSetObserver() {
@Override public void onChanged() {
super.onChanged();
if (mViewpager == null) {
return;
}
int newCount = mViewpager.getAdapter().getCount();
int currentCount = getChildCount();
if (newCount == currentCount) { // No change
return;
} else if (mLastPosition < newCount) {
mLastPosition = mViewpager.getCurrentItem();
} else {
mLastPosition = -1;
}
createIndicators();
}
};
/**
* @deprecated User ViewPager addOnPageChangeListener
*/
@Deprecated public void setOnPageChangeListener(ViewPager.OnPageChangeListener onPageChangeListener) {
if (mViewpager == null) {
throw new NullPointerException("can not find Viewpager , setViewPager first");
}
mViewpager.removeOnPageChangeListener(onPageChangeListener);
mViewpager.addOnPageChangeListener(onPageChangeListener);
}
private void createIndicators() {
removeAllViews();
int count = mViewpager.getAdapter().getCount();
if (count <= 0) {
return;
}
int currentItem = mViewpager.getCurrentItem();
int orientation = getOrientation();
for (int i = 0; i < count; i++) {
if (currentItem == i) {
addIndicator(orientation, mIndicatorBackgroundResId, mImmediateAnimatorOut);
} else {
addIndicator(orientation, mIndicatorUnselectedBackgroundResId,
mImmediateAnimatorIn);
}
}
}
private void addIndicator(int orientation, @DrawableRes int backgroundDrawableId,
Animator animator) {
if (animator.isRunning()) {
animator.end();
animator.cancel();
}
View Indicator = new View(getContext());
Indicator.setBackgroundResource(backgroundDrawableId);
addView(Indicator, mIndicatorWidth, mIndicatorHeight);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) Indicator.getLayoutParams();
if (orientation == HORIZONTAL) {
lp.leftMargin = mIndicatorMargin;
lp.rightMargin = mIndicatorMargin;
} else {
lp.topMargin = mIndicatorMargin;
lp.bottomMargin = mIndicatorMargin;
}
Indicator.setLayoutParams(lp);
animator.setTarget(Indicator);
animator.start();
}
private class ReverseInterpolator implements Interpolator {
@Override public float getInterpolation(float value) {
return Math.abs(1.0f - value);
}
}
public int dip2px(float dpValue) {
final float scale = getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
}
package com.yidianling.dynamic.trendsDetail;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import java.util.List;
/**
* Created by haorui on 2019-12-23.
* Des:
*/
public class SnackbarBehavior extends CoordinatorLayout.Behavior<CircleIndicator> {
public SnackbarBehavior() {
}
public SnackbarBehavior(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
@Override public boolean layoutDependsOn(CoordinatorLayout parent, CircleIndicator child,
View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override public boolean onDependentViewChanged(CoordinatorLayout parent, CircleIndicator child,
View dependency) {
float translationY = getTranslationYForSnackbar(parent, child);
child.setTranslationY(translationY);
return true;
}
private float getTranslationYForSnackbar(CoordinatorLayout parent, CircleIndicator ci) {
float minOffset = 0;
final List<View> dependencies = parent.getDependencies(ci);
for (int i = 0, z = dependencies.size(); i < z; i++) {
final View view = dependencies.get(i);
if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(ci, view)) {
minOffset =
Math.min(minOffset, ViewCompat.getTranslationY(view) - view.getHeight());
}
}
return minOffset;
}
}
\ No newline at end of file
......@@ -100,7 +100,6 @@ import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import me.relex.circleindicator.CircleIndicator;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
......
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime">
<objectAnimator
android:propertyName="alpha"
android:valueType="floatType"
android:valueFrom="0.5"
android:valueTo="1.0"/>
<objectAnimator
android:propertyName="scaleX"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="1.8"/>
<objectAnimator
android:propertyName="scaleY"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="1.8"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@android:color/white"/>
</shape>
\ No newline at end of file
......@@ -387,7 +387,7 @@
android:layout_height="wrap_content"
android:background="@color/dynamic_white" />
<me.relex.circleindicator.CircleIndicator
<com.yidianling.dynamic.trendsDetail.CircleIndicator
android:id="@+id/circle_indicator"
android:layout_width="match_parent"
android:layout_height="28dp"
......
......@@ -64,5 +64,40 @@
<item name="android:backgroundDimEnabled">true</item>
</style>
<declare-styleable name="CircleIndicator"><attr format="dimension" name="ci_width"/><attr format="dimension" name="ci_height"/><attr format="dimension" name="ci_margin"/><attr format="reference" name="ci_animator"/><attr format="reference" name="ci_animator_reverse"/><attr format="reference" name="ci_drawable"/><attr format="reference" name="ci_drawable_unselected"/><attr format="enum" name="ci_orientation">
<enum name="horizontal" value="0"/>
<enum name="vertical" value="1"/>
</attr><attr name="ci_gravity">
<flag name="top" value="0x30"/>
<flag name="bottom" value="0x50"/>
<flag name="left" value="0x03"/>
<flag name="right" value="0x05"/>
<flag name="center_vertical" value="0x10"/>
<flag name="fill_vertical" value="0x70"/>
<flag name="center_horizontal" value="0x01"/>
<flag name="fill_horizontal" value="0x07"/>
<flag name="center" value="0x11"/>
<flag name="fill" value="0x77"/>
<flag name="clip_vertical" value="0x80"/>
<flag name="clip_horizontal" value="0x08"/>
<flag name="start" value="0x00800003"/>
<flag name="end" value="0x00800005"/>
</attr></declare-styleable>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment