修改插件化提示框显示位置为所有界面,修复卸载后不自动跳安装bug,修复下载量超100%bug,添加打包渠道106

This commit is contained in:
huangzhuanghua
2016-07-22 13:57:11 +08:00
parent 8eca878a8b
commit f74ae2a8cf
16 changed files with 86 additions and 87 deletions

View File

@ -208,6 +208,16 @@ public class BaseActivity extends Activity {
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
}
});
} else if ("plugin".equals(showDialog.getType())) {
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
PackageUtils.getPackageNameByPath(BaseActivity.this, showDialog.getPath()), showDialog.getPath());
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
}
}, null);
}
}
}

View File

@ -201,6 +201,16 @@ public class BaseFragmentActivity extends FragmentActivity {
startActivity(PackageUtils.getUninstallIntent(BaseFragmentActivity.this, showDialog.getPath()));
}
});
} else if ("plugin".equals(showDialog.getType())) {
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
PackageUtils.getPackageNameByPath(BaseFragmentActivity.this, showDialog.getPath()), showDialog.getPath());
startActivity(PackageUtils.getUninstallIntent(BaseFragmentActivity.this, showDialog.getPath()));
}
}, null);
}
}
}

View File

@ -21,14 +21,14 @@ public class DataUtils {
public static void init(Application application) {
//TalkingData
//dubug true release false
TCAgent.LOG_ON = true;
TCAgent.LOG_ON = false;
TCAgent.init(application);
TCAgent.setReportUncaughtExceptions(true);
//MTA
// 打开debug开关可查看mta上报日志或错误
// dubug true release false
StatConfig.setDebugEnable(true);
StatConfig.setDebugEnable(false);
// 收集未处理的异常
StatConfig.setAutoExceptionCaught(true);
// 设置数据上报策略
@ -55,7 +55,7 @@ public class DataUtils {
for (String key : var3.keySet()) {
prop.setProperty(key, var3.get(key) + "");
}
StatService.trackCustomBeginKVEvent(var0, var1, prop);
StatService.trackCustomKVEvent(var0, var1, prop);
}
public static void onPause(Activity var0) {

View File

@ -713,14 +713,14 @@ public class DownloadItemUtils {
context.startActivity(PackageUtils
.getInstallIntent(path));
} else {
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
PackageUtils.getPackageNameByPath(context, path), path);
context.startActivity(PackageUtils.getUninstallIntent(context, path));
}
});
}, null);
}
}
}

View File

@ -13,7 +13,7 @@ import java.lang.reflect.Field;
public class Utils {
private static final boolean DEBUG = true;
private static final boolean DEBUG = false;
public static void log(String msg) {
if (DEBUG) {

View File

@ -847,7 +847,7 @@ public class DownloadDialog {
context.startActivity(PackageUtils
.getInstallIntent(path));
} else {
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
@ -855,7 +855,7 @@ public class DownloadDialog {
context.startActivity(PackageUtils.getUninstallIntent(context,
path));
}
});
}, null);
}
}
} else if ("等待".equals(status)) {
@ -943,6 +943,10 @@ public class DownloadDialog {
|| "pause".equals(statusMap.get(downloadEntry
.getUrl()))) {
viewHolder.download_item_tv_status.setText("继续");
} else if (downloadEntry.getStatus().equals(
DownloadStatus.timeout) || downloadEntry.getStatus().equals(
DownloadStatus.neterror)) {
viewHolder.download_item_tv_status.setText("继续");
} else {
viewHolder.download_item_tv_status.setText("插件下载中");
}
@ -953,6 +957,10 @@ public class DownloadDialog {
} else if (downloadEntry.getStatus().equals(
DownloadStatus.pause)) {
viewHolder.download_item_tv_status.setText("继续");
} else if (downloadEntry.getStatus().equals(
DownloadStatus.timeout) || downloadEntry.getStatus().equals(
DownloadStatus.neterror)) {
viewHolder.download_item_tv_status.setText("继续");
} else {
viewHolder.download_item_tv_status.setText("更新中");
}

View File

@ -10,7 +10,8 @@ public interface DownloadListener {
* 更新每一次下载的大小
* @param downloadedSize
*/
void onProgressChanged(int downloadedSize);
// void onProgressChanged(int downloadedSize);
void onProgressChanged(long length, int downloadedSize);
/**
* 更新任务下载状态

View File

@ -7,6 +7,7 @@ import android.os.Message;
import com.gh.common.constant.Constants;
import com.gh.common.util.FileUtils;
import com.gh.common.util.Trace;
import com.gh.common.util.Utils;
import java.text.DecimalFormat;
import java.util.HashMap;
@ -75,8 +76,9 @@ public class DownloadTask implements DownloadListener {
}
@Override
public synchronized void onProgressChanged(int len) {
currSize += len;
// public synchronized void onProgressChanged(int len) {
public synchronized void onProgressChanged(long length, int len) {
currSize = length;
double percent = 0;
if (entry.getSize() != 0) {
percent = currSize * 100.0 / entry.getSize();

View File

@ -56,11 +56,11 @@ public class DownloadThread extends Thread {
//Httpdns替换地址
String newUrl = HttpdnsUtils.getUrls(context, entry.getUrl());
if (newUrl == null){
if (newUrl == null) {
newUrl = entry.getUrl();
getNewurlSuccess = false;
Utils.log("HttpDnsService::获取新地址失败,用原地址进行下载,原地址为::"+newUrl);
}else {
} else {
getNewurlSuccess = true;
Utils.log("HttpDnsService::获取新地址成功,目标地址为::"+newUrl);
}
@ -72,16 +72,13 @@ public class DownloadThread extends Thread {
connection.setRequestMethod("GET");
connection.setConnectTimeout(CONNECT_TIME);
connection.setReadTimeout(READ_TIME);
connection.setRequestProperty("RANGE",
"bytes=" + targetFile.length() + "-");
//获取新地址成功设置HTTP请求头Host域
if (getNewurlSuccess){
if (getNewurlSuccess &&newUrl.endsWith(".apk") ){
//非.apk,结尾的下载地址不需要加请求头Host域
if (newUrl.endsWith(".apk")){
connection.setRequestProperty("Host",url.getHost());
}
}else {
connection.setRequestProperty("RANGE",
"bytes=" + targetFile.length() + "-");
connection.setRequestProperty("Host", url.getHost());
}
//设置自动重定向
@ -103,6 +100,10 @@ public class DownloadThread extends Thread {
connection.setReadTimeout(READ_TIME);
connection.setRequestProperty("RANGE",
"bytes=" + targetFile.length() + "-");
if (getNewurlSuccess &&newUrl.endsWith(".apk") ){
//非.apk,结尾的下载地址不需要加请求头Host域
connection.setRequestProperty("Host", url.getHost());
}
//设置自动重定向
connection.setInstanceFollowRedirects(true);
}
@ -141,7 +142,8 @@ public class DownloadThread extends Thread {
int len;
while ((len = bis.read(buffer)) != -1) {
bos.write(buffer, 0, len);
listener.onProgressChanged(len);
// listener.onProgressChanged(len);
listener.onProgressChanged(targetFile.length(), len);
if (status == DownloadStatus.pause
|| status == DownloadStatus.cancel) {
listener.onStatusChanged(status);

View File

@ -110,7 +110,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
private DismissEntity dismissEntity;
private long start = 0L;
private boolean isShowPluginDialog = false;
private boolean isSentReport = false;
private ArrayMap<String, String> statusMap;
@ -135,24 +134,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
}
}
}
for (Entry<String, DownloadEntry> entry : downloadingEntries
.entrySet()) {
DownloadEntry downloadEntry = entry.getValue();
if (DownloadStatus.done.equals(downloadEntry.getStatus())
&& downloadEntry.getMeta().get("isPlugin") != null) {
if (!RunningUtils
.isApplicationBroughtToBackground(getApplicationContext())
&& RunningUtils.isEqualsTop(
getApplicationContext(),
GameDetailsActivity.class.getName())) {
if (!isShowPluginDialog) {
isShowPluginDialog = true;
showPluginDialog(downloadEntry.getPath(),
downloadEntry.getName());
}
}
}
}
}
};
@ -500,7 +481,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
if (manager.launchSetup(path)) {
startActivity(PackageUtils.getInstallIntent(path));
} else {
DialogUtils.showUninstallDialog(this, new DialogUtils.ConfiremListener() {
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
@ -508,7 +489,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
startActivity(PackageUtils.getUninstallIntent(GameDetailsActivity.this,
path));
}
});
}, null);
}
} else if("等待".equals(str)){
@ -638,28 +619,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
}
}
private void showPluginDialog(final String path, final String gameName) {
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
Map<String, Object> kv6 = new HashMap<String, Object>();
kv6.put("操作", "一次性完成");
DataUtils.onEvent(GameDetailsActivity.this, "插件化", gameName, kv6);
if (FileUtils.isEmptyFile(path)) {
toast("解析包错误");
} else {
MainActivity.uninstallMap.put(PackageUtils.getPackageNameByPath(getApplicationContext(), path), path);
startActivity(PackageUtils.getUninstallIntent(getApplicationContext(), path));
}
}
}, new DialogUtils.DismissListener() {
@Override
public void onDismiss() {
isShowPluginDialog = false;
}
});
}
@Override
public void onPageSelected(int position) {
switch (position) {

View File

@ -26,6 +26,7 @@ import android.view.Window;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request.Method;
import com.android.volley.Response;
@ -293,14 +294,13 @@ public class MainActivity extends BaseFragmentActivity implements
downloadEntry.getMeta().get(
"platform"));
if (platform != null) {
String msg = downloadEntry.getName()
+ " - " + platform;
if (downloadEntry.getMeta().get("isPlugin") != null) {
msg = msg + " - 插件化安装包下载完成";
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntry
.getPath()));
} else {
msg = msg + " - 下载完成";
toast(downloadEntry.getName()
+ " - " + platform + " - 下载完成");
}
toast(msg);
} else {
toast(downloadEntry.getName() + " - 下载完成");
}
@ -1089,6 +1089,7 @@ public class MainActivity extends BaseFragmentActivity implements
}
public void onEventMainThread(EBPackage busFour) {
String packageName = busFour.getPackageName();
// 添加进已安装map中
if ("安装".equals(busFour.getType())) {
@ -1116,19 +1117,24 @@ public class MainActivity extends BaseFragmentActivity implements
url, sp.getBoolean("autodelete", true));
}
} else if ("卸载".equals(busFour.getType())) {
for (DownloadEntry downloadEntry : DownloadManager.getInstance(
getApplicationContext()).getAll()) {
if (downloadEntry.getMeta().get("isPlugin") != null
&& downloadEntry.getMeta().get("package_name")
.equals(packageName)) {
Map<String, Object> kv6 = new HashMap<String, Object>();
kv6.put("安装或卸载", "卸载完成");
DataUtils.onEvent(this, "插件化", downloadEntry.getName(), kv6);
break;
try {
for (DownloadEntry downloadEntry : DownloadManager.getInstance(
getApplicationContext()).getAll()) {
if (downloadEntry.getMeta().get("isPlugin") != null
&& downloadEntry.getMeta().get("package_name")
.equals(packageName)) {
Map<String, Object> kv6 = new HashMap<String, Object>();
kv6.put("安装或卸载", "卸载完成");
DataUtils.onEvent(this, "插件化", downloadEntry.getName(), kv6);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
String path = uninstallMap.get(packageName);
if (path != null) {
uninstallMap.remove(packageName);

View File

@ -431,7 +431,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
if (manager.launchSetup(path)) {
startActivity(PackageUtils.getInstallIntent(path));
} else {
DialogUtils.showUninstallDialog(this, new DialogUtils.ConfiremListener() {
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
@ -439,7 +439,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
startActivity(PackageUtils.getUninstallIntent(NewsActivity.this,
path));
}
});
}, null);
}
} else if ("等待".equals(str)) {

View File

@ -229,7 +229,7 @@ public class SplashScreenActivity extends BaseActivity {
getPlatform();
}
// getDownloadStatus();
getDownloadStatus();
getUISetting();

View File

@ -349,7 +349,7 @@ public class DownLoadManagerFragment extends Fragment {
startActivity(PackageUtils
.getInstallIntent(path));
} else {
DialogUtils.showUninstallDialog(getActivity(), new DialogUtils.ConfiremListener() {
DialogUtils.showPluginDialog(getActivity(), new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
MainActivity.uninstallMap.put(
@ -357,7 +357,7 @@ public class DownLoadManagerFragment extends Fragment {
startActivity(PackageUtils.getUninstallIntent(getActivity(),
path));
}
});
}, null);
}
}
}