package com.ttd.apkbrower;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import com.ttd.apkbrower.FileWrapper;
import com.ttd.apkbrower.R;
import com.ttd.apkbrower.MyAdapter;
import com.ttd.apkbrower.installedApkinfo;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class ApkbrowerActivity extends Activity {
/** Called when the activity is first created. */
private List<String> items = null;
private List<String> paths = null;
private String rootPath = "/";
private String curPath = "/";
private String lastPath = null;
// private String size_s=null;
private TextView mPath;
private TextView fileText;
private ListView listV;
private ImageView imageView ;
private Button buttonConfirm ;
private Button buttondel ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//取得软件包路径root权限
//String apkRoot="chmod 777 "+getPackageCodePath();
//RootCommand(apkRoot);
fileText=(TextView) findViewById(R.id.fileText);
mPath = (TextView) findViewById(R.id.mPath);
listV= (ListView) findViewById(R.id.mlist);
imageView= (ImageView)findViewById(R.id.icon);
buttonConfirm = (Button) findViewById(R.id.buttonConfirm);
buttonConfirm.setEnabled(false);
buttonConfirm.setVisibility(View.GONE);
buttonConfirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String fileName = (String) mPath.getText();
if (fileName.toLowerCase().endsWith(".apk")){
Uri uri = Uri.fromFile( new File(fileName));
Intent intent = new Intent(Intent. ACTION_VIEW );
intent.setDataAndType(uri , "application/vnd.android.package-archive" );
startActivity(intent); } else {
fileText.setTextColor(Color.RED);
fileText.setText("抱歉,当前文件不是APK文件!不能执行安装操作!!请重新选择!!!");
}
}
});
buttondel = (Button) findViewById(R.id.buttondelete);
buttondel.setEnabled(false);
buttondel.setVisibility(View.GONE);
buttondel.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
final String fp = (String) mPath.getText();
final File fd = new File(fp);
String tishi=null;
if(fd.isDirectory()){
tishi="你真的要永久删除目录 "+fp+"及其中所有文件!?";
}else{
tishi="你真的要永久删除文件: "+fp+"?";
}
//生成删除文件的提示框。
new AlertDialog.Builder(ApkbrowerActivity.this)
.setIcon(R.drawable.info)
.setTitle("确认")
.setMessage(tishi)
.setPositiveButton("确定",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface, int which){
deleteFile(fd);
setResult(RESULT_OK);// 确定按钮事件
}
})
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
fileText.setText("你取消了删除操作!");
imageView.setImageDrawable(getResources().getDrawable(R.drawable.info));
setResult(RESULT_CANCELED);// 确定按钮事件
}
})
.show();
}
});
getFileDir(rootPath);//进入系统根目录
/*** 处理listV.Item点击事件,并根据不同情况更新文本框内容、显示与隐藏按键 ***/
listV.setOnItemClickListener(
new AdapterView.OnItemClickListener(){
public void onItemClick(@SuppressWarnings("rawtypes") AdapterView adapterView, View view,int position, long arg3) {
if(paths.get(position).toString().equals("!.00all")){
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("symbl_a", "!.00all");
intent.putExtras(bundle);
intent.setClass(ApkbrowerActivity.this, installedApkinfo.class);
startActivity(intent);
}
else if(paths.get(position).toString().equals("!.01usr"))
{
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("symbl_a", "!.01usr");
intent.putExtras(bundle);
intent.setClass(ApkbrowerActivity.this, installedApkinfo.class);
startActivity(intent);
}
else if(paths.get(position).toString().equals("!.02un"))
{
items = new ArrayList<String>();
paths = new ArrayList<String>();
items.add("!.004");
paths.add(rootPath);
items.add("!.005");
paths.add(rootPath);
File fileApk=Environment.getExternalStorageDirectory();
FindAllAPKFile(fileApk);
listV.setAdapter(new MyAdapter(ApkbrowerActivity.this, items, paths));
}
else{
File file = new File(paths.get(position));
lastPath = file.getParent();
long dirSize=0;
long Tcount=0;
if (file.isDirectory()) {
fileText.setTextColor(Color.GREEN);
if(paths.get(position).equals(rootPath)||paths.get(position).equals("/mnt")||paths.get(position).startsWith("/sys/")||paths.get(position).equals("/sys")){
fileText.setText("\n"+"系统目录");
}else if(paths.get(position).toLowerCase().endsWith("sdcard")||paths.get(position).toLowerCase().equals("/data")||paths.get(position).toLowerCase().equals("/system")){
Long sd_all_size = FileFolder_All_Size(paths.get(position));
Long sd_free_size = FileFolder_Free_Size(paths.get(position));
fileText.setText("\n"+"大小:"+FormetFileSize(sd_all_size)+"可用空间:"+FormetFileSize(sd_free_size));
}else{
try {
Tcount=getlist(file);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
dirSize=getdirFileSize(file);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileText.setText("\n"+"文件总数"+Tcount+"个。大小:"+FormetFileSize(dirSize));
}
Drawable apk_icon = getResources().getDrawable(R.drawable.folder48);
imageView.setImageDrawable(apk_icon);
curPath = paths.get(position);
getFileDir(paths.get(position));
buttonConfirm.setEnabled(false);
butt
- 1
- 2
前往页