mirror of
https://gitlab.shinice.net/pixeldroid/PixelDroid
synced 2024-12-25 22:43:30 +01:00
Merge branch 'master' into notifications
This commit is contained in:
commit
4f87077178
@ -1,6 +1,8 @@
|
||||
package org.pixeldroid.app.postCreation.photoEdit
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.ImageDecoder
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.TypedValue
|
||||
@ -16,6 +18,7 @@ import com.zomato.photofilters.FilterPack
|
||||
import com.zomato.photofilters.imageprocessors.Filter
|
||||
import com.zomato.photofilters.utils.ThumbnailItem
|
||||
import com.zomato.photofilters.utils.ThumbnailsManager
|
||||
import org.pixeldroid.app.utils.bitmapFromUri
|
||||
|
||||
class FilterListFragment : Fragment() {
|
||||
|
||||
@ -54,17 +57,7 @@ class FilterListFragment : Fragment() {
|
||||
private fun displayImage(bitmap: Bitmap?) {
|
||||
val r = Runnable {
|
||||
val tbImage: Bitmap = (if (bitmap == null) {
|
||||
// TODO: Shouldn't use deprecated API on newer versions of Android,
|
||||
// but the proper way to do it seems to crash for OpenGL reasons
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
// ImageDecoder.decodeBitmap(
|
||||
// ImageDecoder.createSource(requireActivity().contentResolver, PhotoEditActivity.imageUri!!))
|
||||
//} else {
|
||||
MediaStore.Images.Media.getBitmap(
|
||||
requireActivity().contentResolver,
|
||||
PhotoEditActivity.imageUri
|
||||
)
|
||||
//}
|
||||
bitmapFromUri(requireActivity().contentResolver, PhotoEditActivity.imageUri)
|
||||
} else {
|
||||
Bitmap.createScaledBitmap(bitmap, 100, 100, false)
|
||||
})
|
||||
|
@ -9,7 +9,6 @@ import android.graphics.Point
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View.GONE
|
||||
@ -28,6 +27,7 @@ import com.zomato.photofilters.imageprocessors.Filter
|
||||
import com.zomato.photofilters.imageprocessors.subfilters.BrightnessSubFilter
|
||||
import com.zomato.photofilters.imageprocessors.subfilters.ContrastSubFilter
|
||||
import com.zomato.photofilters.imageprocessors.subfilters.SaturationSubfilter
|
||||
import org.pixeldroid.app.utils.bitmapFromUri
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
@ -114,9 +114,9 @@ class PhotoEditActivity : BaseActivity() {
|
||||
binding.tabs.setupWithViewPager(binding.viewPager)
|
||||
}
|
||||
|
||||
|
||||
private fun loadImage() {
|
||||
originalImage = MediaStore.Images.Media.getBitmap(contentResolver, imageUri)
|
||||
originalImage = bitmapFromUri(contentResolver, imageUri)
|
||||
|
||||
compressedImage = resizeImage(originalImage!!)
|
||||
compressedOriginalImage = compressedImage!!.copy(BITMAP_CONFIG, true)
|
||||
filteredImage = compressedImage!!.copy(BITMAP_CONFIG, true)
|
||||
|
@ -1,24 +1,26 @@
|
||||
package org.pixeldroid.app.utils
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.*
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.Matrix
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.pixeldroid.app.R
|
||||
import okhttp3.HttpUrl
|
||||
import org.pixeldroid.app.R
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
@ -63,6 +65,47 @@ fun normalizeDomain(domain: String): String {
|
||||
.trim(Char::isWhitespace)
|
||||
}
|
||||
|
||||
fun bitmapFromUri(contentResolver: ContentResolver, uri: Uri?): Bitmap =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
ImageDecoder
|
||||
.decodeBitmap(
|
||||
ImageDecoder.createSource(contentResolver, uri!!)
|
||||
)
|
||||
{ decoder, _, _ -> decoder.isMutableRequired = true }
|
||||
} else {
|
||||
val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
|
||||
modifyOrientation(bitmap!!, contentResolver, uri!!)
|
||||
}
|
||||
|
||||
fun modifyOrientation(
|
||||
bitmap: Bitmap,
|
||||
contentResolver: ContentResolver,
|
||||
uri: Uri
|
||||
): Bitmap {
|
||||
val inputStream = contentResolver.openInputStream(uri)!!
|
||||
val ei = ExifInterface(inputStream)
|
||||
return when (ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
|
||||
ExifInterface.ORIENTATION_ROTATE_90 -> bitmap.rotate(90f)
|
||||
ExifInterface.ORIENTATION_ROTATE_180 -> bitmap.rotate(180f)
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> bitmap.rotate(270f)
|
||||
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> bitmap.flip(horizontal = true, vertical = false)
|
||||
ExifInterface.ORIENTATION_FLIP_VERTICAL -> bitmap.flip(horizontal = false, vertical = true)
|
||||
else -> bitmap
|
||||
}
|
||||
}
|
||||
|
||||
fun Bitmap.rotate(degrees: Float): Bitmap {
|
||||
val matrix = Matrix()
|
||||
matrix.postRotate(degrees)
|
||||
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)
|
||||
}
|
||||
|
||||
fun Bitmap.flip(horizontal: Boolean, vertical: Boolean): Bitmap {
|
||||
val matrix = Matrix()
|
||||
matrix.preScale(if (horizontal) -1f else 1f, if (vertical) -1f else 1f)
|
||||
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)
|
||||
}
|
||||
|
||||
fun BaseActivity.openUrl(url: String): Boolean{
|
||||
|
||||
val intent = CustomTabsIntent.Builder().build()
|
||||
|
Loading…
Reference in New Issue
Block a user