package cn.shangyu.gdxzExpert.activity;//package cn.shangyu.gdxzExpert.activity; // //import android.app.Activity; //import android.content.Context; //import android.content.Intent; //import android.os.Bundle; //import android.os.Environment; // //import android.text.TextUtils; // //import java.io.File; // // //import cn.shangyu.gdxzExpert.R; //import cn.shangyu.gdxzExpert.ui.SuperFileView2; //import cn.shangyu.gdxzExpert.utils.Md5Tool; // // // //public class FileDisplayActivity extends Activity { // // // private String TAG = "FileDisplayActivity"; // SuperFileView2 mSuperFileView; // // String filePath; // // // // // @Override // protected void onCreate( Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_file_display); // init(); // } // // // public void init() { // mSuperFileView = (SuperFileView2) findViewById(R.id.mSuperFileView); // mSuperFileView.setOnGetFilePathListener(new SuperFileView2.OnGetFilePathListener() { // @Override // public void onGetFilePath(SuperFileView2 mSuperFileView2) { // getFilePathAndShowFile(mSuperFileView2); // } // }); // // Intent intent = this.getIntent(); // String path = (String) intent.getSerializableExtra("path"); // // if (!TextUtils.isEmpty(path)) { // setFilePath(path); // } // mSuperFileView.show(); // // } // // // private void getFilePathAndShowFile(SuperFileView2 mSuperFileView2) { // // // if (getFilePath().contains("http")) {//网络地址要先下载 // //// downLoadFromNet(getFilePath(),mSuperFileView2); // // } else { // mSuperFileView2.displayFile(new File(getFilePath())); // } // } // // // @Override // public void onDestroy() { // super.onDestroy(); // if (mSuperFileView != null) { // mSuperFileView.onStopDisplay(); // } // } // // // public static void show(Context context, String url) { // Intent intent = new Intent(context, FileDisplayActivity.class); // Bundle bundle = new Bundle(); // bundle.putSerializable("path", url); // intent.putExtras(bundle); // context.startActivity(intent); // // } // // public void setFilePath(String fileUrl) { // this.filePath = fileUrl; // } // // private String getFilePath() { // return filePath; // } // //// private void downLoadFromNet(final String url,final SuperFileView2 mSuperFileView2) { //// //// //1.网络下载、存储路径、 //// File cacheFile = getCacheFile(url); //// if (cacheFile.exists()) { //// if (cacheFile.length() <= 0) { //// TLog.d(TAG, "删除空文件!!"); //// cacheFile.delete(); //// return; //// } //// } //// //// //// //// LoadFileModel.loadPdfFile(url, new Callback() { //// @Override //// public void onResponse(Call call, Response response) { //// TLog.d(TAG, "下载文件-->onResponse"); //// boolean flag; //// InputStream is = null; //// byte[] buf = new byte[2048]; //// int len = 0; //// FileOutputStream fos = null; //// try { //// ResponseBody responseBody = response.body(); //// is = responseBody.byteStream(); //// long total = responseBody.contentLength(); //// //// File file1 = getCacheDir(url); //// if (!file1.exists()) { //// file1.mkdirs(); //// TLog.d(TAG, "创建缓存目录: " + file1.toString()); //// } //// //// //// //fileN : /storage/emulated/0/pdf/kauibao20170821040512.pdf //// File fileN = getCacheFile(url);//new File(getCacheDir(url), getFileName(url)) //// //// TLog.d(TAG, "创建缓存文件: " + fileN.toString()); //// if (!fileN.exists()) { //// boolean mkdir = fileN.createNewFile(); //// } //// fos = new FileOutputStream(fileN); //// long sum = 0; //// while ((len = is.read(buf)) != -1) { //// fos.write(buf, 0, len); //// sum += len; //// int progress = (int) (sum * 1.0f / total * 100); //// TLog.d(TAG, "写入缓存文件" + fileN.getName() + "进度: " + progress); //// } //// fos.flush(); //// TLog.d(TAG, "文件下载成功,准备展示文件。"); //// //2.ACache记录文件的有效期 //// mSuperFileView2.displayFile(fileN); //// } catch (Exception e) { //// TLog.d(TAG, "文件下载异常 = " + e.toString()); //// } finally { //// try { //// if (is != null) //// is.close(); //// } catch (IOException e) { //// } //// try { //// if (fos != null) //// fos.close(); //// } catch (IOException e) { //// } //// } //// } //// //// @Override //// public void onFailure(Call call, Throwable t) { //// TLog.d(TAG, "文件下载失败"); //// File file = getCacheFile(url); //// if (!file.exists()) { //// TLog.d(TAG, "删除下载失败文件"); //// file.delete(); //// } //// } //// }); //// //// //// } // // /*** // * 获取缓存目录 // * // * @param url // * @return // */ // private File getCacheDir(String url) { // // return new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/007/"); // // } // /*** // * 绝对路径获取缓存文件 // * // * @param url // * @return // */ // private File getCacheFile(String url) { // File cacheFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/007/" // + getFileName(url)); // return cacheFile; // } // // /*** // * 根据链接获取文件名(带类型的),具有唯一性 // * // * @param url // * @return // */ // private String getFileName(String url) { // String fileName = Md5Tool.hashKey(url) + "." + getFileType(url); // return fileName; // } // // /*** // * 获取文件类型 // * // * @param paramString // * @return // */ // private String getFileType(String paramString) { // String str = ""; // // if (TextUtils.isEmpty(paramString)) { // return str; // } // int i = paramString.lastIndexOf('.'); // if (i <= -1) { // return str; // } // // // str = paramString.substring(i + 1); // return str; // } // // //}