diff --git a/app/src/main/java/com/nnbc123/app/MainActivity.java b/app/src/main/java/com/nnbc123/app/MainActivity.java index a6e6a107c..39a475c3f 100644 --- a/app/src/main/java/com/nnbc123/app/MainActivity.java +++ b/app/src/main/java/com/nnbc123/app/MainActivity.java @@ -636,7 +636,7 @@ public class MainActivity extends BaseMvpActivity @SuppressLint("CheckResult") private void firstLoadedUserInfo() { //青少年弹窗处理 - PmDialogShowMrg.get().handle(new WeakReference<>(this)); +// PmDialogShowMrg.get().handle(new WeakReference<>(this)); //通知栏权限判断 NoticationsUiHelper.handle(this, getDialogManager()); diff --git a/app/src/main/java/com/nnbc123/app/home/fragment/MeFragment.kt b/app/src/main/java/com/nnbc123/app/home/fragment/MeFragment.kt index 4f9862024..9b2e857e5 100644 --- a/app/src/main/java/com/nnbc123/app/home/fragment/MeFragment.kt +++ b/app/src/main/java/com/nnbc123/app/home/fragment/MeFragment.kt @@ -433,14 +433,14 @@ class MeFragment : BaseFragment(), View.OnClickListener { "usercenter_nugift_pop_click" ) } - R.id.ll_pm_mode, R.id.tv_me_youth_mode -> PatriarchModeActivity.start(mContext) - R.id.tv_me_real_name -> CommonWebViewActivity.start( - mContext, - UriProvider.getTutuRealNamePage() - ) - R.id.tv_me_service -> { - CustomerServerHelper.contactCustomerServer(mContext) - } +// R.id.ll_pm_mode, R.id.tv_me_youth_mode -> PatriarchModeActivity.start(mContext) +// R.id.tv_me_real_name -> CommonWebViewActivity.start( +// mContext, +// UriProvider.getTutuRealNamePage() +// ) +// R.id.tv_me_service -> { +// CustomerServerHelper.contactCustomerServer(mContext) +// } R.id.tv_user_id -> { mUserInfo?.let { ClipboardUtil.clipboardCopyText(it.erbanNo.toString()) diff --git a/app/src/main/java/com/nnbc123/app/other/activity/SplashActivity.java b/app/src/main/java/com/nnbc123/app/other/activity/SplashActivity.java index bee4bd713..1f0ce7a74 100644 --- a/app/src/main/java/com/nnbc123/app/other/activity/SplashActivity.java +++ b/app/src/main/java/com/nnbc123/app/other/activity/SplashActivity.java @@ -13,6 +13,7 @@ import androidx.databinding.DataBindingUtil; import com.bumptech.glide.request.RequestOptions; import com.netease.nim.uikit.StatusBarUtil; import com.netease.nim.uikit.support.glide.GlideApp; +import com.nnbc123.library.common.util.DeviceUtil; import com.umeng.commonsdk.UMConfigure; import com.nnbc123.app.MainActivity; import com.nnbc123.app.NimMiddleActivity; @@ -20,7 +21,6 @@ import com.nnbc123.app.R; import com.nnbc123.app.application.XChatApplication; import com.nnbc123.app.databinding.ActivitySplashBinding; import com.nnbc123.app.other.SplashBitmapTransformation; -import com.nnbc123.app.other.dialog.PrivacyAgreementDialog; import com.nnbc123.core.channel_page.model.ChannelPageModel; import com.nnbc123.core.initial.InitialModel; import com.nnbc123.core.initial.SplashComponent; @@ -31,7 +31,7 @@ import com.nnbc123.core.utils.SharedPreferenceUtils; * @author xiaoyu * @date 2017/12/30 */ -public class SplashActivity extends AppCompatActivity implements View.OnClickListener, PrivacyAgreementDialog.OnCallBack { +public class SplashActivity extends AppCompatActivity implements View.OnClickListener { public static final String SHOW_PRIVACY_AGREEMENT = "show_privacy_agreement"; private static final int COUNT_DOWN_TIME = 3; @@ -71,30 +71,21 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis @SuppressLint("CheckResult") protected void initiate() { - checkPrivacyAgreement(); - } - - - private void checkPrivacyAgreement() { boolean isShowPrivacyAgreement = (boolean) SharedPreferenceUtils.get(SHOW_PRIVACY_AGREEMENT, true); if (isShowPrivacyAgreement) { - PrivacyAgreementDialog privacyAgreementDialog = new PrivacyAgreementDialog(this); - privacyAgreementDialog.setCancelable(false); - privacyAgreementDialog.setCanceledOnTouchOutside(false); - privacyAgreementDialog.setOnCallBack(this); - privacyAgreementDialog.show(); + SharedPreferenceUtils.put(SHOW_PRIVACY_AGREEMENT, false); + XChatApplication.initOtherSDK(); + showSplash(true); } else { showSplash(false); } } private void showSplash(boolean first) { - - UMConfigure.getOaid(this, oaid -> { - OaidUtil.setOaid(oaid); + if (!TextUtils.isEmpty(DeviceUtil.getAndroidID())) { + OaidUtil.setOaid(DeviceUtil.getAndroidID()); if (first) ChannelPageModel.get().checkAd(); - }); - + } mBinding.tvSkip.setVisibility(View.VISIBLE); // 不过期的,并且已经下载出来图片的闪屏页数据 mLocalSplashVo = InitialModel.get().getLocalSplashVo(); @@ -161,16 +152,4 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis } } - - @Override - public void onFinish(boolean isConfirm) { - if (isConfirm) { - SharedPreferenceUtils.put(SHOW_PRIVACY_AGREEMENT, false); - XChatApplication.initOtherSDK(); - showSplash(true); - } else { - finish(); - System.exit(0); - } - } } diff --git a/app/src/main/java/com/nnbc123/app/ui/setting/SettingActivity.java b/app/src/main/java/com/nnbc123/app/ui/setting/SettingActivity.java index 68bbbecb8..de6686fc5 100644 --- a/app/src/main/java/com/nnbc123/app/ui/setting/SettingActivity.java +++ b/app/src/main/java/com/nnbc123/app/ui/setting/SettingActivity.java @@ -93,26 +93,26 @@ public class SettingActivity extends BaseActivity implements View.OnClickListene setPhoneUI(""); } }); - WithdrawModel.get().getWithdrawUserInfo(AuthModel.get().getCurrentUid()) - .subscribe(withdrawInfo -> { - withdrawInfos = withdrawInfo; - if (withdrawInfo != null) { - if (!TextUtils.isEmpty(withdrawInfo.zxcAccount) && !withdrawInfo.zxcAccount.equals("null")) { - setAlipayUI(withdrawInfo.zxcAccount + "(" + withdrawInfo.zxcAccountName + ")"); - } else { - setAlipayUI(""); - } - } - }); +// WithdrawModel.get().getWithdrawUserInfo(AuthModel.get().getCurrentUid()) +// .subscribe(withdrawInfo -> { +// withdrawInfos = withdrawInfo; +// if (withdrawInfo != null) { +// if (!TextUtils.isEmpty(withdrawInfo.zxcAccount) && !withdrawInfo.zxcAccount.equals("null")) { +// setAlipayUI(withdrawInfo.zxcAccount + "(" + withdrawInfo.zxcAccountName + ")"); +// } else { +// setAlipayUI(""); +// } +// } +// }); } private void setPhoneUI(String phone) { settingBinding.tvPhone.setText(TextUtils.isEmpty(phone) ? "未绑定" : phone); } - private void setAlipayUI(String name) { - settingBinding.tvAlipay.setText(TextUtils.isEmpty(name) ? "未绑定" : name); - } +// private void setAlipayUI(String name) { +// settingBinding.tvAlipay.setText(TextUtils.isEmpty(name) ? "未绑定" : name); +// } private void initData() { settingBinding.versions.setText("V" + BasicConfig.getLocalVersionName(getApplicationContext())); @@ -148,21 +148,21 @@ public class SettingActivity extends BaseActivity implements View.OnClickListene } }); break; - case R.id.rly_alipay_binder://绑定支付宝 - if (UserModel.get().getCacheLoginUserInfo() == null) { - toast("无当前登录用户信息."); - return; - } - if (UserModel.get().getCacheLoginUserInfo().isBindPhone()) { - Intent intent = new Intent(getApplicationContext(), BinderAlipayActivity.class); - Bundle mBundle = new Bundle(); - mBundle.putSerializable("withdrawInfo", withdrawInfos); - intent.putExtras(mBundle); - startActivity(intent); - } else { - BindPhoneActivity.start(context); - } - break; +// case R.id.rly_alipay_binder://绑定支付宝 +// if (UserModel.get().getCacheLoginUserInfo() == null) { +// toast("无当前登录用户信息."); +// return; +// } +// if (UserModel.get().getCacheLoginUserInfo().isBindPhone()) { +// Intent intent = new Intent(getApplicationContext(), BinderAlipayActivity.class); +// Bundle mBundle = new Bundle(); +// mBundle.putSerializable("withdrawInfo", withdrawInfos); +// intent.putExtras(mBundle); +// startActivity(intent); +// } else { +// BindPhoneActivity.start(context); +// } +// break; case R.id.rly_contact_us: UIHelper.openContactUs(this); break; diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 3801f964f..ec39536e3 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -124,47 +124,47 @@ android:layout_marginEnd="15dp" android:background="@color/line_353548" /> - + + + + + + + - + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + - + - + + + + + + + + + + + + - + + + + + + + + + - + + + + + + + + + + + + + + - + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + - + diff --git a/library/src/module_common/java/com/nnbc123/library/common/util/DeviceUtil.kt b/library/src/module_common/java/com/nnbc123/library/common/util/DeviceUtil.kt new file mode 100644 index 000000000..c11268c95 --- /dev/null +++ b/library/src/module_common/java/com/nnbc123/library/common/util/DeviceUtil.kt @@ -0,0 +1,314 @@ +package com.nnbc123.library.common.util + +import android.annotation.SuppressLint +import android.app.ActivityManager +import android.content.Context +import android.os.Build +import android.os.Process +import android.provider.Settings +import android.telephony.TelephonyManager +import android.text.TextUtils +import com.nnbc123.library.common.application.BaseApp +import com.ut.device.UTDevice +import java.io.RandomAccessFile +import java.util.* + +/** + * create by wushaocheng 2023/2/15 + * 获取设备id + */ +object DeviceUtil { + private const val TAG = "DeviceUtils" + private const val ANDROID_ID_KEY = "android_id" + private const val cache_device_id = "cache_device_id" + private var deviceId = "" + private var mcc_mnc = "" + private var mcc = "" + private var mnc = "" + @Volatile + private var ANDROID_ID = "" + + /** + * 获取设备信息 + */ + var deviceDesc = "" + get() { + if (!TextUtils.isEmpty(field)) { + return field + } + field = + String.format("%s-%s-%s", Build.MANUFACTURER, Build.MODEL, Build.VERSION.RELEASE) + return field + } + private set + private const val MB = (1024 * 1024).toLong() + private var sLevelCache: LEVEL? = null + private var sTotalMemory: Long = 0 + + /** + * 获取设备等级,考虑到机身真实内存大小与参数规格里面的不太一致,排除系统可能占用的内存情况后,以下面方式来衡量: + * 1.内存小于等于4GB,定为中低端机 + * 2.内存大于4GB,定为高端机 + */ + fun getLevel(context: Context): LEVEL? { + if (null != sLevelCache) { + return sLevelCache + } + val totalMemory = getTotalMemory(context) + sLevelCache = if (totalMemory > 4 * 1024 * MB) { + //内存大于4GB,定为高端机 + LEVEL.HIGH + } else { + //内存小于等于4GB,定为中低端机 + LEVEL.LOW + } + return sLevelCache + } + + /** + * @return 当前进程id + */ + private val appId: Int + get() = Process.myPid() + + /** + * 获取设备内存总大小 + */ + private fun getTotalMemory(context: Context): Long { + if (0L != sTotalMemory) { + return sTotalMemory + } + val memInfo = ActivityManager.MemoryInfo() + val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + am.getMemoryInfo(memInfo) + sTotalMemory = memInfo.totalMem + return sTotalMemory + } + + /** + * 当前设备是否处于低内存状态 + */ + fun isLowMemory(context: Context): Boolean { + val memInfo = ActivityManager.MemoryInfo() + val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + am.getMemoryInfo(memInfo) + return memInfo.lowMemory + } + + /** + * 获取当前进程剩余内存大小 + */ + val appAvailableMemory: Long + get() { + val runtime = Runtime.getRuntime() + return runtime.totalMemory() - runtime.freeMemory() + } + + /** + * 获取当前设备CPU使用率 + */ + val appCpuRate: Double + get() { + var cpuTime = 0L + var appTime = 0L + var cpuRate = 0.0 + var procStatFile: RandomAccessFile? = null + var appStatFile: RandomAccessFile? = null + try { + procStatFile = RandomAccessFile("/proc/stat", "r") + val procStatString = procStatFile.readLine() + val procStats = procStatString.split(" ".toRegex()).dropLastWhile { it.isEmpty() } + .toTypedArray() + cpuTime = + procStats[2].toLong() + procStats[3].toLong() + procStats[4].toLong() + procStats[5].toLong() + procStats[6].toLong() + procStats[7].toLong() + procStats[8].toLong() + } catch (e: Exception) { + e.printStackTrace() + } finally { + try { + procStatFile?.close() + } catch (e: Exception) { + e.printStackTrace() + } + } + try { + appStatFile = RandomAccessFile("/proc/$appId/stat", "r") + val appStatString = appStatFile.readLine() + val appStats = + appStatString.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + appTime = appStats[13].toLong() + appStats[14].toLong() + } catch (e: Exception) { + e.printStackTrace() + } finally { + try { + appStatFile?.close() + } catch (e: Exception) { + e.printStackTrace() + } + } + if (0L != cpuTime) { + cpuRate = appTime.toDouble() / cpuTime.toDouble() * 100.0 + } + return cpuRate + } + + /** + * 获取设备id + */ + @JvmStatic + fun getDeviceId(context: Context?): String { + if (!TextUtils.isEmpty(deviceId)) { + return deviceId + } + deviceId = Config.getInstance(context).getString(cache_device_id, "") + if (!TextUtils.isEmpty(deviceId)) { + return deviceId + } + deviceId = UTDevice.getUtdid(context) + if (TextUtils.isEmpty(deviceId)) { + deviceId = handyDevicesId + Logger.info(TAG, "use handy deviceId=$deviceId") + } else { + Logger.info(TAG, "use system deviceId=$deviceId") + } + //缓存上次取到的数据,避免有些机型每次打开APP都能拿到一个新的设备id + Config.getInstance(context).putString(cache_device_id, deviceId) + return deviceId + } + + /** + * @return 获取系统id + */ + @SuppressLint("HardwareIds") + @JvmStatic + fun getAndroidID(): String { + if (!TextUtils.isEmpty(ANDROID_ID)) { + Logger.info(TAG, "getAndroidID from cache, ANDROID_ID=$ANDROID_ID") + return ANDROID_ID + } + ANDROID_ID = SPUtils.getString(ANDROID_ID_KEY, "") + if (!TextUtils.isEmpty(ANDROID_ID)) { + Logger.info(TAG, "getAndroidID from SP, ANDROID_ID=$ANDROID_ID") + return ANDROID_ID + } + ANDROID_ID = Settings.Secure.getString( + BaseApp.getContext().contentResolver, + Settings.Secure.ANDROID_ID + ) + Logger.info(TAG, "getAndroidID from system, ANDROID_ID=$ANDROID_ID") + SPUtils.putString(ANDROID_ID_KEY, ANDROID_ID) + return ANDROID_ID + } + + /** + * @return 手动组装设备id + */ + private val handyDevicesId: String + get() { + val devIDShort = + "35" + Build.BOARD.length % 10 + Build.BRAND.length % 10 + Build.DEVICE.length % 10 + Build.MANUFACTURER.length % 10 + Build.MODEL.length % 10 + Build.PRODUCT.length % 10 + val serial = "serial" + return UUID(devIDShort.hashCode().toLong(), serial.hashCode().toLong()).toString() + } + + /** + * @return 移动设备国家代码(英语:Mobile Country Code,MCC)+移动设备网络代码(英语:Mobile Network Code,MNC) + */ + private fun getMCC_MNC(context: Context): String { + if (!TextUtils.isEmpty(mcc_mnc)) { + return mcc_mnc + } + try { + val telManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager + mcc_mnc = telManager.simOperator + if (!TextUtils.isEmpty(mcc_mnc)) { + //双卡双待手机会返回[46001,46002] or [,46007] or [46007,]这种格式, + //先取第一个,如果第一个为空且第二个不为空,则取第二个 + val s = mcc_mnc.split(",".toRegex()).dropLastWhile { it.isEmpty() } + .toTypedArray() + if (s.isNotEmpty() && !TextUtils.isEmpty(s[0])) { + mcc_mnc = s[0] + } else { + if (s.size == 2 && !TextUtils.isEmpty(s[1])) { + mcc_mnc = s[1] + } + } + } + return mcc_mnc + } catch (e: Exception) { + Logger.error(TAG, e.message) + } + return "" + } + + /** + * @return 移动设备国家代码(英语:Mobile Country Code,MCC),三位 + */ + fun getMCC(context: Context): String { + if (!TextUtils.isEmpty(mcc)) { + return mcc + } + try { + val mcc_mnc = getMCC_MNC(context) + if (mcc_mnc.length > 2) { + mcc = mcc_mnc.substring(0, 3) + return mcc + } + } catch (e: Exception) { + Logger.error(TAG, e.message) + } + return "" + } + + /** + * @return 移动设备网络代码(英语:Mobile Network Code,MNC),两位或三位 + */ + fun getMNC(context: Context): String { + if (!TextUtils.isEmpty(mnc)) { + return mnc + } + try { + val mcc_mnc = getMCC_MNC(context) + if (mcc_mnc.length > 3) { + mnc = mcc_mnc.substring(3) + return mnc + } + } catch (e: Exception) { + Logger.error(TAG, e.message) + } + return "" + } + + /** + * 检查指定包名的APP是否已安装了 + * + * @param context 上下文对象 + * @param packageName 包名 + * @return 是否有安装指定包名的APP,true代表已安装,false代表未安装 + */ + fun isAppInstalled(context: Context?, packageName: String): Boolean { + return if (context == null) { + false + } else { + var installed = false + try { + val pm = context.packageManager + val info = pm.getApplicationInfo(packageName, 0) + if (info != null) { + installed = true + } + } catch (e: Exception) { + Logger.error(TAG, "isAppInstalled packageName=$packageName", e) + } + installed + } + } + + /** + * 设备等级划分方案参考Matrix框架, + * 参考:[...](https://github.com/Tencent/matrix/blob/master/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/DeviceUtil.java) + */ + enum class LEVEL(var value: Int) { + HIGH(2), LOW(1); + + } +} \ No newline at end of file