Commit 497b78a2 authored by 赵鹏翔's avatar 赵鹏翔

utils covert

parent 0ac0f500
......@@ -98,7 +98,7 @@ class MiyaApplication : BaseApplication() {
loggingInterceptor = MiyaHttpLoggingInterceptor { message ->
if (!LogFileUtils.isProhibitWrite) {
LogFileUtils.writeLog(
ContextUtils.getContext(),
ContextUtils.getContext()!!,
DateUtils.getDateStringByTimeStamp(System.currentTimeMillis())
.toString() + " $message" + "\n"
)
......@@ -112,7 +112,7 @@ class MiyaApplication : BaseApplication() {
ex.printStackTrace()
if (!LogFileUtils.isProhibitWrite) {
LogFileUtils.writeLog(
ContextUtils.getContext(),
ContextUtils.getContext()!!,
DateUtils.getDateStringByTimeStamp(System.currentTimeMillis())
.toString() + "异常: ${ex.message}" + "\n"
)
......@@ -151,7 +151,7 @@ class MiyaApplication : BaseApplication() {
Runtime.getRuntime().totalMemory()
}\tfreeMemory:${Runtime.getRuntime().freeMemory()}"
LogFileUtils.writeLog(
ContextUtils.getContext(),
ContextUtils.getContext()!!,
"\n${DateUtils.format18(Date())}########onActivitySaveInstanceState() called with:" +
" activity = [$activity]\nmemoryStatus: $memoryStatus"
)
......@@ -167,12 +167,14 @@ class MiyaApplication : BaseApplication() {
private fun activityLifeCycleLog(activity: Activity, lifeName: String) {
XLog.d(DateUtils.format18(Date()) + " $lifeName")
if (!LogFileUtils.isProhibitWrite) {
ContextUtils.getContext()?.let {
LogFileUtils.writeLog(
ContextUtils.getContext(),
it,
"\n${DateUtils.format18(Date())}########$lifeName called with: activity = [$activity]\n"
)
}
}
}
fun resetConfig() {
LocalKeyDataMKManageKit.clearCommonData()
......
......@@ -19,7 +19,7 @@ class DatabaseKeeper {
private val DATABASE_NAME = "pay_data"
val payDatabase: PayDatabase by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
Room.databaseBuilder(ContextUtils.getContext(), PayDatabase::class.java, DATABASE_NAME)
Room.databaseBuilder(ContextUtils.getContext()!!, PayDatabase::class.java, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.build()
}
......
......@@ -17,8 +17,6 @@ import com.blankj.utilcode.util.ToastUtils
import com.fastcashier.lib_common.function.account.AccountService
import com.fastcashier.lib_common.util.clickWithTrigger
import com.miya.fastcashier.databinding.ActivityLoginBinding
import com.miya.fastcashier.util.CenterToasty
import com.miya.fastcashier.util.manage.ChannelManageKit
import com.miya.fastcashier.util.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.viewmodel.LoginViewModel
import com.permissionx.guolindev.PermissionX
......
package com.miya.fastcashier.util;
import android.content.Context;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import es.dmoral.toasty.Toasty;
/**
* 居中的Toasty弹窗 将图片和文字的左右排布,改为了 上下排布
* Created by fengyu on 2018/10/8.
*/
public class CenterToasty {
@CheckResult
public static Toast info(@NonNull Context context, @NonNull CharSequence message, int duration, boolean withIcon) {
Toast toast = Toasty.info(context, message, duration, withIcon);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast info(@NonNull Context context, @NonNull CharSequence message, int duration) {
Toast toast = Toasty.info(context, message, duration);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast info(@NonNull Context context, @NonNull CharSequence message) {
Toast toast = Toasty.info(context, message);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast infox(@NonNull Context context, @NonNull CharSequence message, @NonNull int xOffset) {
Toast toast = Toasty.info(context, message);
transformToast(toast, xOffset, 0);
return toast;
}
@CheckResult
public static Toast normal(@NonNull Context context, @NonNull CharSequence message, int duration) {
Toast toast = Toasty.normal(context, message, duration);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast warning(@NonNull Context context, @NonNull CharSequence message, int duration) {
Toast toast = Toasty.warning(context, message, duration);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast warning(@NonNull Context context, @NonNull CharSequence message, int duration, boolean withIcon) {
Toast toast = Toasty.warning(context, message, duration, withIcon);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast success(@NonNull Context context, @NonNull CharSequence message, int duration, boolean withIcon) {
Toast toast = Toasty.success(context, message, duration, withIcon);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast success(@NonNull Context context, @NonNull CharSequence message, int duration) {
Toast toast = Toasty.success(context, message, duration);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast error(@NonNull Context context, @NonNull CharSequence message, int duration, boolean withIcon) {
Toast toast = Toasty.error(context, message, duration, withIcon);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast error(@NonNull Context context, @NonNull CharSequence message) {
Toast toast = Toasty.error(context, message);
transformToast(toast);
return toast;
}
@CheckResult
public static Toast error(@NonNull Context context, @NonNull CharSequence message, int duration) {
Toast toast = Toasty.error(context, message, duration);
transformToast(toast);
return toast;
}
private static void transformToast(Toast toast) {
LinearLayout linearLayout = (LinearLayout) toast.getView();
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(20, 20, 20, 20);
ImageView icon = (ImageView) linearLayout.getChildAt(0);
icon.setLayoutParams(new LinearLayout.LayoutParams(50, 50));
TextView messageTextView = (TextView) linearLayout.getChildAt(1);
messageTextView.setTextSize(28);
messageTextView.setPadding(0, 30, 0, 30);
messageTextView.setGravity(Gravity.CENTER);
toast.setGravity(Gravity.CENTER, 0, 0);
}
private static void transformToast(Toast toast, int xOffset, int yOffset) {
LinearLayout linearLayout = (LinearLayout) toast.getView();
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(20, 20, 20, 20);
ImageView icon = (ImageView) linearLayout.getChildAt(0);
icon.setLayoutParams(new LinearLayout.LayoutParams(50, 50));
TextView messageTextView = (TextView) linearLayout.getChildAt(1);
messageTextView.setTextSize(28);
messageTextView.setPadding(0, 30, 0, 30);
messageTextView.setGravity(Gravity.CENTER);
toast.setGravity(Gravity.CENTER, xOffset, yOffset);
}
}
package com.miya.fastcashier.util
import android.content.Context
import android.widget.Toast
import es.dmoral.toasty.Toasty
import com.miya.fastcashier.util.CenterToasty
import android.widget.LinearLayout
import android.widget.TextView
import android.view.Gravity
import android.widget.ImageView
import androidx.annotation.CheckResult
/**
* 居中的Toasty弹窗 将图片和文字的左右排布,改为了 上下排布
* Created by fengyu on 2018/10/8.
*/
object CenterToasty {
@CheckResult
fun info(context: Context, message: CharSequence, duration: Int, withIcon: Boolean): Toast {
val toast = Toasty.info(context, message, duration, withIcon)
transformToast(toast)
return toast
}
@CheckResult
fun info(context: Context, message: CharSequence, duration: Int): Toast {
val toast = Toasty.info(context, message, duration)
transformToast(toast)
return toast
}
@CheckResult
fun info(context: Context, message: CharSequence): Toast {
val toast = Toasty.info(context, message)
transformToast(toast)
return toast
}
@CheckResult
fun infox(context: Context, message: CharSequence, xOffset: Int): Toast {
val toast = Toasty.info(context, message)
transformToast(toast, xOffset, 0)
return toast
}
@CheckResult
fun normal(context: Context, message: CharSequence, duration: Int): Toast {
val toast = Toasty.normal(context, message, duration)
transformToast(toast)
return toast
}
@CheckResult
fun warning(context: Context, message: CharSequence, duration: Int): Toast {
val toast = Toasty.warning(context, message, duration)
transformToast(toast)
return toast
}
@CheckResult
fun warning(context: Context, message: CharSequence, duration: Int, withIcon: Boolean): Toast {
val toast = Toasty.warning(context, message, duration, withIcon)
transformToast(toast)
return toast
}
@CheckResult
fun success(context: Context, message: CharSequence, duration: Int, withIcon: Boolean): Toast {
val toast = Toasty.success(context, message, duration, withIcon)
transformToast(toast)
return toast
}
@CheckResult
fun success(context: Context, message: CharSequence, duration: Int): Toast {
val toast = Toasty.success(context, message, duration)
transformToast(toast)
return toast
}
@CheckResult
fun error(context: Context, message: CharSequence, duration: Int, withIcon: Boolean): Toast {
val toast = Toasty.error(context, message, duration, withIcon)
transformToast(toast)
return toast
}
@CheckResult
fun error(context: Context, message: CharSequence): Toast {
val toast = Toasty.error(context, message)
transformToast(toast)
return toast
}
@CheckResult
fun error(context: Context, message: CharSequence, duration: Int): Toast {
val toast = Toasty.error(context, message, duration)
transformToast(toast)
return toast
}
private fun transformToast(toast: Toast) {
val linearLayout = toast.view as LinearLayout?
linearLayout!!.orientation = LinearLayout.VERTICAL
linearLayout.setPadding(20, 20, 20, 20)
val icon = linearLayout.getChildAt(0) as ImageView
icon.layoutParams = LinearLayout.LayoutParams(50, 50)
val messageTextView = linearLayout.getChildAt(1) as TextView
messageTextView.textSize = 28f
messageTextView.setPadding(0, 30, 0, 30)
messageTextView.gravity = Gravity.CENTER
toast.setGravity(Gravity.CENTER, 0, 0)
}
private fun transformToast(toast: Toast, xOffset: Int, yOffset: Int) {
val linearLayout = toast.view as LinearLayout?
linearLayout!!.orientation = LinearLayout.VERTICAL
linearLayout.setPadding(20, 20, 20, 20)
val icon = linearLayout.getChildAt(0) as ImageView
icon.layoutParams = LinearLayout.LayoutParams(50, 50)
val messageTextView = linearLayout.getChildAt(1) as TextView
messageTextView.textSize = 28f
messageTextView.setPadding(0, 30, 0, 30)
messageTextView.gravity = Gravity.CENTER
toast.setGravity(Gravity.CENTER, xOffset, yOffset)
}
}
\ No newline at end of file
package com.miya.fastcashier.util;
import android.content.Context;
/**
* 描述: 上下文相关工具类
*/
public class ContextUtils {
private static Context context;
private ContextUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 初始化工具类
*
* @param context 上下文
*/
public static void init(Context context) {
ContextUtils.context = context.getApplicationContext();
}
/**
* 获取ApplicationContext
*
* @return ApplicationContext
*/
public static Context getContext() {
if (context != null) return context;
throw new NullPointerException("u should init first");
}
}
\ No newline at end of file
package com.miya.fastcashier.util
import android.content.Context
import java.lang.NullPointerException
import java.lang.UnsupportedOperationException
/**
* 描述: 上下文相关工具类
*/
class ContextUtils private constructor() {
companion object {
private var context: Context? = null
/**
* 初始化工具类
*
* @param context 上下文
*/
fun init(context: Context) {
Companion.context = context.applicationContext
}
/**
* 获取ApplicationContext
*
* @return ApplicationContext
*/
fun getContext(): Context? {
if (context != null) return context
throw NullPointerException("u should init first")
}
}
init {
throw UnsupportedOperationException("u can't instantiate me...")
}
}
\ No newline at end of file
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