Commit 9adfd34d authored by mengcuiguang's avatar mengcuiguang

添加签名信息、代码混淆配置等

parent 1f44aa81
......@@ -54,17 +54,17 @@ android {
// 签名配置
signingConfigs {
debug {
// storeFile file(RELEASE_STORE_FILE)
// storePassword RELEASE_STORE_PASSWORD
// keyAlias RELEASE_KEY_ALIAS
// keyPassword RELEASE_KEY_PASSWORD
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
release {
// storeFile file(RELEASE_STORE_FILE)
// storePassword RELEASE_STORE_PASSWORD
// keyAlias RELEASE_KEY_ALIAS
// keyPassword RELEASE_KEY_PASSWORD
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
......@@ -78,7 +78,7 @@ android {
//混淆
minifyEnabled false
zipAlignEnabled false
shrinkResources false//打开
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
......@@ -93,7 +93,7 @@ android {
//混淆
minifyEnabled true
zipAlignEnabled true
shrinkResources true//打开
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
......@@ -111,7 +111,6 @@ android {
// 多渠道打包
productFlavors {
cleaner {}
cleanerpkg {}
}
......@@ -119,8 +118,14 @@ android {
flavor -> flavor.manifestPlaceholders = [CHANNEL_NAME_VALUE: name]
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [CHANNEL_NAME_VALUE: name]
// 自定义输出配置
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
outputFileName = "${variant.productFlavors[0].name}_${defaultConfig.versionName}.apk"
}
}
}
repositories {
......
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# By default, the flags in this file are appended to flags specified
# in /Users/mengcuiguang/Documents/softwareDevelopment/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
......@@ -12,10 +16,285 @@
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
#指定代码的压缩级别
-optimizationpasses 5
#包明不混合大小写
-dontusemixedcaseclassnames
#不去忽略非公共的库类
-dontskipnonpubliclibraryclasses
#优化 不优化输入的类文件
-dontoptimize
#预校验
-dontpreverify
#混淆时是否记录日志
-verbose
# 混淆时所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#保护注解
-keepattributes *Annotation*
#保护内部类 保护反射
-keepattributes Exceptions, Signature, InnerClasses ,EnclosingMethod
# 保持哪些类不被混淆
-keep public class * extends android.app.Fragment
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.data.BroadcastReceiver
-keep public class * extends android.data.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
#如果有引用v4包可以添加下面这行
-keep public class * extends android.support.v4.app.Fragment
#忽略警告
-ignorewarnings
##记录生成的日志数据,gradle build时在本项目根目录输出##
#apk 包内所有 class 的内部结构
-dump class_files.txt
#未混淆的类和成员
-printseeds seeds.txt
#列出从 apk 中删除的代码
-printusage unused.txt
#混淆前后的映射
-printmapping mapping.txt
########记录生成的日志数据,gradle build时 在本项目根目录输出-end######
# ===================== 混淆保护自己项目的部分代码以及引用的第三方jar包library ================
#okhttp
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.** { *;}
-dontwarn okio.**
#忽略警告
-dontwarn retrofit.**
#保留一个完整的包
-keep class retrofit.** {
*;
}
#忽略警告
-dontwarn rx.internal.util.unsafe.**
#保留一个完整的包
-keep class rx.internal.util.unsafe.** {
*;
}
#忽略警告
-dontwarn uk.co.senab.photoview.**
#保留一个完整的包
-keep class uk.co.senab.photoview.** {
*;
}
#忽略警告
-dontwarn rx.internal.util.unsafe.**
#保留一个完整的包
-keep class rx.internal.util.unsafe.** {
*;
}
#忽略警告
-dontwarn com.mints.cleaner.model.bean.**
#保留实体类
-keep class com.mints.cleaner.model.bean.** {
*;
}
#忽略警告
-dontwarn com.mints.cleaner.widget.**
#保留实体类
-keep class com.mints.cleaner.widget.** {
*;
}
#系统的design 忽略警告
-dontwarn android.support.design.widget.**
#保留实体类
-keep class android.support.design.widget.** {
*;
}
#系统的renderscript 忽略警告
-dontwarn android.support.v8.renderscript.**
#保留实体类
-keep class android.support.v8.renderscript.** {
*;
}
#忽略警告
-dontwarn cn.com.library.rxbus.**
#保留实体类
-keep class cn.com.library.rxbus.** {*;}
#忽略警告
-dontwarn cn.fraudmetrix.sdk.**
#保留一个完整的包
-keep class cn.fraudmetrix.sdk.** {
*;
}
#忽略警告
-dontwarn com.nineoldandroids.**
#保留一个完整的包
-keep class com.nineoldandroids.** {
*;
}
#忽略警告
-dontwarn Decoder.**
#保留一个完整的包
-keep class Decoder.** {
*;
}
#忽略警告
-dontwarn com.nostra13.universalimageloader.**
#保留实体类
-keep class com.nostra13.universalimageloader.** {
*;
}
#忽略警告
-dontwarn com.megvii.**
#保留实体类
-keep class com.megvii.** { *; }
-dontwarn cn.jpush.**
-keep class cn.jpush.** { *; }
#如果引用了v4或者v7包
-dontwarn android.support.**
#如果用用到Gson解析包的,直接添加下面这几行就能成功混淆,不然会报错。
#gson
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
# ===================== 混淆保护自己项目的部分代码以及引用的第三方jar包library-end ================
-keep public class * extends android.view.View {
public <init>(android.data.Context);
public <init>(android.data.Context, android.util.AttributeSet);
public <init>(android.data.Context, android.util.AttributeSet, int);
public void set*(...);
}
#保持 native 方法不被混淆
-keepclasseswithmembernames class * {
native <methods>;
}
#保持自定义控件类不被混淆
-keepclasseswithmembers class * {
public <init>(android.data.Context, android.util.AttributeSet);
}
#保持自定义控件类不被混淆
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
#保持 Parcelable 不被混淆
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#保持 Serializable 不被混淆
-keepnames class * implements java.io.Serializable
#保持 Serializable 不被混淆并且enum 类也不被混淆
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
#保持枚举 enum 类不被混淆 如果混淆报错,建议直接使用上面的 -keepclassmembers class * implements java.io.Serializable即可
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * {
public void *ButtonClicked(android.view.View);
}
#不混淆资源类
-keepclassmembers class **.R$* {
public static <fields>;
}
# 避免影响升级功能,需要keep住support包的类
-keep class android.support.**{*;}
# ===================== shareSDK START ================
-dontwarn com.mob.**
-dontwarn cn.sharesdk.**
-dontwarn **.R$*
-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class **.R$* {*;}
-keep class **.R{*;}
-keep class com.mob.**{*;}
# ======================= shareSDK END ===============
# ===================== umeng START ================
-keep class com.umeng.** {*;}
-keepclassmembers class * {
public <init> (org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class com.mints.cleaner.R$*{
public static final int *;
}
# ======================= umeng END ================
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
# ===================== TalkingData START ================
-dontwarn com.tendcloud.tenddata.**
-keep class com.tendcloud.** {*;}
-keep public class com.tendcloud.tenddata.** { public protected *;}
-keepclassmembers class com.tendcloud.tenddata.**{
public void *(***);
}
-keep class com.talkingdata.sdk.TalkingDataSDK {public *;}
-keep class com.apptalkingdata.** {*;}
-keep class dice.** {*; }
-dontwarn dice.**
# ======================= TalkingData END ================
......@@ -28,18 +28,16 @@
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/CustomAppTheme">
<!-- 屏幕适配 -->
<meta-data
android:name="android.max_aspect"
android:value="2.4" />
<activity
android:name=".ui.NavigationActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:name=".ui.splash.SplashActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait">
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -47,6 +45,11 @@
</intent-filter>
</activity>
<activity
android:name=".ui.NavigationActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait"/>
<activity
android:name=".ui.multiClean.MultiCleanActivity"
android:launchMode="singleTop" />
......@@ -60,9 +63,6 @@
android:theme="@style/CustomerTransparentTheme" />
<activity android:name=".ui.web.WebActivity" />
<activity android:name=".ui.fileClean.FileCleanActivity" />
<activity
android:name=".ui.splash.SplashActivity"
android:launchMode="singleTop" />
<activity android:name=".ui.setting.SettingActivity" />
<activity
android:name=".ui.PreviewActivity"
......
......@@ -44,12 +44,16 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
// 视频清理
const val MULTI_TYPE_VIDEO = "VIDEO"
// 音频清理
const val MULTI_TYPE_AUDIO = "AUDIO"
// 压缩包清理
const val MULTI_TYPE_ZIP = "ZIP"
// 安装包清理
const val MULTI_TYPE_APK = "APK"
// 大文件清理
const val MULTI_TYPE_BIGFILE = "OTHERS"
}
......@@ -235,10 +239,14 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
sIsScrolling = true
Glide.with(this@MultiCleanActivity).pauseRequests()
if (!this@MultiCleanActivity.isFinishing) {
Glide.with(this@MultiCleanActivity).pauseRequests()
}
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
if (sIsScrolling) {
Glide.with(this@MultiCleanActivity).resumeRequests()
if (!this@MultiCleanActivity.isFinishing) {
Glide.with(this@MultiCleanActivity).pauseRequests()
}
}
sIsScrolling = false
}
......
package com.mints.cleaner.ui.splash
import android.view.KeyEvent
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.AnimationSet
import com.mints.cleaner.R
import com.mints.cleaner.ui.NavigationActivity
import com.mints.cleaner.util.DeviceInfo
import com.mints.core.base.BaseActivity
import kotlinx.android.synthetic.main.activity_splash.*
/**
* 启动页
*/
class SplashActivity : BaseActivity() {
private val mAlph by lazy { AlphaAnimation(1f, 1f) }
private val animationSet by lazy { AnimationSet(true) }
override fun getLayoutResId(): Int = R.layout.activity_splash
override fun initView() {
if (!isTaskRoot) {
//点击Home键后再点击App图标,会回到原来的界面。今天重新打包后,但是在Debug模式下,一切正常,
// 但是把打完包的apk(Release)安装在其他手机上时,回到桌面后点击图标会重新打开启动页
finish()
return
}
// 校验APP签名
checkAppSign()
}
override fun initData() {
}
override fun toggleIsBack2Left() = true
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return if (keyCode == KeyEvent.KEYCODE_BACK) {
true
} else super.onKeyDown(keyCode, event)
}
override fun onDestroy() {
super.onDestroy()
if (mAlph != null) mAlph.cancel()
if (animationSet != null) {
animationSet.cancel()
animationSet.setAnimationListener(null)
}
}
/**
* 校验App签名
*/
private fun checkAppSign() {
val deviceInfo: DeviceInfo = DeviceInfo.getInstance()
if (!deviceInfo.getSignInfo()) {
finish()
} else {
setAnimation()
}
}
/**
* 动画实现
*/
private fun setAnimation() {
//渐变动画
mAlph.duration = 1000
mAlph.fillAfter = true
//动画集合
animationSet.addAnimation(mAlph)
splash_root.startAnimation(animationSet)
animationSet.setAnimationListener(mAnimationListener)
}
private val mAnimationListener: Animation.AnimationListener =
object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {}
override fun onAnimationRepeat(animation: Animation) {}
override fun onAnimationEnd(animation: Animation) {
readyGoThenKill(NavigationActivity::class.java)
}
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<item
android:id="@android:id/background"
android:drawable="@drawable/progress_bar_bg" />
android:drawable="@color/full_transparent" />
<item android:id="@android:id/progress">
<clip>
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:background="@color/white"
tools:context="com.mints.cleaner.ui.splash.SplashActivity">
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="启动页"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"></TextView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -29,6 +29,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_clean"
adapter="@{adapter}"
android:overScrollMode="never"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
......
......@@ -19,6 +19,7 @@
<color name="green_01">#7FFFAA</color>
<color name="green">#00FF00</color>
<color name="status_bg">#002444</color>
<color name="color_2B3238">#2B3238</color>
<color name="product_net_text">#121B32</color>
<color name="product_text">#172B54</color>
......
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
~
~ Licensed under the Apache License, Version 2.0 (the "License”);
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources>
<drawable name="progress_bar_bg">@color/full_transparent</drawable>
<drawable name="sr_primary">#2B3238</drawable>
<drawable name="sr_primary_r">@color/status_bg</drawable>
</resources>
\ No newline at end of file
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Cleaner</string>
<string name="app_sign">6e61a953</string>
<item name="BaseQuickAdapter_databinding_support" type="id" />
<item name="BaseQuickAdapter_dragging_support" type="id" />
......
<resources>
<style name="CustomAppTheme" parent="AppTheme.Base" />
<style name="AppTheme.NoneTranslucent" parent="AppTheme.Base">
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowAnimationStyle">@null</item>
</style>
<style name="AppTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/color_2B3238</item>
<item name="colorPrimaryDark">@color/color_2B3238</item>
<item name="colorAccent">@color/color_2B3238</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
......@@ -7,7 +23,6 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
p
<style name="CustomerTransparentTheme" parent="AppTheme">
<!-- 为窗体的Enter和Exit设置动画 -->
......
......@@ -6,7 +6,7 @@ object Versions {
const val minSdk = 21
const val targetSdk = 29
const val versionCode = 1
const val versionName = "1.0"
const val versionName = "1.0.0"
const val kotlin = "1.3.72"
const val coroutines = "1.3.9"
......@@ -47,6 +47,7 @@ object Versions {
const val orhanobut_logger = "2.2.0"
const val permissionx = "1.4.0"
const val android_processes = "1.1.1"
const val immersionbar = "2.3.3-beta15"
}
object Deps {
......@@ -97,7 +98,9 @@ object Deps {
const val android_processes = "com.jaredrummler:android-processes:${Versions.android_processes}"
// 类似sharedPreference 可多进程间访问
const val grandcentrix_sharedPreference = "net.grandcentrix.tray:tray:${Versions.grandcentrix_sharedPreference}"
// 权限管理
const val permissionx = "com.permissionx.guolindev:permissionx:${Versions.permissionx}"
// 状态栏适配
const val immersionbar = "com.gyf.immersionbar:immersionbar:${Versions.immersionbar}"
}
\ No newline at end of file
......@@ -38,6 +38,8 @@ dependencies {
implementation Deps.kotlin_stdlib
implementation Deps.appcompat
implementation Deps.core_ktx
// implementation Deps.systembartint
implementation Deps.immersionbar
// Navigation
api Deps.navigation_fragment_ktx
......
package com.mints.core.base
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
......@@ -158,5 +159,84 @@ abstract class BaseAppCompatActivity : TransitionActivity() {
}
}
/**
* startActivity
*
* @param clazz
*/
protected open fun readyGo(clazz: Class<*>) {
val intent = Intent(this, clazz)
startActivity(intent)
}
/**
* startActivity with bundle
*
* @param clazz
* @param bundle
*/
protected open fun readyGo(clazz: Class<*>, bundle: Bundle) {
val intent = Intent(this, clazz)
if (null != bundle) {
intent.putExtras(bundle)
}
startActivity(intent)
}
/**
* startActivity then finish
*
* @param clazz
*/
protected open fun readyGoThenKill(clazz: Class<*>) {
val intent = Intent(this, clazz)
startActivity(intent)
finish()
}
/**
* startActivity with bundle then finish
*
* @param clazz
* @param bundle
*/
protected open fun readyGoThenKill(clazz: Class<*>, bundle: Bundle) {
val intent = Intent(this, clazz)
if (null != bundle) {
intent.putExtras(bundle)
}
startActivity(intent)
finish()
}
/**
* startActivityForResult
*
* @param clazz
* @param requestCode
*/
protected open fun readyGoForResult(clazz: Class<*>, requestCode: Int) {
val intent = Intent(this, clazz)
startActivityForResult(intent, requestCode)
}
/**
* startActivityForResult with bundle
*
* @param clazz
* @param requestCode
* @param bundle
*/
protected open fun readyGoForResult(
clazz: Class<*>,
requestCode: Int,
bundle: Bundle?
) {
val intent = Intent(this, clazz)
if (null != bundle) {
intent.putExtras(bundle)
}
startActivityForResult(intent, requestCode)
}
}
\ No newline at end of file
package com.mints.core.util
import android.annotation.TargetApi
import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowManager
import com.gyf.barlibrary.ImmersionBar
object StatusBarUtil {
/**
* 修改状态栏为全透明
*
* @param activity
*/
@TargetApi(19)
fun transparencyBar(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val window = activity.window
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.TRANSPARENT
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
val window = activity.window
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
)
}
}
/**
* 状态栏亮色模式,设置状态栏黑色文字、图标,
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
*
* @param activity
* @return 1:MIUUI 2:Flyme 3:android6.0
*/
fun StatusBarLightMode(activity: Activity): Int {
var result = 0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (MIUISetStatusBarLightMode(activity, true)) {
//小米
result = 1
} else if (FlymeSetStatusBarLightMode(activity.window, true)) {
//魅族
result = 2
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//6.0以上
activity.window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
result = 3
} else {
//其他的都设置状态栏成半透明的,以下设置半透明是调用第三方ImmersionBar库的,根据个人需求更改,
ImmersionBar.with(activity).statusBarDarkFont(true, 0.5f).init()
}
}
return result
}
/**
* 设置状态栏图标为深色和魅族特定的文字风格
* 可以用来判断是否为Flyme用户
*
* @param window 需要设置的窗口
* @param dark 是否把状态栏文字及图标颜色设置为深色
* @return boolean 成功执行返回true
*/
fun FlymeSetStatusBarLightMode(
window: Window?,
dark: Boolean
): Boolean {
var result = false
if (window != null) {
try {
val lp = window.attributes
val darkFlag = WindowManager.LayoutParams::class.java
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON")
val meizuFlags = WindowManager.LayoutParams::class.java
.getDeclaredField("meizuFlags")
darkFlag.isAccessible = true
meizuFlags.isAccessible = true
val bit = darkFlag.getInt(null)
var value = meizuFlags.getInt(lp)
value = if (dark) {
value or bit
} else {
value and bit.inv()
}
meizuFlags.setInt(lp, value)
window.attributes = lp
result = true
} catch (e: Exception) {
}
}
return result
}
/**
* 需要MIUIV6以上
*
* @param activity
* @param dark 是否把状态栏文字及图标颜色设置为深色
* @return boolean 成功执行返回true
*/
fun MIUISetStatusBarLightMode(activity: Activity, dark: Boolean): Boolean {
var result = false
val window = activity.window
if (window != null) {
val clazz: Class<*> = window.javaClass
try {
var darkModeFlag = 0
val layoutParams =
Class.forName("android.view.MiuiWindowManager\$LayoutParams")
val field =
layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE")
darkModeFlag = field.getInt(layoutParams)
val extraFlagField = clazz.getMethod(
"setExtraFlags",
Int::class.javaPrimitiveType,
Int::class.javaPrimitiveType
)
if (dark) {
extraFlagField.invoke(window, darkModeFlag, darkModeFlag) //状态栏透明且黑色字体
} else {
extraFlagField.invoke(window, 0, darkModeFlag) //清除黑色字体
}
result = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上
if (dark) {
activity.window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
}
}
} catch (e: Exception) {
}
}
return result
}
}
\ No newline at end of file
......@@ -23,4 +23,9 @@ android.injected.testOnly=false
# --------------------------------------------配置属性------------------------------------------
DEBUG_URL="http://39.97.65.143:9082/pos-api/"
RELEASE_URL="https://api.mints-id.com/api-p1/"
\ No newline at end of file
RELEASE_URL="https://api.mints-id.com/api-p1/"
RELEASE_KEY_PASSWORD=mints.clean
RELEASE_KEY_ALIAS=mints_clean
RELEASE_STORE_PASSWORD=mints.clean
RELEASE_STORE_FILE=mints_clean.jks
\ No newline at end of file
package com.mints.ktx.bean
import java.io.Serializable
data class Person(val name:String,val age:Int) : Serializable
\ 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