From 11d50c3c69ec3c7f2c49e742f18af03a45eaa067 Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 15 Oct 2015 20:10:02 +0800 Subject: [PATCH] Support huaji --- .../com/hippo/nimingban/NMBApplication.java | 4 ++ .../nimingban/client/ac/data/ACFeed.java | 2 +- .../nimingban/client/ac/data/ACPost.java | 6 ++- .../hippo/nimingban/util/ResImageGetter.java | 49 ++++++++++++++++++ app/src/main/java/com/hippo/text/Html.java | 21 ++++++-- .../main/res/drawable-hdpi/emoji_huaji.png | Bin 0 -> 898 bytes .../main/res/drawable-xhdpi/emoji_huaji.png | Bin 0 -> 1037 bytes .../main/res/drawable-xxhdpi/emoji_huaji.png | Bin 0 -> 1553 bytes yorozuya | 2 +- 9 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/hippo/nimingban/util/ResImageGetter.java create mode 100644 app/src/main/res/drawable-hdpi/emoji_huaji.png create mode 100644 app/src/main/res/drawable-xhdpi/emoji_huaji.png create mode 100644 app/src/main/res/drawable-xxhdpi/emoji_huaji.png diff --git a/app/src/main/java/com/hippo/nimingban/NMBApplication.java b/app/src/main/java/com/hippo/nimingban/NMBApplication.java index 8ee5b063..bc146896 100644 --- a/app/src/main/java/com/hippo/nimingban/NMBApplication.java +++ b/app/src/main/java/com/hippo/nimingban/NMBApplication.java @@ -33,11 +33,13 @@ import com.hippo.nimingban.util.Crash; import com.hippo.nimingban.util.DB; import com.hippo.nimingban.util.ReadableTime; +import com.hippo.nimingban.util.ResImageGetter; import com.hippo.nimingban.util.Settings; import com.hippo.nimingban.widget.SimpleDrawableHelper; import com.hippo.okhttp.GoodHttpClient; import com.hippo.okhttp.GoodRequestBuilder; import com.hippo.okhttp.ResponseUtils; +import com.hippo.text.Html; import com.hippo.util.NetworkUtils; import com.hippo.yorozuya.FileUtils; import com.hippo.yorozuya.Messenger; @@ -85,6 +87,8 @@ public void onCreate() { GoodRequestBuilder.initialize(this); ResponseUtils.initialize(this); BitmapUtils.initialize(this); + Html.initialize(this); + ResImageGetter.initialize(this); LeakCanary.install(this); diff --git a/app/src/main/java/com/hippo/nimingban/client/ac/data/ACFeed.java b/app/src/main/java/com/hippo/nimingban/client/ac/data/ACFeed.java index f4f0e3dd..98fadb62 100644 --- a/app/src/main/java/com/hippo/nimingban/client/ac/data/ACFeed.java +++ b/app/src/main/java/com/hippo/nimingban/client/ac/data/ACFeed.java @@ -76,7 +76,7 @@ public void generate(Site site) { mUser = Html.fromHtml(userid); } - mContent = ACPost.generateContent(content); + mContent = ACPost.generateContent(content, "", title, name, email); if (!TextUtils.isEmpty(img)) { mThumb = ACUrl.HOST + "/Public/Upload/thumb/" + img + ext; diff --git a/app/src/main/java/com/hippo/nimingban/client/ac/data/ACPost.java b/app/src/main/java/com/hippo/nimingban/client/ac/data/ACPost.java index 05b99d2a..88ded319 100644 --- a/app/src/main/java/com/hippo/nimingban/client/ac/data/ACPost.java +++ b/app/src/main/java/com/hippo/nimingban/client/ac/data/ACPost.java @@ -28,14 +28,17 @@ import android.text.style.StyleSpan; import android.text.style.URLSpan; +import com.hippo.nimingban.R; import com.hippo.nimingban.client.ReferenceSpan; import com.hippo.nimingban.client.ac.ACUrl; import com.hippo.nimingban.client.data.ACSite; import com.hippo.nimingban.client.data.Post; import com.hippo.nimingban.client.data.Reply; import com.hippo.nimingban.client.data.Site; +import com.hippo.nimingban.util.ResImageGetter; import com.hippo.text.Html; import com.hippo.yorozuya.NumberUtils; +import com.hippo.yorozuya.StringUtils; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -271,7 +274,8 @@ public static CharSequence handleEmail(CharSequence content, String email) { public static CharSequence generateContent(String content) { CharSequence charSequence; - charSequence = Html.fromHtml(content); + charSequence = Html.fromHtml(StringUtils.replace(content, "#滑稽", ""), + new ResImageGetter(), null); charSequence = fixURLSpan(charSequence); charSequence = handleReference(charSequence); charSequence = handleTextUrl(charSequence); diff --git a/app/src/main/java/com/hippo/nimingban/util/ResImageGetter.java b/app/src/main/java/com/hippo/nimingban/util/ResImageGetter.java new file mode 100644 index 00000000..c56ded78 --- /dev/null +++ b/app/src/main/java/com/hippo/nimingban/util/ResImageGetter.java @@ -0,0 +1,49 @@ +/* + * Copyright 2015 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.nimingban.util; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; + +import com.hippo.text.Html; +import com.hippo.yorozuya.StringUtils; + +public class ResImageGetter implements Html.ImageGetter { + + private static Resources sResources; + + public static void initialize(Context context) { + sResources = context.getResources(); + } + + @Override + public Drawable getDrawable(String source) { + if (StringUtils.isAllDigit(source)) { + int resId = Integer.parseInt(source); + Drawable d = sResources.getDrawable(resId); + if (d != null) { + d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); + return d; + } else { + return null; + } + } else { + return null; + } + } +} diff --git a/app/src/main/java/com/hippo/text/Html.java b/app/src/main/java/com/hippo/text/Html.java index a073d4a2..670c5fff 100644 --- a/app/src/main/java/com/hippo/text/Html.java +++ b/app/src/main/java/com/hippo/text/Html.java @@ -16,6 +16,7 @@ package com.hippo.text; +import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Color; @@ -67,6 +68,13 @@ * Not all HTML tags are supported. */ public class Html { + + static Resources sResources; + + public static void initialize(Context context) { + sResources = context.getResources(); + } + /** * Retrieves images for HTML <img> tags. */ @@ -654,8 +662,7 @@ private static void startImg(SpannableStringBuilder text, } if (d == null) { - d = Resources.getSystem(). - getDrawable(R.drawable.unknown_image); + d = Html.sResources.getDrawable(R.drawable.unknown_image); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } @@ -876,9 +883,13 @@ public Header(int level) { } /** - * Converts an HTML color (named or numeric) to an integer RGB value. - * - * @param colorString Non-null color string. + * Parse the color string, and return the corresponding color-int. + * If the string cannot be parsed, throws an IllegalArgumentException + * exception. Supported formats are: + * #RRGGBB + * #AARRGGBB + * rgb(255, 255, 255) + * or color name */ @ColorInt public static int getHtmlColor(@NonNull String colorString) { diff --git a/app/src/main/res/drawable-hdpi/emoji_huaji.png b/app/src/main/res/drawable-hdpi/emoji_huaji.png new file mode 100644 index 0000000000000000000000000000000000000000..3bd73624b0b6add87d7e19c0678c1491b25e1bc4 GIT binary patch literal 898 zcmV-|1AY97P)v`RD?tjl2fDj3p{u$NzWdN^anI&5l@0AA)Xpf35Z@ovBg9MQ|$+WjnaIy zG1N3!XWs6nn{+?YW)m%RU`Uo^o_XHqoteCE0FLd58F$ctYJB)IzJ$;x(7otl%U25M z3+S)VV|{`3<*pDyB9wd<-FLt>B+;jk*n%a5kO(O-jUMT6H=^i|kyzo-gk&-ad26gN zQps;bit8bnwn%Y3CSyvt>@xijH9}oGF9lsBfIx=<<5Ifa6>p822m7Ems?MVAr_0lhuQ=1csvja zg-m0l%?#APMn`Slr^elP|JF&`Dv3N2iAZf(wJ0eu*d|A3HaM2OkO;yCkenGwF`V66O*2b!ll zgpBZcy`Y^fd)E{)!say&S1@pX4XRrL)c^EbPKGcEn{udg>JegNy#Gv&J(O3kSWZa6 zRB|Xe^$5|i6HZ^u0)Ju~N=q)w2@xh?Qx0`bJwmZYFJ7N##n&i6i;9_?u(fjTBP9Q( zBpIP=^K2!#w?Rv4i7*I@FbP{VrI*dRjGa*^@Z60AE5Ki=+Z_`k48kHz!dB-pBqZMs z*pJ1Es9%&`K%F5C&lprgG@lx{0)PgjE3h220?$Ij3$})0&}JQijM-tkPLX zX0)S2{$|z=zZ28EAfjqM}V zY=gzd1SU0<8l-Mgnxo@ukl97Cyy}GQykp;3AoXbIspgDz7sdbbD&6Zp8;+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.png b/app/src/main/res/drawable-xxhdpi/emoji_huaji.png new file mode 100644 index 0000000000000000000000000000000000000000..1898470260a0d0704b232aba7c53d375358d329c GIT binary patch literal 1553 zcmV+s2JZQZP)9?MHI(pP134r>iiH& zKqbgX%BgsPY1fGve0-DXA_?aGmN-uvwPHRGA2m~O5ur4eXA8juF0 z0mZjZ21H;GPrhlR#dxu( ziv(&eR)DxWO>visLz|}lr3$w*6u^PC%u*kTS%yZo`^J_xjINfd3Z%j)0gww+Va?;?`EoqkP(6+hQR6Sc6 zM+O-?c8VG4A!hWB)yy${ik_Hm{?=B7nU%ZNtyx-N?CA1h1F_Dubw$861}5bh$fdPuEa;XGoW=M`;OzTfl-RA`p4)V3(V@*NaCbDiWmSqR0WrF}3K0ttm zg8<4LAV3-IVr_6S-TVS7|9;x)iOuH$*WWrXaK_)`dz=C3(F=y|JAqF3$@v8~PS*usHqkWnVPn~t6V@zwrir<;j& z#OnM+YypX~L2ikAE$_A0+DoB$#reU@XNtD^B8~wYGKsZM-|&Jb-GTs`mIZ4u7Ol=t z#>&+o3uF>wk1RNI-NFIlTWM#UpAU@R*ex7U#y={ajl~qiDGOwTtdch4Wt*^{{Xy6= zl5v{xqvAQ+9Ow84S8Ww{)NmgDaNd^IU(FS4)-J@JH&icoTy%bbf%`@lY&8c2+z(5V z!GUZNI8t3g1L8ZfntT?)FMZ-(6Qn3(62@}EflMs|^R%DcWxjT~^8GYOVNJh8KBk~3 z)*N-;Z}A3|W-A0_(P{ywUmkZ*G3WdoQBb-KcztnBvcU6X6J$J3EIU-e2?b~`NcAckKef2c`r(35%n1wM0cf|?OMDmZ)MAY% zG@Q_YgqY-d912R7$t_e(NnkOUc)Eb82ju-d4&}&hdmgAmUr;inn69TwPqWI$L;{ElQwK;@Y})a%LZ^s#V{ zu=GC`@L3ulRwd$JQ|P8}xkCfeO#{+^G@yvv{{jpEN@apS8$25|00000NkvXXu0mjf DrRD0J literal 0 HcmV?d00001 diff --git a/yorozuya b/yorozuya index 021ec117..22f17b9c 160000 --- a/yorozuya +++ b/yorozuya @@ -1 +1 @@ -Subproject commit 021ec11712e1de365cdcfe90d22c2072f96868f6 +Subproject commit 22f17b9ce3bfb35058fc64d81bf68f47bb7aa85f