Skip to content

Commit

Permalink
Squashed 'libs/utils/' changes from 5b22440..4520f51
Browse files Browse the repository at this point in the history
4520f51 build.gradle fix to push the pom/aar to maven central
c977755 update gradle wrapper to version 2.2
e0d1927 add central maven config
94d1dbb Merge branch 'release/3.7' into develop
8ff9413 fix AppLogViewerActivity when a log is message is null
7c208db Merge pull request #2264 from wordpress-mobile/issue/2222-theme-preview-title
9eb7273 new BlogUtils.getHostNameFromAccountMap function
a80859d Theme live preview no longer changes the activity title
6186933 Photo viewer now uses low quality for the lo-res image
2eb9839 Simplified comments
bfa7ecb Switched to quality enum which defaults to medium
a2ce056 Added default quality param to photon
5a48a06 html encode log entries in AppLog.toHtml()
c8a4d89 fix #103: retain menu drawer scroll position after switching activities
c1e0778 Merge branch 'develop' into issue/985-make-sfactory-private
fe1d125 fix build files for android studio 1.0
f7a2d48 Merge remote-tracking branch 'origin/develop' into issue/985-make-sfactory-private
72fe2b7 update support lib version for travis
0b03b71 Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into feature/material-appcompat
0f5751d Merge branch 'develop' into release/3.4
b68f755 remove unused code (refresh button)
cb8321b fix #985: maks sFactory private - force injection in test module
faae1d3 Merge branch 'release/3.4' into issue/1982-simperium-concurrency Conflicts: 	WordPress/src/main/java/org/wordpress/android/models/Note.java
a0982d1 Updated build.gradle to specify com.android.support:appcompat-v7:21.0.2
3a0c45e Removed unsuccessful fix for #1982.
b967d59 first step at replacing PreferenceActivity by a PreferenceFragment + ActionBarActivity
92d4e15 Merge branch 'develop' into feature/material-appcompat
7c8d5ab Merge branch 'release/3.4' into develop
1e499a6 Merge branch 'hotfix/3.3.1' into release/3.4
7a4a364 Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into feature/material-appcompat
5451df7 update subtrees to use build tools 21.1.1
4024637 rename PullToRefresh to SwipeToRefresh
0d8d414 remove unused viewClass in PTR constructor
2424201 fix circle spinner color style
d392885 Return a copy of the JSONObject in getDiffableValue().
106affa replace Chris Banes' PullToRefresh by the native SwipeToRefresh view
3108a36 Merge remote-tracking branch 'origin/develop' into feature/1961-add-mentions-to-commenting
db25827 Merge branch 'develop' into issue/1958-round-avatars
2801610 Merge remote-tracking branch 'origin/develop' into feature/1961-add-mentions-to-commenting
6ac0248 Merge branch 'hotfix/3.3.1' into release/3.4
eb70e6f upgrade to android-gradle 0.14.0
9bc4ba6 Rounds all WPNetworkImageViews with `AVATAR` type.
c2fd6c7 Initial commit adding mentions to notification comments
0a3da42 Added image spans directly instead of using Html.fromHtml().

git-subtree-dir: libs/utils
git-subtree-split: 4520f51
  • Loading branch information
maxme committed Feb 6, 2015
1 parent 78d3966 commit 1824f63
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 347 deletions.
69 changes: 52 additions & 17 deletions WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,54 +1,89 @@

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:1.0.0'
}
}

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'

repositories {
mavenCentral()
maven { url 'http://wordpress-mobile.github.io/WordPress-Android' }
}

dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.github.castorflex.smoothprogressbar:library:0.4.0'
compile 'org.wordpress:pulltorefresh-main:0.9.7@aar' // org.wordpress version includes some fixes
compile 'com.android.support:support-v13:19.1.0'
compile 'com.mcxiaoke.volley:library:1.0.10'
compile 'com.android.support:support-v13:21.0.3'
}

android {
publishNonDefault true

compileSdkVersion 19
buildToolsVersion "19.1.0"
buildToolsVersion "21.1.1"

defaultConfig {
applicationId "org.wordpress.android.util"
versionName "1.2.0"
versionName "1.3.0"
minSdkVersion 14
targetSdkVersion 19
}
}

version android.defaultConfig.versionName
group = "org.wordpress"
archivesBaseName = "utils"

signing {
required {
has("release") && project.properties.containsKey("signing.keyId") && project.properties.containsKey("signing.secretKeyRingFile")
}
sign configurations.archives
}

uploadArchives {
repositories {
mavenDeployer {
def repo_url = ""
if (project.hasProperty("repository")) {
repo_url = project.repository
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: project.properties.ossrhUsername, password: project.properties.ossrhPassword)
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: project.properties.ossrhUsername, password: project.properties.ossrhPassword)
}

pom.project {
name 'WordPress-Utils-Android'
packaging 'aar'
description 'Utils lib for WordPress-Android'
url 'https://github.com/wordpress-mobile/WordPress-Utils-Android'
scm {
connection 'scm:git:https://github.com/wordpress-mobile/WordPress-Utils-Android.git'
developerConnection 'scm:git:https://github.com/wordpress-mobile/WordPress-Utils-Android.git'
url 'https://github.com/wordpress-mobile/WordPress-Utils-Android'
}

licenses {
license {
name 'The MIT License (MIT)'
url 'http://opensource.org/licenses/MIT'
}
}

developers {
developer {
id 'maxme'
name 'Maxime Biais'
email 'maxime@automattic.com'
}
}
}
repository(url: repo_url)
pom.version = android.defaultConfig.versionName
pom.groupId = "org.wordpress"
pom.artifactId = "wordpress-utils"
}
}
}
7 changes: 6 additions & 1 deletion WordPressUtils/gradle.properties-example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
repository=file:///Users/max/work/automattic/WordPress-Android-gh-pages/
ossrhUsername=hello
ossrhPassword=world

signing.keyId=byebye
signing.password=secret
signing.secretKeyRingFile=/home/user/secret.gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.wordpress.android.util;

import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;

public class ActivityUtils {
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getCurrentFocus() != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class AppLog {
// T for Tag
public enum T {READER, EDITOR, MEDIA, NUX, API, STATS, UTILS, NOTIFS, DB, POSTS, COMMENTS, THEMES, TESTS, PROFILING, SIMPERIUM}
public enum T {READER, EDITOR, MEDIA, NUX, API, STATS, UTILS, NOTIFS, DB, POSTS, COMMENTS, THEMES, TESTS, PROFILING, SIMPERIUM, SUGGESTION}
public static final String TAG = "WordPress";
public static final int HEADER_LINE_COUNT = 2;

Expand All @@ -33,40 +33,46 @@ public static void enableRecording(boolean enable) {
}

public static void v(T tag, String message) {
message = StringUtils.notNullStr(message);
Log.v(TAG + "-" + tag.toString(), message);
addEntry(tag, LogLevel.v, message);
}

public static void d(T tag, String message) {
message = StringUtils.notNullStr(message);
Log.d(TAG + "-" + tag.toString(), message);
addEntry(tag, LogLevel.d, message);
}

public static void i(T tag, String message) {
message = StringUtils.notNullStr(message);
Log.i(TAG + "-" + tag.toString(), message);
addEntry(tag, LogLevel.i, message);
}

public static void w(T tag, String message) {
message = StringUtils.notNullStr(message);
Log.w(TAG + "-" + tag.toString(), message);
addEntry(tag, LogLevel.w, message);
}

public static void e(T tag, String message) {
message = StringUtils.notNullStr(message);
Log.e(TAG + "-" + tag.toString(), message);
addEntry(tag, LogLevel.e, message);
}

public static void e(T tag, String message, Throwable tr) {
message = StringUtils.notNullStr(message);
Log.e(TAG + "-" + tag.toString(), message, tr);
addEntry(tag, LogLevel.e, message + " - exception: " + tr.getMessage());
addEntry(tag, LogLevel.e, "StackTrace: " + getHTMLStringStackTrace(tr));
addEntry(tag, LogLevel.e, "StackTrace: " + getStringStackTrace(tr));
}

public static void e(T tag, Throwable tr) {
Log.e(TAG + "-" + tag.toString(), tr.getMessage(), tr);
addEntry(tag, LogLevel.e, tr.getMessage());
addEntry(tag, LogLevel.e, "StackTrace: " + getHTMLStringStackTrace(tr));
addEntry(tag, LogLevel.e, "StackTrace: " + getStringStackTrace(tr));
}

public static void e(T tag, String volleyErrorMsg, int statusCode) {
Expand Down Expand Up @@ -113,15 +119,15 @@ private static class LogEntry {

private String toHtml() {
StringBuilder sb = new StringBuilder()
.append("<font color='")
.append("<font color=\"")
.append(logLevel.toHtmlColor())
.append("'>")
.append("\">")
.append("[")
.append(logTag.name())
.append("] ")
.append(logLevel.name())
.append(": ")
.append(logText)
.append(TextUtils.htmlEncode(logText).replace("\n", "<br />"))
.append("</font>");
return sb.toString();
}
Expand Down Expand Up @@ -164,9 +170,6 @@ private static String getStringStackTrace(Throwable throwable) {
return errors.toString();
}

private static String getHTMLStringStackTrace(Throwable throwable) {
return getStringStackTrace(throwable).replace("\n", "<br/>");
}

/*
* returns entire log as html for display (see AppLogViewerActivity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,25 @@ public int compare(Object blog1, Object blog2) {
/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
*/
public static String getBlogNameFromAccountMap(Map<String, Object> account) {
String blogName = StringUtils.unescapeHTML(MapUtils.getMapStr(account, "blogName"));
public static String getBlogNameOrHostNameFromAccountMap(Map<String, Object> account) {
String blogName = getBlogNameFromAccountMap(account);
if (blogName.trim().length() == 0) {
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}
return blogName;
}
}

/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
*/
public static String getBlogNameFromAccountMap(Map<String, Object> account) {
return StringUtils.unescapeHTML(MapUtils.getMapStr(account, "blogName"));
}

/**
* Return blog url (host part only) if trimmed name is an empty string
*/
public static String getHostNameFromAccountMap(Map<String, Object> account) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,6 @@ public static Bitmap getCircularBitmap(final Bitmap bitmap) {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);

// outline
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(1f);
paint.setColor(Color.DKGRAY);
canvas.drawOval(rectF, paint);

return output;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.wordpress.android.util.AppLog.T;

import java.util.ArrayList;
import java.util.Iterator;

public class JSONUtil {
private static String QUERY_SEPERATOR=".";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.wordpress.android.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.ListView;

Expand Down Expand Up @@ -33,4 +37,22 @@ public void restoreScrollOffset() {
mListView.setItemChecked(mSelectedPosition, true);
}
}

public void saveToPreferences(Context context, String uniqueId) {
saveScrollOffset();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = settings.edit();
editor.putInt("scroll-position-manager-index-" + uniqueId, mListViewScrollStateIndex);
editor.putInt("scroll-position-manager-offset-" + uniqueId, mListViewScrollStateOffset);
editor.putInt("scroll-position-manager-selected-position-" + uniqueId, mSelectedPosition);
editor.apply();
}

public void restoreFromPreferences(Context context, String uniqueId) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
mListViewScrollStateIndex = settings.getInt("scroll-position-manager-index-" + uniqueId, 0);
mListViewScrollStateOffset = settings.getInt("scroll-position-manager-offset-" + uniqueId, 0);
mSelectedPosition = settings.getInt("scroll-position-manager-selected-position-" + uniqueId, 0);
restoreScrollOffset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public static String fixAvatar(final String imageUrl, int avatarSz) {
return "";

// if this isn't a gravatar image, return as resized photon image url
if (!imageUrl.contains("gravatar.com"))
if (!imageUrl.contains("gravatar.com")) {
return getPhotonImageUrl(imageUrl, avatarSz, avatarSz);
}

// remove all other params, then add query string for size and "mystery man" default
return UrlUtils.removeQuery(imageUrl) + "?s=" + avatarSz + "&d=mm";
Expand All @@ -35,9 +36,18 @@ public static boolean isMshotsUrl(final String imageUrl) {
}

/*
* returns a photon url for the passed image with the resize query set to the passed dimensions
* returns a photon url for the passed image with the resize query set to the passed
* dimensions - note that the passed quality parameter will only affect JPEGs
*/
public static enum Quality {
HIGH,
MEDIUM,
LOW
}
public static String getPhotonImageUrl(String imageUrl, int width, int height) {
return getPhotonImageUrl(imageUrl, width, height, Quality.MEDIUM);
}
public static String getPhotonImageUrl(String imageUrl, int width, int height, Quality quality) {
if (TextUtils.isEmpty(imageUrl)) {
return "";
}
Expand All @@ -54,30 +64,39 @@ public static String getPhotonImageUrl(String imageUrl, int width, int height) {
// don't use with GIFs - photon breaks animated GIFs, and sometimes returns a GIF that
// can't be read by BitmapFactory.decodeByteArray (used by Volley in ImageRequest.java
// to decode the downloaded image)
// ex: http://i0.wp.com/lusianne.files.wordpress.com/2013/08/193.gif?resize=768,320
if (imageUrl.endsWith(".gif")) {
return imageUrl;
}

// if this is an "mshots" url, skip photon and return it with a query that sets the width/height
// (these are screenshots of the blog that often appear in freshly pressed posts)
// see http://wp.tutsplus.com/tutorials/how-to-generate-website-screenshots-for-your-wordpress-site/
// ex: http://s.wordpress.com/mshots/v1/http%3A%2F%2Fnickbradbury.com?w=600
if (isMshotsUrl(imageUrl)) {
return imageUrl + "?w=" + width + "&h=" + height;
}

final String qualityParam;
switch (quality) {
case HIGH:
qualityParam = "quality=100";
break;
case LOW:
qualityParam = "quality=35";
break;
default: // medium
qualityParam = "quality=65";
break;
}

// if both width & height are passed use the "resize" param, use only "w" or "h" if just
// one of them is set, otherwise no query string
// one of them is set
final String query;
if (width > 0 && height > 0) {
query = "?resize=" + width + "," + height;
query = "?resize=" + width + "," + height + "&" + qualityParam;
} else if (width > 0) {
query = "?w=" + width;
query = "?w=" + width + "&" + qualityParam;
} else if (height > 0) {
query = "?h=" + height;
query = "?h=" + height + "&" + qualityParam;
} else {
query = "";
query = "?" + qualityParam;
}

// return passed url+query if it's already a photon url
Expand Down
Loading

0 comments on commit 1824f63

Please sign in to comment.