Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bc27690
Updating ActionBar title. Save button is now Undo.
tonyr59h Jul 14, 2015
24e47d5
Merge branch 'develop' into feature/site-settings-review
tonyr59h Sep 3, 2015
53c3a16
Merge branch 'develop' into feature/site-settings-review
tonyr59h Sep 10, 2015
2411844
Merge branch 'develop' into feature/site-settings-review
tonyr59h Sep 16, 2015
6fcdac2
Merge branch 'develop' into feature/site-settings-review
tonyr59h Sep 22, 2015
c1e2716
Merge branch 'develop' into feature/site-settings-review
tonyr59h Sep 30, 2015
4750b89
Merge branch 'release/4.7' into feature/site-settings-review
tonyr59h Oct 23, 2015
c600314
Merge branch 'develop' into feature/site-settings-review
tonyr59h Nov 10, 2015
0a7732e
Merge branch 'develop' into feature/site-settings-review
tonyr59h Nov 20, 2015
8c562ca
Merge branch 'develop' into feature/site-settings-review
tonyr59h Dec 7, 2015
5d281f1
Merge branch 'develop' into feature/site-settings-review
tonyr59h Dec 14, 2015
920ea46
Merge develop into site-settings-review
tonyr59h Jan 6, 2016
1857d7e
Added ShortcodeUtils with methods for converting VideoPress ids to sh…
aforcier Jan 30, 2016
db6e3fc
Removed unused StringUtils.getLanguageString method
aforcier Jan 30, 2016
28f8cd3
Merge pull request #4 from wordpress-mobile/sync-wpandroid
tonyr59h Jan 30, 2016
c611f1e
1.9.0 version bump
aforcier Jan 30, 2016
75a7f0c
new MediaUtils function: getImageWidthSettingFromString
maxme Jun 2, 2016
df1619f
use MediaUtils.getImageWidthSettingFromString instead of referring to…
maxme Jun 2, 2016
f992286
Merge commit 'c611f1eddb7f8321be051ebb3c117f0f9af77274' into issue/41…
maxme Jun 2, 2016
09adc06
Update to latest utils version
maxme Jun 3, 2016
c925f2d
fix an issue with initial max width value in legacy image settings
maxme Jun 3, 2016
e3c0168
Merge branch 'hotfix/5.4.1' into issue/4147-translated-original-size
maxme Jun 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.android.util.helpers.MediaGalleryImageSpan;
import org.wordpress.android.util.helpers.WPImageSpan;
import org.wordpress.android.widgets.SuggestionAutoCompleteText;
import org.wordpress.android.widgets.WPViewPager;
import org.wordpress.mediapicker.MediaItem;
import org.wordpress.mediapicker.source.MediaSource;
Expand Down Expand Up @@ -1560,7 +1559,7 @@ private boolean addMediaVisualEditor(Uri imageUri) {
}

Blog blog = WordPress.getCurrentBlog();
if (!blog.getMaxImageWidth().equals("Original Size")) {
if (MediaUtils.getImageWidthSettingFromString(blog.getMaxImageWidth()) != Integer.MAX_VALUE) {
// If the user has selected a maximum image width for uploads, rescale the image accordingly
path = ImageUtils.createResizedImageWithMaxWidth(this, path, Integer.parseInt(blog.getMaxImageWidth()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,9 @@ private String uploadImage(MediaFile mediaFile) {
// We won't resize gif images to keep them awesome.
boolean shouldUploadResizedVersion = false;
// If it's not a gif and blog don't keep original size, there is a chance we need to resize
if (!mimeType.equals("image/gif") && !mBlog.getMaxImageWidth().equals("Original Size")) {
//check the picture settings
if (!mimeType.equals("image/gif") && MediaUtils.getImageWidthSettingFromString(mBlog.getMaxImageWidth())
!= Integer.MAX_VALUE) {
// check the picture settings
int pictureSettingWidth = mediaFile.getWidth();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Expand Down Expand Up @@ -696,7 +697,7 @@ private String uploadVideo(MediaFile mediaFile) {
}
} else {
// set the width of the video to the thumbnail width, else 640x480
if (!mBlog.getMaxImageWidth().equals("Original Size")) {
if (MediaUtils.getImageWidthSettingFromString(mBlog.getMaxImageWidth()) != Integer.MAX_VALUE) {
xRes = mBlog.getMaxImageWidth();
yRes = String.valueOf(Math.round(Integer.valueOf(mBlog.getMaxImageWidth()) * 0.75));
} else {
Expand Down
15 changes: 7 additions & 8 deletions WordPress/src/main/java/org/wordpress/android/util/WPHtml.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Locale;

/**
* This class processes HTML strings into displayable styled text. Not all HTML
Expand Down Expand Up @@ -449,22 +450,20 @@ public static String getContent(WPImageSpan imageSpan) {
String localBlogID = imageSpan.getMediaFile().getBlogId();
Blog currentBlog = WordPress.wpDB.instantiateBlogByLocalId(Integer.parseInt(localBlogID));
// If it's not a gif and blog don't keep original size, there is a chance we need to resize
if (currentBlog != null && !mediaFile.getMimeType().equals("image/gif") &&
!currentBlog.getMaxImageWidth().equals("Original Size")) {
int maxImageWidth = Integer.parseInt(currentBlog.getMaxImageWidth());
// use the correct resize settings.
width = Math.min(width, maxImageWidth);
if (currentBlog != null && !mediaFile.getMimeType().equals("image/gif")
&& MediaUtils.getImageWidthSettingFromString(currentBlog.getMaxImageWidth()) != Integer.MAX_VALUE) {
width = MediaUtils.getMaximumImageWidth(width, currentBlog.getMaxImageWidth());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note here, the older code was keeping the 0 for width while the newer code will have width become 1024.

// Use inline CSS on self-hosted blogs to enforce picture resize settings
if (!currentBlog.isDotcomFlag()) {
inlineCSS = String.format(" style=\"width:%dpx;max-width:%dpx;\" ", width, width);
inlineCSS = String.format(Locale.US, " style=\"width:%dpx;max-width:%dpx;\" ", width, width);
}
}

content = content + "<a href=\"" + url + "\"><img" + inlineCSS + "title=\"" + title + "\" "
+ alignmentCSS + "alt=\"image\" src=\"" + url + "?w=" + width +"\" /></a>";

if (!caption.equals("")) {
content = String.format("[caption id=\"\" align=\"%s\" width=\"%d\" caption=\"%s\"]%s[/caption]",
content = String.format(Locale.US,
"[caption id=\"\" align=\"%s\" width=\"%d\" caption=\"%s\"]%s[/caption]",
alignment, width, TextUtils.htmlEncode(caption), content);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/analytics/WordPressAnalytics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
dependencies {
compile 'com.automattic:tracks:1.1.0'
compile 'com.mixpanel.android:mixpanel-android:4.6.4'
compile 'org.wordpress:utils:1.9.0'
compile 'org.wordpress:utils:1.10.0'
}

android {
Expand Down
2 changes: 1 addition & 1 deletion libs/editor/WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'org.wordpress:utils:1.9.0'
compile 'org.wordpress:utils:1.10.0'

// Test libraries
testCompile 'junit:junit:4.11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.MediaUtils;
import org.wordpress.android.util.ToastUtils;

import java.util.Arrays;
Expand All @@ -41,12 +42,9 @@
* when the fragment is dismissed to restore it.
*/
public class ImageSettingsDialogFragment extends DialogFragment {

public static final int IMAGE_SETTINGS_DIALOG_REQUEST_CODE = 5;
public static final String IMAGE_SETTINGS_DIALOG_TAG = "image-settings";

private static final int DEFAULT_MAX_IMAGE_WIDTH = 1024;

private JSONObject mImageMeta;
private int mMaxImageWidth;

Expand Down Expand Up @@ -170,7 +168,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mLinkTo.setText(mImageMeta.getString("linkUrl"));

mMaxImageWidth = getMaximumImageWidth(mImageMeta.getInt("naturalWidth"), bundle.getString("maxWidth"));
mMaxImageWidth = MediaUtils.getMaximumImageWidth(mImageMeta.getInt("naturalWidth"),
bundle.getString("maxWidth"));

setupWidthSeekBar(widthSeekBar, mWidthText, mImageMeta.getInt("width"));

Expand Down Expand Up @@ -396,34 +395,6 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
});
}

/**
* Calculate and return the maximum allowed image width by comparing the width of the image at its full size with
* the maximum upload width set in the blog settings
* @param naturalImageWidth the image's natural (full) width
* @param imageWidthBlogSettingString the maximum upload width set in the blog settings
* @return
*/
public static int getMaximumImageWidth(int naturalImageWidth, String imageWidthBlogSettingString) {
int imageWidthBlogSetting = Integer.MAX_VALUE;

if (!imageWidthBlogSettingString.equals("Original Size")) {
try {
imageWidthBlogSetting = Integer.valueOf(imageWidthBlogSettingString);
} catch (NumberFormatException e) {
AppLog.e(AppLog.T.EDITOR, e);
}
}

int imageWidthPictureSetting = naturalImageWidth == 0 ? Integer.MAX_VALUE : naturalImageWidth;

if (Math.min(imageWidthPictureSetting, imageWidthBlogSetting) == Integer.MAX_VALUE) {
// Default value in case of errors reading the picture size and the blog settings is set to Original size
return DEFAULT_MAX_IMAGE_WIDTH;
} else {
return Math.min(imageWidthPictureSetting, imageWidthBlogSetting);
}
}

/**
* Return the integer value of the width EditText, adjusted to be within the given min and max, and stripped of the
* 'px' units
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import org.wordpress.android.util.helpers.WPUnderlineSpan;
import org.wordpress.android.util.widgets.WPEditText;

import java.util.Locale;

public class LegacyEditorFragment extends EditorFragmentAbstract implements TextWatcher,
WPEditText.OnSelectionChangedListener, View.OnTouchListener {
public static final int ACTIVITY_REQUEST_CODE_CREATE_LINK = 4;
Expand Down Expand Up @@ -483,7 +485,7 @@ private WPEditImageSpan createWPEditImageSpanLocal(Context context, MediaFile me
}
}
WPEditImageSpan imageSpan = new WPEditImageSpan(context, thumbnailBitmap, imageUri);
mediaFile.setWidth(MediaUtils.getMinimumImageWidth(context, imageUri, mBlogSettingMaxImageWidth));
mediaFile.setWidth(MediaUtils.getMaximumImageWidth(context, imageUri, mBlogSettingMaxImageWidth));
imageSpan.setMediaFile(mediaFile);
return imageSpan;
}
Expand Down Expand Up @@ -742,7 +744,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
alignmentSpinner.setAdapter(adapter);

imageWidthText.setText(String.valueOf(mediaFile.getWidth()) + "px");
seekBar.setProgress(mediaFile.getWidth());
titleText.setText(mediaFile.getTitle());
caption.setText(mediaFile.getCaption());
Expand All @@ -758,9 +759,10 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

alignmentSpinner.setSelection(mediaFile.getHorizontalAlignment(), true);

final int maxWidth = MediaUtils.getMinimumImageWidth(getActivity(),
final int maxWidth = MediaUtils.getMaximumImageWidth(getActivity(),
imageSpan.getImageSource(), mBlogSettingMaxImageWidth);
seekBar.setMax(maxWidth / 10);
imageWidthText.setText(String.format(Locale.US, "%dpx", maxWidth));
if (mediaFile.getWidth() != 0) {
seekBar.setProgress(mediaFile.getWidth() / 10);
}
Expand All @@ -778,7 +780,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress == 0) {
progress = 1;
}
imageWidthText.setText(progress * 10 + "px");
imageWidthText.setText(String.format(Locale.US, "%dpx", progress * 10));
}
});

Expand Down
2 changes: 1 addition & 1 deletion libs/networking/WordPressNetworking/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
}

dependencies {
compile 'org.wordpress:utils:1.9.0'
compile 'org.wordpress:utils:1.10.0'
compile 'com.automattic:rest:1.0.3'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.TimeZone;

public class MediaUtils {
private static final int DEFAULT_MAX_IMAGE_WIDTH = 1024;

public static boolean isValidImage(String url) {
if (url == null) {
return false;
Expand Down Expand Up @@ -114,29 +116,52 @@ public static Uri getLastRecordedVideoUri(Activity activity) {
return Uri.parse(contentUri.toString() + "/" + cursor.getLong(0));
}

// Calculate the minimun width between the blog setting and picture real width
public static int getMinimumImageWidth(Context context, Uri curStream, String imageWidthBlogSettingString) {
int imageWidthBlogSetting = Integer.MAX_VALUE;

if (!imageWidthBlogSettingString.equals("Original Size")) {
try {
imageWidthBlogSetting = Integer.valueOf(imageWidthBlogSettingString);
} catch (NumberFormatException e) {
AppLog.e(T.POSTS, e);
}
/**
* Get image width setting from the image width site setting string. This string can be an int, in this case it's
* the maximum image width defined by the site.
* Examples:
* "1000" will return 1000
* "Original Size" will return Integer.MAX_VALUE
* "Largeur originale" will return Integer.MAX_VALUE
* null will return Integer.MAX_VALUE
* @param imageWidthSiteSettingString Image width site setting string
* @return Integer.MAX_VALUE if image width is not defined or invalid, maximum image width in other cases.
*/
public static int getImageWidthSettingFromString(String imageWidthSiteSettingString) {
if (imageWidthSiteSettingString == null) {
return Integer.MAX_VALUE;
}
try {
return Integer.valueOf(imageWidthSiteSettingString);
} catch (NumberFormatException e) {
return Integer.MAX_VALUE;
}
}

int[] dimensions = ImageUtils.getImageSize(curStream, context);
int imageWidthPictureSetting = dimensions[0] == 0 ? Integer.MAX_VALUE : dimensions[0];
/**
* Calculate and return the maximum allowed image width by comparing the width of the image at its full size with
* the maximum upload width set in the blog settings
* @param imageWidth the image's natural (full) width
* @param imageWidthSiteSettingString the maximum upload width set in the site settings
* @return maximum allowed image width
*/
public static int getMaximumImageWidth(int imageWidth, String imageWidthSiteSettingString) {
int imageWidthBlogSetting = getImageWidthSettingFromString(imageWidthSiteSettingString);
int imageWidthPictureSetting = imageWidth == 0 ? Integer.MAX_VALUE : imageWidth;

if (Math.min(imageWidthPictureSetting, imageWidthBlogSetting) == Integer.MAX_VALUE) {
// Default value in case of errors reading the picture size and the blog settings is set to Original size
return 1024;
// Default value in case of errors reading the picture size or the blog settings is set to Original size
return DEFAULT_MAX_IMAGE_WIDTH;
} else {
return Math.min(imageWidthPictureSetting, imageWidthBlogSetting);
}
}

public static int getMaximumImageWidth(Context context, Uri curStream, String imageWidthBlogSettingString) {
int[] dimensions = ImageUtils.getImageSize(curStream, context);
return getMaximumImageWidth(dimensions[0], imageWidthBlogSettingString);
}

public static boolean isInMediaStore(Uri mediaUri) {
// Check if the image is externally hosted (Picasa/Google Photos for example)
if (mediaUri != null && mediaUri.toString().startsWith("content://media/")) {
Expand Down