Tusky-App-Android/app/src/main/java/com/keylesspalace/tusky/view/MediaPreviewImageView.kt

130 lines
4.8 KiB
Kotlin
Raw Normal View History

Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
/* Copyright 2018 Jochem Raat <jchmrt@riseup.net>
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.view
import android.content.Context
import android.graphics.Matrix
import android.graphics.drawable.Drawable
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.util.FocalPointUtil
/**
* This is an extension of the standard android ImageView, which makes sure to update the custom
* matrix when its size changes if a focal point is set.
*
* If a focal point is set on this view, it will use the FocalPointUtil to update the image
* matrix each time the size of the view is changed. This is needed to ensure that the correct
* cropping is maintained.
*
* However if there is no focal point set (e.g. it is null), then this view should simply
* act exactly the same as an ordinary android ImageView.
*/
Add UI for image-attachment "focus" (#2620) * Attempt-zero implementation of a "focus" feature for image attachments. Choose "Set focus" in the attachment menu, tap once to select focus point (no visual feedback currently), tap "OK". Works in tests. * Remove code duplication between 'update description' and 'update focus' * Fix ktlint/bitrise failures * Make updateMediaItem private * When focus is set on a post attachment the preview focuses correctly. ProgressImageView now inherits from MediaPreviewImageView. * Replace use of PointF for Focus where focus is represented, fix ktlint * Substitute 'focus' for 'focus point' in strings * First attempt draw focus point. Only updates on initial load. Modeled on code from RoundedCorners builtin from Glide * Redraw focus after each tap * Dark curtain where focus isn't (now looks like mastosoc) * Correct ktlint for FocusDialog * draft: switch to overlay for focus indicator * Draw focus circle, but ImageView and FocusIndicatorView seem to share a single canvas * Switch focus circle to path approach * Correctly scale, save and load focuses. Clamp to visible area. Focus editor looks and feels right * ktlint fixes and comments * Focus indicator drawing should use device-independent pixels * Shrink focus window when it gets unattractively tall (no linting, misbehaves on wide aspect ratio screens) * Correct max-height behavior for screens in landscape mode * Focus attachment result is are flipped on x axis; fix this * Correctly thread focus through on scheduled posts, redrafted posts, and drafts (but draft focus is lost on post) * More focus ktlint fixes * Fix specific case where a draft is given a focus, then deleted, then posted in that order * Fix accidental file change in focus PR * ktLint fix * Fix property style warnings in focus * Fix remaining style warnings from focus PR Co-authored-by: Conny Duck <k.pozniak@gmx.at>
2022-09-21 20:28:06 +02:00
open class MediaPreviewImageView
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
@JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr), RequestListener<Drawable> {
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
private var focus: Attachment.Focus? = null
private var focalMatrix: Matrix? = null
/**
* Set the focal point for this view.
*/
fun setFocalPoint(focus: Attachment.Focus?) {
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
this.focus = focus
super.setScaleType(ScaleType.MATRIX)
if (focalMatrix == null) {
focalMatrix = Matrix()
}
}
/**
* Remove the focal point from this view (if there was one).
*/
fun removeFocalPoint() {
super.setScaleType(ScaleType.CENTER_CROP)
focus = null
}
/**
* Overridden getScaleType method which returns CENTER_CROP if we have a focal point set.
*
* This is necessary because the Android transitions framework tries to copy the scale type
* from this view to the PhotoView when animating between this view and the detailed view of
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
* the image. Since the PhotoView does not support a MATRIX scale type, the app would crash
* if we simply passed that on, so instead we pretend that CENTER_CROP is still used here
* even if we have a focus point set.
*/
override fun getScaleType(): ScaleType {
2019-04-20 22:36:44 +02:00
return if (focus != null) {
ScaleType.CENTER_CROP
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
} else {
2019-04-20 22:36:44 +02:00
super.getScaleType()
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
}
}
/**
* Overridden setScaleType method which only accepts the new type if we don't have a focal
* point set.
*
*/
override fun setScaleType(type: ScaleType) {
if (focus != null) {
super.setScaleType(ScaleType.MATRIX)
} else {
super.setScaleType(type)
}
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
return false
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
}
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
recalculateMatrix(width, height, resource)
return false
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
}
/**
* Called when the size of the view changes, it calls the FocalPointUtil to update the
* matrix if we have a set focal point. It then reassigns the matrix to this imageView.
*/
override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {
recalculateMatrix(width, height, drawable)
super.onSizeChanged(width, height, oldWidth, oldHeight)
}
private fun recalculateMatrix(width: Int, height: Int, drawable: Drawable?) {
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
if (drawable != null && focus != null && focalMatrix != null) {
scaleType = ScaleType.MATRIX
FocalPointUtil.updateFocalPointMatrix(
width.toFloat(), height.toFloat(),
drawable.intrinsicWidth.toFloat(), drawable.intrinsicHeight.toFloat(),
focus as Attachment.Focus, focalMatrix as Matrix
)
Set image previews correctly according to their focal points (#899) * Add serialization of the meta-data and focus objects These objects are added in some attachments. This commit adds data classes which are able to serialize these (partially) in preparation for the ability to honour the focal point information in image previews. * Implement correctly honouring the focal point meta-data in previews This commit adds code which ensures that the image previews of media attachments to toots are correctly cropped to always show the focal point of the image (if it is specified). It should not in any way influence how previews of media without a focal point are shown. To achieve the correct crop on the image a few components were needed: First of all we needed a way to influence how the image is cropped into the ImageView. It turns out that the preferred way to do this is by setting the ScaleType to MATRIX and adjusting the matrix of the image as needed. This matrix allows us to scale and transform the image in the way we need to make sure that the focal point is visible within the view. For this purpose we have the FocalPointEnforcer which can calculate and set the appropriate matrix on an ImageView as soon as the image is loaded. However a second problem is that we need to make sure that this matrix is updated whenever the size of the ImageView changes. The size might change for example because the orientation of the device changed from portrait to landscape or vice versas, or for a number of other reasons such as the screen being split vertically or something like that. To be able to hook onto this event we need to create a new extended version of the ImageView class, which we call MediaPreviewImageView. This class behaves exactly the same as a normal ImageView, however if the focalPointEnforcer of this view is set, then it will call this enforcer to update the image matrix any time the size is changed. So this commit changes all media previews in the item_status.xml and item_status_detailled.xml layout files to the new MediaPreviewImageView class. Additionally in the code for loading the images into the previews a new case is added which tests if there is a focus attribute in the meta-data. If so it makes sure to create and set the FocalPointEnforcer. * Fix typos in documentation comment "to" -> "too" * Use static imports to remove clutter in FocalPointEnforcerTest Instead of duplication Assert. in front of every assertEquals, simply statically import it. * Move the MetaData and Focus classes into the Attachment class Since they are very strongly linked to the attachment class and are themselves very small. * Refactor the focal point handling code - All the code modifying the actual members of the MediaPreviewImageView is now in this class itself. This class still uses the FocalPointUtil to calculate the new Matrix, but it now handles setting this new Matrix itself. - The FocalPointEnforcer has been renamed to the FocalPointUtil to reflect that it only calculates the correct matrix, but doesn't set anything on the MediaPreviewImageView. - The Matrix used to control the cropping of the MediaPreviewImageViews is now only allocated a single time per view instead of each time the view is resized. This is done by caching the Matrix and passing it to the FocalPointUtil to update on each resize. * Only reallocate focalMatrix if it is not yet initialized This helps prevent unnecessary allocations in the case where setFocalPoint is called multiple times. * Change checking of availability of objects to use != null As pointed out, the 'is' keyword is meant for checking types, not for checking non-nullness. * Make updateFocalPointMatrix() return nothing This makes it clearer that it actually mutates the matrix it is given. * Fix bug with transitions crashing the PhotoView Due to the android transitions for some reason copying the scaletype from the MediaPreviewImageView to the PhotoView during the transition, the PhotoView would crash on pictures with a focal point, since PhotoView doesn't support ScaleType.MATRIX. This is solved by the workaround of overriding both the getScaleType and setScaleType methods to ensure that we use the MATRIX type in the preview and the center_crop type in the PhotoView. Additionally this commit also makes sure to remove the focal point when the MediaPreviewImageView is recycled. * Fix bug in overriden getScaleType Instead of simply returning the scaleType we need to return the super.getScaleType() method, to avoid crashing. * Merge changes from master Mainly the migration to androidx.
2018-12-28 16:32:07 +01:00
imageMatrix = focalMatrix
}
}
}