快传(接收方图片缩略图尚需改进, 连接断开处理尚需改进),安装包清理, 网页传网页乱码未解决
This commit is contained in:
200
app/src/main/java/com/gh/gamecenter/CleanApkActivity.java
Normal file
200
app/src/main/java/com/gh/gamecenter/CleanApkActivity.java
Normal file
@ -0,0 +1,200 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.adapter.CleanApkAdapter;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/24.
|
||||
*/
|
||||
public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.OnScanListener {
|
||||
|
||||
@BindView(R.id.apk_count) TextView mApkCount;
|
||||
@BindView(R.id.apk_rv) RecyclerView mApkRv;
|
||||
@BindView(R.id.delete_btn) TextView mApkDeleteBtn;
|
||||
@BindView(R.id.select_game_all) CheckBox mApkSelectAll;
|
||||
@BindView(R.id.scan_pb) ProgressBar mScanPb;
|
||||
@BindView(R.id.reuse_nodata_skip_tv_hint) TextView mNodataSkipTv;
|
||||
@BindView(R.id.reuse_nodata_skip_tv_btn) TextView mNodataSkipBtn;
|
||||
@BindView(R.id.reuse_nodata_skip) LinearLayout mNodataSkipLl;
|
||||
@BindView(R.id.delete_bottom) LinearLayout mDeleteBottom;
|
||||
@BindView(R.id.select_game_installed_ll) RelativeLayout mInstallAllData;
|
||||
|
||||
private CleanApkAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_clean_apk, null);
|
||||
init(contentView, "选择游戏");
|
||||
|
||||
mNodataSkipLl.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new CleanApkAdapter(this, mApkDeleteBtn);
|
||||
mApkRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mApkRv.setAdapter(mAdapter);
|
||||
|
||||
mApkSelectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
ArrayMap<Integer, Boolean> selectPosition = new ArrayMap<>();
|
||||
int itemCount = mAdapter.getItemCount();
|
||||
if (isChecked) {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, true);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter.setSelectPosition(selectPosition);
|
||||
mAdapter.notifyItemRangeChanged(0, itemCount);
|
||||
}
|
||||
});
|
||||
|
||||
mNodataSkipBtn.setText("去首页看看");
|
||||
mNodataSkipTv.setText("安装包已清理干净\n快去发现更多好玩的游戏吧!");
|
||||
|
||||
}
|
||||
|
||||
@OnClick({R.id.delete_btn, R.id.reuse_nodata_skip_tv_btn})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.delete_btn: {
|
||||
String s = mApkDeleteBtn.getText().toString();
|
||||
if ("停止扫描".equals(s)) {
|
||||
mAdapter.isStopScan();
|
||||
} else {
|
||||
if (s.equals("一键删除")) {
|
||||
Utils.toast(CleanApkActivity.this, "请选择需要删除的安装包");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<InstallGameEntity> apkList = mAdapter.getApkList();
|
||||
final ArrayMap<Integer, Boolean> selectPosition = mAdapter.getSelectPosition();
|
||||
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i) && apkList.get(i).getInstallStatus() == 1) {
|
||||
DialogUtils.showWarningDialog(CleanApkActivity.this, "删除安装包"
|
||||
, "已选的安装包中可能包含未安装的应用,确定删除吗?", "取消 ", "确定"
|
||||
, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
deleteApk(apkList, selectPosition);
|
||||
}
|
||||
}, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
deleteApk(apkList, selectPosition);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case R.id.reuse_nodata_skip_tv_btn: {
|
||||
Intent intent = new Intent(CleanApkActivity.this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
EventBus.getDefault().post(new EBSkip("GameFragment", 0));
|
||||
}
|
||||
}.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteApk(List<InstallGameEntity> apkList, ArrayMap<Integer, Boolean> selectPosition) {
|
||||
long size = 0;
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i)) {
|
||||
InstallGameEntity installGameEntity = apkList.get(i);
|
||||
size = size + installGameEntity.getGameSize();
|
||||
File file = new File(installGameEntity.getGamePath());
|
||||
if (file.isFile() && file.exists()) {
|
||||
file.delete();
|
||||
mAdapter.deleteApk(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double allSize = (((float)size/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(allSize) + "MB";
|
||||
Utils.toast(CleanApkActivity.this, "删除成功,已为您节省" + sizeName + "空间");
|
||||
|
||||
mAdapter.notifyDataSetChanged(); // 刷新Adapter position
|
||||
|
||||
if (apkList.size() == 0) { // 全部删除
|
||||
mNodataSkipLl.setVisibility(View.VISIBLE);
|
||||
mInstallAllData.setVisibility(View.GONE);
|
||||
mDeleteBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanOver() {
|
||||
mApkDeleteBtn.setText("一键删除");
|
||||
mApkDeleteBtn.setBackgroundResource(R.drawable.game_item_btn_red_style);
|
||||
|
||||
long allSize = 0;
|
||||
|
||||
List<InstallGameEntity> apkList = mAdapter.getApkList();
|
||||
for (InstallGameEntity installGameEntity : apkList) {
|
||||
allSize = allSize + installGameEntity.getGameSize();
|
||||
}
|
||||
|
||||
double size = (((float)allSize/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
mApkCount.setText(Html.fromHtml("找到" + apkList.size() + "个安装包,占用"
|
||||
+ "<font color=\"#ff0000\">" + sizeName + "</font>"+ "空间"));
|
||||
mScanPb.setVisibility(View.GONE);
|
||||
mApkSelectAll.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noData() {
|
||||
mNodataSkipBtn.setText("去首页看看");
|
||||
mNodataSkipTv.setText("暂无游戏");
|
||||
mNodataSkipLl.setVisibility(View.VISIBLE);
|
||||
mInstallAllData.setVisibility(View.GONE);
|
||||
mDeleteBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user