[Update]优化摄像头直播交互、UI

This commit is contained in:
chenfufeng
2022-07-26 16:14:34 +08:00
parent ab4a807c59
commit 1d1916da02
29 changed files with 105 additions and 1249 deletions

View File

@@ -168,6 +168,7 @@ ext {
crashreportupgrade : "com.mogo.test:crashreport-upgrade:${CRASHREPORT_UPGRADE_VERSION}",
apm_insight : 'com.volcengine:apm_insight:1.4.5.cn',
apm_insight_crash : 'com.volcengine:apm_insight_crash:1.4.5-rc.3',
cicle_indicator : 'me.relex:circleindicator:2.1.6',
//========================= TTS语音 Maven 版本管理 =========================
ttsbase : "com.mogo.tts:tts-base:${TTS_BASE_VERSION}",

View File

@@ -74,6 +74,7 @@ dependencies {
implementation rootProject.ext.dependencies.mogoami
implementation rootProject.ext.dependencies.android_start_up
implementation rootProject.ext.dependencies.cicle_indicator
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
api rootProject.ext.dependencies.mogoaicloudservicesdk
api rootProject.ext.dependencies.mogocommons

View File

@@ -1,7 +1,6 @@
package com.mogo.eagle.core.function.hmi.ui.camera
import android.content.Context
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.view.View
@@ -13,9 +12,6 @@ import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import com.mogo.eagle.core.utilcode.util.ToastUtils
import com.mogo.eagle.core.widget.indicator.enums.IndicatorOrientation
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.enums.IndicatorStyle
import com.mogo.eagle.core.widget.media.video.SimpleVideoPlayer
import com.mogo.module.common.dialog.BaseFloatDialog
import com.shuyu.gsyvideoplayer.GSYVideoManager
@@ -25,7 +21,6 @@ import com.shuyu.gsyvideoplayer.player.IjkPlayerManager
import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
import kotlinx.android.synthetic.main.road_video_dialog.*
import kotlinx.android.synthetic.main.view_camera_list.view.*
import tv.danmaku.ijk.media.player.IjkMediaPlayer
@@ -37,8 +32,6 @@ class RoadVideoDialog(context: Context) : BaseFloatDialog(context), LifecycleObs
private val TAG = "RoadVideoDialog"
private var mVideoUrl: String = ""
private val gsyVideoOptionBuilder by lazy {
GSYVideoOptionBuilder()
}
@@ -56,14 +49,14 @@ class RoadVideoDialog(context: Context) : BaseFloatDialog(context), LifecycleObs
PorterDuff.Mode.MULTIPLY
)
setCanceledOnTouchOutside(false)
roundLayout.setScrollListener { is2Left ->
roundLayout.setScrollListener { isNextPage ->
/**
* 如果画面向左滚动
*/
val calIndex = if (is2Left) {
curPlayIndex - 1
} else {
val calIndex = if (isNextPage) {
curPlayIndex + 1
} else {
curPlayIndex - 1
}
// 检查数组越界
if (calIndex >= 0 && calIndex < infList.size) {
@@ -71,8 +64,7 @@ class RoadVideoDialog(context: Context) : BaseFloatDialog(context), LifecycleObs
infList[curPlayIndex].ip?.let {
playVideo(it)
}
indicatorView.onPageScrolled(calIndex, 0f, 0)
indicatorView.onPageSelected(calIndex)
indicatorView.animatePageSelected(calIndex)
}
}
roadVideoClose.setOnClickListener {
@@ -109,17 +101,8 @@ class RoadVideoDialog(context: Context) : BaseFloatDialog(context), LifecycleObs
}
private fun initIndicatorView() {
indicatorView.notifyDataChanged(infList.size)
indicatorView.setSlideMode(IndicatorSlideMode.SCALE)
indicatorView.setOrientation(IndicatorOrientation.INDICATOR_HORIZONTAL)
indicatorView.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
indicatorView.setSliderColor(
Color.parseColor("#FFFFFF"), Color.parseColor("#26C5FD"),
Color.parseColor("#26C5FD")
)
indicatorView.setSliderWidth(9f, 54f)
indicatorView.setSliderHeight(9f)
indicatorView.setSliderGap(36f)
curPlayIndex = 0
indicatorView.createIndicators(infList.size, curPlayIndex)
}
private fun initVideoPlayer() {

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<size android:width="16px" android:height="16px" />
<gradient android:startColor="#2972FF" android:endColor="#27C8FF" />
</shape>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<size android:width="16px" android:height="16px" />
<solid android:color="#80FFFFFF" />
</shape>

View File

@@ -27,22 +27,34 @@
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvCameraDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="61px"
android:layout_marginBottom="49px"
android:textColor="@color/v2x_white"
android:textSize="42px"
android:visibility="gone"
/>
</com.mogo.eagle.core.widget.RoundConstraintLayout>
<com.mogo.eagle.core.widget.indicator.IndicatorView
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:vpi_orientation="horizontal"
app:vpi_slide_mode="scale"
app:vpi_slider_checked_color="@color/hmi_traffic_light_red_color_up"
app:vpi_slider_normal_color="@color/hmi_check_keyboard_input_field"
app:vpi_slider_radius="@dimen/dp_20"
app:vpi_style="round_rect"
android:layout_width="1736px"
android:layout_height="32px"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/roundLayout"
android:layout_marginTop="60px"
app:ci_drawable="@drawable/indicator_selected_bg"
app:ci_width="16px"
app:ci_height="16px"
app:ci_gravity="center"
app:ci_drawable_unselected="@drawable/indicator_unselected_bg"
/>
<androidx.core.widget.ContentLoadingProgressBar

View File

@@ -783,8 +783,8 @@ public class AMapCustomView
MakerWithCount marker = new MakerWithCount(getContext());
marker.setCount(count);
marker.measure(View.MeasureSpec.makeMeasureSpec(110, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(108, View.MeasureSpec.EXACTLY));
marker.measure(View.MeasureSpec.makeMeasureSpec(116, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(116, View.MeasureSpec.EXACTLY));
marker.layout(0, 0, marker.getMeasuredWidth(), marker.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(marker.getWidth(), marker.getHeight(), Bitmap.Config.ARGB_8888);
marker.draw(new Canvas(bitmap));

View File

@@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:maxWidth="108px"
android:maxHeight="108px"
android:padding="2px"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

View File

@@ -6,6 +6,7 @@ import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -18,7 +19,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
* desc :
* version: 1.0
*/
public class RoundConstraintLayout extends ConstraintLayout {
public class RoundConstraintLayout extends ConstraintLayout implements GestureDetector.OnGestureListener {
private float roundLayoutRadius = 14f;
private Path roundPath;
@@ -30,6 +31,8 @@ public class RoundConstraintLayout extends ConstraintLayout {
private IScrollListener mScrollListener;
private GestureDetector mDetector;
public RoundConstraintLayout(Context context) {
this(context, null);
}
@@ -52,6 +55,7 @@ public class RoundConstraintLayout extends ConstraintLayout {
setWillNotDraw(false);//如果你继承的是ViewGroup,注意此行,否则draw方法是不会回调的;
roundPath = new Path();
rectF = new RectF();
mDetector = new GestureDetector(getContext(), this);
}
private void setRoundPath() {
@@ -92,25 +96,13 @@ public class RoundConstraintLayout extends ConstraintLayout {
int x = (int) ev.getX();
int y = (int) ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
intercepted = false;
break;
case MotionEvent.ACTION_MOVE:
int deltaX = x - mLastXIntercept;
int deltaY = y - mLastYIntercept;
if (Math.abs(deltaX) > Math.abs(deltaY)) {
intercepted = true;
if (mScrollListener != null) {
// 向左滑动,则向右滚动
mScrollListener.onScroll(x - mLastXIntercept >= 0);
}
} else {
intercepted = false;
}
break;
case MotionEvent.ACTION_UP:
intercepted = false;
break;
default:
break;
}
@@ -119,11 +111,53 @@ public class RoundConstraintLayout extends ConstraintLayout {
return intercepted;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mDetector != null) {
return mDetector.onTouchEvent(event);
} else {
return super.onTouchEvent(event);
}
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e2 != null) {
float deltaX = e2.getX() - (e1 != null ? e1.getX() : 0f);
float deltaY = e2.getY() - (e1 != null ? e1.getY() : 0f);
if (Math.abs(deltaX) > Math.abs(deltaY)) {
if (mScrollListener != null) {
mScrollListener.onScroll(velocityX < 0);
}
}
}
return true;
}
public interface IScrollListener {
/**
*
* @param is2Left : 画面向左滚动
*/
void onScroll(boolean is2Left);
void onScroll(boolean isNextPage);
}
}

View File

@@ -1,68 +0,0 @@
package com.mogo.eagle.core.widget.indicator
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import com.mogo.eagle.core.widget.indicator.annotation.AIndicatorOrientation
import com.mogo.eagle.core.widget.indicator.base.BaseIndicatorView
import com.mogo.eagle.core.widget.indicator.drawer.DrawerProxy
import com.mogo.eagle.core.widget.indicator.enums.IndicatorOrientation
import com.mogo.eagle.core.widget.indicator.option.AttrsController
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
class IndicatorView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : BaseIndicatorView(context, attrs, defStyleAttr) {
private var mDrawerProxy: DrawerProxy
init {
AttrsController.initAttrs(context, attrs, mIndicatorOptions)
mDrawerProxy = DrawerProxy(mIndicatorOptions)
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
mDrawerProxy.onLayout(changed, left, top, right, bottom)
}
override fun onMeasure(
widthMeasureSpec: Int,
heightMeasureSpec: Int
) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val measureResult = mDrawerProxy.onMeasure(widthMeasureSpec, heightMeasureSpec)
setMeasuredDimension(measureResult.measureWidth, measureResult.measureHeight)
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
rotateCanvas(canvas)
mDrawerProxy.onDraw(canvas)
}
override fun setIndicatorOptions(options: IndicatorOptions) {
super.setIndicatorOptions(options)
mDrawerProxy.setIndicatorOptions(options)
}
override fun notifyDataChanged(itemCount:Int) {
mDrawerProxy = DrawerProxy(mIndicatorOptions)
super.notifyDataChanged(itemCount)
}
private fun rotateCanvas(canvas: Canvas) {
if (mIndicatorOptions.orientation == IndicatorOrientation.INDICATOR_VERTICAL) {
canvas.rotate(90f, width / 2f, width / 2f)
} else if (mIndicatorOptions.orientation == IndicatorOrientation.INDICATOR_RTL) {
canvas.rotate(180f, width / 2f, height / 2f)
}
}
fun setOrientation(@AIndicatorOrientation orientation: Int) {
mIndicatorOptions.orientation = orientation;
}
}

View File

@@ -1,17 +0,0 @@
package com.mogo.eagle.core.widget.indicator.annotation
import androidx.annotation.IntDef
import com.mogo.eagle.core.widget.indicator.enums.IndicatorOrientation
/**
*
* @author zhangpan
* @date 2021/1/21
*/
@IntDef(
IndicatorOrientation.INDICATOR_HORIZONTAL, IndicatorOrientation.INDICATOR_VERTICAL,
IndicatorOrientation.INDICATOR_RTL
)
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
annotation class AIndicatorOrientation()

View File

@@ -1,19 +0,0 @@
package com.mogo.eagle.core.widget.indicator.annotation
import androidx.annotation.IntDef
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode.Companion.COLOR
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode.Companion.NORMAL
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode.Companion.SCALE
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode.Companion.SMOOTH
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode.Companion.WORM
/**
* <pre>
* Created by zhangpan on 2019-10-18.
* Description:
</pre> *
*/
@IntDef(NORMAL, SMOOTH, WORM, COLOR, SCALE)
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
annotation class AIndicatorSlideMode

View File

@@ -1,15 +0,0 @@
package com.mogo.eagle.core.widget.indicator.annotation
import androidx.annotation.IntDef
import com.mogo.eagle.core.widget.indicator.enums.IndicatorStyle
/**
* <pre>
* Created by zhangpan on 2019-10-18.
* Description:
</pre> *
*/
@IntDef(IndicatorStyle.CIRCLE, IndicatorStyle.DASH, IndicatorStyle.ROUND_RECT)
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
annotation class AIndicatorStyle

View File

@@ -1,204 +0,0 @@
package com.mogo.eagle.core.widget.indicator.base
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.annotation.ColorInt
import androidx.recyclerview.widget.RecyclerView
import com.mogo.eagle.core.widget.indicator.annotation.AIndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.annotation.AIndicatorStyle
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhangpan on 2019-09-04.
* Description:IndicatorView基类处理了页面滑动。
* </pre>
*/
@Suppress("UNUSED")
open class BaseIndicatorView constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : View(context, attrs, defStyleAttr), IIndicator {
var mIndicatorOptions: IndicatorOptions
private var recyclerView: RecyclerView? = null
init {
mIndicatorOptions = IndicatorOptions()
}
fun setPageSize(pageSize: Int): BaseIndicatorView {
mIndicatorOptions.pageSize = pageSize
return this
}
// 页面选定
fun onPageSelected(position: Int) {
if (getSlideMode() == IndicatorSlideMode.NORMAL) {
setCurrentPosition(position)
setSlideProgress(0f)
invalidate()
}
}
// 滚动距离
fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
if (getSlideMode() != IndicatorSlideMode.NORMAL && getPageSize() > 1) {
scrollSlider(position, positionOffset)
invalidate()
}
}
private fun scrollSlider(position: Int, positionOffset: Float) {
if (mIndicatorOptions.slideMode == IndicatorSlideMode.SCALE
|| mIndicatorOptions.slideMode == IndicatorSlideMode.COLOR) {
setCurrentPosition(position)
setSlideProgress(positionOffset)
} else {
if (position % getPageSize() == getPageSize() - 1) { // 最后一个页面与第一个页面
if (positionOffset < 0.5) {
setCurrentPosition(position)
setSlideProgress(0f)
} else {
setCurrentPosition(0)
setSlideProgress(0f)
}
} else { // 中间页面
setCurrentPosition(position)
setSlideProgress(positionOffset)
}
}
}
override fun notifyDataChanged(itemCount: Int) {
setPageSize(itemCount)
requestLayout()
invalidate()
}
private fun setupViewPager() {
}
fun getNormalSlideWidth(): Float {
return mIndicatorOptions.normalSliderWidth
}
fun setNormalSlideWidth(normalSliderWidth: Float) {
mIndicatorOptions.normalSliderWidth = normalSliderWidth
}
fun getCheckedSlideWidth(): Float {
return mIndicatorOptions.checkedSliderWidth
}
fun setCheckedSlideWidth(checkedSliderWidth: Float) {
mIndicatorOptions.checkedSliderWidth = checkedSliderWidth
}
val checkedSliderWidth: Float
get() = mIndicatorOptions.checkedSliderWidth
fun setCurrentPosition(currentPosition: Int) {
mIndicatorOptions.currentPosition = currentPosition
}
fun getCurrentPosition(): Int {
return mIndicatorOptions.currentPosition
}
fun getIndicatorGap(indicatorGap: Float) {
mIndicatorOptions.sliderGap = indicatorGap
}
fun setIndicatorGap(indicatorGap: Float) {
mIndicatorOptions.sliderGap = indicatorGap
}
fun setCheckedColor(@ColorInt normalColor: Int) {
mIndicatorOptions.checkedSliderColor = normalColor
}
fun getCheckedColor(): Int {
return mIndicatorOptions.checkedSliderColor
}
fun setNormalColor(@ColorInt normalColor: Int) {
mIndicatorOptions.normalSliderColor = normalColor
}
fun getSlideProgress(): Float {
return mIndicatorOptions.slideProgress
}
fun setSlideProgress(slideProgress: Float) {
mIndicatorOptions.slideProgress = slideProgress
}
fun getPageSize(): Int {
return mIndicatorOptions.pageSize
}
fun setSliderColor(
@ColorInt normalColor: Int,
@ColorInt selectedColor: Int,
@ColorInt selectedEndColor: Int
): BaseIndicatorView {
mIndicatorOptions.setSliderColor(normalColor, selectedColor,selectedEndColor)
return this
}
fun setSliderWidth(sliderWidth: Float): BaseIndicatorView {
mIndicatorOptions.setSliderWidth(sliderWidth)
return this
}
fun setSliderWidth(
normalSliderWidth: Float,
selectedSliderWidth: Float
): BaseIndicatorView {
mIndicatorOptions.setSliderWidth(normalSliderWidth, selectedSliderWidth)
return this
}
fun setSliderGap(sliderGap: Float): BaseIndicatorView {
mIndicatorOptions.sliderGap = sliderGap
return this
}
fun getSlideMode(): Int {
return mIndicatorOptions.slideMode
}
fun setSlideMode(@AIndicatorSlideMode slideMode: Int): BaseIndicatorView {
mIndicatorOptions.slideMode = slideMode
return this
}
fun setIndicatorStyle(@AIndicatorStyle indicatorStyle: Int): BaseIndicatorView {
mIndicatorOptions.indicatorStyle = indicatorStyle
return this
}
fun setSliderHeight(sliderHeight: Float): BaseIndicatorView {
mIndicatorOptions.sliderHeight = sliderHeight
return this
}
fun showIndicatorWhenOneItem(showIndicatorWhenOneItem: Boolean) {
mIndicatorOptions.showIndicatorOneItem = showIndicatorWhenOneItem
}
fun onPageScrollStateChanged(state: Int) {
}
override fun setIndicatorOptions(options: IndicatorOptions) {
mIndicatorOptions = options
}
}

View File

@@ -1,17 +0,0 @@
package com.mogo.eagle.core.widget.indicator.base
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhangpan on 2019-09-02.
* Description:
</pre> *
*/
interface IIndicator {
fun notifyDataChanged(itemCount:Int)
fun setIndicatorOptions(options: IndicatorOptions)
}

View File

@@ -1,94 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.animation.ArgbEvaluator
import android.graphics.Paint
import com.mogo.eagle.core.widget.indicator.enums.IndicatorOrientation
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhpan on 2019/11/23.
* Description:
</pre> *
*/
abstract class BaseDrawer internal constructor(internal var mIndicatorOptions: IndicatorOptions) :
IDrawer {
private val mMeasureResult: MeasureResult
internal var maxWidth: Float = 0.toFloat()
internal var minWidth: Float = 0.toFloat()
internal var mPaint: Paint = Paint()
internal var argbEvaluator: ArgbEvaluator? = null
companion object {
const val INDICATOR_PADDING_ADDITION = 6
const val INDICATOR_PADDING = 3
}
protected val isWidthEquals: Boolean
get() = mIndicatorOptions.normalSliderWidth == mIndicatorOptions.checkedSliderWidth
init {
mPaint.isAntiAlias = true
mMeasureResult = MeasureResult()
if (mIndicatorOptions.slideMode == IndicatorSlideMode.SCALE
|| mIndicatorOptions.slideMode == IndicatorSlideMode.COLOR
) {
argbEvaluator = ArgbEvaluator()
}
}
override fun onMeasure(
widthMeasureSpec: Int,
heightMeasureSpec: Int
): MeasureResult {
maxWidth =
mIndicatorOptions.normalSliderWidth.coerceAtLeast(mIndicatorOptions.checkedSliderWidth)
minWidth =
mIndicatorOptions.normalSliderWidth.coerceAtMost(mIndicatorOptions.checkedSliderWidth)
if (mIndicatorOptions.orientation == IndicatorOrientation.INDICATOR_VERTICAL) {
mMeasureResult.setMeasureResult(measureHeight(), measureWidth())
} else {
mMeasureResult.setMeasureResult(measureWidth(), measureHeight())
}
return mMeasureResult
}
protected open fun measureHeight(): Int {
return mIndicatorOptions.sliderHeight.toInt() + INDICATOR_PADDING
}
private fun measureWidth(): Int {
val pageSize = mIndicatorOptions.pageSize
val indicatorGap = mIndicatorOptions.sliderGap
return ((pageSize - 1) * indicatorGap + maxWidth + (pageSize - 1) * minWidth).toInt() + INDICATOR_PADDING_ADDITION
}
override fun onLayout(
changed: Boolean,
left: Int,
top: Int,
right: Int,
bottom: Int
) {
}
inner class MeasureResult {
var measureWidth: Int = 0
internal set
var measureHeight: Int = 0
internal set
internal fun setMeasureResult(
measureWidth: Int,
measureHeight: Int
) {
this.measureWidth = measureWidth
this.measureHeight = measureHeight
}
}
}

View File

@@ -1,157 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.graphics.Canvas
import android.graphics.RectF
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
import com.mogo.eagle.core.widget.indicator.utils.IndicatorUtils
/**
* <pre>
* Created by zhpan on 2019/11/23.
* Description: Circle Indicator drawer.
</pre> *
*/
class CircleDrawer internal constructor(indicatorOptions: IndicatorOptions) : BaseDrawer(
indicatorOptions
) {
private val rectF = RectF()
override fun measureHeight(): Int {
return maxWidth.toInt() + INDICATOR_PADDING_ADDITION
}
override fun onDraw(canvas: Canvas) {
val pageSize = mIndicatorOptions.pageSize
if (pageSize > 1 || mIndicatorOptions.showIndicatorOneItem && pageSize == 1) {
drawNormal(canvas)
drawSlider(canvas)
}
}
private fun drawNormal(canvas: Canvas) {
val normalIndicatorWidth = mIndicatorOptions.normalSliderWidth
mPaint.color = mIndicatorOptions.normalSliderColor
for (i in 0 until mIndicatorOptions.pageSize) {
val coordinateX = IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, i)
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
drawCircle(canvas, coordinateX, coordinateY, normalIndicatorWidth / 2)
}
}
private fun drawSlider(canvas: Canvas) {
mPaint.color = mIndicatorOptions.checkedSliderColor
when (mIndicatorOptions.slideMode) {
IndicatorSlideMode.NORMAL, IndicatorSlideMode.SMOOTH -> drawCircleSlider(canvas)
IndicatorSlideMode.WORM -> drawWormSlider(canvas)
IndicatorSlideMode.SCALE -> drawScaleSlider(canvas)
IndicatorSlideMode.COLOR -> drawColor(canvas)
}
}
private fun drawColor(canvas: Canvas) {
val currentPosition = mIndicatorOptions.currentPosition
val slideProgress = mIndicatorOptions.slideProgress
val coordinateX = IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
var evaluate = argbEvaluator?.evaluate(
slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = (evaluate as Int)
drawCircle(canvas, coordinateX, coordinateY, mIndicatorOptions.normalSliderWidth / 2)
// 绘制可循环的ViewPager指示器渐变
evaluate = argbEvaluator?.evaluate(
1 - slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = evaluate as Int
val nextCoordinateX = if (currentPosition == mIndicatorOptions.pageSize - 1) {
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, 0)
} else {
coordinateX + mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
}
drawCircle(canvas, nextCoordinateX, coordinateY, mIndicatorOptions.checkedSliderWidth / 2)
}
private fun drawScaleSlider(canvas: Canvas) {
val currentPosition = mIndicatorOptions.currentPosition
val slideProgress = mIndicatorOptions.slideProgress
val coordinateX = IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
if (slideProgress < 1) {
val evaluate = argbEvaluator?.evaluate(
slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = (evaluate as Int)
val radius =
mIndicatorOptions.checkedSliderWidth / 2 - (mIndicatorOptions.checkedSliderWidth / 2 - mIndicatorOptions.normalSliderWidth / 2) * slideProgress
drawCircle(canvas, coordinateX, coordinateY, radius)
}
if (currentPosition == mIndicatorOptions.pageSize - 1) {
val evaluate = argbEvaluator?.evaluate(
slideProgress, mIndicatorOptions.normalSliderColor, mIndicatorOptions.checkedSliderColor
)
mPaint.color = evaluate as Int
val nextCoordinateX = maxWidth / 2
val nextRadius = minWidth / 2 + (maxWidth / 2 - minWidth / 2) * (slideProgress)
drawCircle(canvas, nextCoordinateX, coordinateY, nextRadius)
} else {
if (slideProgress > 0) {
val evaluate = argbEvaluator?.evaluate(
slideProgress, mIndicatorOptions.normalSliderColor, mIndicatorOptions.checkedSliderColor
)
mPaint.color = evaluate as Int
val nextCoordinateX =
coordinateX + mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
val nextRadius =
mIndicatorOptions.normalSliderWidth / 2 + (mIndicatorOptions.checkedSliderWidth / 2 - mIndicatorOptions.normalSliderWidth / 2) * slideProgress
drawCircle(canvas, nextCoordinateX, coordinateY, nextRadius)
}
}
}
private fun drawCircleSlider(canvas: Canvas) {
val currentPosition = mIndicatorOptions.currentPosition
val startCoordinateX =
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
val endCoordinateX = IndicatorUtils.getCoordinateX(
mIndicatorOptions, maxWidth, (currentPosition + 1) % mIndicatorOptions.pageSize
)
val coordinateX =
startCoordinateX + (endCoordinateX - startCoordinateX) * mIndicatorOptions.slideProgress
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
val radius = mIndicatorOptions.checkedSliderWidth / 2
drawCircle(canvas, coordinateX, coordinateY, radius)
}
private fun drawWormSlider(canvas: Canvas) {
val sliderHeight = mIndicatorOptions.normalSliderWidth
val slideProgress = mIndicatorOptions.slideProgress
val currentPosition = mIndicatorOptions.currentPosition
val distance = mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
val startCoordinateX =
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
val left = startCoordinateX + (distance * (slideProgress - 0.5f) * 2.0f).coerceAtLeast(
0f
) - mIndicatorOptions.normalSliderWidth / 2 + INDICATOR_PADDING
val right = startCoordinateX + (distance * slideProgress * 2f).coerceAtMost(
distance
) + mIndicatorOptions.normalSliderWidth / 2 + INDICATOR_PADDING
rectF.set(left, INDICATOR_PADDING.toFloat(), right, sliderHeight + INDICATOR_PADDING)
canvas.drawRoundRect(rectF, sliderHeight, sliderHeight, mPaint)
}
private fun drawCircle(
canvas: Canvas,
coordinateX: Float,
coordinateY: Float,
radius: Float
) {
canvas.drawCircle(
coordinateX + INDICATOR_PADDING, coordinateY + INDICATOR_PADDING, radius, mPaint
)
}
}

View File

@@ -1,20 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.graphics.Canvas
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhpan on 2019/11/23.
* Description: Dash Indicator Drawer.
</pre> *
*/
class DashDrawer internal constructor(indicatorOptions: IndicatorOptions) : RectDrawer(
indicatorOptions
) {
override fun drawDash(canvas: Canvas) {
canvas.drawRect(mRectF, mPaint)
}
}

View File

@@ -1,20 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import com.mogo.eagle.core.widget.indicator.enums.IndicatorStyle
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhpan on 2019/11/24.
* Description: Indicator Drawer Factory.
</pre> *
*/
internal object DrawerFactory {
fun createDrawer(indicatorOptions: IndicatorOptions): IDrawer {
return when (indicatorOptions.indicatorStyle) {
IndicatorStyle.DASH -> DashDrawer(indicatorOptions)
IndicatorStyle.ROUND_RECT -> RoundRectDrawer(indicatorOptions)
else -> CircleDrawer(indicatorOptions)
}
}
}

View File

@@ -1,48 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.graphics.Canvas
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhpan on 2019/11/23.
* Description: Indicator Drawer Proxy.
</pre> *
*/
class DrawerProxy(indicatorOptions: IndicatorOptions) : IDrawer {
private lateinit var mIDrawer: IDrawer
init {
init(indicatorOptions)
}
private fun init(indicatorOptions: IndicatorOptions) {
mIDrawer = DrawerFactory.createDrawer(indicatorOptions)
}
override fun onLayout(
changed: Boolean,
left: Int,
top: Int,
right: Int,
bottom: Int
) {
}
override fun onMeasure(
widthMeasureSpec: Int,
heightMeasureSpec: Int
): BaseDrawer.MeasureResult {
return mIDrawer.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
override fun onDraw(canvas: Canvas) {
mIDrawer.onDraw(canvas)
}
fun setIndicatorOptions(indicatorOptions: IndicatorOptions) {
init(indicatorOptions)
}
}

View File

@@ -1,28 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.graphics.Canvas
import com.mogo.eagle.core.widget.indicator.drawer.BaseDrawer
/**
* <pre>
* Created by zhpan on 2019/11/23.
* Description:
</pre> *
*/
interface IDrawer {
fun onLayout(
changed: Boolean,
left: Int,
top: Int,
right: Int,
bottom: Int
)
fun onMeasure(
widthMeasureSpec: Int,
heightMeasureSpec: Int
): BaseDrawer.MeasureResult
fun onDraw(canvas: Canvas)
}

View File

@@ -1,220 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.graphics.*
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
import com.mogo.eagle.core.widget.indicator.utils.IndicatorUtils
/**
* <pre>
* Created by zhpan on 2020/1/17.
* Description:
</pre> *
*/
open class RectDrawer internal constructor(indicatorOptions: IndicatorOptions) : BaseDrawer(
indicatorOptions
) {
internal var mRectF: RectF = RectF()
override fun onDraw(canvas: Canvas) {
val pageSize = mIndicatorOptions.pageSize
if (pageSize > 1 || mIndicatorOptions.showIndicatorOneItem && pageSize == 1) {
if (isWidthEquals && mIndicatorOptions.slideMode != IndicatorSlideMode.NORMAL) {
drawUncheckedSlider(canvas, pageSize)
drawCheckedSlider(canvas)
} else { // 单独处理normalWidth与checkedWidth不一致的情况
if (mIndicatorOptions.slideMode == IndicatorSlideMode.SCALE) {
for (i in 0 until pageSize) {
drawScaleSlider(canvas, i)
}
} else {
drawInequalitySlider(canvas, pageSize)
}
}
}
}
private fun drawScaleSlider(
canvas: Canvas,
i: Int
) {
val checkedColor = mIndicatorOptions.checkedSliderColor
val indicatorGap = mIndicatorOptions.sliderGap
val sliderHeight = mIndicatorOptions.sliderHeight
val currentPosition = mIndicatorOptions.currentPosition
val normalWidth = mIndicatorOptions.normalSliderWidth
val checkedWidth = mIndicatorOptions.checkedSliderWidth
when {
i < currentPosition -> {
mPaint.color = mIndicatorOptions.normalSliderColor
val left: Float = if (currentPosition == mIndicatorOptions.pageSize - 1) {
(i * normalWidth + i * indicatorGap) + (checkedWidth - normalWidth) * mIndicatorOptions.slideProgress
} else {
(i * normalWidth + i * indicatorGap)
}
mRectF.set(left, 0f, left + normalWidth, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
}
i == currentPosition -> {
mPaint.color = checkedColor
val slideProgress = mIndicatorOptions.slideProgress
if (currentPosition == mIndicatorOptions.pageSize - 1) {
val evaluate = argbEvaluator?.evaluate(
slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = (evaluate as Int)
val right =
(mIndicatorOptions.pageSize - 1) * (normalWidth + mIndicatorOptions.sliderGap) + checkedWidth
val left = right - checkedWidth + (checkedWidth - normalWidth) * (slideProgress)
mRectF.set(left, 0f, right, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
} else {
if (slideProgress < 1) {
val evaluate = argbEvaluator?.evaluate(
slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = (evaluate as Int)
val left = i * normalWidth + i * indicatorGap
val right = left + normalWidth + (checkedWidth - normalWidth) * (1 - slideProgress)
mRectF.set(left, 0f, right, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
}
}
if (currentPosition == mIndicatorOptions.pageSize - 1) {
if (slideProgress > 0) {
val evaluate = argbEvaluator?.evaluate(
1 - slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = evaluate as Int
val left = 0f
val right = left + normalWidth + (checkedWidth - normalWidth) * slideProgress
mRectF.set(left, 0f, right, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
}
} else {
if (slideProgress > 0) {
val evaluate = argbEvaluator?.evaluate(
1 - slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = evaluate as Int
val right =
i * normalWidth + i * indicatorGap + normalWidth + (indicatorGap + checkedWidth)
val left = right - (normalWidth) - (checkedWidth - normalWidth) * (slideProgress)
mRectF.set(left, 0f, right, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
}
}
}
else -> {
if ((currentPosition + 1 != i || mIndicatorOptions.slideProgress == 0f)) { // 避免多余绘制
mPaint.color = mIndicatorOptions.normalSliderColor
val left = i * minWidth + i * indicatorGap + (checkedWidth - minWidth)
mRectF.set(left, 0f, left + minWidth, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,false)
}
}
}
}
private fun drawUncheckedSlider(
canvas: Canvas,
pageSize: Int
) {
for (i in 0 until pageSize) {
mPaint.color = mIndicatorOptions.normalSliderColor
val left = i * maxWidth + i * +mIndicatorOptions.sliderGap + (maxWidth - minWidth)
mRectF.set(left, 0f, left + minWidth, mIndicatorOptions.sliderHeight)
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
}
}
private fun drawInequalitySlider(
canvas: Canvas,
pageSize: Int
) {
var left = 0f
for (i in 0 until pageSize) {
val sliderWidth = (if (i == mIndicatorOptions.currentPosition) maxWidth else minWidth)
mPaint.color =
if (i == mIndicatorOptions.currentPosition) mIndicatorOptions.checkedSliderColor else mIndicatorOptions.normalSliderColor
mRectF.set(left, 0f, left + sliderWidth, mIndicatorOptions.sliderHeight)
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
left += sliderWidth + mIndicatorOptions.sliderGap
}
}
private fun drawCheckedSlider(canvas: Canvas) {
mPaint.color = mIndicatorOptions.checkedSliderColor
when (mIndicatorOptions.slideMode) {
IndicatorSlideMode.SMOOTH -> drawSmoothSlider(canvas)
IndicatorSlideMode.WORM -> drawWormSlider(canvas)
IndicatorSlideMode.COLOR -> drawColorSlider(canvas)
}
}
private fun drawColorSlider(canvas: Canvas) {
val currentPosition = mIndicatorOptions.currentPosition
val slideProgress = mIndicatorOptions.slideProgress
val left = currentPosition * minWidth + currentPosition * mIndicatorOptions.sliderGap
if (slideProgress < 0.99) {
val evaluate = argbEvaluator?.evaluate(
slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = (evaluate as Int)
mRectF.set(left, 0f, left + minWidth, mIndicatorOptions.sliderHeight)
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
}
var nextSliderLeft = left + mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
if (currentPosition == mIndicatorOptions.pageSize - 1) {
nextSliderLeft = 0f
}
val evaluate = argbEvaluator?.evaluate(
1 - slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
)
mPaint.color = evaluate as Int
mRectF.set(nextSliderLeft, 0f, nextSliderLeft + minWidth, mIndicatorOptions.sliderHeight)
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
}
private fun drawWormSlider(canvas: Canvas) {
val sliderHeight = mIndicatorOptions.sliderHeight
val slideProgress = mIndicatorOptions.slideProgress
val currentPosition = mIndicatorOptions.currentPosition
val distance = mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
val startCoordinateX =
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
val left = startCoordinateX + (distance * (slideProgress - 0.5f) * 2.0f).coerceAtLeast(
0f
) - mIndicatorOptions.normalSliderWidth / 2
val right = startCoordinateX + (distance * slideProgress * 2f).coerceAtMost(
distance
) + mIndicatorOptions.normalSliderWidth / 2
mRectF.set(left, 0f, right, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,false)
}
private fun drawSmoothSlider(canvas: Canvas) {
val currentPosition = mIndicatorOptions.currentPosition
val indicatorGap = mIndicatorOptions.sliderGap
val sliderHeight = mIndicatorOptions.sliderHeight
val left =
currentPosition * maxWidth + currentPosition * +indicatorGap + (maxWidth + indicatorGap) * mIndicatorOptions.slideProgress
mRectF.set(left, 0f, left + maxWidth, sliderHeight)
drawRoundRect(canvas, sliderHeight, sliderHeight,false)
}
protected open fun drawRoundRect(
canvas: Canvas,
rx: Float,
ry: Float,
isWidth:Boolean
) {
drawDash(canvas)
}
protected open fun drawDash(canvas: Canvas) {}
}

View File

@@ -1,38 +0,0 @@
package com.mogo.eagle.core.widget.indicator.drawer
import android.graphics.Canvas
import android.graphics.LinearGradient
import android.graphics.Shader
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhpan on 2019/11/26.
* Description:
</pre> *
*/
class RoundRectDrawer internal constructor(val indicatorOptions: IndicatorOptions) : RectDrawer(
indicatorOptions
) {
override fun drawRoundRect(canvas: Canvas, rx: Float, ry: Float, isWidth: Boolean) {
if(isWidth) {
val linearGradient =
LinearGradient(
mRectF.left,
(mRectF.bottom - mRectF.top) / 2,
mRectF.right,
(mRectF.bottom - mRectF.top) / 2,
indicatorOptions.checkedSliderColor,
indicatorOptions.checkedEndSliderColor,
Shader.TileMode.CLAMP
)
mPaint.shader = linearGradient
}else{
mPaint.color = indicatorOptions.normalSliderColor
mPaint.shader = null
}
canvas.drawRoundRect(mRectF, rx, ry, mPaint)
}
}

View File

@@ -1,16 +0,0 @@
package com.mogo.eagle.core.widget.indicator.enums
import android.widget.LinearLayout
/**
*
* @author zhangpan
* @date 2021/1/21
*/
class IndicatorOrientation {
companion object {
const val INDICATOR_HORIZONTAL = LinearLayout.HORIZONTAL
const val INDICATOR_VERTICAL = LinearLayout.VERTICAL
const val INDICATOR_RTL = 3
}
}

View File

@@ -1,17 +0,0 @@
package com.mogo.eagle.core.widget.indicator.enums
/**
* <pre>
* Created by zhangpan on 2019-10-18.
* Description:
</pre> *
*/
interface IndicatorSlideMode {
companion object {
const val NORMAL = 0
const val SMOOTH = 2
const val WORM = 3
const val SCALE = 4
const val COLOR = 5
}
}

View File

@@ -1,15 +0,0 @@
package com.mogo.eagle.core.widget.indicator.enums
/**
* <pre>
* Created by zhangpan on 2019-10-18.
* Description:
</pre> *
*/
interface IndicatorStyle {
companion object {
const val CIRCLE = 0
const val DASH = 1 shl 1
const val ROUND_RECT = 1 shl 2
}
}

View File

@@ -1,38 +0,0 @@
package com.mogo.eagle.core.widget.indicator.option;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mogo.eagle.core.widget.R;
import com.mogo.eagle.core.widget.indicator.utils.IndicatorUtils;
public class AttrsController {
public static void initAttrs(@NonNull Context context, @Nullable AttributeSet attrs,
IndicatorOptions indicatorOptions) {
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IndicatorView);
int indicatorSlideMode = typedArray.getInt(R.styleable.IndicatorView_vpi_slide_mode, 0);
int indicatorStyle = typedArray.getInt(R.styleable.IndicatorView_vpi_style, 0);
int checkedColor = typedArray.getColor(R.styleable.IndicatorView_vpi_slider_checked_color,
Color.parseColor("#6C6D72"));
int normalColor = typedArray.getColor(R.styleable.IndicatorView_vpi_slider_normal_color,
Color.parseColor("#8C18171C"));
int orientation = typedArray.getInt(R.styleable.IndicatorView_vpi_orientation, 0);
float radius = typedArray.getDimension(R.styleable.IndicatorView_vpi_slider_radius,
IndicatorUtils.dp2px(8));
indicatorOptions.setCheckedColor(checkedColor);
indicatorOptions.setNormalSliderColor(normalColor);
indicatorOptions.setOrientation(orientation);
indicatorOptions.setIndicatorStyle(indicatorStyle);
indicatorOptions.setSlideMode(indicatorSlideMode);
indicatorOptions.setSliderWidth(radius * 2, radius * 2);
typedArray.recycle();
}
}
}

View File

@@ -1,114 +0,0 @@
package com.mogo.eagle.core.widget.indicator.option
import android.graphics.Color
import com.mogo.eagle.core.widget.indicator.annotation.AIndicatorOrientation
import com.mogo.eagle.core.widget.indicator.annotation.AIndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.annotation.AIndicatorStyle
import com.mogo.eagle.core.widget.indicator.enums.IndicatorOrientation
import com.mogo.eagle.core.widget.indicator.enums.IndicatorSlideMode
import com.mogo.eagle.core.widget.indicator.utils.IndicatorUtils
/**
* <pre>
* Created by zhpan on 2019/11/20.
* Description:Indicator的配置参数
</pre> *
*/
class IndicatorOptions {
@AIndicatorOrientation
var orientation = IndicatorOrientation.INDICATOR_HORIZONTAL
@AIndicatorStyle
var indicatorStyle: Int = 0
/**
* Indicator滑动模式目前仅支持两种
*
* @see IndicatorSlideMode.NORMAL
*
* @see IndicatorSlideMode.SMOOTH
*/
@AIndicatorSlideMode
var slideMode: Int = 0
/**
* 页面size
*/
var pageSize: Int = 0
/**
* 未选中时Indicator颜色
*/
var normalSliderColor: Int = 0
/**
* 选中时Indicator颜色
*/
var checkedSliderColor: Int = 0
/**
* 选中时IndicatorEnd颜色
*/
var checkedEndSliderColor: Int = 0
/**
* Indicator间距
*/
var sliderGap: Float = 0f
var sliderHeight: Float = 0f
get() = if (field > 0) field else normalSliderWidth / 2
var normalSliderWidth: Float = 0f
var checkedSliderWidth: Float = 0f
/**
* 指示器当前位置
*/
var currentPosition: Int = 0
/**
* 从一个点滑动到另一个点的进度
*/
var slideProgress: Float = 0f
var showIndicatorOneItem: Boolean = false
init {
normalSliderWidth = IndicatorUtils.dp2px(8f)
.toFloat()
checkedSliderWidth = normalSliderWidth
sliderGap = normalSliderWidth
normalSliderColor = Color.parseColor("#8C18171C")
checkedSliderColor = Color.parseColor("#8C6C6D72")
slideMode = IndicatorSlideMode.NORMAL
}
fun setCheckedColor(checkedColor: Int) {
this.checkedSliderColor = checkedColor
}
fun setSliderWidth(
normalIndicatorWidth: Float,
checkedIndicatorWidth: Float
) {
this.normalSliderWidth = normalIndicatorWidth
this.checkedSliderWidth = checkedIndicatorWidth
}
fun setSliderWidth(sliderWidth: Float) {
setSliderWidth(sliderWidth, sliderWidth)
}
fun setSliderColor(
normalColor: Int,
checkedColor: Int,
selectedEndColor: Int
) {
this.normalSliderColor = normalColor
this.checkedSliderColor = checkedColor
this.checkedEndSliderColor = selectedEndColor
}
}

View File

@@ -1,31 +0,0 @@
package com.mogo.eagle.core.widget.indicator.utils
import android.content.res.Resources
import com.mogo.eagle.core.widget.indicator.option.IndicatorOptions
/**
* <pre>
* Created by zhangpan on 2020-01-20.
* Description:
</pre> *
*/
object IndicatorUtils {
@JvmStatic
fun dp2px(dpValue: Float): Int {
return (0.5f + dpValue * Resources.getSystem().displayMetrics.density).toInt()
}
fun getCoordinateX(
indicatorOptions: IndicatorOptions,
maxDiameter: Float,
index: Int
): Float {
val normalIndicatorWidth = indicatorOptions.normalSliderWidth
return maxDiameter / 2 + (normalIndicatorWidth + indicatorOptions.sliderGap) * index
}
fun getCoordinateY(maxDiameter: Float): Float {
return maxDiameter / 2
}
}