Skip to content

Commit 4d1d85e

Browse files
committed
Merge commit '7c21964c64da28781fbb63fa9ea22509d320bb0f' into develop
2 parents 5de9f05 + 7c21964 commit 4d1d85e

File tree

4 files changed

+134
-53
lines changed

4 files changed

+134
-53
lines changed

WordPressUtils/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,17 @@ uploadArchives {
9191
}
9292
}
9393
}
94+
95+
android.libraryVariants.all { variant ->
96+
97+
task("generate${variant.name}Javadoc", type: Javadoc) {
98+
description "Generates Javadoc for $variant.name."
99+
source = variant.javaCompile.source
100+
classpath = files(variant.javaCompile.classpath.files, android.getBootClasspath())
101+
102+
options {
103+
links "http://docs.oracle.com/javase/7/docs/api/"
104+
}
105+
exclude '**/R.java'
106+
}
107+
}

WordPressUtils/src/main/java/org/wordpress/android/util/AlertUtils.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class AlertUtils {
3030
*/
3131
public static void showAlert(Context context, int titleId, int messageId) {
3232
Dialog dlg = new AlertDialog.Builder(context)
33-
.setTitle(titleId)
34-
.setPositiveButton(android.R.string.ok, null)
35-
.setMessage(messageId)
36-
.create();
33+
.setTitle(titleId)
34+
.setPositiveButton(android.R.string.ok, null)
35+
.setMessage(messageId)
36+
.create();
3737

3838
dlg.show();
3939
}
@@ -42,14 +42,14 @@ public static void showAlert(Context context, int titleId, int messageId) {
4242
* Show Alert Dialog
4343
* @param context
4444
* @param titleId
45-
* @param messageId
45+
* @param message
4646
*/
4747
public static void showAlert(Context context, int titleId, String message) {
4848
Dialog dlg = new AlertDialog.Builder(context)
49-
.setTitle(titleId)
50-
.setPositiveButton(android.R.string.ok, null)
51-
.setMessage(message)
52-
.create();
49+
.setTitle(titleId)
50+
.setPositiveButton(android.R.string.ok, null)
51+
.setMessage(message)
52+
.create();
5353

5454
dlg.show();
5555
}
@@ -65,15 +65,15 @@ public static void showAlert(Context context, int titleId, String message) {
6565
* @param negativeListener
6666
*/
6767
public static void showAlert(Context context, int titleId, int messageId,
68-
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener,
69-
CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener) {
68+
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener,
69+
CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener) {
7070
Dialog dlg = new AlertDialog.Builder(context)
71-
.setTitle(titleId)
72-
.setPositiveButton(positiveButtontxt, positiveListener)
73-
.setNegativeButton(negativeButtontxt, negativeListener)
74-
.setMessage(messageId)
75-
.setCancelable(false)
76-
.create();
71+
.setTitle(titleId)
72+
.setPositiveButton(positiveButtontxt, positiveListener)
73+
.setNegativeButton(negativeButtontxt, negativeListener)
74+
.setMessage(messageId)
75+
.setCancelable(false)
76+
.create();
7777

7878
dlg.show();
7979
}
@@ -82,20 +82,19 @@ public static void showAlert(Context context, int titleId, int messageId,
8282
* Show Alert Dialog
8383
* @param context
8484
* @param titleId
85-
* @param messageId
85+
* @param message
8686
* @param positiveButtontxt
8787
* @param positiveListener
8888
*/
8989
public static void showAlert(Context context, int titleId, String message,
90-
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener) {
90+
CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener) {
9191
Dialog dlg = new AlertDialog.Builder(context)
92-
.setTitle(titleId)
93-
.setPositiveButton(positiveButtontxt, positiveListener)
94-
.setMessage(message)
95-
.setCancelable(false)
96-
.create();
92+
.setTitle(titleId)
93+
.setPositiveButton(positiveButtontxt, positiveListener)
94+
.setMessage(message)
95+
.setCancelable(false)
96+
.create();
9797

9898
dlg.show();
9999
}
100-
}
101-
100+
}

WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.NoSuchElementException;
1212

1313
/**
14-
* simple wrapper for Android log calls, enables recording & displaying log
14+
* simple wrapper for Android log calls, enables recording and displaying log
1515
*/
1616
public class AppLog {
1717
// T for Tag
@@ -26,56 +26,105 @@ private AppLog() {
2626
throw new AssertionError();
2727
}
2828

29-
/*
30-
* defaults to false, pass true to capture log so it can be displayed by AppLogViewerActivity
29+
/**
30+
* Capture log so it can be displayed by AppLogViewerActivity
31+
* @param enable A boolean flag to capture log. Default is false, pass true to enable recording
3132
*/
3233
public static void enableRecording(boolean enable) {
3334
mEnableRecording = enable;
3435
}
3536

37+
/**
38+
* Sends a VERBOSE log message
39+
* @param tag Used to identify the source of a log message.
40+
* It usually identifies the class or activity where the log call occurs.
41+
* @param message The message you would like logged.
42+
*/
3643
public static void v(T tag, String message) {
3744
message = StringUtils.notNullStr(message);
3845
Log.v(TAG + "-" + tag.toString(), message);
3946
addEntry(tag, LogLevel.v, message);
4047
}
4148

49+
/**
50+
* Sends a DEBUG log message
51+
* @param tag Used to identify the source of a log message.
52+
* It usually identifies the class or activity where the log call occurs.
53+
* @param message The message you would like logged.
54+
*/
4255
public static void d(T tag, String message) {
4356
message = StringUtils.notNullStr(message);
4457
Log.d(TAG + "-" + tag.toString(), message);
4558
addEntry(tag, LogLevel.d, message);
4659
}
4760

61+
/**
62+
* Sends a INFO log message
63+
* @param tag Used to identify the source of a log message.
64+
* It usually identifies the class or activity where the log call occurs.
65+
* @param message The message you would like logged.
66+
*/
4867
public static void i(T tag, String message) {
4968
message = StringUtils.notNullStr(message);
5069
Log.i(TAG + "-" + tag.toString(), message);
5170
addEntry(tag, LogLevel.i, message);
5271
}
5372

73+
/**
74+
* Sends a WARN log message
75+
* @param tag Used to identify the source of a log message.
76+
* It usually identifies the class or activity where the log call occurs.
77+
* @param message The message you would like logged.
78+
*/
5479
public static void w(T tag, String message) {
5580
message = StringUtils.notNullStr(message);
5681
Log.w(TAG + "-" + tag.toString(), message);
5782
addEntry(tag, LogLevel.w, message);
5883
}
5984

85+
/**
86+
* Sends a ERROR log message
87+
* @param tag Used to identify the source of a log message.
88+
* It usually identifies the class or activity where the log call occurs.
89+
* @param message The message you would like logged.
90+
*/
6091
public static void e(T tag, String message) {
6192
message = StringUtils.notNullStr(message);
6293
Log.e(TAG + "-" + tag.toString(), message);
6394
addEntry(tag, LogLevel.e, message);
6495
}
6596

97+
/**
98+
* Send a ERROR log message and log the exception.
99+
* @param tag Used to identify the source of a log message.
100+
* It usually identifies the class or activity where the log call occurs.
101+
* @param message The message you would like logged.
102+
* @param tr An exception to log
103+
*/
66104
public static void e(T tag, String message, Throwable tr) {
67105
message = StringUtils.notNullStr(message);
68106
Log.e(TAG + "-" + tag.toString(), message, tr);
69107
addEntry(tag, LogLevel.e, message + " - exception: " + tr.getMessage());
70108
addEntry(tag, LogLevel.e, "StackTrace: " + getStringStackTrace(tr));
71109
}
72110

111+
/**
112+
* Sends a ERROR log message and the exception with StackTrace
113+
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
114+
* @param tr An exception to log to get StackTrace
115+
*/
73116
public static void e(T tag, Throwable tr) {
74117
Log.e(TAG + "-" + tag.toString(), tr.getMessage(), tr);
75118
addEntry(tag, LogLevel.e, tr.getMessage());
76119
addEntry(tag, LogLevel.e, "StackTrace: " + getStringStackTrace(tr));
77120
}
78121

122+
/**
123+
* Sends a ERROR log message
124+
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
125+
* @param volleyErrorMsg
126+
* @param statusCode
127+
*/
79128
public static void e(T tag, String volleyErrorMsg, int statusCode) {
80129
if (TextUtils.isEmpty(volleyErrorMsg)) {
81130
return;
@@ -178,8 +227,10 @@ private static String getStringStackTrace(Throwable throwable) {
178227
return errors.toString();
179228
}
180229

181-
/*
182-
* returns entire log as html for display (see AppLogViewerActivity)
230+
/**
231+
* Returns entire log as html for display (see AppLogViewerActivity)
232+
* @param context
233+
* @return Arraylist of Strings containing log messages
183234
*/
184235
public static ArrayList<String> toHtmlList(Context context) {
185236
ArrayList<String> items = new ArrayList<String>();
@@ -195,24 +246,26 @@ public static ArrayList<String> toHtmlList(Context context) {
195246
return items;
196247
}
197248

198-
/*
199-
* returns entire log as plain text
249+
/**
250+
* Converts the entire log to plain text
251+
* @param context
252+
* @return The log as plain text
200253
*/
201254
public static String toPlainText(Context context) {
202255
StringBuilder sb = new StringBuilder();
203256

204257
// add version & device info
205258
sb.append("WordPress Android version: " + PackageUtils.getVersionName(context)).append("\n")
206-
.append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");
259+
.append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");
207260

208261
Iterator<LogEntry> it = mLogEntries.iterator();
209262
int lineNum = 1;
210263
while (it.hasNext()) {
211-
sb.append(String.format("%02d - ", lineNum))
212-
.append(it.next().mLogText)
213-
.append("\n");
264+
sb.append(String.format("%02d - ", lineNum))
265+
.append(it.next().mLogText)
266+
.append("\n");
214267
lineNum++;
215268
}
216269
return sb.toString();
217270
}
218-
}
271+
}

WordPressUtils/src/main/java/org/wordpress/android/util/HtmlUtils.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
import org.wordpress.android.util.helpers.WPQuoteSpan;
1616

1717
public class HtmlUtils {
18-
/*
19-
* removes html from the passed string - relies on Html.fromHtml which handles invalid HTML,
18+
19+
/**
20+
* Removes html from the passed string - relies on Html.fromHtml which handles invalid HTML,
2021
* but it's very slow, so avoid using this where performance is important
22+
* @param text String containing html
23+
* @return String without HTML
2124
*/
2225
public static String stripHtml(final String text) {
2326
if (TextUtils.isEmpty(text)) {
@@ -26,9 +29,11 @@ public static String stripHtml(final String text) {
2629
return Html.fromHtml(text).toString().trim();
2730
}
2831

29-
/*
30-
* this is much faster than stripHtml() but should only be used when we know the html is valid
32+
/**
33+
* This is much faster than stripHtml() but should only be used when we know the html is valid
3134
* since the regex will be unpredictable with invalid html
35+
* @param str String containing only valid html
36+
* @return String without HTML
3237
*/
3338
public static String fastStripHtml(String str) {
3439
if (TextUtils.isEmpty(str)) {
@@ -50,7 +55,7 @@ public static String fastStripHtml(String str) {
5055
}
5156

5257
/*
53-
* same as apache.commons.lang.StringUtils.stripStart() but also removes non-breaking
58+
* Same as apache.commons.lang.StringUtils.stripStart() but also removes non-breaking
5459
* space (160) chars
5560
*/
5661
private static String trimStart(final String str) {
@@ -65,8 +70,10 @@ private static String trimStart(final String str) {
6570
return str.substring(start);
6671
}
6772

68-
/*
69-
* convert html entities to actual Unicode characters - relies on commons apache lang
73+
/**
74+
* Convert html entities to actual Unicode characters - relies on commons apache lang
75+
* @param text String to be decoded to Unicode
76+
* @return String containing unicode characters
7077
*/
7178
public static String fastUnescapeHtml(final String text) {
7279
if (text == null || !text.contains("&")) {
@@ -75,8 +82,11 @@ public static String fastUnescapeHtml(final String text) {
7582
return StringEscapeUtils.unescapeHtml(text);
7683
}
7784

78-
/*
79-
* converts an R.color.xxx resource to an HTML hex color
85+
/**
86+
* Converts an R.color.xxx resource to an HTML hex color
87+
* @param context Android Context
88+
* @param resId Android R.color.xxx
89+
* @return A String HTML hex color code
8090
*/
8191
public static String colorResToHtmlColor(Context context, int resId) {
8292
try {
@@ -86,12 +96,14 @@ public static String colorResToHtmlColor(Context context, int resId) {
8696
}
8797
}
8898

89-
/*
90-
* remove <script>..</script> blocks from the passed string - added to project after noticing
99+
/**
100+
* Remove {@code <script>..</script>} blocks from the passed string - added to project after noticing
91101
* comments on posts that use the "Sociable" plugin ( http://wordpress.org/plugins/sociable/ )
92-
* may have a script block which contains <!--//--> followed by a CDATA section followed by <!]]>,
93-
* all of which will show up if we don't strip it here (example: http://cl.ly/image/0J0N3z3h1i04 )
94-
* first seen at http://houseofgeekery.com/2013/11/03/13-terrible-x-men-we-wont-see-in-the-movies/
102+
* may have a script block which contains {@code <!--//-->} followed by a CDATA section followed by {@code <!]]>,}
103+
* all of which will show up if we don't strip it here.
104+
* @see <a href="http://wordpress.org/plugins/sociable/">Wordpress Sociable Plugin</a>
105+
* @return String without {@code <script>..</script>}, {@code <!--//-->} blocks followed by a CDATA section followed by {@code <!]]>,}
106+
* @param text String containing script tags
95107
*/
96108
public static String stripScript(final String text) {
97109
if (text == null) {
@@ -114,7 +126,10 @@ public static String stripScript(final String text) {
114126
}
115127

116128
/**
117-
* an alternative to Html.fromHtml() supporting <ul>, <ol>, <blockquote> tags and replacing EmoticonsUtils with Emojis
129+
* An alternative to Html.fromHtml() supporting {@code <ul>}, {@code <ol>}, {@code <blockquote>}
130+
* tags and replacing EmoticonsUtils with Emojis
131+
* @param source
132+
* @param wpImageGetter
118133
*/
119134
public static SpannableStringBuilder fromHtml(String source, WPImageGetter wpImageGetter) {
120135
SpannableStringBuilder html;

0 commit comments

Comments
 (0)