[状态栏]状态栏需求代码提交
[状态栏]网络可访问状态获取
This commit is contained in:
@@ -8,8 +8,7 @@ import android.graphics.drawable.GradientDrawable
|
||||
import android.text.*
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.util.TypedValue
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.*
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
@@ -40,20 +39,38 @@ val <T: View> T.lifecycleOwner: LifecycleOwner
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
it.currentState = Lifecycle.State.STARTED
|
||||
}
|
||||
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
it.currentState = Lifecycle.State.RESUMED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||
override fun onViewAttachedToWindow(v: View?) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
it.currentState = Lifecycle.State.STARTED
|
||||
}
|
||||
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
it.currentState = Lifecycle.State.RESUMED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewDetachedFromWindow(v: View?) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
this@lifecycleOwner.removeOnAttachStateChangeListener(this)
|
||||
it.currentState = Lifecycle.State.DESTROYED
|
||||
}
|
||||
@@ -159,7 +176,6 @@ val Int.PX: Int
|
||||
val Int.SP: Int
|
||||
get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, this.toFloat(), Utils.getApp().resources.displayMetrics).toInt()
|
||||
|
||||
|
||||
fun <T: EditText> T.watch(@IntRange(from = 1) maxCharCount: Int, onCountChanged:((count: Int) -> Unit)? = null, onTextChanged:((editable: Editable?) -> Unit)? = null, onReachMaxCountAction:((text: T) -> Unit)? = null, onGetFocus:((text: T) -> Unit)? = null) {
|
||||
doAfterTextChanged { itx ->
|
||||
onTextChanged?.invoke(itx)
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.mogo.eagle.core.utilcode.rv.divider
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import android.util.Pair
|
||||
import android.util.*
|
||||
import android.view.View
|
||||
import androidx.annotation.IntRange
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
@@ -84,17 +84,23 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD
|
||||
}
|
||||
} else {
|
||||
val averageDistance = (((spanCount - 1) * mHorizontalInnerSpace + 2 * mHorizontalExternalSpace + deltaHL + deltaHR) * 1.0f / spanCount).toInt()
|
||||
Log.d("UUUU", "step::0::$averageDistance: lastRight: $mLastRight : state: $state " )
|
||||
if (spanIndex == 0) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
Log.d("UUUU", "step::1::$averageDistance: lastRight: $mLastRight" )
|
||||
} else if (spanIndex == spanCount - 1) {
|
||||
outRect.right = mHorizontalExternalSpace + deltaHR
|
||||
outRect.left = averageDistance - outRect.right
|
||||
Log.d("UUUU", "step::2::$averageDistance: lastRight: $mLastRight ::outRect.left: ${outRect.left}" )
|
||||
} else {
|
||||
outRect.left = mHorizontalInnerSpace - mLastRight
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
if (state.didStructureChange()) {
|
||||
mLastRight = outRect.right
|
||||
}
|
||||
Log.d("UUUU", "step::2::$averageDistance: lastRight: $mLastRight ::outRect.left: ${outRect.left}" )
|
||||
}
|
||||
} //所在的行数
|
||||
if (lookUp.getSpanGroupIndex(childPosition, spanCount) == lookUp.getSpanGroupIndex(mFromPosition, spanCount)) {
|
||||
@@ -131,7 +137,9 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD
|
||||
} else {
|
||||
outRect.top = mVerticalInnerSpace - mLastBottom
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
mLastBottom = outRect.bottom
|
||||
if (state.didStructureChange()) {
|
||||
mLastBottom = outRect.bottom
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lookUp.getSpanGroupIndex(childPosition, spanCount) == lookUp.getSpanGroupIndex(mFromPosition, spanCount)) { //第一列
|
||||
@@ -222,7 +230,9 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD
|
||||
} else {
|
||||
outRect.left = mHorizontalInnerSpace - mLastRight
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
if (state.didStructureChange()) {
|
||||
mLastRight = outRect.right
|
||||
}
|
||||
}
|
||||
}
|
||||
if (childPosition == mFromPosition) {
|
||||
@@ -279,7 +289,9 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD
|
||||
} else {
|
||||
outRect.top = mVerticalInnerSpace - mLastBottom
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
mLastBottom = outRect.bottom
|
||||
if (state.didStructureChange()) {
|
||||
mLastBottom = outRect.bottom
|
||||
}
|
||||
}
|
||||
}
|
||||
if (childPosition == mFromPosition) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.eagle.core.utilcode.util;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@@ -56,6 +57,7 @@ public final class PermissionUtils {
|
||||
|
||||
private static SimpleCallback sSimpleCallback4WriteSettings;
|
||||
private static SimpleCallback sSimpleCallback4DrawOverlays;
|
||||
private static SimpleCallback sSimpleCallback4AccessFineLocation;
|
||||
|
||||
/**
|
||||
* Return the permissions used in application.
|
||||
@@ -152,6 +154,19 @@ public final class PermissionUtils {
|
||||
PermissionActivityImpl.start(PermissionActivityImpl.TYPE_WRITE_SETTINGS);
|
||||
}
|
||||
|
||||
public static void requestAccessFineLocation(final SimpleCallback callback) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (isGranted(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
if (callback != null) {
|
||||
callback.onGranted();
|
||||
}
|
||||
return;
|
||||
}
|
||||
sSimpleCallback4AccessFineLocation = callback;
|
||||
PermissionActivityImpl.start(PermissionActivityImpl.TYPE_ACCESS_FINE_LOCATION);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private static void startWriteSettingsActivity(final Activity activity, final int requestCode) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
|
||||
@@ -424,6 +439,7 @@ public final class PermissionUtils {
|
||||
private static final int TYPE_RUNTIME = 0x01;
|
||||
private static final int TYPE_WRITE_SETTINGS = 0x02;
|
||||
private static final int TYPE_DRAW_OVERLAYS = 0x03;
|
||||
private static final int TYPE_ACCESS_FINE_LOCATION = 0x04;
|
||||
|
||||
private static int currentRequestCode = -1;
|
||||
|
||||
@@ -483,6 +499,9 @@ public final class PermissionUtils {
|
||||
} else if (type == TYPE_DRAW_OVERLAYS) {
|
||||
currentRequestCode = TYPE_DRAW_OVERLAYS;
|
||||
startOverlayPermissionActivity(activity, TYPE_DRAW_OVERLAYS);
|
||||
} else if (type == TYPE_ACCESS_FINE_LOCATION) {
|
||||
currentRequestCode = TYPE_ACCESS_FINE_LOCATION;
|
||||
startOverlayPermissionActivity(activity, TYPE_ACCESS_FINE_LOCATION);
|
||||
} else {
|
||||
activity.finish();
|
||||
Log.e("PermissionUtils", "type is wrong.");
|
||||
@@ -550,6 +569,15 @@ public final class PermissionUtils {
|
||||
sSimpleCallback4DrawOverlays.onDenied();
|
||||
}
|
||||
sSimpleCallback4DrawOverlays = null;
|
||||
} else if (requestCode == TYPE_ACCESS_FINE_LOCATION) {
|
||||
if (sSimpleCallback4AccessFineLocation == null) {
|
||||
return;
|
||||
}
|
||||
if (isGranted(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
sSimpleCallback4AccessFineLocation.onGranted();
|
||||
} else {
|
||||
sSimpleCallback4AccessFineLocation.onDenied();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user