¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.keyCabinet; |
| | | |
| | | import android.app.Application; |
| | | import android.content.Context; |
| | | import android.hardware.usb.UsbDevice; |
| | | import android.net.Uri; |
| | | import android.os.CountDownTimer; |
| | | import android.text.TextUtils; |
| | | import android.widget.ImageView; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.doumee.keyCabinet.bean.DevConfigBean; |
| | | import com.doumee.keyCabinet.bean.LoginBean; |
| | | import com.doumee.keyCabinet.utils.CrashHandler; |
| | | import com.bumptech.glide.Glide; |
| | | import com.doumee.keyCabinet.utils.TimeUtils; |
| | | import com.doumee.lib_coremodel.base.CoreConfig; |
| | | import com.doumee.lib_coremodel.http.other.OkHttpNetworkFetcher; |
| | | import com.doumee.lib_coremodel.util.SpUtil; |
| | | import com.doumee.keyCabinet.bean.MemberBean; |
| | | import com.doumee.keyCabinet.utils.LanguageUtil; |
| | | import com.facebook.fresco.helper.Phoenix; |
| | | import com.facebook.imagepipeline.core.ImagePipelineConfig; |
| | | import com.facebook.imagepipeline.listener.RequestListener; |
| | | import com.facebook.imagepipeline.listener.RequestLoggingListener; |
| | | import com.orhanobut.logger.AndroidLogAdapter; |
| | | import com.orhanobut.logger.FormatStrategy; |
| | | import com.orhanobut.logger.Logger; |
| | | import com.orhanobut.logger.PrettyFormatStrategy; |
| | | import com.scwang.smart.refresh.footer.ClassicsFooter; |
| | | import com.scwang.smart.refresh.header.ClassicsHeader; |
| | | import com.scwang.smart.refresh.layout.SmartRefreshLayout; |
| | | import com.scwang.smart.refresh.layout.api.RefreshFooter; |
| | | import com.scwang.smart.refresh.layout.api.RefreshHeader; |
| | | import com.scwang.smart.refresh.layout.api.RefreshLayout; |
| | | import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator; |
| | | import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator; |
| | | import com.yuyh.library.imgsel.ISNav; |
| | | |
| | | import java.io.File; |
| | | import java.util.HashSet; |
| | | import java.util.Random; |
| | | import java.util.Set; |
| | | |
| | | import dagger.hilt.android.HiltAndroidApp; |
| | | import okhttp3.OkHttpClient; |
| | | import timber.log.Timber; |
| | | |
| | | @HiltAndroidApp |
| | | public class MApplication extends Application { |
| | | |
| | | public static Context mContext; |
| | | private static CountDownTimer countTimer; |
| | | public static int nLan = 0;//䏿ç¨0ï¼å
¶ä»ç¨1 |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | mContext=this; |
| | | //åå§åæ¥å¿æå° |
| | | FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder() |
| | | .showThreadInfo(false) //ï¼å¯éï¼æ¯å¦æ¾ç¤ºçº¿ç¨ä¿¡æ¯ã é»è®¤å¼ä¸ºtrue |
| | | .methodCount(2) // ï¼å¯éï¼è¦æ¾ç¤ºçæ¹æ³è¡æ°ã é»è®¤2 |
| | | .methodOffset(0) // ï¼å¯éï¼è®¾ç½®è°ç¨å æ ç彿°åç§»å¼ï¼0çè¯å仿å°è¯¥Logç彿°å¼å§è¾åºå æ ä¿¡æ¯ï¼é»è®¤æ¯0 |
| | | //.logStrategy(customLog) //ï¼å¯éï¼æ´æ¹è¦æå°çæ¥å¿çç¥ã é»è®¤LogCat |
| | | .tag("Logger") |
| | | //ï¼å¯éï¼æ¯ä¸ªæ¥å¿çå
¨å±æ è®°ã é»è®¤PRETTY_LOGGERï¼å¦ä¸å¾ï¼ |
| | | .build(); |
| | | Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy){ |
| | | @Override |
| | | public boolean isLoggable(int priority, @Nullable String tag) { |
| | | return BuildConfig.DEBUG;//æ§å¶æ¯å¦è¾åºæ¥å¿ |
| | | } |
| | | }); |
| | | |
| | | Timber.plant(new Timber.DebugTree() { |
| | | @Override protected void log(int priority, String tag, String message, Throwable t) { |
| | | if(BuildConfig.DEBUG){ |
| | | System.out.println(TimeUtils.getNowDate()+" "+tag+" ===> "+message); |
| | | //Logger.log(priority, tag, message, t); |
| | | } |
| | | } |
| | | }); |
| | | //设置å
¨å±çHeaderæå»ºå¨ |
| | | SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() { |
| | | @Override |
| | | public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) { |
| | | layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//å
¨å±è®¾ç½®ä¸»é¢é¢è² |
| | | return new ClassicsHeader(context);//.setTimeFormat(new DynamicTimeFormat("æ´æ°äº %s"));//æå®ä¸ºç»å
¸Headerï¼é»è®¤æ¯ è´å¡å°é·è¾¾Header |
| | | } |
| | | }); |
| | | //设置å
¨å±çFooteræå»ºå¨ |
| | | SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() { |
| | | @Override |
| | | public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) { |
| | | //æå®ä¸ºç»å
¸Footerï¼é»è®¤æ¯ BallPulseFooter |
| | | return new ClassicsFooter(context).setDrawableSize(20); |
| | | } |
| | | }); |
| | | // èªå®ä¹å¾çå è½½å¨ |
| | | ISNav.getInstance().init(new com.yuyh.library.imgsel.common.ImageLoader() { |
| | | @Override |
| | | public void displayImage(Context context, String path, ImageView imageView) { |
| | | Glide.with(context).load(Uri.fromFile(new File(path))).into(imageView); |
| | | } |
| | | }); |
| | | initFresco(); |
| | | SpUtil.init(this); |
| | | CoreConfig.nomalPicId=R.mipmap.ic_vipimg; |
| | | CoreConfig.nomalHeadPicId=R.mipmap.ic_vipimg; |
| | | addCrash(); |
| | | setLanguage(); |
| | | } |
| | | |
| | | /** |
| | | * 设置è¯è¨ |
| | | */ |
| | | private void setLanguage() { |
| | | String language = SpUtil.getString("language"); |
| | | if(TextUtils.isEmpty(language)){ |
| | | return; |
| | | } |
| | | LanguageUtil.changeAppLanguage(this,language); |
| | | } |
| | | |
| | | private void initFresco() { |
| | | Set<RequestListener> requestListeners = new HashSet<>(); |
| | | requestListeners.add(new RequestLoggingListener()); |
| | | |
| | | OkHttpClient okHttpClient = new OkHttpClient.Builder() |
| | | .build(); |
| | | |
| | | ImagePipelineConfig imagePipelineConfig = new com.facebook.fresco.helper.config.PhoenixConfig.Builder(this) |
| | | .setNetworkFetcher(new OkHttpNetworkFetcher(okHttpClient)) |
| | | .setRequestListeners(requestListeners) |
| | | .build(); |
| | | Phoenix.init(this, imagePipelineConfig); |
| | | } |
| | | public static interface CountTimerCallBack{ |
| | | void onFinish(); |
| | | void onTick(long millisUntilFinished); |
| | | } |
| | | |
| | | private static CountTimerCallBack timerCallBack; |
| | | public static void initCountTimer(boolean isToGuild,CountTimerCallBack callBack){ |
| | | if(countTimer!=null){ |
| | | countTimer.cancel(); |
| | | } |
| | | if(timerCallBack!=null){ |
| | | timerCallBack = null; |
| | | } |
| | | if(configBean==null){ |
| | | return; |
| | | } |
| | | timerCallBack = callBack; |
| | | countTimer = new CountDownTimer(60*1000, 1*1000) { |
| | | @Override |
| | | public void onTick(long millisUntilFinished) { |
| | | //Timber.tag("CountTimer==>").d(millisUntilFinished+""); |
| | | if (timerCallBack!=null) { |
| | | timerCallBack.onTick(millisUntilFinished); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | Timber.tag("CountTimer==>").d("onFinish"); |
| | | if (timerCallBack!=null) { |
| | | timerCallBack.onFinish(); |
| | | } |
| | | } |
| | | }; |
| | | } |
| | | |
| | | public static void startCountTimer(){ |
| | | if(countTimer!=null){ |
| | | countTimer.start(); |
| | | } |
| | | } |
| | | |
| | | private void addCrash(){ |
| | | try { |
| | | CrashHandler crashHandler = CrashHandler.getInstance(); |
| | | crashHandler.init(this); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | System.out.println("é误æ¥å¿4"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | public static void stopCountTimer() { |
| | | if(countTimer!=null){ |
| | | countTimer.cancel(); |
| | | } |
| | | } |
| | | |
| | | private static DevConfigBean configBean; |
| | | public static void saveConfigBean(DevConfigBean bean){ |
| | | configBean = bean; |
| | | } |
| | | |
| | | public static DevConfigBean getConfigBean(){ |
| | | if(configBean==null){ |
| | | configBean = new DevConfigBean(); |
| | | } |
| | | return configBean; |
| | | } |
| | | |
| | | private static UsbDevice customDevice; |
| | | |
| | | public static UsbDevice getUsbDevice() { |
| | | return customDevice; |
| | | } |
| | | |
| | | public static void setUsbDevice(UsbDevice device) { |
| | | customDevice = device; |
| | | } |
| | | |
| | | private static LoginBean loginBean; |
| | | |
| | | public static LoginBean getLoginBean() { |
| | | if(loginBean==null){ |
| | | loginBean = new LoginBean(); |
| | | } |
| | | return loginBean; |
| | | } |
| | | |
| | | public static void setLoginBean(LoginBean cookie) { |
| | | MApplication.loginBean = cookie; |
| | | } |
| | | |
| | | private static Random random; |
| | | public static boolean nextBoolean(){ |
| | | if(random==null){ |
| | | random = new Random(); |
| | | } |
| | | return random.nextBoolean(); |
| | | } |
| | | } |