| | |
| | | package cn.flightfeather.thirdapp.util |
| | | |
| | | import android.app.Activity |
| | | import android.app.Dialog |
| | | import android.content.Intent |
| | | import android.graphics.Bitmap |
| | | import android.net.Uri |
| | |
| | | import android.support.v4.app.Fragment |
| | | import android.support.v4.app.FragmentActivity |
| | | import android.support.v4.content.FileProvider |
| | | import android.webkit.MimeTypeMap |
| | | import cn.flightfeather.thirdapp.util.file.FileUtils |
| | | import com.flightfeather.taizhang.common.utils.download.UpDownloadUtil |
| | | import org.jetbrains.anko.toast |
| | | import java.io.File |
| | | import java.io.FileOutputStream |
| | | |
| | |
| | | } ?: "" |
| | | } |
| | | |
| | | fun shareFile(activity: Activity?, path: String?) { |
| | | if (path?.contains("http") == true) { |
| | | var d: Dialog? = null |
| | | activity?.let { |
| | | d = DialogUtil2.showLoadingDialog(it, "下载中", false, null) |
| | | } |
| | | UpDownloadUtil.download(activity, path, FileUtils.getFileName(path), { |
| | | d?.dismiss() |
| | | share(activity, it) |
| | | }, { |
| | | activity?.toast("下载失败") |
| | | d?.dismiss() |
| | | }) |
| | | } else { |
| | | share(activity, path) |
| | | } |
| | | } |
| | | |
| | | fun saveBitmap(path: String, bitmap: Bitmap) { |
| | | fun saveBitmap(path: String, bitmap: Bitmap): Boolean { |
| | | val file = File(path) |
| | | if (!file.parentFile.exists()) { |
| | | file.parentFile.mkdirs() |
| | |
| | | } |
| | | try { |
| | | val out = FileOutputStream(file) |
| | | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) |
| | | bitmap.compress(Bitmap.CompressFormat.PNG, 100, out) |
| | | out.flush() |
| | | out.close() |
| | | return true |
| | | } catch (e: Throwable) { |
| | | e.printStackTrace() |
| | | } |
| | | |
| | | return false |
| | | } |
| | | |
| | | private fun share(activity: Activity?, path: String?) { |
| | | val uri = FileUtils.getUri(activity, path) |
| | | val extension = FileUtils.getExtensionName(path) |
| | | val intent = Intent().apply { |
| | | action = Intent.ACTION_SEND |
| | | putExtra(Intent.EXTRA_STREAM, uri) |
| | | type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) |
| | | } |
| | | activity?.startActivity(Intent.createChooser(intent, "分享文档")) |
| | | } |
| | | |
| | | private fun getFilePath(): String { |