mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Panorama (#4467)
* panoramic images fixed * made requested changes * Minor refactoring Co-authored-by: Aditya Srivastava <iamaditya2009@gmail.com>
This commit is contained in:
parent
810c797be2
commit
c8a31a32ea
1 changed files with 45 additions and 0 deletions
|
|
@ -29,6 +29,16 @@ public class ImageInfo implements Serializable {
|
||||||
@Nullable private String user;
|
@Nullable private String user;
|
||||||
@Nullable private String timestamp;
|
@Nullable private String timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query width, default width parameter of the API query in pixels.
|
||||||
|
*/
|
||||||
|
final private static int QUERY_WIDTH = 640;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Threshold height, the minimum height of the image in pixels.
|
||||||
|
*/
|
||||||
|
final private static int THRESHOLD_HEIGHT = 220;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getSource() {
|
public String getSource() {
|
||||||
return StringUtils.defaultString(source);
|
return StringUtils.defaultString(source);
|
||||||
|
|
@ -50,11 +60,24 @@ public class ImageInfo implements Serializable {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the thumbnail width.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getThumbWidth() { return thumbWidth; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the thumbnail height.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getThumbHeight() { return thumbHeight; }
|
||||||
|
|
||||||
@NonNull public String getMimeType() {
|
@NonNull public String getMimeType() {
|
||||||
return StringUtils.defaultString(mimeType, "*/*");
|
return StringUtils.defaultString(mimeType, "*/*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull public String getThumbUrl() {
|
@NonNull public String getThumbUrl() {
|
||||||
|
updateThumbUrl();
|
||||||
return StringUtils.defaultString(thumbUrl);
|
return StringUtils.defaultString(thumbUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,4 +96,26 @@ public class ImageInfo implements Serializable {
|
||||||
@Nullable public ExtMetadata getMetadata() {
|
@Nullable public ExtMetadata getMetadata() {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the ThumbUrl if image dimensions are not sufficient.
|
||||||
|
* Specifically, in panoramic images the height retrieved is less than required due to large width to height ratio,
|
||||||
|
* so we update the thumb url keeping a minimum height threshold.
|
||||||
|
*/
|
||||||
|
private void updateThumbUrl() {
|
||||||
|
// If thumbHeight retrieved from API is less than THRESHOLD_HEIGHT
|
||||||
|
if(getThumbHeight() < THRESHOLD_HEIGHT){
|
||||||
|
// If thumbWidthRetrieved is same as queried width ( If not tells us that the image has no larger dimensions. )
|
||||||
|
if(getThumbWidth() == QUERY_WIDTH){
|
||||||
|
// Calculate new width depending on the aspect ratio.
|
||||||
|
final int finalWidth = (int)(THRESHOLD_HEIGHT * getThumbWidth() * 1.0 / getThumbHeight());
|
||||||
|
thumbHeight = THRESHOLD_HEIGHT;
|
||||||
|
thumbWidth = finalWidth;
|
||||||
|
final String toReplace = "/" + QUERY_WIDTH + "px";
|
||||||
|
final int position = thumbUrl.lastIndexOf(toReplace);
|
||||||
|
thumbUrl = (new StringBuilder(thumbUrl)).replace(position, position + toReplace.length(), "/" + thumbWidth + "px").toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue