...
 
Commits (4)
package net.dankito.utils.android.clipboard
import android.content.ClipData
import android.content.ClipDescription
import android.os.Build
import net.dankito.utils.clipboard.ClipboardContent
import net.dankito.utils.web.UrlUtil
class AndroidClipboardContent(private val item: ClipData.Item, private val description: ClipDescription, private val urlUtil: UrlUtil) : ClipboardContent() {
override fun hasPlainText() = description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)
override val plainText = item.text?.toString()
override fun hasUrl(): Boolean {
// urls are mostly copied as plain text to clipboard, not as Android Uri
return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST) ||
(hasPlainText() && plainText != null && urlUtil.isHttpUri(plainText.trim()))
}
override val url: String?
get() {
if(description.hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
return item.uri?.toString()
}
else if(plainText != null && urlUtil.isHttpUri(plainText.trim())) {
return plainText.trim()
}
return null
}
override fun hasHtml(): Boolean {
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)
}
return false
}
override val html: String?
get() {
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
return item.htmlText
}
return item.text?.toString()
}
// Android Clipboard can only contain plain text, html, an uri or an intent
override fun hasRtf() = false
override val rtf = null
override fun hasImage() = false
override val image = null
override fun hasFiles() = false
override val files = null
}
\ No newline at end of file
package net.dankito.utils.android.image
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import net.dankito.utils.AsyncResult
import net.dankito.utils.image.ImageCache
import java.io.File
import java.util.concurrent.ConcurrentHashMap
class BitmapCache(private val imageCache: ImageCache) {
private val bitmapsCache = ConcurrentHashMap<String, Bitmap>()
fun getBitmapForUrlAsync(url: String, callback: (AsyncResult<Bitmap>) -> Unit) {
val cachedBitmap = bitmapsCache[url]
if(cachedBitmap != null) {
callback(AsyncResult(true, result = cachedBitmap))
}
else {
imageCache.getCachedForRetrieveIconForUrlAsync(url) { result ->
result.result?.let { file ->
val bitmap = createAndCacheBitmap(url, file)
if(bitmap != null) {
callback(AsyncResult(true, result = bitmap))
}
else {
callback(AsyncResult(false, Exception("Could not decode bitmap from file $file")))
}
}
result.error?.let { callback(AsyncResult(false, it)) }
}
}
}
private fun createAndCacheBitmap(url: String, file: File): Bitmap? {
val bitmap = BitmapFactory.decodeFile(file.path)
if(bitmap != null) {
bitmapsCache.put(url, bitmap)
}
return bitmap
}
fun clear() {
bitmapsCache.clear()
}
}
\ No newline at end of file
package net.dankito.utils.android.network
import android.content.Intent
import net.dankito.utils.network.NetworkConnectivityManagerBase
import net.dankito.utils.network.NetworkHelper
class AndroidNetworkConnectivityManager(networkHelper: NetworkHelper) : NetworkConnectivityManagerBase(networkHelper) {
fun handleConnectivityChangedIntent(intent: Intent) {
networkInterfacesChanged()
}
}
\ No newline at end of file
package net.dankito.utils.android.network
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
abstract class NetworkConnectivityChangeBroadcastReceiverBase : BroadcastReceiver() {
protected abstract fun getNetworkConnectivityManager(): AndroidNetworkConnectivityManager
override fun onReceive(context: Context?, intent: Intent?) {
if(intent != null && intent.action == ConnectivityManager.CONNECTIVITY_ACTION) {
getNetworkConnectivityManager().handleConnectivityChangedIntent(intent)
}
}
}
\ No newline at end of file
package net.dankito.utils.android.ui.image
import net.dankito.utils.ui.image.Image
class AndroidImage : Image
\ No newline at end of file