diff --git a/config/repository.gradle b/config/repository.gradle index 57b7e11..c21208a 100644 --- a/config/repository.gradle +++ b/config/repository.gradle @@ -54,7 +54,7 @@ static Repository innerNewRepository() { ] def anko_version = '0.10.7' - def kotlin_version = '1.3.11' + def kotlin_version = '1.3.41' def kotlinLibraries = [ //Kotlin diff --git a/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt b/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt index b0cef5f..a60a980 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt +++ b/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt @@ -98,7 +98,7 @@ fun FragmentManager.popBackTo(flag: String, immediate: Boolean = false) { if (immediate) { popBackStackImmediate(flag, 0) } else { - popBackStack(flag,0) + popBackStack(flag, 0) } } @@ -254,7 +254,7 @@ class EnhanceFragmentTransaction constructor( fragmentTransaction.add(confirmLayoutId(containerId), fragment, nonnullTag) if (transition) { //set a transition - setTransitionOpen() + setOpeningTransition() } return this } @@ -271,7 +271,7 @@ class EnhanceFragmentTransaction constructor( fragmentTransaction.replace(confirmLayoutId(containerId), fragment, nonnullTag) //set a transition if (transition) { - setTransitionOpen() + setOpeningTransition() } return this } @@ -298,7 +298,7 @@ class EnhanceFragmentTransaction constructor( fun replaceWithDefaultContainer(fragment: Fragment, tag: String? = null, transition: Boolean = true): FragmentTransaction { val nonnullTag = (tag ?: fragment.javaClassName()) if (transition) { - setTransitionOpen() + setOpeningTransition() } return fragmentTransaction.replace(FragmentConfig.defaultContainerId(), fragment, nonnullTag) } @@ -319,15 +319,16 @@ class EnhanceFragmentTransaction constructor( } } - fun setTransitionOpen(): FragmentTransaction { + @Suppress + fun setOpeningTransition(): FragmentTransaction { return fragmentTransaction.setTransition(TRANSIT_FRAGMENT_OPEN) } - fun setTransitionClose(): FragmentTransaction { + fun setClosingTransition(): FragmentTransaction { return fragmentTransaction.setTransition(TRANSIT_FRAGMENT_CLOSE) } - fun setTransitionFade(): FragmentTransaction { + fun setFadingTransition(): FragmentTransaction { return fragmentTransaction.setTransition(TRANSIT_FRAGMENT_FADE) } diff --git a/lib_base/src/main/java/com/android/base/widget/ratio/CenterDrawableTextView.java b/lib_base/src/main/java/com/android/base/widget/ratio/CenterDrawableTextView.java new file mode 100644 index 0000000..9eca97b --- /dev/null +++ b/lib_base/src/main/java/com/android/base/widget/ratio/CenterDrawableTextView.java @@ -0,0 +1,104 @@ +package com.android.base.widget.ratio; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.drawable.Drawable; +import android.text.TextPaint; +import android.util.AttributeSet; +import android.view.Gravity; + +/** + * 应用场景,比如:当 TextView 的 width 为 match 时,此时使用的 leftDrawable 是靠左的,且无法通过 Gravity 属性来修改其位置。该控件用于类似此种情况下使 Drawable 居中,仅支持单个方向的 Drawable。 + * 优先级为:左、上、右、下。 + * + * @author Ztiany + * Email: 1169654504@qq.com + */ +public class CenterDrawableTextView extends RatioTextView { + + private Paint.FontMetrics metrics = new Paint.FontMetrics(); + + public CenterDrawableTextView(Context context) { + super(context); + } + + public CenterDrawableTextView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CenterDrawableTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onDraw(Canvas canvas) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setToCenterPadding(compoundDrawables, canvas); + super.onDraw(canvas); + } + + private void setToCenterPadding(Drawable[] compoundDrawables, Canvas canvas) { + if (compoundDrawables == null) { + return; + } + + Drawable leftDrawable = compoundDrawables[0]; + Drawable topDrawable = compoundDrawables[1]; + Drawable rightDrawable = compoundDrawables[2]; + Drawable bottomDrawable = compoundDrawables[3]; + + if (leftDrawable != null) { + setLeftDrawableCenter(canvas, leftDrawable); + } else if (topDrawable != null) { + setTopDrawableCenter(canvas, topDrawable); + } else if (rightDrawable != null) { + setRightDrawableCenter(canvas, rightDrawable); + } else if (bottomDrawable != null) { + setBottomDrawableCenter(canvas, bottomDrawable); + } + } + + private void setBottomDrawableCenter(Canvas canvas, Drawable downDrawable) { + setGravity(Gravity.BOTTOM | getGravity()); + + int compoundDrawablePadding = getCompoundDrawablePadding(); + TextPaint paint = getPaint(); + paint.getFontMetrics(metrics); + float contentHeight = (metrics.bottom - metrics.top + compoundDrawablePadding + downDrawable.getIntrinsicHeight()); + int measuredHeight = getMeasuredHeight(); + canvas.translate(0F, -(measuredHeight / 2.0F - contentHeight / 2)); + } + + private void setRightDrawableCenter(Canvas canvas, Drawable rightDrawable) { + setGravity(Gravity.END | getGravity()); + + int compoundDrawablePadding = getCompoundDrawablePadding(); + TextPaint paint = getPaint(); + float measureText = paint.measureText(getText().toString()); + float contentWidth = (measureText + compoundDrawablePadding + rightDrawable.getIntrinsicHeight()); + int measuredWidth = getMeasuredWidth(); + canvas.translate(-(measuredWidth / 2.0F - contentWidth / 2), 0F); + } + + private void setLeftDrawableCenter(Canvas canvas, Drawable leftDrawable) { + setGravity(Gravity.START | getGravity()); + + int compoundDrawablePadding = getCompoundDrawablePadding(); + TextPaint paint = getPaint(); + float measureText = paint.measureText(getText().toString()); + float contentWidth = (measureText + compoundDrawablePadding + leftDrawable.getIntrinsicHeight()); + int measuredWidth = getMeasuredWidth(); + canvas.translate((measuredWidth / 2.0F - contentWidth / 2), 0F); + } + + private void setTopDrawableCenter(Canvas canvas, Drawable topDrawable) { + int compoundDrawablePadding = getCompoundDrawablePadding(); + TextPaint paint = getPaint(); + paint.getFontMetrics(metrics); + float contentHeight = (metrics.bottom - metrics.top + compoundDrawablePadding + topDrawable.getIntrinsicHeight()); + int measuredHeight = getMeasuredHeight(); + canvas.translate(0F, (measuredHeight / 2.0F - contentHeight / 2)); + } + +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/widget/ratio/TopDrawableCenterTextView.java b/lib_base/src/main/java/com/android/base/widget/ratio/TopDrawableCenterTextView.java deleted file mode 100644 index 4fe0250..0000000 --- a/lib_base/src/main/java/com/android/base/widget/ratio/TopDrawableCenterTextView.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.android.base.widget.ratio; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.drawable.Drawable; -import android.text.TextPaint; -import android.util.AttributeSet; - -/** - * 使 TopDrawable 居中,不要设置 gravity 属性为 center 或 center_vertical - * - * @author Ztiany - * Email: 1169654504@qq.com - */ -public class TopDrawableCenterTextView extends RatioTextView { - - private Paint.FontMetrics metrics = new Paint.FontMetrics(); - - public TopDrawableCenterTextView(Context context) { - super(context); - } - - public TopDrawableCenterTextView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public TopDrawableCenterTextView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @Override - protected void onDraw(Canvas canvas) { - Drawable[] compoundDrawables = getCompoundDrawables(); - setToCenterPadding(compoundDrawables, canvas); - super.onDraw(canvas); - } - - private void setToCenterPadding(Drawable[] compoundDrawables, Canvas canvas) { - if (compoundDrawables == null) { - return; - } - - Drawable topDrawable = compoundDrawables[1]; - - if (topDrawable == null) { - return; - } - - int compoundDrawablePadding = getCompoundDrawablePadding(); - TextPaint paint = getPaint(); - paint.getFontMetrics(metrics); - float contentHeight = (metrics.bottom - metrics.top + compoundDrawablePadding + topDrawable.getIntrinsicHeight()); - int measuredHeight = getMeasuredHeight(); - canvas.translate(0, measuredHeight / 2 - contentHeight / 2); - } - -}