Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fastdevelop
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高超
fastdevelop
Commits
cd862ad3
Commit
cd862ad3
authored
Jan 30, 2019
by
gao.chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载更新,动态设置drawble
parent
e89e38d3
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
341 additions
and
77 deletions
+341
-77
app/src/main/AndroidManifest.xml
+1
-0
app/src/main/java/com/mayi/demo/DownLoadAPKActivity.java
+51
-0
app/src/main/java/com/mayi/demo/FunctionActivity.java
+2
-3
app/src/main/java/com/mayi/demo/MainActivity.java
+2
-0
app/src/main/java/com/mayi/demo/PermissionActivity.java
+5
-22
app/src/main/res/layout/activity_function.xml
+2
-0
app/src/main/res/layout/activity_permission.xml
+0
-7
app/src/main/res/layout/avtivity_download_apk.xml
+26
-0
fastDevelop/build.gradle
+2
-2
fastDevelop/src/main/AndroidManifest.xml
+2
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/bean/AppConfig.java
+0
-9
fastDevelop/src/main/java/com/mayi/fastdevelop/commonpage/UpdateDownLoadAPKActvity.java
+109
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/constant/RequestCode.java
+5
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/util/DownLoadUtil.java
+18
-16
fastDevelop/src/main/java/com/mayi/fastdevelop/util/DrawableUtils.java
+41
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/view/LoadingPictures.java
+1
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/view/installapk/AppUpgradeManager.java
+51
-6
fastDevelop/src/main/res/layout/dialog_update.xml
+21
-12
fastDevelop/src/main/res/values/strings.xml
+2
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
cd862ad3
...
...
@@ -42,6 +42,7 @@
<activity
android:name=
".ViewActviity"
/>
<activity
android:name=
".QRActivity"
/>
<activity
android:name=
".TitleActivity"
/>
<activity
android:name=
".DownLoadAPKActivity"
/>
</application>
<!-- 配置APP ID -->
...
...
app/src/main/java/com/mayi/demo/DownLoadAPKActivity.java
0 → 100644
View file @
cd862ad3
package
com
.
mayi
.
demo
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.view.View
;
import
com.mayi.fastdevelop.bean.AppConfig
;
import
com.mayi.fastdevelop.commonpage.UpdateDownLoadAPKActvity
;
public
class
DownLoadAPKActivity
extends
UpdateDownLoadAPKActvity
{
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
avtivity_download_apk
);
findViewById
(
R
.
id
.
b1
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
UpdateDownLoadAPK
();
}
});
findViewById
(
R
.
id
.
b2
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
forceUpdateDownLoadAPK
();
}
});
}
private
void
forceUpdateDownLoadAPK
()
{
AppConfig
appConfig
=
new
AppConfig
();
appConfig
.
setServerVersion
(
3
);
appConfig
.
setFileSize
(
"40"
);
appConfig
.
setForceUpdate
(
true
);
appConfig
.
setNeedUpdate
(
true
);
appConfig
.
setUpdateRemark
(
"强制更新\n强制更新"
);
appConfig
.
setUpdateUrl
(
"https://kuka-life.oss-cn-hangzhou.aliyuncs.com/usermanager/app/android/userManager.apk"
);
downLoadAPK
(
appConfig
);
}
private
void
UpdateDownLoadAPK
()
{
AppConfig
appConfig
=
new
AppConfig
();
appConfig
.
setNeedUpdate
(
true
);
appConfig
.
setServerVersion
(
3
);
appConfig
.
setFileSize
(
"40"
);
appConfig
.
setUpdateRemark
(
"提示更新\n提示更新"
);
appConfig
.
setUpdateUrl
(
"https://kuka-life.oss-cn-hangzhou.aliyuncs.com/usermanager/app/android/userManager.apk"
);
downLoadAPK
(
appConfig
);
}
}
app/src/main/java/com/mayi/demo/FunctionActivity.java
View file @
cd862ad3
...
...
@@ -28,11 +28,10 @@ public class FunctionActivity extends BaseActivity{
findViewById
(
R
.
id
.
b3
).
setOnClickListener
(
new
OnMultiClickListener
()
{
@Override
public
void
onMultiClick
(
View
v
)
{
downLoadAPK
(
);
gotoActivity
(
DownLoadAPKActivity
.
class
);
}
});
}
private
void
downLoadAPK
()
{
}
}
app/src/main/java/com/mayi/demo/MainActivity.java
View file @
cd862ad3
...
...
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
import
android.widget.Button
;
import
com.mayi.fastdevelop.base.BaseActivity
;
import
com.mayi.fastdevelop.util.DrawableUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -46,6 +47,7 @@ public class MainActivity extends BaseActivity {
public
void
onBindViewHolder
(
@NonNull
MyViewHolder
viewHolder
,
int
i
)
{
viewHolder
.
tv
.
setOnClickListener
(
list
.
get
(
i
).
getClickListener
());
viewHolder
.
tv
.
setText
(
list
.
get
(
i
).
getText
());
DrawableUtils
.
setStatePressedDrawable
(
viewHolder
.
tv
,
"#555555"
,
"#F00000"
,
"#999999"
);
}
@Override
...
...
app/src/main/java/com/mayi/demo/PermissionActivity.java
View file @
cd862ad3
...
...
@@ -24,44 +24,27 @@ public class PermissionActivity extends BaseActivity {
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_permission
);
Button
install
=
findViewById
(
R
.
id
.
install
);
Button
apply
=
findViewById
(
R
.
id
.
apply
);
final
TextView
result
=
findViewById
(
R
.
id
.
result
);
final
TextView
result
=
findViewById
(
R
.
id
.
result
);
apply
.
setOnClickListener
(
new
OnMultiClickListener
()
{
@Override
public
void
onMultiClick
(
View
v
)
{
PermissionUtil
.
requestPermission
(
new
PermissionUtil
.
PermissionCallback
()
{
@Override
public
void
onSuccess
(
List
<
String
>
data
)
{
showToast
(
"ANT PermissionUtil"
+
"onSuccess:"
+
JSON
.
toJSONString
(
data
));
result
.
setText
(
"请求成功:"
+
JSON
.
toJSONString
(
data
));
showToast
(
"ANT PermissionUtil"
+
"onSuccess:"
+
JSON
.
toJSONString
(
data
));
result
.
setText
(
"请求成功:"
+
JSON
.
toJSONString
(
data
));
}
@Override
public
void
onFail
(
List
<
String
>
data
)
{
showToast
(
"ANT PermissionUtil"
+
"onFail:"
+
JSON
.
toJSONString
(
data
));
result
.
setText
(
"请求失败:"
+
JSON
.
toJSONString
(
data
));
showToast
(
"ANT PermissionUtil"
+
"onFail:"
+
JSON
.
toJSONString
(
data
));
result
.
setText
(
"请求失败:"
+
JSON
.
toJSONString
(
data
));
}
},
Permission
.
Group
.
CAMERA
);
}
});
install
.
setOnClickListener
(
new
OnMultiClickListener
()
{
@Override
public
void
onMultiClick
(
View
v
)
{
PermissionUtil
.
installAPP
(
new
PermissionUtil
.
PermissionInstallCallback
()
{
@Override
public
void
onSuccess
()
{
showToast
(
"安装成功"
);
}
@Override
public
void
onFail
()
{
showToast
(
"安装失败"
);
}
},
Environment
.
getExternalStorageDirectory
().
getAbsolutePath
()+
"/"
+
"app-debug.apk"
);
}
});
}
...
...
app/src/main/res/layout/activity_function.xml
View file @
cd862ad3
...
...
@@ -26,6 +26,7 @@
android:layout_height=
"wrap_content"
android:text=
"下载安装APP"
/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
app/src/main/res/layout/activity_permission.xml
View file @
cd862ad3
...
...
@@ -15,10 +15,4 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<Button
android:id=
"@+id/install"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"安装APP"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/avtivity_download_apk.xml
0 → 100644
View file @
cd862ad3
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<Button
android:id=
"@+id/b1"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"下载安装APP"
/>
<Button
android:id=
"@+id/b2"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"强制下载安装APP"
/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
fastDevelop/build.gradle
View file @
cd862ad3
...
...
@@ -6,8 +6,8 @@ android {
defaultConfig
{
minSdkVersion
19
targetSdkVersion
28
versionCode
1
versionName
"1.
0
"
versionCode
2
versionName
"1.
1
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
ndk
{
// 设置支持的SO库架构
...
...
fastDevelop/src/main/AndroidManifest.xml
View file @
cd862ad3
...
...
@@ -2,6 +2,8 @@
xmlns:tools=
"http://schemas.android.com/tools"
package=
"com.mayi.fastdevelop"
>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.KILL_BACKGROUND_PROCESSES"
/>
<uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
...
...
fastDevelop/src/main/java/com/mayi/fastdevelop/bean/AppConfig.java
View file @
cd862ad3
...
...
@@ -8,7 +8,6 @@ import java.io.Serializable;
* app 启动 - 配置信息
*/
public
class
AppConfig
implements
Serializable
{
private
String
wxUpdateUrl
;
// "微信更新地址",
/**
* 是否需要更新.
*/
...
...
@@ -39,14 +38,6 @@ public class AppConfig implements Serializable {
*/
private
String
updateRemark
;
public
String
getWxUpdateUrl
()
{
return
wxUpdateUrl
;
}
public
void
setWxUpdateUrl
(
String
wxUpdateUrl
)
{
this
.
wxUpdateUrl
=
wxUpdateUrl
;
}
public
String
getFileSize
()
{
return
fileSize
;
}
...
...
fastDevelop/src/main/java/com/mayi/fastdevelop/commonpage/UpdateDownLoadAPKActvity.java
0 → 100644
View file @
cd862ad3
package
com
.
mayi
.
fastdevelop
.
commonpage
;
import
android.app.DownloadManager
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.provider.Settings
;
import
android.support.annotation.Nullable
;
import
com.mayi.fastdevelop.base.BaseActivity
;
import
com.mayi.fastdevelop.bean.AppConfig
;
import
com.mayi.fastdevelop.constant.Key
;
import
com.mayi.fastdevelop.constant.RequestCode
;
import
com.mayi.fastdevelop.util.DownLoadUtil
;
import
com.mayi.fastdevelop.util.PermissionUtil
;
import
com.mayi.fastdevelop.util.SpUtil
;
import
com.mayi.fastdevelop.util.ToastUtil
;
import
com.mayi.fastdevelop.view.installapk.AppUpgradeManager
;
/**
* 下载安装Activity
*/
public
abstract
class
UpdateDownLoadAPKActvity
extends
BaseActivity
{
private
ApkInstallReceiver
receiver
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
"android.intent.action.DOWNLOAD_COMPLETE"
);
filter
.
addAction
(
"android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"
);
filter
.
addAction
(
DownloadManager
.
ACTION_DOWNLOAD_COMPLETE
);
receiver
=
new
ApkInstallReceiver
();
registerReceiver
(
receiver
,
filter
);
}
public
void
downLoadAPK
(
AppConfig
appConfig
)
{
AppUpgradeManager
appUpgradeManager
=
new
AppUpgradeManager
(
this
);
appUpgradeManager
.
showUpdateTipDialog
(
appConfig
);
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
{
if
(
requestCode
==
RequestCode
.
REQUEST_CODE_APP_INSTALL
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
if
(
getPackageManager
().
canRequestPackageInstalls
())
{
installApk
();
}
else
{
showToast
(
"未允许应用安装,无法升级!"
);
}
}
}
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
}
private
class
ApkInstallReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
if
(
intent
.
getAction
().
equals
(
DownloadManager
.
ACTION_DOWNLOAD_COMPLETE
))
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
//开启设置安装未知来源应用权限界面
if
(!
context
.
getPackageManager
().
canRequestPackageInstalls
())
{
Intent
intent2
=
new
Intent
(
Settings
.
ACTION_MANAGE_UNKNOWN_APP_SOURCES
);
startActivityForResult
(
intent2
,
RequestCode
.
REQUEST_CODE_APP_INSTALL
);
ToastUtil
.
show
(
context
,
"请允许安装应用!"
);
return
;
}
}
installApk
();
}
}
}
private
void
installApk
()
{
long
id
=
SpUtil
.
get
(
Key
.
ANT_DOWNLOAD_ID
,
-
1L
);
if
(-
1
!=
id
)
{
DownloadManager
dManager
=
(
DownloadManager
)
getSystemService
(
Context
.
DOWNLOAD_SERVICE
);
Uri
downloadFileUri
=
dManager
!=
null
?
dManager
.
getUriForDownloadedFile
(
id
)
:
null
;
if
(
downloadFileUri
==
null
)
{
return
;
}
PermissionUtil
.
installAPP
(
new
PermissionUtil
.
PermissionInstallCallback
()
{
@Override
public
void
onSuccess
()
{
showToast
(
"安装成功"
);
SpUtil
.
set
(
Key
.
ANT_DOWNLOAD_ID
,
-
1L
);
}
@Override
public
void
onFail
()
{
showToast
(
"安装失败"
);
SpUtil
.
set
(
Key
.
ANT_DOWNLOAD_ID
,
-
1L
);
}
},
DownLoadUtil
.
getRealPathFromURI
(
this
,
downloadFileUri
));
}
}
@Override
protected
void
onDestroy
()
{
unregisterReceiver
(
receiver
);
super
.
onDestroy
();
}
}
fastDevelop/src/main/java/com/mayi/fastdevelop/constant/RequestCode.java
0 → 100644
View file @
cd862ad3
package
com
.
mayi
.
fastdevelop
.
constant
;
public
class
RequestCode
{
public
static
final
int
REQUEST_CODE_APP_INSTALL
=
0x00
;
}
fastDevelop/src/main/java/com/mayi/fastdevelop/util/DownLoadUtil.java
View file @
cd862ad3
...
...
@@ -3,15 +3,14 @@ package com.mayi.fastdevelop.util;
import
android.app.DownloadManager
;
import
android.app.DownloadManager.Request
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.os.Environment
;
import
android.provider.MediaStore
;
import
android.webkit.MimeTypeMap
;
import
com.mayi.fastdevelop.constant.Key
;
import
java.io.File
;
/**
* 下载更新的util 主要是负责 版本的相关更新工作
...
...
@@ -47,20 +46,6 @@ public class DownLoadUtil {
}
}
//文件的安装 方法
public
static
boolean
install
(
Context
context
,
String
filePath
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
File
file
=
new
File
(
filePath
);
if
(
file
!=
null
&&
file
.
length
()
>
0
&&
file
.
exists
()
&&
file
.
isFile
())
{
intent
.
setDataAndType
(
Uri
.
parse
(
"file://"
+
filePath
),
"application/vnd.android.package-archive"
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
context
.
startActivity
(
intent
);
return
true
;
}
return
false
;
}
///获取当前下载进度
public
static
int
[]
getBytesAndStatus
(
Context
context
,
long
downloadId
)
{
DownloadManager
downLoadManager
=
(
DownloadManager
)
context
.
getSystemService
(
Context
.
DOWNLOAD_SERVICE
);
...
...
@@ -84,5 +69,21 @@ public class DownLoadUtil {
return
bytesAndStatus
;
}
//根据uri 获取实际路径
public
static
String
getRealPathFromURI
(
Context
context
,
Uri
contentURI
)
{
String
result
;
Cursor
cursor
=
context
.
getContentResolver
().
query
(
contentURI
,
new
String
[]{
MediaStore
.
Images
.
ImageColumns
.
DATA
},
//
null
,
null
,
null
);
if
(
cursor
==
null
)
{
result
=
contentURI
.
getPath
();
}
else
{
cursor
.
moveToFirst
();
int
index
=
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
ImageColumns
.
DATA
);
result
=
cursor
.
getString
(
index
);
cursor
.
close
();
}
return
result
;
}
}
\ No newline at end of file
fastDevelop/src/main/java/com/mayi/fastdevelop/util/DrawableUtils.java
0 → 100644
View file @
cd862ad3
package
com
.
mayi
.
fastdevelop
.
util
;
import
android.graphics.Color
;
import
android.graphics.drawable.GradientDrawable
;
import
android.graphics.drawable.StateListDrawable
;
import
android.view.View
;
//动态设置Drawable
public
class
DrawableUtils
{
/**
* 设置view背景
* @param view
* @param str_strokeColor
* @param str_fillColor 点击时颜色
* @param str_unFillColor 未点击时颜色
*/
public
static
void
setStatePressedDrawable
(
View
view
,
String
str_strokeColor
,
String
str_fillColor
,
String
str_unFillColor
){
StateListDrawable
drawable
=
new
StateListDrawable
();
int
strokeWidth
=
1
;
// 1dp 边框宽度
int
roundRadius
=
5
;
// 5dp 圆角半径
int
strokeColor
=
Color
.
parseColor
(
str_strokeColor
);
//边框颜色
int
fillColor
=
Color
.
parseColor
(
str_fillColor
);
//内部填充颜色
GradientDrawable
statePressed
=
new
GradientDrawable
();
//创建drawable
statePressed
.
setColor
(
fillColor
);
statePressed
.
setCornerRadius
(
roundRadius
);
statePressed
.
setStroke
(
strokeWidth
,
strokeColor
);
int
unfillColor
=
Color
.
parseColor
(
str_unFillColor
);
//内部填充颜色
GradientDrawable
unStatePressed
=
new
GradientDrawable
();
//创建drawable
unStatePressed
.
setColor
(
unfillColor
);
unStatePressed
.
setCornerRadius
(
roundRadius
);
unStatePressed
.
setStroke
(
strokeWidth
,
strokeColor
);
drawable
.
addState
(
new
int
[]{
android
.
R
.
attr
.
state_pressed
},
statePressed
);
drawable
.
addState
(
new
int
[]{-
android
.
R
.
attr
.
state_pressed
},
unStatePressed
);
view
.
setBackground
(
drawable
);
}
}
fastDevelop/src/main/java/com/mayi/fastdevelop/view/LoadingPictures.java
View file @
cd862ad3
...
...
@@ -27,6 +27,7 @@ public class LoadingPictures {
public
static
void
loadFile
(
File
file
,
ImageView
img
)
{
Picasso
.
with
(
img
.
getContext
())
.
load
(
file
)
.
resize
(
2000
,
2000
)
.
placeholder
(
placeholder
)
.
error
(
error
)
.
into
(
img
);
...
...
fastDevelop/src/main/java/com/mayi/fastdevelop/view/AppUpgradeManager.java
→
fastDevelop/src/main/java/com/mayi/fastdevelop/view/
installapk/
AppUpgradeManager.java
View file @
cd862ad3
package
com
.
mayi
.
fastdevelop
.
view
;
package
com
.
mayi
.
fastdevelop
.
view
.
installapk
;
import
android.Manifest
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.ColorFilter
;
import
android.graphics.drawable.ColorDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.GradientDrawable
;
import
android.graphics.drawable.StateListDrawable
;
import
android.net.Uri
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.view.View
;
import
android.widget.ProgressBar
;
import
android.widget.TextView
;
...
...
@@ -12,9 +24,15 @@ import com.mayi.fastdevelop.bean.AppConfig;
import
com.mayi.fastdevelop.constant.Key
;
import
com.mayi.fastdevelop.util.ActivitysManager
;
import
com.mayi.fastdevelop.util.DownLoadUtil
;
import
com.mayi.fastdevelop.util.PermissionUtil
;
import
com.mayi.fastdevelop.util.SpUtil
;
import
com.mayi.fastdevelop.util.ToastUtil
;
import
com.mayi.fastdevelop.view.dialog.BaseDialog
;
import
com.mayi.fastdevelop.view.dialog.DialogViewHolder
;
import
com.yanzhenjie.permission.AndPermission
;
import
com.yanzhenjie.permission.Rationale
;
import
java.util.List
;
/**
* APP 升级管理
...
...
@@ -36,7 +54,10 @@ public class AppUpgradeManager {
/**
* 显示更新提示
*/
private
void
showUpdateTipDialog
(
final
AppConfig
info
)
{
public
void
showUpdateTipDialog
(
final
AppConfig
info
)
{
if
(!
info
.
isNeedUpdate
())
{
return
;
}
new
BaseDialog
(
mContext
,
R
.
layout
.
dialog_update
)
{
@Override
public
void
convert
(
DialogViewHolder
holder
)
{
...
...
@@ -46,9 +67,19 @@ public class AppUpgradeManager {
@Override
public
void
onClick
(
View
v
)
{
dismiss
();
showApkProgressDialog
();
mHandler
.
post
(
mRunnable
);
DownLoadUtil
.
downLoadAPK
(
mContext
,
info
.
getUpdateUrl
());
PermissionUtil
.
requestPermission
(
new
PermissionUtil
.
PermissionCallback
()
{
@Override
public
void
onSuccess
(
List
<
String
>
data
)
{
showApkProgressDialog
();
mHandler
.
post
(
mRunnable
);
DownLoadUtil
.
downLoadAPK
(
mContext
,
info
.
getUpdateUrl
());
}
@Override
public
void
onFail
(
List
<
String
>
data
)
{
ToastUtil
.
show
(
mContext
,
"没有下载权限,无法下载APK"
);
}
},
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
);
}
});
holder
.
setOnClick
(
R
.
id
.
txt_cancel
,
new
View
.
OnClickListener
()
{
...
...
@@ -56,7 +87,21 @@ public class AppUpgradeManager {
public
void
onClick
(
View
v
)
{
dismiss
();
//如果是强制更新 点击取消 直接退出app
ActivitysManager
.
exitApp
(
mContext
);
if
(
info
.
isForceUpdate
())
{
ActivitysManager
.
exitApp
(
mContext
);
}
}
});
holder
.
setOnClick
(
R
.
id
.
txt_browsers
,
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
dismiss
();
Intent
intent
=
new
Intent
();
intent
.
setAction
(
"android.intent.action.VIEW"
);
Uri
content_url
=
Uri
.
parse
(
info
.
getUpdateUrl
());
intent
.
setData
(
content_url
);
mContext
.
startActivity
(
intent
);
}
});
}
...
...
fastDevelop/src/main/res/layout/dialog_update.xml
View file @
cd862ad3
...
...
@@ -47,31 +47,40 @@
android:layout_marginLeft=
"@dimen/space_30px"
android:layout_marginRight=
"@dimen/space_30px"
android:layout_marginTop=
"30dp"
android:orientation=
"
horizont
al"
>
android:orientation=
"
vertic
al"
>
<TextView
android:id=
"@+id/txt_
cancel
"
android:layout_width=
"
0dp
"
android:id=
"@+id/txt_
sure
"
android:layout_width=
"
match_parent
"
android:layout_height=
"45dp"
android:layout_marginRight=
"@dimen/space_40px"
android:layout_weight=
"1"
android:background=
"@drawable/bg_white_border_accent_rectangle"
android:background=
"@drawable/btn_accont_grey_radius"
android:gravity=
"center"
android:text=
"@string/
cancel
"
android:textColor=
"@color/
colorAccent
"
android:text=
"@string/
sure
"
android:textColor=
"@color/
white
"
android:textSize=
"@dimen/txt_size_36px"
/>
<TextView
android:id=
"@+id/txt_
sure
"
android:layout_width=
"
0dp
"
android:id=
"@+id/txt_
browsers
"
android:layout_width=
"
match_parent
"
android:layout_height=
"45dp"
android:layout_
weight=
"1
"
android:layout_
marginTop=
"@dimen/im_dp_10
"
android:background=
"@drawable/btn_accont_grey_radius"
android:gravity=
"center"
android:text=
"@string/
sure
"
android:text=
"@string/
go_browsers
"
android:textColor=
"@color/white"
android:textSize=
"@dimen/txt_size_36px"
/>
<TextView
android:id=
"@+id/txt_cancel"
android:layout_width=
"match_parent"
android:layout_height=
"45dp"
android:layout_marginTop=
"@dimen/im_dp_10"
android:background=
"@drawable/bg_white_border_accent_rectangle"
android:gravity=
"center"
android:text=
"@string/cancel"
android:textColor=
"@color/colorAccent"
android:textSize=
"@dimen/txt_size_36px"
/>
</LinearLayout>
</LinearLayout>
...
...
fastDevelop/src/main/res/values/strings.xml
View file @
cd862ad3
...
...
@@ -10,4 +10,6 @@
<string
name=
"app_version_update"
>
新版本发布
</string>
<string
name=
"package_size"
>
更新包大小:%1$sM
</string>
<string
name=
"downloading"
>
正在下载
</string>
<string
name=
"install_apk_error"
>
安装APK错误
</string>
<string
name=
"go_browsers"
>
跳转浏览器,下载安装APK
</string>
</resources>
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