private void saveImage(int index) { String dest = AcApp.getPreferenceImageSaveDir(); String path = mList.get(index); Uri uri = Uri.parse(path); File saveFile; if (uri.getScheme().equals("http")) { // FIXME: volley 的缓存任务还没有被执行的时候是会获取不到数据的 byte[] diskCache = AcApp.getDataInDiskCache(path); if (diskCache != null) { saveFile = new File(dest + "/" + FileUtil.getHashName(path)); if (!FileUtil.save(diskCache, saveFile.getAbsolutePath())) { saveFile = null; } } else { File cache = FileUtil.generateImageCacheFile(path); saveFile = FileUtil.copy(cache, dest); } } else { File cache = new File(uri.getPath()); saveFile = FileUtil.copy(cache, dest); } if (saveFile != null && saveFile.exists()) { MobclickAgent.onEvent(this, "save_pic"); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(saveFile)); sendBroadcast(intent); AcApp.showToast(getString(R.string.save_success) + ":" + saveFile.getAbsolutePath()); } else AcApp.showToast(getString(R.string.save_failed)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDownloadMan = AcApp.getDownloadManager(); mBar = getSupportActionBar(); mBar.setTitle("下载管理"); if (!AcApp.isExternalStorageAvailable()) { setContentView(R.layout.no_sd_layout); return; } setContentView(R.layout.list_layout); Intent service = new Intent(this, DownloadService.class); bindService(service, conn, BIND_AUTO_CREATE); mStateArray = getResources().getStringArray(R.array.download_state); // TODO 换成popupwindow或者其他的显示方式 ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( mBar.getThemedContext(), R.array.download_state, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); mBar.setListNavigationCallbacks(adapter, this); initView(); }
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_download_delete: int i = 0; for (DownloadJob job : mAdapter.getCheckedJobs()) { mDownloadMan.deleteDownload(job); i++; } AcApp.showToast("删除完毕 - 共" + i + "项"); break; case R.id.menu_download_resume: AcApp.showToast("继续"); for (DownloadJob job : mAdapter.getCheckedJobs()) { if (job.getProgress() != 100) { job.setListener(mDownloadService.mJobListener); job.resume(); mDownloadMan.getProvider().resume(job); } } break; case R.id.menu_download_pause: AcApp.showToast("暂停"); for (DownloadJob job : mAdapter.getCheckedJobs()) { if (DownloadManager.isRunningStatus(job.getStatus())) { job.setListener(mDownloadService.mJobListener); job.pause(); } } break; case R.id.menu_select_all: mAdapter.checkedAll(); break; } return true; }