Skip to content

Commit

Permalink
move WPEditText to WordPressUtils and reorganize WordPressUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Feb 9, 2015
1 parent 9fc7eee commit ac92a69
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.content.Context;
import android.content.DialogInterface;

public class AlertUtil {
public class AlertUtils {
/**
* Show Alert Dialog
* @param context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES;

public class Emoticons {
public class EmoticonsUtils {
public static final int EMOTICON_COLOR = 0xFF21759B;
private static final boolean HAS_EMOJI = SDK_INT >= VERSION_CODES.JELLY_BEAN;
private static final Map<String, String> wpSmilies;
Expand Down Expand Up @@ -82,7 +82,7 @@ public static String lookupImageSmiley(String url, String ifNone){
public static Spanned replaceEmoticonsWithEmoji(SpannableStringBuilder html){
ImageSpan imgs[] = html.getSpans(0, html.length(), ImageSpan.class);
for (ImageSpan img : imgs) {
String emoticon = Emoticons.lookupImageSmiley(img.getSource());
String emoticon = EmoticonsUtils.lookupImageSmiley(img.getSource());
if (!emoticon.equals("")) {
int start = html.getSpanStart(img);
html.replace(start, html.getSpanEnd(img), emoticon);
Expand All @@ -103,4 +103,4 @@ public static String replaceEmoticonsWithEmoji(final String text) {
return text;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import android.text.style.QuoteSpan;

import org.apache.commons.lang.StringEscapeUtils;
import org.wordpress.android.util.helpers.WPHtmlTagHandler;
import org.wordpress.android.util.helpers.WPImageGetter;
import org.wordpress.android.util.helpers.WPQuoteSpan;

public class HtmlUtils {
/*
Expand Down Expand Up @@ -111,7 +114,7 @@ public static String stripScript(final String text) {
}

/**
* an alternative to Html.fromHtml() supporting <ul>, <ol>, <blockquote> tags and replacing Emoticons with Emojis
* an alternative to Html.fromHtml() supporting <ul>, <ol>, <blockquote> tags and replacing EmoticonsUtils with Emojis
*/
public static SpannableStringBuilder fromHtml(String source, WPImageGetter wpImageGetter) {
SpannableStringBuilder html;
Expand All @@ -121,7 +124,7 @@ public static SpannableStringBuilder fromHtml(String source, WPImageGetter wpIma
// In case our tag handler fails
html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, null);
}
Emoticons.replaceEmoticonsWithEmoji(html);
EmoticonsUtils.replaceEmoticonsWithEmoji(html);
QuoteSpan spans[] = html.getSpans(0, html.length(), QuoteSpan.class);
for (QuoteSpan span : spans) {
html.setSpan(new WPQuoteSpan(), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(span));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.ArrayList;
import java.util.Iterator;

public class JSONUtil {
public class JSONUtils {
private static String QUERY_SEPERATOR=".";
private static String QUERY_ARRAY_INDEX_START="[";
private static String QUERY_ARRAY_INDEX_END="]";
Expand All @@ -19,7 +19,7 @@ public class JSONUtil {

private static final String JSON_NULL_STR = "null";

private static final String TAG="JSONUtil";
private static final String TAG="JSONUtils";
/**
* Given a JSONObject and a key path (e.g property.child) and a default it will
* traverse the object graph and pull out the desired property
Expand Down Expand Up @@ -232,4 +232,4 @@ public static JSONObject getJSONChild(final JSONObject jsonParent, final String
}
return jsonChild;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public static String replaceUnicodeSurrogateBlocksWithHTMLEntities(final String
final int codepoint = inputString.codePointAt(offset);
final char current = inputString.charAt(offset);
if (Character.isHighSurrogate(current) || Character.isLowSurrogate(current)) {
if (Emoticons.wpSmiliesCodePointToText.get(codepoint) != null) {
out.append(Emoticons.wpSmiliesCodePointToText.get(codepoint));
if (EmoticonsUtils.wpSmiliesCodePointToText.get(codepoint) != null) {
out.append(EmoticonsUtils.wpSmiliesCodePointToText.get(codepoint));
} else {
final String htmlEscapedChar = "&#x" + Integer.toHexString(codepoint) + ";";
out.append(htmlEscapedChar);
Expand Down Expand Up @@ -275,4 +275,4 @@ public static int stringToInt(String s, int defaultValue) {
return defaultValue;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.regex.Pattern;

public class UserEmail {
public class UserEmailUtils {
/**
* Get primary account and return its name if it matches the email address pattern.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

import android.content.Context;
import android.content.SharedPreferences;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//This Handy-Dandy class acquired and tweaked from http://stackoverflow.com/a/3145655/309558
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

import java.util.Timer;
import java.util.TimerTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util.ptr;
package org.wordpress.android.util.helpers;

import android.app.Activity;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

//See: http://stackoverflow.com/a/11024200
public class Version implements Comparable<Version> {
Expand Down Expand Up @@ -44,4 +44,4 @@ public Version(String version) {
return false;
return this.compareTo((Version) that) == 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

import android.text.Editable;
import android.text.Html;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
Expand All @@ -10,7 +10,9 @@
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;

import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.PhotonUtils;

import java.lang.ref.WeakReference;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

import android.graphics.Canvas;
import android.graphics.Paint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.helpers;

import android.app.Activity;
import android.view.View;
Expand Down Expand Up @@ -38,4 +38,4 @@ public void onProgressChanged(WebView webView, int progress) {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.util;
package org.wordpress.android.util.widgets;

import android.content.Context;
import android.text.Layout;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.wordpress.android.util.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;

public class WPEditText extends EditText {
private EditTextImeBackListener mOnImeBack;
private OnSelectionChangedListener onSelectionChangedListener;

public WPEditText(Context context) {
super(context);
}

public WPEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}

public WPEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (onSelectionChangedListener != null) {
onSelectionChangedListener.onSelectionChanged();
}
}

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
&& event.getAction() == KeyEvent.ACTION_UP) {
if (mOnImeBack != null)
mOnImeBack.onImeBack(this, this.getText().toString());
}

return super.onKeyPreIme(keyCode, event);
}

public void setOnEditTextImeBackListener(EditTextImeBackListener listener) {
mOnImeBack = listener;
}

public interface EditTextImeBackListener {
public abstract void onImeBack(WPEditText ctrl, String text);
}

public void setOnSelectionChangedListener(OnSelectionChangedListener listener) {
onSelectionChangedListener = listener;
}

public interface OnSelectionChangedListener {
public abstract void onSelectionChanged();
}
}

0 comments on commit ac92a69

Please sign in to comment.