Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
SkinLibrary
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gaodapeng
SkinLibrary
Commits
47c1673e
Commit
47c1673e
authored
Jul 01, 2021
by
gaodapeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改非androidx版本,增加maven脚本
parent
ccfe73a2
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
260 additions
and
34 deletions
+260
-34
build.gradle
demo/build.gradle
+4
-4
MainActivity.java
demo/src/main/java/com/study/skindemo/MainActivity.java
+5
-2
OneApplication.java
demo/src/main/java/com/study/skindemo/OneApplication.java
+1
-1
build.gradle
skin-lib/build.gradle
+31
-1
AndroidManifest.xml
skin-lib/src/main/AndroidManifest.xml
+2
-1
ActivityLifeCycleCallback.java
...ain/java/com/miya/skin_lib/ActivityLifeCycleCallback.java
+2
-2
SkinAttribute.java
skin-lib/src/main/java/com/miya/skin_lib/SkinAttribute.java
+9
-10
SkinLayoutInflaterFactory.java
...ain/java/com/miya/skin_lib/SkinLayoutInflaterFactory.java
+2
-2
SkinManager.java
skin-lib/src/main/java/com/miya/skin_lib/SkinManager.java
+6
-6
SkinPreference.java
skin-lib/src/main/java/com/miya/skin_lib/SkinPreference.java
+1
-1
SkinViewSupport.java
...-lib/src/main/java/com/miya/skin_lib/SkinViewSupport.java
+1
-1
SkinResources.java
.../src/main/java/com/miya/skin_lib/utils/SkinResources.java
+1
-2
SkinThemeUtils.java
...src/main/java/com/miya/skin_lib/utils/SkinThemeUtils.java
+194
-0
ExampleUnitTest.kt
skin-lib/src/test/java/com/study/libs/ExampleUnitTest.kt
+1
-1
No files found.
demo/build.gradle
View file @
47c1673e
apply
plugin:
'com.android.application'
android
{
compileSdkVersion
2
9
buildToolsVersion
"2
9.0.2
"
compileSdkVersion
2
8
buildToolsVersion
"2
8.0.3
"
defaultConfig
{
applicationId
"com.study.skindemo"
minSdkVersion
18
targetSdkVersion
2
9
targetSdkVersion
2
8
versionCode
1
versionName
"1.0"
...
...
@@ -29,7 +29,7 @@ dependencies {
implementation
fileTree
(
dir:
"libs"
,
include:
[
"*.jar"
])
implementation
"com.android.support:support-v13:28.0.0"
implementation
'com.google.android.material:material:1.2.1'
implementation
'com.android.support.constraint:constraint-layout:
1.1.2
'
implementation
'com.android.support.constraint:constraint-layout:
2.0.4
'
implementation
project
(
':skin-lib'
)
testImplementation
'junit:junit:4.12'
...
...
demo/src/main/java/com/study/skindemo/MainActivity.java
View file @
47c1673e
package
com
.
study
.
skindemo
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
androidx.annotation.RequiresApi
;
import
com.study.libs.SkinManager
;
import
com.miya.skin_lib.SkinManager
;
import
java.io.File
;
...
...
@@ -18,6 +20,7 @@ public class MainActivity extends AppCompatActivity {
setContentView
(
R
.
layout
.
activity_main
);
findViewById
(
R
.
id
.
btnCtl
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
@Override
public
void
onClick
(
View
v
)
{
SkinManager
.
getInstance
()
...
...
demo/src/main/java/com/study/skindemo/OneApplication.java
View file @
47c1673e
...
...
@@ -2,7 +2,7 @@ package com.study.skindemo;
import
android.app.Application
;
import
com.
study.libs
.SkinManager
;
import
com.
miya.skin_lib
.SkinManager
;
public
class
OneApplication
extends
Application
{
...
...
skin-lib/build.gradle
View file @
47c1673e
apply
plugin:
'com.android.library'
apply
plugin:
"maven-publish"
apply
plugin:
'maven'
//发布到maven 库中的插件
def
supportLibVersion
=
"28.0.0"
android
{
...
...
@@ -26,6 +28,34 @@ android {
dependencies
{
implementation
fileTree
(
dir:
"libs"
,
include:
[
"*.jar"
])
implementation
"com.android.support:support-v13:${supportLibVersion}"
testImplementation
'junit:junit:4.12'
}
//设置动态属性
ext
{
//发布到仓库用户名
publishUserName
=
"face-dev"
//发布到仓库地址
publishUserPassword
=
"Face-dev@2019"
//仓库地址
publishURL
=
"https://nexus.infra.miyatech.com/repository/shualianzhifu/"
publishVersion
=
'1.0'
//skin-lib-compat表示兼容之前版本,skin-lib是androidx版本的
publishArtifactId
=
"skin-lib-compat"
publishGroupId
=
'com.miya.iot'
}
uploadArchives
{
repositories
.
mavenDeployer
{
repository
(
url:
publishURL
)
{
//RELEASE
authentication
(
userName:
publishUserName
,
password:
publishUserPassword
)
}
pom
.
project
{
version
publishVersion
artifactId
publishArtifactId
groupId
publishGroupId
packaging
'aar'
description
'skin_lib'
}
}
}
\ No newline at end of file
skin-lib/src/main/AndroidManifest.xml
View file @
47c1673e
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.study.libs"
>
package=
"com.miya.skin_lib"
>
</manifest>
\ No newline at end of file
skin-lib/src/main/java/com/
study/libs
/ActivityLifeCycleCallback.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/ActivityLifeCycleCallback.java
View file @
47c1673e
package
com
.
study
.
libs
;
package
com
.
miya
.
skin_lib
;
import
android.app.Activity
;
import
android.app.Application
;
...
...
@@ -7,7 +7,7 @@ import android.support.annotation.NonNull;
import
android.support.v4.view.LayoutInflaterCompat
;
import
android.view.LayoutInflater
;
import
com.
study.libs
.utils.SkinThemeUtils
;
import
com.
miya.skin_lib
.utils.SkinThemeUtils
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
...
...
skin-lib/src/main/java/com/
study/libs
/SkinAttribute.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/SkinAttribute.java
View file @
47c1673e
package
com
.
study
.
libs
;
package
com
.
miya
.
skin_lib
;
import
android.graphics.drawable.ColorDrawable
;
import
android.graphics.drawable.Drawable
;
...
...
@@ -8,8 +8,7 @@ import android.view.View;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.study.libs.utils.SkinResources
;
import
com.study.libs.utils.SkinThemeUtils
;
import
com.miya.skin_lib.utils.SkinThemeUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -110,7 +109,7 @@ public class SkinAttribute {
Drawable
left
=
null
,
top
=
null
,
right
=
null
,
bottom
=
null
;
switch
(
skinPair
.
attributeName
)
{
case
"background"
:
Object
background
=
SkinResources
.
getInstance
().
getBackground
(
skinPair
Object
background
=
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getBackground
(
skinPair
.
resId
);
//背景可能是 @color 也可能是 @drawable
if
(
background
instanceof
Integer
)
{
...
...
@@ -120,7 +119,7 @@ public class SkinAttribute {
}
break
;
case
"src"
:
background
=
SkinResources
.
getInstance
().
getBackground
(
skinPair
.
resId
);
background
=
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getBackground
(
skinPair
.
resId
);
if
(
background
instanceof
Integer
)
{
((
ImageView
)
view
).
setImageDrawable
(
new
ColorDrawable
((
Integer
)
background
));
...
...
@@ -129,20 +128,20 @@ public class SkinAttribute {
}
break
;
case
"textColor"
:
((
TextView
)
view
).
setTextColor
(
SkinResources
.
getInstance
().
getColorStateList
((
TextView
)
view
).
setTextColor
(
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getColorStateList
(
skinPair
.
resId
));
break
;
case
"drawableLeft"
:
left
=
SkinResources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
left
=
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
break
;
case
"drawableTop"
:
top
=
SkinResources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
top
=
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
break
;
case
"drawableRight"
:
right
=
SkinResources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
right
=
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
break
;
case
"drawableBottom"
:
bottom
=
SkinResources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
bottom
=
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
getDrawable
(
skinPair
.
resId
);
break
;
default
:
break
;
...
...
skin-lib/src/main/java/com/
study/libs
/SkinLayoutInflaterFactory.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/SkinLayoutInflaterFactory.java
View file @
47c1673e
package
com
.
study
.
libs
;
package
com
.
miya
.
skin_lib
;
import
android.app.Activity
;
import
android.content.Context
;
...
...
@@ -10,7 +10,7 @@ import android.util.AttributeSet;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
com.
study.libs
.utils.SkinThemeUtils
;
import
com.
miya.skin_lib
.utils.SkinThemeUtils
;
import
java.lang.reflect.Constructor
;
import
java.util.HashMap
;
...
...
skin-lib/src/main/java/com/
study/libs
/SkinManager.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/SkinManager.java
View file @
47c1673e
package
com
.
study
.
libs
;
package
com
.
miya
.
skin_lib
;
import
android.app.Application
;
import
android.content.pm.PackageInfo
;
...
...
@@ -9,7 +9,7 @@ import android.os.Build;
import
android.support.annotation.RequiresApi
;
import
android.text.TextUtils
;
import
com.
study.libs.utils.SkinResource
s
;
import
com.
miya.skin_lib.utils.SkinThemeUtil
s
;
import
java.io.File
;
import
java.lang.reflect.Method
;
...
...
@@ -29,7 +29,7 @@ public class SkinManager extends Observable {
private
SkinManager
(
Application
application
)
{
this
.
application
=
application
;
SkinPreference
.
init
(
application
.
getApplicationContext
());
SkinResources
.
init
(
application
);
Skin
ThemeUtils
.
Skin
Resources
.
init
(
application
);
application
.
registerActivityLifecycleCallbacks
(
new
ActivityLifeCycleCallback
(
this
));
loadSkin
(
SkinPreference
.
getInstance
().
getSkin
());
}
...
...
@@ -60,7 +60,7 @@ public class SkinManager extends Observable {
public
void
loadSkin
(
String
skinPath
)
{
if
(
TextUtils
.
isEmpty
(
skinPath
)
&&
!
new
File
(
skinPath
).
exists
())
{
//如果为空或者不存在该文件,则不用管
SkinPreference
.
getInstance
().
reset
();
SkinResources
.
getInstance
().
reset
();
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
reset
();
}
else
{
try
{
Resources
appResource
=
application
.
getResources
();
...
...
@@ -71,7 +71,7 @@ public class SkinManager extends Observable {
Resources
skinResources
=
new
Resources
(
assetManager
,
appResource
.
getDisplayMetrics
(),
appResource
.
getConfiguration
());
PackageManager
packageManager
=
application
.
getPackageManager
();
PackageInfo
info
=
packageManager
.
getPackageArchiveInfo
(
skinPath
,
PackageManager
.
GET_ACTIVITIES
);
SkinResources
.
getInstance
().
applySkin
(
skinResources
,
info
.
packageName
);
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
applySkin
(
skinResources
,
info
.
packageName
);
SkinPreference
.
getInstance
().
setSkin
(
skinPath
);
}
catch
(
Exception
e
)
{
...
...
@@ -87,7 +87,7 @@ public class SkinManager extends Observable {
*/
public
void
reset
()
{
SkinPreference
.
getInstance
().
reset
();
SkinResources
.
getInstance
().
reset
();
Skin
ThemeUtils
.
Skin
Resources
.
getInstance
().
reset
();
setChanged
();
notifyObservers
();
}
...
...
skin-lib/src/main/java/com/
study/libs
/SkinPreference.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/SkinPreference.java
View file @
47c1673e
package
com
.
study
.
libs
;
package
com
.
miya
.
skin_lib
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
...
...
skin-lib/src/main/java/com/
study/libs
/SkinViewSupport.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/SkinViewSupport.java
View file @
47c1673e
package
com
.
study
.
libs
;
package
com
.
miya
.
skin_lib
;
public
interface
SkinViewSupport
{
...
...
skin-lib/src/main/java/com/
study/libs
/utils/SkinResources.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/utils/SkinResources.java
View file @
47c1673e
package
com
.
study
.
libs
.
utils
;
package
com
.
miya
.
skin_lib
.
utils
;
import
android.content.Context
;
import
android.content.res.ColorStateList
;
...
...
@@ -10,7 +10,6 @@ import android.text.TextUtils;
public
class
SkinResources
{
//皮肤包的包名
private
String
skinPkgName
;
//是否使用默认的皮肤,用原始的内容
...
...
skin-lib/src/main/java/com/
study/libs
/utils/SkinThemeUtils.java
→
skin-lib/src/main/java/com/
miya/skin_lib
/utils/SkinThemeUtils.java
View file @
47c1673e
package
com
.
study
.
libs
.
utils
;
package
com
.
miya
.
skin_lib
.
utils
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.res.ColorStateList
;
import
android.content.res.Resources
;
import
android.content.res.TypedArray
;
import
android.graphics.drawable.Drawable
;
import
android.os.Build
;
import
android.support.v4.content.res.ResourcesCompat
;
import
android.text.TextUtils
;
/**
* 修改主题信息
...
...
@@ -70,4 +76,119 @@ public class SkinThemeUtils {
}
}
public
static
class
SkinResources
{
//皮肤包的包名
private
String
skinPkgName
;
//是否使用默认的皮肤,用原始的内容
private
boolean
isDefaultSkin
=
true
;
//app原始的resource
private
Resources
appResources
;
//皮肤包的resources
private
Resources
skinResources
;
private
static
volatile
SkinResources
instance
;
private
SkinResources
(
Context
context
)
{
appResources
=
context
.
getResources
();
}
public
static
void
init
(
Context
context
)
{
if
(
null
==
instance
)
{
synchronized
(
SkinResources
.
class
)
{
if
(
null
==
instance
)
{
instance
=
new
SkinResources
(
context
);
}
}
}
}
public
static
SkinResources
getInstance
()
{
return
instance
;
}
public
void
reset
()
{
skinResources
=
null
;
skinPkgName
=
null
;
isDefaultSkin
=
true
;
}
public
void
applySkin
(
Resources
resources
,
String
pkgName
)
{
skinResources
=
resources
;
skinPkgName
=
pkgName
;
//是否使用默认皮肤
isDefaultSkin
=
TextUtils
.
isEmpty
(
pkgName
)
||
resources
==
null
;
}
/**
* 1. 通过原始app中的resId获取到自己的名字(R.color.icon_up,获取到的就是icon_up)和类型
* 2. 根据名字和类型获取皮肤包中的ID
*/
public
int
getIdentifier
(
int
resId
)
{
if
(
isDefaultSkin
)
{
return
resId
;
}
//获取名称,如:icon_up
String
resName
=
appResources
.
getResourceEntryName
(
resId
);
//获取类型,如:drawable
String
resType
=
appResources
.
getResourceTypeName
(
resId
);
int
skinId
=
skinResources
.
getIdentifier
(
resName
,
resType
,
skinPkgName
);
return
skinId
;
}
/**
* 输入主app的id,获取皮肤包中的
*/
public
int
getColor
(
int
resId
)
{
if
(
isDefaultSkin
)
{
return
appResources
.
getColor
(
resId
);
}
int
skinId
=
getIdentifier
(
resId
);
if
(
skinId
==
0
)
{
return
appResources
.
getColor
(
resId
);
}
return
skinResources
.
getColor
(
skinId
);
}
public
Drawable
getDrawable
(
int
resId
)
{
if
(
isDefaultSkin
)
{
return
ResourcesCompat
.
getDrawable
(
appResources
,
resId
,
null
);
}
int
skinId
=
getIdentifier
(
resId
);
if
(
skinId
==
0
)
{
return
ResourcesCompat
.
getDrawable
(
appResources
,
resId
,
null
);
}
return
ResourcesCompat
.
getDrawable
(
skinResources
,
skinId
,
null
);
}
public
ColorStateList
getColorStateList
(
int
resId
)
{
if
(
isDefaultSkin
)
{
return
ResourcesCompat
.
getColorStateList
(
appResources
,
resId
,
null
);
}
int
skinId
=
getIdentifier
(
resId
);
if
(
skinId
==
0
)
{
return
ResourcesCompat
.
getColorStateList
(
appResources
,
resId
,
null
);
}
return
ResourcesCompat
.
getColorStateList
(
skinResources
,
skinId
,
null
);
}
/**
* 可能是Color 也可能是drawable
*
* @return
*/
public
Object
getBackground
(
int
resId
)
{
String
resourceTypeName
=
appResources
.
getResourceTypeName
(
resId
);
if
(
"color"
.
equals
(
resourceTypeName
))
{
return
getColor
(
resId
);
}
else
{
// drawable
return
getDrawable
(
resId
);
}
}
}
}
skin-lib/src/test/java/com/study/libs/ExampleUnitTest.kt
View file @
47c1673e
package
com.
study.libs
package
com.
miya.skin_lib
import
org.junit.Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment