package com.honey.filecompress;

import java.io.File;
 


 



import com.honey.utils.ZipFileThread;
import com.honey.utils.ZipTool;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap.CompressFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

	Button Btn_Compress;
	private ProgressDialog progressDialog;
	File file ;
	
	// 处理解压/压缩返回信息
		private Handler zipHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				Bundle bundle = msg.getData();
				int exitType = bundle.getInt("OPTION_STATUS");
				switch (exitType) {
				 
				case ZipTool.EXIST_ZIPFILE:
					Toast.makeText(MainActivity.this, "输入的压缩文件已经存在于该目录中", Toast.LENGTH_LONG).show();
					break;
				  
				case ZipTool.ZIPOPTION_FAIL:
					Toast.makeText(MainActivity.this, "操作失败", Toast.LENGTH_LONG).show();
				 
					break;
				default:
					Toast.makeText(MainActivity.this, "操作成功", Toast.LENGTH_LONG).show();
					break;
				}
			 
				progressDialog.dismiss();
			}
		};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Btn_Compress = (Button) findViewById(R.id.button1);
		Btn_Compress.setOnClickListener(this);
//		file = new File("/sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons");
		file = new File("/mnt/internal_sd/Download");
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button1:
		
			zipFile(file);

			break;

		default:
			break;
		}

	} 
	private void zipFile(File file) {
		
		String zipFileName ="addons";
		progressDialog = ProgressDialog.show(this, "提示信息", "正在压缩请稍候...", true, false);

		ZipFileThread zft = new ZipFileThread();
		zft.setFile(file);
		zft.setHandlePath("/sdcard/Download"+ zipFileName);
		zft.setHandler(zipHandler);
		zft.start();
		 
	}
	
	
	

	
	

}
