Commit f990cdfb authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 95119d20
...@@ -214,6 +214,8 @@ dependencies { ...@@ -214,6 +214,8 @@ dependencies {
// 三方接入 // 三方接入
// leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
// shareSdk // shareSdk
implementation project(':shareSdkLib') implementation project(':shareSdkLib')
// umeng // umeng
......
...@@ -21,6 +21,7 @@ object TopOnNativeAd { ...@@ -21,6 +21,7 @@ object TopOnNativeAd {
private val TAG = TopOnNativeAd::class.java.simpleName private val TAG = TopOnNativeAd::class.java.simpleName
var context: Context? = null
var atNatives: ATNative? = null var atNatives: ATNative? = null
var mNativeAd: NativeAd? = null var mNativeAd: NativeAd? = null
var anyThinkNativeAdView: ATNativeAdView? = null var anyThinkNativeAdView: ATNativeAdView? = null
...@@ -32,6 +33,7 @@ object TopOnNativeAd { ...@@ -32,6 +33,7 @@ object TopOnNativeAd {
* 应用初始化 * 应用初始化
*/ */
fun init(context: Context) { fun init(context: Context) {
this.context = context
atNatives = ATNative(context, TopOnManager.INFORMATION_ID, object : ATNativeNetworkListener { atNatives = ATNative(context, TopOnManager.INFORMATION_ID, object : ATNativeNetworkListener {
override fun onNativeAdLoaded() { override fun onNativeAdLoaded() {
LogUtil.e(TAG, "onNativeAdLoaded") LogUtil.e(TAG, "onNativeAdLoaded")
...@@ -61,16 +63,16 @@ object TopOnNativeAd { ...@@ -61,16 +63,16 @@ object TopOnNativeAd {
/** /**
* 预加载 * 预加载
*/ */
fun loadNativeAd(context: Context, frameLayout: FrameLayout?) { fun loadNativeAd(frameLayout: FrameLayout?) {
atNatives?.makeAdRequest() atNatives?.makeAdRequest()
showNativeAd(context,frameLayout) showNativeAd(frameLayout)
} }
/** /**
* 显示 * 显示
*/ */
fun showNativeAd(context: Context, frameLayout: FrameLayout?) { private fun showNativeAd(frameLayout: FrameLayout?) {
val nativeAd = atNatives?.nativeAd val nativeAd = atNatives?.nativeAd
nativeAd?.let { nativeAd?.let {
if (mNativeAd != null) { if (mNativeAd != null) {
...@@ -118,7 +120,7 @@ object TopOnNativeAd { ...@@ -118,7 +120,7 @@ object TopOnNativeAd {
it.prepare(anyThinkNativeAdView, anyThinkRender.getClickView(), null) it.prepare(anyThinkNativeAdView, anyThinkRender.getClickView(), null)
if (anyThinkNativeAdView != null && anyThinkNativeAdView!!.parent == null) { if (anyThinkNativeAdView != null && anyThinkNativeAdView!!.parent == null) {
frameLayout?.addView(anyThinkNativeAdView, FrameLayout.LayoutParams(context.getResources().getDisplayMetrics().widthPixels, containerHeight)) frameLayout?.addView(anyThinkNativeAdView, FrameLayout.LayoutParams(context?.getResources()!!.getDisplayMetrics().widthPixels, containerHeight))
} }
} }
} }
...@@ -138,6 +140,8 @@ object TopOnNativeAd { ...@@ -138,6 +140,8 @@ object TopOnNativeAd {
} }
fun onDestroy() { fun onDestroy() {
anyThinkNativeAdView?.destory()
mNativeAd?.destory() mNativeAd?.destory()
context = null
} }
} }
\ No newline at end of file
...@@ -30,11 +30,7 @@ public class AppConfig { ...@@ -30,11 +30,7 @@ public class AppConfig {
public static volatile double curLatitude = 0;//纬度 39.977181 public static volatile double curLatitude = 0;//纬度 39.977181
public static volatile String curAddress = "授权定位权限后获取位置";//位置 public static volatile String curAddress = "授权定位权限后获取位置";//位置
public static volatile String poiName = "";//位置 public static volatile String poiName = "";//位置
public static volatile String aoiName = "";//建筑
public static volatile double preChangeLongitude = 1;//位置变化改变 上一次经度 116.307511
public static volatile double preChangeLatitude = 1;//位置变化改变 上一次纬度 39.977181
// public static volatile int canSaveMinimumM = 50;//范围 米
public static volatile int canSaveMinimumM = 1;//范围 米 public static volatile int canSaveMinimumM = 1;//范围 米
......
...@@ -35,7 +35,7 @@ class VipPayManager private constructor(activity: Activity) { ...@@ -35,7 +35,7 @@ class VipPayManager private constructor(activity: Activity) {
private fun init(activity: Activity) { private fun init(activity: Activity) {
this.activity = activity this.activity = activity
spUtil = SPUtil.getInstance(activity) spUtil = SPUtil.getInstance()
} }
/** /**
...@@ -56,19 +56,19 @@ class VipPayManager private constructor(activity: Activity) { ...@@ -56,19 +56,19 @@ class VipPayManager private constructor(activity: Activity) {
/** /**
* 跳转支付界面 type-3 五折, type-4 全款 * 跳转支付界面 type-3 五折, type-4 全款
*/ */
fun gotoPayPage(type: Int) { // fun gotoPayPage(type: Int) {
if (activity == null) return // if (activity == null) return
//
if (TextUtils.equals("onePrice", spUtil?.getString(Constant.PAY_PAGE_TYPE))) { // if (TextUtils.equals("onePrice", spUtil?.getString(Constant.PAY_PAGE_TYPE))) {
//固定套餐 // //固定套餐
readyGo(Vip2Activity::class.java) // readyGo(Vip2Activity::class.java)
} else { // } else {
//多价格套餐 // //多价格套餐
val bundle = Bundle() // val bundle = Bundle()
bundle.putInt(Constant.PRICE_TYPE, type) // bundle.putInt(Constant.PRICE_TYPE, type)
readyGo(Vip3Activity::class.java, bundle) // readyGo(Vip3Activity::class.java, bundle)
} // }
} // }
private fun readyGo(clazz: Class<*>?) { private fun readyGo(clazz: Class<*>?) {
activity.let { activity.let {
......
...@@ -26,6 +26,9 @@ import java.util.* ...@@ -26,6 +26,9 @@ import java.util.*
class MainFragmentPresenter : BasePresenter<MainFragmentView>() { class MainFragmentPresenter : BasePresenter<MainFragmentView>() {
/**
* 获取关心的人
*/
fun getAllReqMy() { fun getAllReqMy() {
AppHttpManager.getInstance(loanApplication) AppHttpManager.getInstance(loanApplication)
.call(loanService.getCares(), .call(loanService.getCares(),
......
...@@ -30,7 +30,7 @@ class CallMeActivity : BaseActivity(), View.OnClickListener { ...@@ -30,7 +30,7 @@ class CallMeActivity : BaseActivity(), View.OnClickListener {
if (UserManager.getInstance().vipFlag) { if (UserManager.getInstance().vipFlag) {
rlCallmeQQ.visibility = View.VISIBLE rlCallmeQQ.visibility = View.VISIBLE
val phone = SPUtil.getInstance(context).getString(Constant.USER_TELEPHONE) val phone = SPUtil.getInstance().getString(Constant.USER_TELEPHONE)
tvCallPhone.text = phone tvCallPhone.text = phone
} else { } else {
rlCallmeQQ.visibility = View.GONE rlCallmeQQ.visibility = View.GONE
......
...@@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentTransaction; ...@@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentTransaction;
import com.mints.xunmi.MintsApplication; import com.mints.xunmi.MintsApplication;
import com.mints.xunmi.R; import com.mints.xunmi.R;
import com.mints.xunmi.ad.TopOnNativeAd;
import com.mints.xunmi.common.AppConfig; import com.mints.xunmi.common.AppConfig;
import com.mints.xunmi.common.Constant; import com.mints.xunmi.common.Constant;
import com.mints.xunmi.manager.MainAmapLocationManager; import com.mints.xunmi.manager.MainAmapLocationManager;
...@@ -93,6 +94,8 @@ public class MainActivity extends BaseActivity implements MainView { ...@@ -93,6 +94,8 @@ public class MainActivity extends BaseActivity implements MainView {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
TopOnNativeAd.INSTANCE.onDestroy();
} }
@Override @Override
......
package com.mints.xunmi.ui.activitys; //package com.mints.xunmi.ui.activitys;
//
import android.Manifest; //import android.Manifest;
import android.annotation.TargetApi; //import android.annotation.TargetApi;
import android.app.Activity; //import android.app.Activity;
import android.content.pm.PackageManager; //import android.content.pm.PackageManager;
import android.os.Build; //import android.os.Build;
import android.os.Handler; //import android.os.Handler;
import android.os.Looper; //import android.os.Looper;
import android.util.Log; //import android.util.Log;
import android.view.KeyEvent; //import android.view.KeyEvent;
import android.view.View; //import android.view.View;
import android.view.ViewGroup; //import android.view.ViewGroup;
import android.widget.FrameLayout; //import android.widget.FrameLayout;
import android.widget.ImageView; //import android.widget.ImageView;
import android.widget.TextView; //import android.widget.TextView;
//
import com.mints.library.net.netstatus.NetUtils; //import com.mints.library.net.netstatus.NetUtils;
import com.mints.xunmi.R; //import com.mints.xunmi.R;
import com.mints.xunmi.ui.activitys.base.BaseActivity; //import com.mints.xunmi.ui.activitys.base.BaseActivity;
import com.mints.xunmi.utils.PreferencesService; //import com.mints.xunmi.utils.PreferencesService;
import com.qq.e.ads.splash.SplashAD; //import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener; //import com.qq.e.ads.splash.SplashADListener;
import com.qq.e.comm.util.AdError; //import com.qq.e.comm.util.AdError;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
import butterknife.Bind; //import butterknife.Bind;
//
/** ///**
* 后台返回时每次都展示 // * 后台返回时每次都展示
*/ // */
public class SplashADActivity extends BaseActivity implements SplashADListener { //public class SplashADActivity extends BaseActivity implements SplashADListener {
//
@Bind(R.id.fl_splash) // @Bind(R.id.fl_splash)
FrameLayout flSplashRoot; // FrameLayout flSplashRoot;
//
private SplashAD splashAD; // private SplashAD splashAD;
private ViewGroup container; // private ViewGroup container;
private TextView skipView; // private TextView skipView;
private ImageView splashHolder; // private ImageView splashHolder;
private static final String SKIP_TEXT = "点击跳过 %d"; // private static final String SKIP_TEXT = "点击跳过 %d";
//
public boolean canJump = false; // public boolean canJump = false;
private PreferencesService ps; // private PreferencesService ps;
//
/** // /**
* 为防止无广告时造成视觉上类似于"闪退"的情况,设定无广告时页面跳转根据需要延迟一定时间,demo // * 为防止无广告时造成视觉上类似于"闪退"的情况,设定无广告时页面跳转根据需要延迟一定时间,demo
* 给出的延时逻辑是从拉取广告开始算开屏最少持续多久,仅供参考,开发者可自定义延时逻辑,如果开发者采用demo // * 给出的延时逻辑是从拉取广告开始算开屏最少持续多久,仅供参考,开发者可自定义延时逻辑,如果开发者采用demo
* 中给出的延时逻辑,也建议开发者考虑自定义minSplashTimeWhenNoAD的值(单位ms) // * 中给出的延时逻辑,也建议开发者考虑自定义minSplashTimeWhenNoAD的值(单位ms)
**/ // **/
private int minSplashTimeWhenNoAD = 3000; // private int minSplashTimeWhenNoAD = 3000;
/** // /**
* 记录拉取广告的时间 // * 记录拉取广告的时间
*/ // */
private long fetchSplashADTime = 0; // private long fetchSplashADTime = 0;
private Handler handler = new Handler(Looper.getMainLooper()); // private Handler handler = new Handler(Looper.getMainLooper());
//
@Override // @Override
protected int getContentViewLayoutID() { // protected int getContentViewLayoutID() {
return R.layout.activity_splash_ylh; // return R.layout.activity_splash_ylh;
} // }
//
@Override // @Override
protected void initViewsAndEvents() { // protected void initViewsAndEvents() {
if (!NetUtils.isNetworkConnected(getContext())) { // if (!NetUtils.isNetworkConnected(getContext())) {
finish(); // finish();
} else { // } else {
//
try { // try {
container = (ViewGroup) this.findViewById(R.id.splash_container);
fetchSplashAD(this, container, skipView, getPosId(), this, 0);
} catch (Exception e) {
readyGoOtherActivity();
}
// container = (ViewGroup) this.findViewById(R.id.splash_container); // container = (ViewGroup) this.findViewById(R.id.splash_container);
// if (Build.VERSION.SDK_INT >= 23) { // fetchSplashAD(this, container, skipView, getPosId(), this, 0);
// checkAndRequestPermission(); // } catch (Exception e) {
// readyGoOtherActivity();
// }
//
//// container = (ViewGroup) this.findViewById(R.id.splash_container);
//// if (Build.VERSION.SDK_INT >= 23) {
//// checkAndRequestPermission();
//// } else {
//// // 如果是Android6.0以下的机器,建议在manifest中配置相关权限,这里可以直接调用SDK
//// fetchSplashAD(this, container, skipView, getPosId(), this, 0);
//// }
// }
// }
//
// @Override
// protected boolean isApplyKitKatTranslucency() {
// return false;
// }
//
// private String getPosId() {
// String posId = "9041722459847446";
// return posId;
// }
//
// /**
// * ----------非常重要----------
// * <p>
// * Android6.0以上的权限适配简单示例:
// * <p>
// * 如果targetSDKVersion >= 23,那么建议动态申请相关权限,再调用广点通SDK
// * <p>
// * SDK不强制校验下列权限(即:无下面权限sdk也可正常工作),但建议开发者申请下面权限,尤其是READ_PHONE_STATE权限
// * <p>
// * READ_PHONE_STATE权限用于允许SDK获取用户标识,
// * 针对单媒体的用户,允许获取权限的,投放定向广告;不允许获取权限的用户,投放通投广告,媒体可以选择是否把用户标识数据提供给优量汇,并承担相应广告填充和eCPM单价下降损失的结果。
// * <p>
// * Demo代码里是一个基本的权限申请示例,请开发者根据自己的场景合理地编写这部分代码来实现权限申请。
// * 注意:下面的`checkSelfPermission`和`requestPermissions`方法都是在Android6.0的SDK中增加的API,如果您的App还没有适配到Android6.0以上,则不需要调用这些方法,直接调用广点通SDK即可。
// */
// @TargetApi(Build.VERSION_CODES.M)
// private void checkAndRequestPermission() {
// List<String> lackedPermission = new ArrayList<String>();
// if (!(checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)) {
// lackedPermission.add(Manifest.permission.READ_PHONE_STATE);
// }
//
// if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
// lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION);
// }
//
// // 快手SDK所需相关权限,存储权限,此处配置作用于流量分配功能,关于流量分配,详情请咨询商务;如果您的APP不需要快手SDK的流量分配功能,则无需申请SD卡权限
// if (!(checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
// lackedPermission.add(Manifest.permission.READ_EXTERNAL_STORAGE);
// }
// if (!(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
// lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
// }
//
// // 如果需要的权限都已经有了,那么直接调用SDK
// if (lackedPermission.size() == 0) {
// fetchSplashAD(this, container, skipView, getPosId(), this, 0);
// } else { // } else {
// // 如果是Android6.0以下的机器,建议在manifest中配置相关权限,这里可以直接调用SDK // // 否则,建议请求所缺少的权限,在onRequestPermissionsResult中再看是否获得权限
// String[] requestPermissions = new String[lackedPermission.size()];
// lackedPermission.toArray(requestPermissions);
// requestPermissions(requestPermissions, 1024);
// }
// }
//
// private boolean hasAllPermissionsGranted(int[] grantResults) {
// for (int grantResult : grantResults) {
// if (grantResult == PackageManager.PERMISSION_DENIED) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) {
// fetchSplashAD(this, container, skipView, getPosId(), this, 0); // fetchSplashAD(this, container, skipView, getPosId(), this, 0);
// } else {
//// Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show();
//// Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
//// intent.setData(Uri.parse("package:" + getPackageName()));
//// startActivity(intent);
//// finish();
// readyGoOtherActivity();
// }
// } // }
} //
} // /**
// * 拉取开屏广告,开屏广告的构造方法有3种,详细说明请参考开发者文档。
@Override // *
protected boolean isApplyKitKatTranslucency() { // * @param activity 展示广告的activity
return false; // * @param adContainer 展示广告的大容器
} // * @param skipContainer 自定义的跳过按钮:传入该view给SDK后,SDK会自动给它绑定点击跳过事件。SkipView的样式可以由开发者自由定制,其尺寸限制请参考activity_splash.xml或者接入文档中的说明。
// * @param posId 广告位ID
private String getPosId() { // * @param adListener 广告状态监听器
String posId = "9041722459847446"; // * @param fetchDelay 拉取广告的超时时长:取值范围[3000, 5000],设为0表示使用广点通SDK默认的超时时长。
return posId; // */
} // private void fetchSplashAD(Activity activity, ViewGroup adContainer, View skipContainer,
// String posId, SplashADListener adListener, int fetchDelay) {
/** // fetchSplashADTime = System.currentTimeMillis();
* ----------非常重要---------- // splashAD = new SplashAD(activity, skipContainer, posId, adListener, fetchDelay);
* <p> // splashAD.fetchAndShowIn(adContainer);
* Android6.0以上的权限适配简单示例: // }
* <p> //
* 如果targetSDKVersion >= 23,那么建议动态申请相关权限,再调用广点通SDK // @Override
* <p> // public void onADPresent() {
* SDK不强制校验下列权限(即:无下面权限sdk也可正常工作),但建议开发者申请下面权限,尤其是READ_PHONE_STATE权限 // Log.i("AD_DEMO", "SplashADPresent");
* <p> // }
* READ_PHONE_STATE权限用于允许SDK获取用户标识, //
* 针对单媒体的用户,允许获取权限的,投放定向广告;不允许获取权限的用户,投放通投广告,媒体可以选择是否把用户标识数据提供给优量汇,并承担相应广告填充和eCPM单价下降损失的结果。 // @Override
* <p> // public void onADClicked() {
* Demo代码里是一个基本的权限申请示例,请开发者根据自己的场景合理地编写这部分代码来实现权限申请。 // Log.i("AD_DEMO", "SplashADClicked clickUrl: "
* 注意:下面的`checkSelfPermission`和`requestPermissions`方法都是在Android6.0的SDK中增加的API,如果您的App还没有适配到Android6.0以上,则不需要调用这些方法,直接调用广点通SDK即可。 // + (splashAD.getExt() != null ? splashAD.getExt().get("clickUrl") : ""));
*/ // }
@TargetApi(Build.VERSION_CODES.M) //
private void checkAndRequestPermission() { // /**
List<String> lackedPermission = new ArrayList<String>(); // * 倒计时回调,返回广告还将被展示的剩余时间。
if (!(checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)) { // * 通过这个接口,开发者可以自行决定是否显示倒计时提示,或者还剩几秒的时候显示倒计时
lackedPermission.add(Manifest.permission.READ_PHONE_STATE); // *
} // * @param millisUntilFinished 剩余毫秒数
// */
if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { // @Override
lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION); // public void onADTick(long millisUntilFinished) {
} // Log.i("AD_DEMO", "SplashADTick " + millisUntilFinished + "ms");
// if (skipView != null) {
// 快手SDK所需相关权限,存储权限,此处配置作用于流量分配功能,关于流量分配,详情请咨询商务;如果您的APP不需要快手SDK的流量分配功能,则无需申请SD卡权限 // skipView.setText(String.format(SKIP_TEXT, Math.round(millisUntilFinished / 1000f)));
if (!(checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) { // }
lackedPermission.add(Manifest.permission.READ_EXTERNAL_STORAGE); // }
} //
if (!(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) { // @Override
lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); // public void onADExposure() {
} // Log.i("AD_DEMO", "SplashADExposure");
// }
// 如果需要的权限都已经有了,那么直接调用SDK //
if (lackedPermission.size() == 0) { // @Override
fetchSplashAD(this, container, skipView, getPosId(), this, 0); // public void onADLoaded(long expireTimestamp) {
} else { // Log.i("AD_DEMO", "SplashADFetch expireTimestamp: " + expireTimestamp
// 否则,建议请求所缺少的权限,在onRequestPermissionsResult中再看是否获得权限 // + ", eCPMLevel = " + splashAD.getECPMLevel());
String[] requestPermissions = new String[lackedPermission.size()]; // }
lackedPermission.toArray(requestPermissions); //
requestPermissions(requestPermissions, 1024); // @Override
} // public void onADDismissed() {
} // Log.i("AD_DEMO", "SplashADDismissed");
// next();
private boolean hasAllPermissionsGranted(int[] grantResults) { // }
for (int grantResult : grantResults) { //
if (grantResult == PackageManager.PERMISSION_DENIED) { // @Override
return false; // public void onNoAD(AdError error) {
} // String str = String.format("LoadSplashADFail, eCode=%d, errorMsg=%s", error.getErrorCode(),
} // error.getErrorMsg());
return true; // Log.i("AD_DEMO", str);
} // /**
// * 为防止无广告时造成视觉上类似于"闪退"的情况,设定无广告时页面跳转根据需要延迟一定时间,demo
@Override // * 给出的延时逻辑是从拉取广告开始算开屏最少持续多久,仅供参考,开发者可自定义延时逻辑,如果开发者采用demo
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { // * 中给出的延时逻辑,也建议开发者考虑自定义minSplashTimeWhenNoAD的值
super.onRequestPermissionsResult(requestCode, permissions, grantResults); // **/
if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) { // long alreadyDelayMills = System.currentTimeMillis() - fetchSplashADTime;//从拉广告开始到onNoAD已经消耗了多少时间
fetchSplashAD(this, container, skipView, getPosId(), this, 0); // long shouldDelayMills = alreadyDelayMills > minSplashTimeWhenNoAD ? 0 : minSplashTimeWhenNoAD
} else { // - alreadyDelayMills;//为防止加载广告失败后立刻跳离开屏可能造成的视觉上类似于"闪退"的情况,根据设置的minSplashTimeWhenNoAD
// Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show(); // // 计算出还需要延时多久
// Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); // handler.postDelayed(new Runnable() {
// intent.setData(Uri.parse("package:" + getPackageName())); // @Override
// startActivity(intent); // public void run() {
// readyGoOtherActivity();
// }
// }, shouldDelayMills);
// }
//
// /**
// * 设置一个变量来控制当前开屏页面是否可以跳转,当开屏广告为普链类广告时,点击会打开一个广告落地页,此时开发者还不能打开自己的App主页。当从广告落地页返回以后,
// * 才可以跳转到开发者自己的App主页;当开屏广告是App类广告时只会下载App。
// */
// private void next() {
// if (canJump) {
// readyGoOtherActivity();
// } else {
// canJump = true;
// }
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// canJump = false;
// }
//
// @Override
// protected void onResume() {
// super.onResume();
// if (canJump) {
// next();
// }
// canJump = true;
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// handler.removeCallbacksAndMessages(null);
// }
//
// /**
// * 开屏页一定要禁止用户对返回按钮的控制,否则将可能导致用户手动退出了App而广告无法正常曝光和计费
// */
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// return true;
// }
// return super.onKeyDown(keyCode, event);
// }
//
// private void readyGoOtherActivity() {
// finish(); // finish();
readyGoOtherActivity(); // }
} //}
}
/**
* 拉取开屏广告,开屏广告的构造方法有3种,详细说明请参考开发者文档。
*
* @param activity 展示广告的activity
* @param adContainer 展示广告的大容器
* @param skipContainer 自定义的跳过按钮:传入该view给SDK后,SDK会自动给它绑定点击跳过事件。SkipView的样式可以由开发者自由定制,其尺寸限制请参考activity_splash.xml或者接入文档中的说明。
* @param posId 广告位ID
* @param adListener 广告状态监听器
* @param fetchDelay 拉取广告的超时时长:取值范围[3000, 5000],设为0表示使用广点通SDK默认的超时时长。
*/
private void fetchSplashAD(Activity activity, ViewGroup adContainer, View skipContainer,
String posId, SplashADListener adListener, int fetchDelay) {
fetchSplashADTime = System.currentTimeMillis();
splashAD = new SplashAD(activity, skipContainer, posId, adListener, fetchDelay);
splashAD.fetchAndShowIn(adContainer);
}
@Override
public void onADPresent() {
Log.i("AD_DEMO", "SplashADPresent");
}
@Override
public void onADClicked() {
Log.i("AD_DEMO", "SplashADClicked clickUrl: "
+ (splashAD.getExt() != null ? splashAD.getExt().get("clickUrl") : ""));
}
/**
* 倒计时回调,返回广告还将被展示的剩余时间。
* 通过这个接口,开发者可以自行决定是否显示倒计时提示,或者还剩几秒的时候显示倒计时
*
* @param millisUntilFinished 剩余毫秒数
*/
@Override
public void onADTick(long millisUntilFinished) {
Log.i("AD_DEMO", "SplashADTick " + millisUntilFinished + "ms");
if (skipView != null) {
skipView.setText(String.format(SKIP_TEXT, Math.round(millisUntilFinished / 1000f)));
}
}
@Override
public void onADExposure() {
Log.i("AD_DEMO", "SplashADExposure");
}
@Override
public void onADLoaded(long expireTimestamp) {
Log.i("AD_DEMO", "SplashADFetch expireTimestamp: " + expireTimestamp
+ ", eCPMLevel = " + splashAD.getECPMLevel());
}
@Override
public void onADDismissed() {
Log.i("AD_DEMO", "SplashADDismissed");
next();
}
@Override
public void onNoAD(AdError error) {
String str = String.format("LoadSplashADFail, eCode=%d, errorMsg=%s", error.getErrorCode(),
error.getErrorMsg());
Log.i("AD_DEMO", str);
/**
* 为防止无广告时造成视觉上类似于"闪退"的情况,设定无广告时页面跳转根据需要延迟一定时间,demo
* 给出的延时逻辑是从拉取广告开始算开屏最少持续多久,仅供参考,开发者可自定义延时逻辑,如果开发者采用demo
* 中给出的延时逻辑,也建议开发者考虑自定义minSplashTimeWhenNoAD的值
**/
long alreadyDelayMills = System.currentTimeMillis() - fetchSplashADTime;//从拉广告开始到onNoAD已经消耗了多少时间
long shouldDelayMills = alreadyDelayMills > minSplashTimeWhenNoAD ? 0 : minSplashTimeWhenNoAD
- alreadyDelayMills;//为防止加载广告失败后立刻跳离开屏可能造成的视觉上类似于"闪退"的情况,根据设置的minSplashTimeWhenNoAD
// 计算出还需要延时多久
handler.postDelayed(new Runnable() {
@Override
public void run() {
readyGoOtherActivity();
}
}, shouldDelayMills);
}
/**
* 设置一个变量来控制当前开屏页面是否可以跳转,当开屏广告为普链类广告时,点击会打开一个广告落地页,此时开发者还不能打开自己的App主页。当从广告落地页返回以后,
* 才可以跳转到开发者自己的App主页;当开屏广告是App类广告时只会下载App。
*/
private void next() {
if (canJump) {
readyGoOtherActivity();
} else {
canJump = true;
}
}
@Override
protected void onPause() {
super.onPause();
canJump = false;
}
@Override
protected void onResume() {
super.onResume();
if (canJump) {
next();
}
canJump = true;
}
@Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacksAndMessages(null);
}
/**
* 开屏页一定要禁止用户对返回按钮的控制,否则将可能导致用户手动退出了App而广告无法正常曝光和计费
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
private void readyGoOtherActivity() {
finish();
}
}
...@@ -2,6 +2,7 @@ package com.mints.xunmi.ui.activitys; ...@@ -2,6 +2,7 @@ package com.mints.xunmi.ui.activitys;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
...@@ -163,5 +164,11 @@ public class SplashAdShowActivity extends BaseActivity implements ATSplashAdList ...@@ -163,5 +164,11 @@ public class SplashAdShowActivity extends BaseActivity implements ATSplashAdList
} }
} }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
} }
...@@ -2,6 +2,7 @@ package com.mints.xunmi.ui.activitys; ...@@ -2,6 +2,7 @@ package com.mints.xunmi.ui.activitys;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
...@@ -128,5 +129,11 @@ public class SplashBackActivity extends BaseActivity implements ATSplashAdListen ...@@ -128,5 +129,11 @@ public class SplashBackActivity extends BaseActivity implements ATSplashAdListen
} }
} }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
} }
...@@ -3,14 +3,13 @@ package com.mints.xunmi.ui.fragment ...@@ -3,14 +3,13 @@ package com.mints.xunmi.ui.fragment
import android.Manifest import android.Manifest
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Message
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
import android.widget.FrameLayout
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.mints.library.recyclerview.HeaderAndFooterRecyclerViewAdapter import com.mints.library.recyclerview.HeaderAndFooterRecyclerViewAdapter
import com.mints.library.recyclerview.RecyclerViewUtils import com.mints.library.recyclerview.RecyclerViewUtils
import com.mints.library.utils.nodoubleclick.AntiShake import com.mints.library.utils.nodoubleclick.AntiShake
import com.mints.xunmi.BuildConfig
import com.mints.xunmi.R import com.mints.xunmi.R
import com.mints.xunmi.ad.TopOnNativeAd import com.mints.xunmi.ad.TopOnNativeAd
import com.mints.xunmi.common.AppConfig import com.mints.xunmi.common.AppConfig
...@@ -26,7 +25,10 @@ import com.mints.xunmi.ui.adapter.MyConcernedPeopleAdapter ...@@ -26,7 +25,10 @@ import com.mints.xunmi.ui.adapter.MyConcernedPeopleAdapter
import com.mints.xunmi.ui.adapter.MyMainConcernedPeopleAdapterFooter import com.mints.xunmi.ui.adapter.MyMainConcernedPeopleAdapterFooter
import com.mints.xunmi.ui.fragment.base.BaseFragment import com.mints.xunmi.ui.fragment.base.BaseFragment
import com.mints.xunmi.ui.widgets.* import com.mints.xunmi.ui.widgets.*
import com.mints.xunmi.utils.LogUtil
import com.mints.xunmi.utils.SPUtil import com.mints.xunmi.utils.SPUtil
import com.mints.xunmi.utils.WeakHandler
import com.mints.xunmi.utils.WeakHandler.IHandler
import com.tbruyelle.rxpermissions.RxPermissions import com.tbruyelle.rxpermissions.RxPermissions
import kotlinx.android.synthetic.main.fragment_main_first.* import kotlinx.android.synthetic.main.fragment_main_first.*
...@@ -36,10 +38,17 @@ import kotlinx.android.synthetic.main.fragment_main_first.* ...@@ -36,10 +38,17 @@ import kotlinx.android.synthetic.main.fragment_main_first.*
* 时间:2020/6/4 17:30 * 时间:2020/6/4 17:30
*/ */
class MainFragment : BaseFragment() class MainFragment : BaseFragment()
, MainFragmentView, MyConcernedPeopleAdapter.OnItemClickListener, View.OnClickListener { , MainFragmentView, MyConcernedPeopleAdapter.OnItemClickListener
, View.OnClickListener, IHandler {
private val TAG = MainFragment::class.java.simpleName private val TAG = MainFragment::class.java.simpleName
/*首页位置刷新相关*/
private var refreshLocationFlag = true
private val LOCATION_TIME: Long = 3000
private val LOCATION_MSG: Int = 102
private var mHandler: WeakHandler? = null
private var friendsSetBottomDialog: FriendsSetBottomDialog? = null private var friendsSetBottomDialog: FriendsSetBottomDialog? = null
private var powerDialog: PowerDialog? = null private var powerDialog: PowerDialog? = null
private var messageDialog: MessageDialog? = null private var messageDialog: MessageDialog? = null
...@@ -69,7 +78,7 @@ class MainFragment : BaseFragment() ...@@ -69,7 +78,7 @@ class MainFragment : BaseFragment()
context?.let { context?.let {
TopOnNativeAd.init(it) TopOnNativeAd.init(it)
TopOnNativeAd.loadNativeAd(it, null) TopOnNativeAd.loadNativeAd(null)
} }
linearLayoutManager = LinearLayoutManager(activity) linearLayoutManager = LinearLayoutManager(activity)
...@@ -85,6 +94,8 @@ class MainFragment : BaseFragment() ...@@ -85,6 +94,8 @@ class MainFragment : BaseFragment()
// discountDialog() // discountDialog()
// } // }
// } // }
mHandler = WeakHandler(this)
} }
override fun onHiddenChanged(hidden: Boolean) { override fun onHiddenChanged(hidden: Boolean) {
...@@ -129,27 +140,34 @@ class MainFragment : BaseFragment() ...@@ -129,27 +140,34 @@ class MainFragment : BaseFragment()
getCares(null) getCares(null)
mainFragmentPresenter?.userLogin(context!!) mainFragmentPresenter?.userLogin(context!!)
} }
// refreshLocationFlag = true
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
} }
} }
override fun onPause() {
super.onPause()
refreshLocationFlag = false
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
mHandler?.removeCallbacksAndMessages(null)
mHandler = null
mainFragmentPresenter.detachView() mainFragmentPresenter.detachView()
} }
override fun getCares(data: MyCareBean?) { override fun getCares(data: MyCareBean?) {
if (activity != null && !activity!!.isFinishing()) { if (activity != null && !activity!!.isFinishing()) {
myConcernedPeopleBeanArrayList = arrayListOf<MyCareBean.ListBean>() myConcernedPeopleBeanArrayList = arrayListOf<MyCareBean.ListBean>()
val people = MyCareBean.ListBean() myConcernedPeopleBeanArrayList?.addAll(listOf(getMyLocationInfo()))
people.cmobile = "我自己"
people.update = System.currentTimeMillis() / 1000
people.gpsMsg = AppConfig.curAddress
people.cuid = Constant.MY_USER_UID
(myConcernedPeopleBeanArrayList as ArrayList<MyCareBean.ListBean>).addAll(listOf(people))
if (data != null && data.list != null && data.list.size > 0) { if (data != null && data.list != null && data.list.size > 0) {
(myConcernedPeopleBeanArrayList as ArrayList<MyCareBean.ListBean>).addAll(data.list) myConcernedPeopleBeanArrayList?.addAll(data.list)
} }
initRvView() initRvView()
...@@ -298,7 +316,7 @@ class MainFragment : BaseFragment() ...@@ -298,7 +316,7 @@ class MainFragment : BaseFragment()
} }
private fun initManager() { private fun initManager() {
spUtil = SPUtil.getInstance(context) spUtil = SPUtil.getInstance()
userManager = UserManager.getInstance() userManager = UserManager.getInstance()
// 首次安装APP时,只弹一次权限声明 // 首次安装APP时,只弹一次权限声明
...@@ -410,22 +428,46 @@ class MainFragment : BaseFragment() ...@@ -410,22 +428,46 @@ class MainFragment : BaseFragment()
* 五折弹窗 * 五折弹窗
*/ */
private fun discountDialog() { private fun discountDialog() {
discountDialog = DiscountDialog(context, object : DialogListener() { // discountDialog = DiscountDialog(context, object : DialogListener() {
override fun onClick(v: View) { // override fun onClick(v: View) {
if (activity != null && !activity!!.isFinishing() && // if (activity != null && !activity!!.isFinishing() &&
discountDialog != null && discountDialog!!.isShowing()) { // discountDialog != null && discountDialog!!.isShowing()) {
discountDialog!!.onDestory() // discountDialog!!.onDestory()
discountDialog!!.dismiss() // discountDialog!!.dismiss()
} // }
when (v.id) { // when (v.id) {
R.id.tv_dialog_discount -> { // R.id.tv_dialog_discount -> {
if (!userManager?.vipFlag!!) { // if (!userManager?.vipFlag!!) {
activity?.let { VipPayManager.getInstance(it)!!.gotoPayPage(3) } // activity?.let { VipPayManager.getInstance(it)!!.gotoPayPage(3) }
// }
// }
// }
// }
// })
// discountDialog!!.show()
} }
override fun handleMsg(msg: Message?) {
if (msg?.what == LOCATION_MSG) {
if (activity != null && !activity!!.isFinishing() && refreshLocationFlag) {
LogUtil.d(TAG, "mainfragment handleMsg")
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
myConcernedPeopleBeanArrayList?.set(0, getMyLocationInfo())
myConcernedPeopleAdapter.notifyItemChanged(0)
} }
} }
} }
})
discountDialog!!.show() fun getMyLocationInfo(): MyCareBean.ListBean {
val people = MyCareBean.ListBean()
people.cmobile = "我自己"
people.update = System.currentTimeMillis() / 1000
people.gpsMsg = AppConfig.curAddress
people.cuid = Constant.MY_USER_UID
return people
} }
} }
\ No newline at end of file
...@@ -68,7 +68,7 @@ class MyFragment : BaseFragment() ...@@ -68,7 +68,7 @@ class MyFragment : BaseFragment()
} }
myPresenter.attachView(this) myPresenter.attachView(this)
spUtil = SPUtil.getInstance(context) spUtil = SPUtil.getInstance()
userManager = UserManager.getInstance() userManager = UserManager.getInstance()
drawable = activity?.let { ContextCompat.getDrawable(it, R.mipmap.ic_launcher) } drawable = activity?.let { ContextCompat.getDrawable(it, R.mipmap.ic_launcher) }
initListener() initListener()
...@@ -92,7 +92,7 @@ class MyFragment : BaseFragment() ...@@ -92,7 +92,7 @@ class MyFragment : BaseFragment()
myPresenter?.userLogin(context!!) myPresenter?.userLogin(context!!)
} }
// context?.let { TopOnNativeAd.loadNativeAd(it, flMyAdContainer) } TopOnNativeAd.loadNativeAd(flMyAdContainer)
} }
} }
...@@ -168,7 +168,6 @@ class MyFragment : BaseFragment() ...@@ -168,7 +168,6 @@ class MyFragment : BaseFragment()
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
TopOnNativeAd.onDestroy()
myPresenter.detachView() myPresenter.detachView()
} }
...@@ -187,12 +186,6 @@ class MyFragment : BaseFragment() ...@@ -187,12 +186,6 @@ class MyFragment : BaseFragment()
override fun getSysBaseMsg(msgNum: Int, notifyNum: Int, phone: String) { override fun getSysBaseMsg(msgNum: Int, notifyNum: Int, phone: String) {
if (activity != null && !activity!!.isFinishing()) { if (activity != null && !activity!!.isFinishing()) {
// if (msgNum >= 1) {
// ivMyFragmentNofity.setImageResource(R.mipmap.ic_main_msg_enable)
// } else {
// ivMyFragmentNofity.setImageResource(R.mipmap.ic_main_msg)
// }
if (notifyNum >= 1) { if (notifyNum >= 1) {
messageDialog() messageDialog()
} }
...@@ -271,21 +264,6 @@ class MyFragment : BaseFragment() ...@@ -271,21 +264,6 @@ class MyFragment : BaseFragment()
readyGo(WebActivity::class.java, bundle) readyGo(WebActivity::class.java, bundle)
} }
R.id.rlMyShare -> { R.id.rlMyShare -> {
// sendSMS(BuildConfig.MainIp + "instructions.html")
// val wechat_sp = ShareParams()
// wechat_sp.shareType = Platform.SHARE_WEBPAGE
// wechat_sp.title = Constant.SHARE_TITLE
// wechat_sp.text = Constant.SHARE_CONTENT
// wechat_sp.imageData = ImageUtil.drawableToBitmap(drawable)
// wechat_sp.url = Constant.SHARE_URL
// val wechat = ShareSDK.getPlatform(Wechat.NAME)
// if (wechat.isClientValid) {
// // 执行图文分享
// wechat.share(wechat_sp)
// } else {
// showToast("请先安装微信")
// }
bottomDialog = BottomDialog.create(supportFragmentManager) bottomDialog = BottomDialog.create(supportFragmentManager)
.setViewListener { v -> .setViewListener { v ->
v.findViewById<LinearLayout>(R.id.llDialogShareWx).setOnClickListener(this) v.findViewById<LinearLayout>(R.id.llDialogShareWx).setOnClickListener(this)
...@@ -326,22 +304,6 @@ class MyFragment : BaseFragment() ...@@ -326,22 +304,6 @@ class MyFragment : BaseFragment()
} }
AppPackageUsageUtils.gotoMessage(context, "") AppPackageUsageUtils.gotoMessage(context, "")
// val sp = ShareParams()
// sp.title = Constant.SHARE_TITLE
// sp.titleUrl = Constant.SHARE_URL
// sp.text = Constant.SHARE_CONTENT
// sp.site = getString(R.string.app_name)
// sp.siteUrl = Constant.SHARE_URL
// val qq = ShareSDK.getPlatform(QQ.NAME)
// if (qq.isClientValid) {
// // 执行图文分享
// qq.share(sp)
// } else {
// showToast("请先安装QQ")
// }
} }
R.id.tvDialogShareNext -> { R.id.tvDialogShareNext -> {
if (activity != null && !activity!!.isFinishing()) { if (activity != null && !activity!!.isFinishing()) {
......
...@@ -6,6 +6,7 @@ import android.content.Intent ...@@ -6,6 +6,7 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Message
import android.provider.Settings import android.provider.Settings
import android.text.TextUtils import android.text.TextUtils
import android.view.LayoutInflater import android.view.LayoutInflater
...@@ -29,6 +30,7 @@ import com.mints.xunmi.ui.activitys.CarePeopleActivity ...@@ -29,6 +30,7 @@ import com.mints.xunmi.ui.activitys.CarePeopleActivity
import com.mints.xunmi.ui.activitys.MyLocusActivity import com.mints.xunmi.ui.activitys.MyLocusActivity
import com.mints.xunmi.utils.LogUtil import com.mints.xunmi.utils.LogUtil
import com.mints.xunmi.utils.TimeRender import com.mints.xunmi.utils.TimeRender
import com.mints.xunmi.utils.WeakHandler
import com.tbruyelle.rxpermissions.RxPermissions import com.tbruyelle.rxpermissions.RxPermissions
import kotlinx.android.synthetic.main.fragment_main_position.* import kotlinx.android.synthetic.main.fragment_main_position.*
import java.util.* import java.util.*
...@@ -39,10 +41,16 @@ import java.util.* ...@@ -39,10 +41,16 @@ import java.util.*
* 时间:2020/6/4 17:30 * 时间:2020/6/4 17:30
*/ */
class PositionFragment : Fragment() class PositionFragment : Fragment()
, PositionView, View.OnClickListener { , PositionView, View.OnClickListener, WeakHandler.IHandler {
private val TAG = PositionFragment::class.java.simpleName private val TAG = PositionFragment::class.java.simpleName
/*首页位置刷新相关*/
private var refreshLocationFlag = true
private val LOCATION_TIME: Long = 3000
private val LOCATION_MSG: Int = 103
private var mHandler: WeakHandler? = null
private lateinit var positionPresenter: PositionPresenter private lateinit var positionPresenter: PositionPresenter
private var mapLayout: View? = null private var mapLayout: View? = null
...@@ -82,6 +90,7 @@ class PositionFragment : Fragment() ...@@ -82,6 +90,7 @@ class PositionFragment : Fragment()
positionPresenter?.userLogin(context!!) positionPresenter?.userLogin(context!!)
} }
mHandler = WeakHandler(this)
initMapStyle() initMapStyle()
initListener() initListener()
...@@ -120,19 +129,21 @@ class PositionFragment : Fragment() ...@@ -120,19 +129,21 @@ class PositionFragment : Fragment()
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (AppConfig.fragmentClickFlag === Constant.FRAGMENT_CLICK_POSITION) { if (AppConfig.fragmentClickFlag === Constant.FRAGMENT_CLICK_POSITION) {
tvFragmentPositionPosition.text = AppConfig.curAddress tvFragmentPositionPosition.text = AppConfig.curAddress
tvFragmentPositionDate.text = TimeRender.formatDate(Date(), TimeRender.ALL_FORMAT_LINE2) tvFragmentPositionDate.text = TimeRender.formatDate(Date(), TimeRender.ALL_FORMAT_LINE2)
if (mapPosition != null) { if (mapPosition != null) {
mapPosition.onResume() mapPosition.onResume()
} }
LogUtil.d(TAG, " PositionFragment onResume")
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
} }
} }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
refreshLocationFlag = false
if (mapPosition != null) { if (mapPosition != null) {
mapPosition.onPause() mapPosition.onPause()
} }
...@@ -148,6 +159,9 @@ class PositionFragment : Fragment() ...@@ -148,6 +159,9 @@ class PositionFragment : Fragment()
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
mHandler?.removeCallbacksAndMessages(null)
mHandler = null
mMap?.let { mMap?.let {
mMap!!.setOnMyLocationChangeListener(null) mMap!!.setOnMyLocationChangeListener(null)
mMap = null mMap = null
...@@ -191,20 +205,20 @@ class PositionFragment : Fragment() ...@@ -191,20 +205,20 @@ class PositionFragment : Fragment()
// 实现定位蓝点 // 实现定位蓝点
myLocationStyle = MyLocationStyle() //初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE)//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。 myLocationStyle = MyLocationStyle() //初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE)//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
myLocationStyle?.let { myLocationStyle?.let {
myLocationStyle!!.showMyLocation(true)//设置是否显示定位小蓝点,用于满足只想使用定位,不想使用定位小蓝点的场景,设置false以后图面上不再有定位蓝点的概念,但是会持续回调位置信息。 it.showMyLocation(true)//设置是否显示定位小蓝点,用于满足只想使用定位,不想使用定位小蓝点的场景,设置false以后图面上不再有定位蓝点的概念,但是会持续回调位置信息。
myLocationStyle!!.interval(5000) //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。 it.interval(5000) //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
} }
mMap?.let { mMap?.let {
uiSettings = mMap!!.getUiSettings() uiSettings = it.getUiSettings()
mMap!!.moveCamera(CameraUpdateFactory.zoomTo(16F))//设置希望展示的地图缩放级别 it.moveCamera(CameraUpdateFactory.zoomTo(16F))//设置希望展示的地图缩放级别
mMap!!.setMyLocationStyle(myLocationStyle!!.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE))//连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动 it.setMyLocationStyle(myLocationStyle!!.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE))//连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动
mMap!!.setMyLocationEnabled(true) // 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。 it.setMyLocationEnabled(true) // 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
} }
uiSettings?.let { uiSettings?.let {
uiSettings!!.setMyLocationButtonEnabled(false)//设置默认定位按钮是否显示 it.setMyLocationButtonEnabled(false)//设置默认定位按钮是否显示
uiSettings!!.setScaleControlsEnabled(false)//设置地图默认的比例尺是否显示 it.setScaleControlsEnabled(false)//设置地图默认的比例尺是否显示
uiSettings!!.setZoomControlsEnabled(false)//设置缩放按钮 it.setZoomControlsEnabled(false)//设置缩放按钮
} }
} }
...@@ -215,15 +229,12 @@ class PositionFragment : Fragment() ...@@ -215,15 +229,12 @@ class PositionFragment : Fragment()
} }
override fun showLoading(msg: String?) { override fun showLoading(msg: String?) {
TODO("Not yet implemented")
} }
override fun showToast(msg: String?) { override fun showToast(msg: String?) {
TODO("Not yet implemented")
} }
override fun hideLoading() { override fun hideLoading() {
TODO("Not yet implemented")
} }
override fun getBaseApplication(): MintsApplication = activity?.application as MintsApplication override fun getBaseApplication(): MintsApplication = activity?.application as MintsApplication
...@@ -263,4 +274,18 @@ class PositionFragment : Fragment() ...@@ -263,4 +274,18 @@ class PositionFragment : Fragment()
builder.setCancelable(false) builder.setCancelable(false)
builder.show() builder.show()
} }
override fun handleMsg(msg: Message?) {
if (msg?.what == LOCATION_MSG) {
if (activity != null && !activity!!.isFinishing() && refreshLocationFlag) {
LogUtil.d(TAG, "PositionFragment handleMsg")
tvFragmentPositionPosition?.text = AppConfig.curAddress
tvFragmentPositionDate?.text = TimeRender.formatDate(Date(), TimeRender.ALL_FORMAT_LINE2)
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
}
}
}
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ package com.mints.xunmi.utils; ...@@ -3,6 +3,8 @@ package com.mints.xunmi.utils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import com.mints.xunmi.MintsApplication;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -22,9 +24,9 @@ public class SPUtil { ...@@ -22,9 +24,9 @@ public class SPUtil {
private static SPUtil spUtil; private static SPUtil spUtil;
public static SPUtil getInstance(Context context) { public static SPUtil getInstance() {
if (spUtil == null) { if (spUtil == null) {
mContext = context; mContext = MintsApplication.getContext();
spUtil = new SPUtil(); spUtil = new SPUtil();
mPreferences = mContext.getSharedPreferences(mShareName, Context.MODE_PRIVATE); mPreferences = mContext.getSharedPreferences(mShareName, Context.MODE_PRIVATE);
} }
......
...@@ -399,6 +399,7 @@ ...@@ -399,6 +399,7 @@
android:scaleType="fitXY" android:scaleType="fitXY"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="20pt" android:layout_marginTop="20pt"
android:layout_marginBottom="20pt"
android:src="@mipmap/bg_banner" /> android:src="@mipmap/bg_banner" />
</LinearLayout> </LinearLayout>
......
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