Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
MobileManager
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wang Xu
MobileManager
Commits
087cd240
Commit
087cd240
authored
Mar 31, 2020
by
Baoxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修改设置密码界面的小眼睛图标/两次激活延时
parent
248b41e2
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
515 additions
and
34 deletions
+515
-34
AndroidManifest.xml
Launcher3/AndroidManifest.xml
+5
-0
cb_selector.xml
Launcher3/res/drawable/cb_selector.xml
+3
-2
ic_chevron_right_gray_24dp.xml
Launcher3/res/drawable/ic_chevron_right_gray_24dp.xml
+5
-0
ic_visibility_gray_24dp.xml
Launcher3/res/drawable/ic_visibility_gray_24dp.xml
+5
-0
ic_visibility_off_gray_24dp.xml
Launcher3/res/drawable/ic_visibility_off_gray_24dp.xml
+5
-0
show_pwd.png
Launcher3/res/drawable/show_pwd.png
+0
-0
small_eyes.png
Launcher3/res/drawable/small_eyes.png
+0
-0
activity_pwd_pin_set.xml
Launcher3/res/layout/activity_pwd_pin_set.xml
+6
-6
activity_use_app.xml
Launcher3/res/layout/activity_use_app.xml
+64
-0
strings.xml
Launcher3/res/values/strings.xml
+4
-1
AppUseActivity.kt
.../com/android/launcher3/function/setting/AppUseActivity.kt
+43
-0
SettingActivity.kt
...com/android/launcher3/function/setting/SettingActivity.kt
+1
-1
ActivationHelper.kt
...java/com/secspace/lib/common/function/ActivationHelper.kt
+29
-24
WorkManager.kt
...main/java/com/secspace/lib/common/function/WorkManager.kt
+2
-0
TimeProgress.java
...a/com/secspace/lib/common/function/view/TimeProgress.java
+343
-0
No files found.
Launcher3/AndroidManifest.xml
View file @
087cd240
...
@@ -106,6 +106,11 @@
...
@@ -106,6 +106,11 @@
android:excludeFromRecents=
"true"
android:excludeFromRecents=
"true"
android:theme=
"@style/SettingTheme"
></activity>
android:theme=
"@style/SettingTheme"
></activity>
<activity
<activity
android:name=
".function.setting.AppUseActivity"
android:excludeFromRecents=
"true"
android:theme=
"@style/SettingTheme"
></activity>
<activity
android:name=
".ManagerAuthActivity"
android:name=
".ManagerAuthActivity"
android:excludeFromRecents=
"true"
android:excludeFromRecents=
"true"
android:theme=
"@style/Theme.AppCompat.Light.NoActionBar"
/>
android:theme=
"@style/Theme.AppCompat.Light.NoActionBar"
/>
...
...
Launcher3/res/drawable/cb_selector.xml
View file @
087cd240
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<selector
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:state_checked=
"true"
<item
android:state_checked=
"true"
android:drawable=
"@drawable/
small_eyes
"
/>
<!--选中时效果-->
android:drawable=
"@drawable/
ic_visibility_off_gray_24dp
"
/>
<!--选中时效果-->
<item
android:state_checked=
"false"
<item
android:state_checked=
"false"
android:drawable=
"@drawable/
show_pwd
"
/>
<!--未选中时效果-->
android:drawable=
"@drawable/
ic_visibility_gray_24dp
"
/>
<!--未选中时效果-->
</selector>
</selector>
\ No newline at end of file
Launcher3/res/drawable/ic_chevron_right_gray_24dp.xml
0 → 100644
View file @
087cd240
<vector
android:height=
"24dp"
android:tint=
"#ABABAB"
android:viewportHeight=
"24.0"
android:viewportWidth=
"24.0"
android:width=
"24dp"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<path
android:fillColor=
"#FF000000"
android:pathData=
"M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"
/>
</vector>
Launcher3/res/drawable/ic_visibility_gray_24dp.xml
0 → 100644
View file @
087cd240
<vector
android:height=
"24dp"
android:tint=
"#ABABAB"
android:viewportHeight=
"24.0"
android:viewportWidth=
"24.0"
android:width=
"24dp"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<path
android:fillColor=
"#FF000000"
android:pathData=
"M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"
/>
</vector>
Launcher3/res/drawable/ic_visibility_off_gray_24dp.xml
0 → 100644
View file @
087cd240
<vector
android:height=
"24dp"
android:tint=
"#ABABAB"
android:viewportHeight=
"24.0"
android:viewportWidth=
"24.0"
android:width=
"24dp"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<path
android:fillColor=
"#FF000000"
android:pathData=
"M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"
/>
</vector>
Launcher3/res/drawable/show_pwd.png
deleted
100644 → 0
View file @
248b41e2
1.62 KB
Launcher3/res/drawable/small_eyes.png
deleted
100644 → 0
View file @
248b41e2
1.46 KB
Launcher3/res/layout/activity_pwd_pin_set.xml
View file @
087cd240
...
@@ -55,10 +55,10 @@
...
@@ -55,10 +55,10 @@
<CheckBox
<CheckBox
android:id=
"@+id/cb_show_pwd"
android:id=
"@+id/cb_show_pwd"
android:layout_width=
"
40dp
"
android:layout_width=
"
wrap_content
"
android:layout_height=
"
25dp
"
android:layout_height=
"
wrap_content
"
android:layout_centerVertical=
"true"
android:layout_centerVertical=
"true"
android:layout_marginRight=
"
2
0dp"
android:layout_marginRight=
"
1
0dp"
android:button=
"@drawable/cb_selector"
android:button=
"@drawable/cb_selector"
android:checked=
"true"
/>
android:checked=
"true"
/>
</LinearLayout>
</LinearLayout>
...
@@ -91,10 +91,10 @@
...
@@ -91,10 +91,10 @@
<CheckBox
<CheckBox
android:id=
"@+id/cb_show_pwd_again"
android:id=
"@+id/cb_show_pwd_again"
android:layout_width=
"
40dp
"
android:layout_width=
"
wrap_content
"
android:layout_height=
"
25dp
"
android:layout_height=
"
wrap_content
"
android:layout_centerVertical=
"true"
android:layout_centerVertical=
"true"
android:layout_marginRight=
"
2
0dp"
android:layout_marginRight=
"
1
0dp"
android:button=
"@drawable/cb_selector"
android:button=
"@drawable/cb_selector"
android:checked=
"true"
/>
android:checked=
"true"
/>
</LinearLayout>
</LinearLayout>
...
...
Launcher3/res/layout/activity_use_app.xml
0 → 100644
View file @
087cd240
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:fitsSystemWindows=
"true"
android:orientation=
"vertical"
tools:context=
"com.android.launcher3.function.setting.AppUseActivity"
>
<TextView
android:id=
"@+id/tv_setting_title"
android:layout_width=
"match_parent"
android:layout_height=
"48dp"
android:drawableStart=
"@mipmap/ic_back"
android:drawablePadding=
"10dp"
android:gravity=
"center_vertical"
android:onClick=
"close"
android:paddingLeft=
"16dp"
android:paddingRight=
"16dp"
android:text=
"@string/edu_item_about"
android:textColor=
"#363636"
android:textSize=
"16sp"
/>
<View
android:layout_width=
"match_parent"
android:layout_height=
"1dp"
android:background=
"#DDDFE1"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"48dp"
android:gravity=
"center_vertical"
android:background=
"@color/bg_white"
android:onClick=
"more"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/tv_app_use_time"
android:layout_width=
"wrap_content"
android:layout_height=
"48dp"
android:gravity=
"center_vertical"
android:onClick=
"close"
android:paddingLeft=
"16dp"
android:paddingRight=
"16dp"
android:text=
"@string/edu_item_app_use_last_day"
android:textColor=
"#363636"
android:textSize=
"16sp"
/>
<com.qmuiteam.qmui.widget.QMUIEmptyView
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"48dp"
android:drawableEnd=
"@drawable/ic_chevron_right_gray_24dp"
android:gravity=
"center_vertical"
android:text=
"@string/edu_item_app_use_more"
android:textColor=
"#ABABAB"
android:textSize=
"15sp"
/>
</LinearLayout>
</LinearLayout>
Launcher3/res/values/strings.xml
View file @
087cd240
...
@@ -375,9 +375,12 @@
...
@@ -375,9 +375,12 @@
<string
name=
"edu_item_input_encryted_error"
>
未获取到密保答案
</string>
<string
name=
"edu_item_input_encryted_error"
>
未获取到密保答案
</string>
<string
name=
"edu_item_input_answer1_error"
>
问题一答案错误
</string>
<string
name=
"edu_item_input_answer1_error"
>
问题一答案错误
</string>
<string
name=
"edu_item_input_answer2_error"
>
问题二答案错误
</string>
<string
name=
"edu_item_input_answer2_error"
>
问题二答案错误
</string>
<string
name=
"edu_item_input_encryted_title"
>
请输入密保答案用于修改密码
</string>
<string
name=
"edu_item_input_encryted_title"
>
请输入密保答案用于修改密码
</string>
<string
name=
"edu_item_app_use_title"
>
应用使用情况
</string>
<string
name=
"edu_item_app_use_last_day"
>
最近一天使用时长: %1$s分钟
</string>
<string
name=
"edu_item_app_use_more"
>
更多
</string>
</resources>
</resources>
Launcher3/src/com/android/launcher3/function/setting/AppUseActivity.kt
0 → 100644
View file @
087cd240
package
com.android.launcher3.function.setting
import
android.content.Context
import
android.content.Intent
import
android.os.Bundle
import
android.view.View
import
android.widget.GridLayout
import
android.widget.LinearLayout
import
com.android.launcher3.BaseActivity
import
com.android.launcher3.R
import
com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
import
com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
import
com.secspace.lib.common.utils.*
import
kotlinx.android.synthetic.main.activity_setting.*
import
kotlinx.android.synthetic.main.activity_setting.tv_setting_title
import
kotlinx.android.synthetic.main.activity_use_app.*
class
AppUseActivity
:
BaseActivity
()
{
private
var
mContext
:
Context
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setAndroidNativeLightStatusBar
(
true
)
setContentView
(
R
.
layout
.
activity_use_app
)
mContext
=
this
initView
()
}
private
fun
initView
()
{
tv_setting_title
.
setText
(
R
.
string
.
edu_item_app_use_title
)
tv_app_use_time
.
text
=
String
.
format
(
getString
(
R
.
string
.
edu_item_app_use_last_day
),
"50"
)
}
fun
close
(
view
:
View
?)
{
finish
()
}
fun
more
(
view
:
View
)
{
}
}
\ No newline at end of file
Launcher3/src/com/android/launcher3/function/setting/SettingActivity.kt
View file @
087cd240
...
@@ -56,7 +56,7 @@ class SettingActivity : BaseActivity() {
...
@@ -56,7 +56,7 @@ class SettingActivity : BaseActivity() {
dp2px
(
48f
))
dp2px
(
48f
))
QMUIGroupListView
.
newSection
(
mContext
)
QMUIGroupListView
.
newSection
(
mContext
)
.
addItemView
(
wlan
)
{
IntentUtil
.
startWifiSetting
(
mContext
)
}
.
addItemView
(
wlan
)
{
IntentUtil
.
startWifiSetting
(
mContext
)
}
.
addItemView
(
appUse
)
{
ToastUtil
.
showShort
(
mContext
,
R
.
string
.
edu_toast_wait
)
}
.
addItemView
(
appUse
)
{
startActivity
(
Intent
(
mContext
,
AppUseActivity
::
class
.
java
)
)
}
.
addItemView
(
buy
)
{
startActivity
(
Intent
(
mContext
,
SettingBuyActivity
::
class
.
java
))
}
.
addItemView
(
buy
)
{
startActivity
(
Intent
(
mContext
,
SettingBuyActivity
::
class
.
java
))
}
.
addItemView
(
about
)
{
startActivity
(
Intent
(
mContext
,
SettingAboutActivity
::
class
.
java
))
}
.
addItemView
(
about
)
{
startActivity
(
Intent
(
mContext
,
SettingAboutActivity
::
class
.
java
))
}
.
addTo
(
grouplistview
)
.
addTo
(
grouplistview
)
...
...
lib_common/src/main/java/com/secspace/lib/common/function/ActivationHelper.kt
View file @
087cd240
...
@@ -101,6 +101,7 @@ object ActivationHelper {
...
@@ -101,6 +101,7 @@ object ActivationHelper {
return
withContext
(
Dispatchers
.
IO
)
{
return
withContext
(
Dispatchers
.
IO
)
{
val
file
=
File
(
FILE_PATH
+
context
.
packageName
,
PROBATION_FILE_NAME
)
val
file
=
File
(
FILE_PATH
+
context
.
packageName
,
PROBATION_FILE_NAME
)
if
(!
file
.
exists
())
{
if
(!
file
.
exists
())
{
Log
.
e
(
"TAG1"
,
"isProbationFromLocal 1"
)
return
@withContext
false
return
@withContext
false
}
}
val
map
:
HashMap
<
String
?,
*>?
val
map
:
HashMap
<
String
?,
*>?
...
@@ -129,33 +130,37 @@ object ActivationHelper {
...
@@ -129,33 +130,37 @@ object ActivationHelper {
}
}
}
}
private
suspend
fun
probation
(
context
:
Context
):
Boolean
{
private
suspend
fun
probation
(
context
:
Context
):
Boolean
{
val
map
:
MutableMap
<
String
?,
String
?>
=
HashMap
()
return
withContext
(
Dispatchers
.
IO
){
val
currentTime
=
getCurrentTimeByNet
()
val
map
:
MutableMap
<
String
?,
String
?>
=
HashMap
()
if
(
currentTime
==
-
1L
)
{
Log
.
e
(
"TAG1"
,
"probation 1"
)
return
false
val
currentTime
=
getCurrentTimeByNet
()
}
Log
.
e
(
"TAG1"
,
"probation 2"
)
val
endTime
=
currentTime
+
PROBATION_TIME
if
(
currentTime
==
-
1L
)
{
map
[
SP_IS_ACTIVE
]
=
DesUtil
.
encrypt
(
PROBATION
)
return
@withContext
false
map
[
SP_TRIAL_ACTIVE_END_TIME
]
=
DesUtil
.
encrypt
(
endTime
.
toString
())
map
[
SP_ACTIVE_CODE
]
=
DesUtil
.
encrypt
(
"无"
)
map
[
SP_TRIAL_ACTIVE_START_TIME
]
=
DesUtil
.
encrypt
(
currentTime
.
toString
())
try
{
val
fileDir
=
File
(
FILE_PATH
+
context
.
packageName
)
if
(!
fileDir
.
exists
())
{
fileDir
.
mkdirs
()
}
}
val
file
=
File
(
fileDir
,
PROBATION_FILE_NAME
)
val
endTime
=
currentTime
+
PROBATION_TIME
if
(!
file
.
exists
())
{
map
[
SP_IS_ACTIVE
]
=
DesUtil
.
encrypt
(
PROBATION
)
file
.
createNewFile
()
map
[
SP_TRIAL_ACTIVE_END_TIME
]
=
DesUtil
.
encrypt
(
endTime
.
toString
())
map
[
SP_ACTIVE_CODE
]
=
DesUtil
.
encrypt
(
"无"
)
map
[
SP_TRIAL_ACTIVE_START_TIME
]
=
DesUtil
.
encrypt
(
currentTime
.
toString
())
try
{
val
fileDir
=
File
(
FILE_PATH
+
context
.
packageName
)
if
(!
fileDir
.
exists
())
{
fileDir
.
mkdirs
()
}
val
file
=
File
(
fileDir
,
PROBATION_FILE_NAME
)
if
(!
file
.
exists
())
{
file
.
createNewFile
()
}
XmlUtils
.
writeMapXml
(
map
,
FileOutputStream
(
file
))
}
catch
(
e
:
XmlPullParserException
)
{
return
@withContext
false
}
catch
(
e
:
IOException
)
{
return
@withContext
false
}
}
XmlUtils
.
writeMapXml
(
map
,
FileOutputStream
(
file
))
return
@withContext
true
}
catch
(
e
:
XmlPullParserException
)
{
return
false
}
catch
(
e
:
IOException
)
{
return
false
}
}
return
true
}
}
private
fun
getValueByXmlKey
(
context
:
Context
,
key
:
String
,
fileName
:
String
):
String
{
private
fun
getValueByXmlKey
(
context
:
Context
,
key
:
String
,
fileName
:
String
):
String
{
...
...
lib_common/src/main/java/com/secspace/lib/common/function/WorkManager.kt
View file @
087cd240
...
@@ -20,6 +20,7 @@ import com.secspace.mdmengine.api.manager.MdmFactoryManager
...
@@ -20,6 +20,7 @@ import com.secspace.mdmengine.api.manager.MdmFactoryManager
import
com.skr.activation.network.linstener.CheckActiveStatusListener
import
com.skr.activation.network.linstener.CheckActiveStatusListener
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
java.io.File
import
java.io.File
...
@@ -62,6 +63,7 @@ object WorkManager {
...
@@ -62,6 +63,7 @@ object WorkManager {
SwitchInMdm
.
onInit
(
launcher
)
SwitchInMdm
.
onInit
(
launcher
)
activate
(
launcher
)
activate
(
launcher
)
// checkLocalUpdateFile() //检查本地更新文件
// checkLocalUpdateFile() //检查本地更新文件
delay
(
5000
)
ActivationHelper
.
checkActivate
(
launcher
,
EduCheckActiveStatusListener
(
launcher
))
ActivationHelper
.
checkActivate
(
launcher
,
EduCheckActiveStatusListener
(
launcher
))
}
}
isChecksCompleted
=
true
isChecksCompleted
=
true
...
...
lib_common/src/main/java/com/secspace/lib/common/function/view/TimeProgress.java
0 → 100644
View file @
087cd240
package
com
.
secspace
.
lib
.
common
.
function
.
view
;
import
android.animation.ValueAnimator
;
import
android.content.Context
;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
android.graphics.Rect
;
import
android.graphics.RectF
;
import
android.support.annotation.Nullable
;
import
android.util.AttributeSet
;
import
android.util.TypedValue
;
import
android.view.View
;
import
android.view.animation.AccelerateDecelerateInterpolator
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
/**
* 应用使用时间进度条
*/
public
class
TimeProgress
extends
View
{
private
Paint
bgPaint
;
private
Paint
textPaint
;
private
int
mWidth
;
private
int
mHeight
;
private
List
<
Integer
>
times
=
new
ArrayList
<>();
private
List
<
Integer
>
paintColors
=
new
ArrayList
<>();
private
float
allTime
=
0
F
;
private
float
animationValue
;
private
float
cylindricalStartLeft
;
private
float
indicatorMargin
;
/**
* 进度动画
*/
private
ValueAnimator
progressAnimator
;
/**
* 动画执行时间
*/
private
int
duration
=
1000
;
/**
* 动画延时启动时间
*/
private
int
startDelay
=
500
;
/**
* 进度条画笔的宽度
*/
private
int
progressPaintWidth
;
private
int
progressHeight
;
private
int
textHeight
;
/**
* 柱状图距提示文字的高度
*/
private
int
tipsMargin
;
private
int
textSize
;
/**
* 进度条背景颜色
*/
private
int
bgColor
=
0xFFf66b12
;
/**
* 进度条颜色
*/
private
int
progressColor
=
0xFFf66b12
;
private
RectF
bgRectF
=
new
RectF
();
/**
* 圆角矩形的圆角半径
*/
private
int
roundRectRadius
;
private
int
paddingLeft
;
private
int
paddingTop
;
private
int
paddingRight
;
private
int
paddingBottom
;
public
TimeProgress
(
Context
context
)
{
this
(
context
,
null
);
}
public
TimeProgress
(
Context
context
,
@Nullable
AttributeSet
attrs
)
{
this
(
context
,
attrs
,
0
);
}
public
TimeProgress
(
Context
context
,
@Nullable
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
init
();
initPaint
();
initTextPaint
();
times
.
add
(
10
);
times
.
add
(
20
);
times
.
add
(
80
);
times
.
add
(
50
);
Comparator
<
Integer
>
reverseComparator
=
Collections
.
reverseOrder
();
Collections
.
sort
(
times
,
reverseComparator
);
paintColors
.
add
(
0xFF13A6FA
);
paintColors
.
add
(
0xFF9BFA13
);
paintColors
.
add
(
0xFFFAB613
);
paintColors
.
add
(
0xFFE5E5E5
);
allTime
=
160
;
}
/**
* 初始化画笔宽度及view大小
*/
private
void
init
()
{
progressPaintWidth
=
dp2px
(
5
);
progressHeight
=
dp2px
(
15
);
roundRectRadius
=
dp2px
(
3
);
indicatorMargin
=
dp2px
(
1
);
tipsMargin
=
progressHeight
;
textSize
=
dp2px
(
12
);
}
private
void
initPaint
()
{
bgPaint
=
getPaint
(
progressPaintWidth
,
bgColor
,
Paint
.
Style
.
FILL
);
}
/**
* 初始化文字画笔
*/
private
void
initTextPaint
()
{
textPaint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
textPaint
.
setColor
(
progressColor
);
textPaint
.
setTextSize
(
textSize
);
textPaint
.
setTextAlign
(
Paint
.
Align
.
CENTER
);
textPaint
.
setAntiAlias
(
true
);
}
private
int
getTextHeight
(
String
text
,
Paint
paint
)
{
Rect
rect
=
new
Rect
();
paint
.
getTextBounds
(
text
,
0
,
text
.
length
(),
rect
);
return
rect
.
height
();
}
private
int
getTextWidth
(
String
text
,
Paint
paint
)
{
Rect
rect
=
new
Rect
();
paint
.
getTextBounds
(
text
,
0
,
text
.
length
(),
rect
);
return
rect
.
width
();
}
/**
* 统一处理paint
*
* @param strokeWidth 画笔宽度
* @param color 颜色
* @param style 风格
* @return paint
*/
private
Paint
getPaint
(
int
strokeWidth
,
int
color
,
Paint
.
Style
style
)
{
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
paint
.
setStrokeWidth
(
strokeWidth
);
paint
.
setColor
(
color
);
paint
.
setAntiAlias
(
true
);
paint
.
setStyle
(
style
);
return
paint
;
}
@Override
protected
void
onMeasure
(
int
widthMeasureSpec
,
int
heightMeasureSpec
)
{
int
widthMode
=
MeasureSpec
.
getMode
(
widthMeasureSpec
);
int
width
=
MeasureSpec
.
getSize
(
widthMeasureSpec
);
int
heightMode
=
MeasureSpec
.
getMode
(
heightMeasureSpec
);
int
height
=
MeasureSpec
.
getSize
(
heightMeasureSpec
);
setMeasuredDimension
(
measureWidth
(
widthMode
,
width
),
measureHeight
(
heightMode
,
height
));
}
/**
* 测量宽度
*
* @param mode
* @param width
* @return
*/
private
int
measureWidth
(
int
mode
,
int
width
)
{
switch
(
mode
)
{
case
MeasureSpec
.
UNSPECIFIED
:
case
MeasureSpec
.
AT_MOST
:
break
;
case
MeasureSpec
.
EXACTLY
:
mWidth
=
width
;
break
;
}
return
mWidth
;
}
public
void
setWidth
(
int
width
)
{
mWidth
=
width
;
}
/**
* 测量高度
*
* @param mode
* @param height
* @return
*/
private
int
measureHeight
(
int
mode
,
int
height
)
{
switch
(
mode
)
{
case
MeasureSpec
.
UNSPECIFIED
:
case
MeasureSpec
.
AT_MOST
:
textHeight
=
getTextHeight
(
"measureHeight"
,
textPaint
);
mHeight
=
progressPaintWidth
+
progressHeight
+
tipsMargin
+
textHeight
*
2
+
paddingTop
+
paddingBottom
;
break
;
case
MeasureSpec
.
EXACTLY
:
mHeight
=
height
;
break
;
}
return
mHeight
;
}
@Override
protected
void
onDraw
(
Canvas
canvas
)
{
super
.
onDraw
(
canvas
);
// 初始化width,padding等参数
parameterAssignment
();
// 绘制横向柱状图
drawHorizontalCylindrical
(
canvas
);
drawIndicator
(
canvas
);
}
private
void
drawIndicator
(
Canvas
canvas
)
{
// 平分后每份的长度
float
share
=
mWidth
/
times
.
size
();
float
x
,
y
;
for
(
int
i
=
0
;
i
<
times
.
size
();
i
++)
{
int
time
=
times
.
get
(
i
);
String
text
=
time
+
"分钟"
;
textPaint
.
setColor
(
0xff000000
);
bgPaint
.
setColor
(
paintColors
.
get
(
i
));
float
textHeight
=
getTextHeight
(
text
,
textPaint
);
float
textWidth
=
getTextWidth
(
text
,
textPaint
);
x
=
share
*
i
+
share
/
2
;
if
(
i
==
0
)
{
x
=
x
+
paddingLeft
;
}
y
=
textHeight
+
tipsMargin
+
progressHeight
;
if
(
i
==
times
.
size
()
-
1
)
{
y
=
y
-
paddingBottom
;
}
canvas
.
drawRect
(
x
-
textWidth
,
y
-
textHeight
+
indicatorMargin
,
x
-
textWidth
+
textHeight
,
y
+
indicatorMargin
,
bgPaint
);
canvas
.
drawText
(
text
,
x
,
y
,
textPaint
);
canvas
.
drawText
(
text
,
x
,
y
+
textHeight
+
tipsMargin
/
3
,
textPaint
);
}
}
private
void
drawHorizontalCylindrical
(
Canvas
canvas
)
{
for
(
int
i
=
0
;
i
<
times
.
size
();
i
++)
{
int
time
=
times
.
get
(
i
);
float
rate
=
time
/
allTime
;
if
(
i
==
0
)
{
bgRectF
.
left
=
cylindricalStartLeft
+
paddingLeft
;
}
else
{
bgRectF
.
left
=
cylindricalStartLeft
+
10
;
}
bgPaint
.
setColor
(
paintColors
.
get
(
i
));
bgRectF
.
top
=
paddingTop
;
bgRectF
.
right
=
mWidth
*
rate
*
animationValue
/
100
+
cylindricalStartLeft
;
bgRectF
.
bottom
=
bgRectF
.
top
+
progressHeight
;
if
(
i
==
times
.
size
()
-
1
)
{
bgRectF
.
right
=
mWidth
*
rate
*
animationValue
/
100
-
paddingRight
+
cylindricalStartLeft
;
}
cylindricalStartLeft
=
bgRectF
.
right
;
canvas
.
drawRoundRect
(
bgRectF
,
roundRectRadius
,
roundRectRadius
,
bgPaint
);
}
cylindricalStartLeft
=
0
;
}
public
void
initAnimation
()
{
progressAnimator
=
ValueAnimator
.
ofFloat
(
0
,
100
);
progressAnimator
.
setDuration
(
duration
);
progressAnimator
.
setStartDelay
(
startDelay
);
progressAnimator
.
setInterpolator
(
new
AccelerateDecelerateInterpolator
());
progressAnimator
.
addUpdateListener
(
new
ValueAnimator
.
AnimatorUpdateListener
()
{
@Override
public
void
onAnimationUpdate
(
ValueAnimator
valueAnimator
)
{
animationValue
=
(
float
)
valueAnimator
.
getAnimatedValue
();
invalidate
();
}
});
if
(!
progressAnimator
.
isStarted
())
{
progressAnimator
.
start
();
}
}
private
void
parameterAssignment
()
{
mWidth
=
getMeasuredWidth
();
paddingLeft
=
getPaddingLeft
();
paddingTop
=
getPaddingTop
();
paddingRight
=
getPaddingRight
();
paddingBottom
=
getPaddingBottom
();
}
/**
* 格式化数字(保留一位小数)
*
* @param money
* @return
*/
public
static
String
formatNum
(
int
money
)
{
DecimalFormat
format
=
new
DecimalFormat
(
"0"
);
return
format
.
format
(
money
);
}
/**
* dp 2 px
*
* @param dpVal
*/
protected
int
dp2px
(
int
dpVal
)
{
return
(
int
)
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
dpVal
,
getResources
().
getDisplayMetrics
());
}
/**
* sp 2 px
*
* @param spVal
* @return
*/
protected
int
sp2px
(
int
spVal
)
{
return
(
int
)
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_SP
,
spVal
,
getResources
().
getDisplayMetrics
());
}
}
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