Java Code Examples for android.text.Html
The following examples show how to use
android.text.Html. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: andela-crypto-app Source File: MainActivity.java License: Apache License 2.0 | 6 votes |
private void init() { emptyText.setText(Html.fromHtml(getString(R.string.text_empty_message))); adapter = new CardsAdapter(); adapter.setOnItemClickListener(this); adapter.setOnCardActionListener(this); adapter.setEmptyView(emptyView); LinearLayoutManager layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); List<Country> all = countryBox.getAll(); adapter.setCountries(all); loadRates(all.toArray(new Country[0])); swipeRefreshLayout.setOnRefreshListener(() -> loadRates(adapter.getCountries().toArray(new Country[0]))); }
Example 2
Source Project: kute Source File: InitialDetailDialogs.java License: Apache License 2.0 | 6 votes |
private void addBottomDots(int currentPage) { dots = new TextView[3]; int colorsActive = ResourcesCompat.getColor(getResources(), R.color.dot_active, null); int colorsInactive = ResourcesCompat.getColor(getResources(), R.color.dot_inactive, null); dotsLayout.removeAllViews(); for (int i = 0; i < dots.length; i++) { dots[i] = new TextView(this); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // a certain method is not valid for versions below adroid nougat dots[i].setText(Html.fromHtml("•", Html.FROM_HTML_MODE_COMPACT)); } else { dots[i].setText(Html.fromHtml("•")); } dots[i].setTextSize(35); dots[i].setTextColor(colorsInactive); dotsLayout.addView(dots[i]); } if (dots.length > 0) dots[currentPage].setTextColor(colorsActive); }
Example 3
Source Project: kcanotify_h5-master Source File: KcaInfoActivity.java License: GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_info); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle(getResources().getString(R.string.setting_menu_app_info)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); app_gpl = (TextView) findViewById(R.id.app_gpl); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { app_gpl.setText(Html.fromHtml(KcaUtils.format(getString(R.string.ia_gpl), getString(R.string.app_brand)), Html.FROM_HTML_MODE_LEGACY)); } else { app_gpl.setText(Html.fromHtml((KcaUtils.format(getString(R.string.ia_gpl), getString(R.string.app_brand))))); } app_gpl.setMovementMethod(LinkMovementMethod.getInstance()); }
Example 4
Source Project: Noyze Source File: HelpActivity.java License: Apache License 2.0 | 6 votes |
@Override public View getView(int position, View view, ViewGroup container) { ViewHolder mHolder; if (view != null) { mHolder = (ViewHolder) view.getTag(); } else { view = makeLayout(); mHolder = new ViewHolder(view); view.setTag(mHolder); } // Get the key and value from our LinkedHashMap. final Entry<CharSequence, Integer> mEntry = mItems.get(position); final CharSequence mMessage = mEntry.getKey(); final int mImageRes = mEntry.getValue(); // Set the values from our ViewHolder. mHolder.mText.setText(((mMessage instanceof String) ? Html.fromHtml((String) mMessage) : mMessage)); if (mImageRes != R.id.help_text && mImageRes != 0) { mHolder.mText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, mImageRes); } return view; }
Example 5
Source Project: QuickLyric Source File: MainActivity.java License: GNU General Public License v3.0 | 6 votes |
private void onAppUpdated(int versionCode) { String changelog = ChangelogStringBuilder.getChangelog(getResources(), versionCode); if (changelog == null || changelog.isEmpty()) return; CharSequence spannedChangelog = Html.fromHtml(changelog); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle(string.changelog) .setCancelable(true) .setPositiveButton(android.R.string.ok, (dialog12, which) -> dialog12.dismiss()) .setNegativeButton(string.rate_us, (dialog1, which) -> { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.geecko.QuickLyric"))); dialog1.dismiss(); }) .setNeutralButton(string.translate_us, (dialog3, which) -> { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/quicklyric"))); dialog3.dismiss(); }) .setMessage(spannedChangelog) .create(); dialog.show(); }
Example 6
Source Project: Auie Source File: UEFontAwesome.java License: GNU General Public License v2.0 | 6 votes |
public UEFontAwesomeDrawable(Context context, final View view, String text, int color) { this.text = Html.fromHtml(text).toString(); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTypeface(typeface); mTextPaint.setDither(true); mTextPaint.setColor(color); mTextPaint.setTextAlign(Paint.Align.CENTER); mTextPaint.measureText(text); view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { width = view.getWidth(); height = view.getHeight(); mTextPaint.setTextSize(Math.min(width, height)); view.getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); }
Example 7
Source Project: incubator-taverna-mobile Source File: TutorialActivity.java License: Apache License 2.0 | 6 votes |
public void addBottomDots(int currentPage) { TextView[] dots = new TextView[TutorialSliderEnum.values().length]; int[] colorsActive = getResources().getIntArray(R.array.array_dot_active); int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive); dotsLayout.removeAllViews(); for (int i = 0; i < dots.length; i++) { dots[i] = new TextView(this); dots[i].setText(Html.fromHtml("•")); dots[i].setTextSize(35); dots[i].setTextColor(colorsInactive[currentPage]); dotsLayout.addView(dots[i]); } if (dots.length > 0) dots[currentPage].setTextColor(colorsActive[currentPage]); }
Example 8
Source Project: barcodescanner-lib-aar Source File: TitleRetriever.java License: MIT License | 6 votes |
@Override void retrieveSupplementalInfo() { CharSequence contents; try { contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096); } catch (IOException ioe) { // ignore this return; } if (contents != null && contents.length() > 0) { Matcher m = TITLE_PATTERN.matcher(contents); if (m.find()) { String title = m.group(1); if (title != null && !title.isEmpty()) { title = Html.fromHtml(title).toString(); if (title.length() > MAX_TITLE_LEN) { title = title.substring(0, MAX_TITLE_LEN) + "..."; } append(httpUrl, null, new String[] {title}, httpUrl); } } } }
Example 9
Source Project: android-open-project-demo Source File: ContentTextViewFragment.java License: Apache License 2.0 | 6 votes |
private void initView(View v) { tvAbout=(TextView)v.findViewById(R.id.tv_about); tvAbout.setMovementMethod(LinkMovementMethod.getInstance()); tvAbout.setText(Html.fromHtml((getResources().getString((R.string.app_about))))); ptr = (PtrClassicFrameLayout) v.findViewById(R.id.ptr_main); ptr.setPtrHandler(new PtrDefaultHandler() { @Override public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) { new Handler().postDelayed(new Runnable() { @Override public void run() { ptr.refreshComplete(); } }, 2000); } }); }
Example 10
Source Project: ExamplesAndroid Source File: MainActivity.java License: Apache License 2.0 | 6 votes |
private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id, CharSequence address, CharSequence phoneNumber, Uri websiteUri) { Log.e(TAG, res.getString(R.string.place_details, name, id, address, phoneNumber, websiteUri)); return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber, websiteUri)); }
Example 11
Source Project: Moment Source File: AboutActivity.java License: GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); getWindow().setStatusBarColor(Color.TRANSPARENT); setContentView(R.layout.about_activity); TextView sourceCode = (TextView) findViewById(R.id.source_code); sourceCode.setText(Html.fromHtml(getString(R.string.source_code))); sourceCode.setMovementMethod(new LinkMovementMethod()); TextView appVersion = (TextView) findViewById(R.id.app_version); appVersion.setText(String.format("v%s", BuildConfig.VERSION_NAME)); TextView openSource = (TextView) findViewById(R.id.open_source); openSource.setText(Html.fromHtml(getString(R.string.open_source_used))); openSource.setMovementMethod(new LinkMovementMethod()); }
Example 12
Source Project: flickr-uploader Source File: PreferencesAdvancedActivity.java License: GNU General Public License v2.0 | 6 votes |
private void render() { BackgroundExecutor.execute(new Runnable() { @Override public void run() { final long size = FlickrUploader.getLogSize(); final List<String> autoupload_delay_values = Arrays.asList(getResources().getStringArray(R.array.autoupload_delay_values)); final String[] autoupload_delay_entries = getResources().getStringArray(R.array.autoupload_delay_entries); final String autoupload_delay_value = Utils.getStringProperty("autoupload_delay", autoupload_delay_values.get(0)); runOnUiThread(new Runnable() { @Override public void run() { findPreference("clear_logs").setSummary("Files size: " + Utils.formatFileSize(size)); String autoupload_delay = autoupload_delay_entries[autoupload_delay_values.indexOf(autoupload_delay_value)]; if (autoupload_delay.equalsIgnoreCase("custom")) { findPreference("autoupload_delay").setSummary(autoupload_delay); } else { findPreference("autoupload_delay").setSummary(autoupload_delay); } findPreference("upload_description").setSummary(Html.fromHtml(Utils.getUploadDescription())); findPreference("custom_tags").setSummary(Utils.getStringProperty("custom_tags")); } }); } }); }
Example 13
Source Project: DoraemonKit Source File: DbDebugFragment.java License: Apache License 2.0 | 6 votes |
private void initView() throws Exception { if (!DebugDB.isServerRunning()) { DebugDB.initialize(DoraemonKit.APPLICATION, new DebugDBFactory()); DebugDB.initialize(DoraemonKit.APPLICATION, new DebugDBEncryptFactory()); } HomeTitleBar titleBar = findViewById(R.id.title_bar); titleBar.setListener(new HomeTitleBar.OnTitleBarClickListener() { @Override public void onRightClick() { finish(); } }); TextView tvTip = findViewById(R.id.tv_tip); tvTip.setText(Html.fromHtml(getResources().getString(R.string.dk_kit_db_debug_desc))); tvIp = findViewById(R.id.tv_ip); if (DebugDB.isServerRunning()) { tvIp.setText("" + DebugDB.getAddressLog().replace("Open ", "").replace("in your browser", "")); } else { tvIp.setText("servse is not start"); } }
Example 14
Source Project: diycode Source File: TopicReplyAdapter.java License: Apache License 2.0 | 6 votes |
/** * 在此处处理数据 * * @param position 位置 * @param holder view holder * @param bean 数据 */ @Override public void convert(int position, RecyclerViewHolder holder, TopicReply bean) { final User user = bean.getUser(); holder.setText(R.id.username, user.getLogin()); holder.setText(R.id.time, TimeUtil.computePastTime(bean.getUpdated_at())); ImageView avatar = holder.get(R.id.avatar); ImageUtils.loadImage(mContext, user.getAvatar_url(), avatar); TextView content = holder.get(R.id.content); // TODO 评论区代码问题 content.setText(Html.fromHtml(HtmlUtil.removeP(bean.getBody_html()), new GlideImageGetter(mContext, content), null)); holder.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, UserActivity.class); intent.putExtra(UserActivity.USER, user); mContext.startActivity(intent); } }, R.id.avatar, R.id.username); }
Example 15
Source Project: Cheerleader Source File: ArtistView.java License: Apache License 2.0 | 6 votes |
/** * Set the {@link SoundCloudUser} used as model. * * @param artist user used as artist. */ public void setModel(SoundCloudUser artist) { mModel = artist; if (mModel != null) { Picasso.with(getContext()) .load( SoundCloudArtworkHelper.getCoverUrl( mModel, SoundCloudArtworkHelper.XLARGE ) ) .fit() .centerInside() .into(mAvatar); mArtistName.setText(mModel.getFullName()); mTracks.setText( String.format( getResources().getString(R.string.artist_view_track_count), mModel.getTrackCount() ) ); mDescription.setText(Html.fromHtml(mModel.getDescription())); this.setVisibility(VISIBLE); } }
Example 16
Source Project: comfortreader Source File: FullscreenActivity.java License: GNU General Public License v3.0 | 6 votes |
public void playAutomated(int milliseconds){ Log.i("Fullscreen", "automatic loading webview"); String html = segmenterObject.getsegmentoutputNextTick(tickdistance); contentView.setText(Html.fromHtml(html)); settingsload.saveAddReadCharacters(tickdistance); settingsload.saveAddReadingTime(milliseconds); if (segmenterObject.tickposition == 0){ texthaschanged(); } if (segmenterObject.finished){ stop(); controlsView2.setVisibility(View.VISIBLE); } }
Example 17
Source Project: jterm-cswithandroid Source File: AnagramsActivity.java License: Apache License 2.0 | 6 votes |
private void processWord(EditText editText) { TextView resultView = (TextView) findViewById(R.id.resultView); String word = editText.getText().toString().trim().toLowerCase(); if (word.length() == 0) { return; } String color = "#cc0029"; if (dictionary.isGoodWord(word, currentWord) && anagrams.contains(word)) { anagrams.remove(word); color = "#00aa29"; } else { word = "X " + word; } resultView.append(Html.fromHtml(String.format("<font color=%s>%s</font><BR>", color, word))); editText.setText(""); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.show(); }
Example 18
Source Project: PanoramaGL Source File: SimpleVrPanoramaActivity.java License: Apache License 2.0 | 6 votes |
/** * Called when the app is launched via the app icon or an intent using the adb command above. This * initializes the app and loads the image to render. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); // Make the source link clickable. TextView sourceText = (TextView) findViewById(R.id.source); sourceText.setText(Html.fromHtml(getString(R.string.source))); sourceText.setMovementMethod(LinkMovementMethod.getInstance()); panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view); panoWidgetView.setEventListener(new ActivityEventListener()); // Initial launch of the app or an Activity recreation due to rotation. handleIntent(getIntent()); }
Example 19
Source Project: Bluefruit_LE_Connect_Android_V2 Source File: BlePeripheralsAdapter.java License: MIT License | 6 votes |
private static Spanned getAdvertisementDescription(Context context, BlePeripheral blePeripheral) { final int deviceType = BleScanner.getDeviceType(blePeripheral); String text; switch (deviceType) { case kDeviceType_Beacon: text = getBeaconAdvertisementDescription(context, blePeripheral); break; case kDeviceType_UriBeacon: text = getUriBeaconAdvertisementDescription(context, blePeripheral); break; default: text = getCommonAdvertisementDescription(context, blePeripheral); break; } Spanned result; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { result = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY); } else { result = Html.fromHtml(text); } return result; }
Example 20
Source Project: standardlib Source File: HtmlFormatter.java License: Apache License 2.0 | 6 votes |
public static Spanned format(String html, Boolean withImages) { if (!withImages) { html = html.replaceAll("<img.+?>", ""); } return Html.fromHtml(html, null, new Html.TagHandler() { @Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (opening && tag.equals("li")) { output.append("\n") .append("\t\u2022 "); } } }); }
Example 21
Source Project: DeviceConnect-Android Source File: FaBoConnectFragment.java License: MIT License | 6 votes |
/** * ログ表示用TextViewにメッセージを追加します. * * @param msg 追加するメッセージ */ private synchronized void addLogMessage(final String msg) { String lastMsg = mTextViewLog.getText().toString(); if (DEBUG) { Log.i(TAG, "lastMsg" + lastMsg); } String newMsg = lastMsg; if (!lastMsg.isEmpty()) { newMsg += "<br>"; } newMsg += "<font color=\"#00FF00\"> ✓ </font>" + msg; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { mTextViewLog.setText(Html.fromHtml(newMsg, 0)); } else { mTextViewLog.setText(Html.fromHtml(newMsg)); } }
Example 22
Source Project: SystemUITuner2 Source File: Exceptions.java License: MIT License | 5 votes |
public void systemSettings(Activity activity, final Context appContext, Exception e, String page) { //exceptions for System Settings (should only be needed on API > 22) Log.e(page, e.getMessage()); //log error e.printStackTrace(); if (!activity.isDestroyed()) { new AlertDialog.Builder(activity) //show details dialog .setIcon(alertRed) .setTitle(Html.fromHtml("<font color='#ff0000'>" + activity.getResources().getText(R.string.error) + "</font>")) .setMessage(activity.getResources().getText(R.string.system_settings_failed) + "\n\n\"" + e.getMessage() + "\"") .setPositiveButton(activity.getResources().getText(R.string.ok), null) .show(); } }
Example 23
Source Project: tapchat-android Source File: VerifyHostnameActivity.java License: Apache License 2.0 | 5 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { String hostname = getArguments().getString(MemorizingHostnameVerifier.EXTRA_HOSTNAME); String fingerprint = getArguments().getString(MemorizingHostnameVerifier.EXTRA_FINGERPRINT); return new AlertDialog.Builder(getActivity()) .setMessage(Html.fromHtml(getString(R.string.verify_hostname_message, hostname, fingerprint))) .setPositiveButton(R.string._continue, this) .setNegativeButton(android.R.string.cancel, this) .create(); }
Example 24
Source Project: letv Source File: AlipayAutoPayDialog.java License: Apache License 2.0 | 5 votes |
private void getTipsMessages() { this.mIsNotOpenContinusMonthly = getArguments().getBoolean(AlipayConstant.NOT_OPEN_CONTINUE_MONTHLY, true); this.mIsMobileVipFlag = getArguments().getBoolean(AlipayConstant.IS_MOBILE_VIP_FLAG, true); if (PreferencesManager.getInstance().getAlipayAutoOpenStatus()) { if (this.mIsMobileVipFlag) { this.mTipsTitle = TipUtils.getTipTitle(CHANGE_MOBILE_ALIPAY_AUTO_PAY, getString(2131099722)); this.mTipsMessage = TipUtils.getTipMessage(CHANGE_MOBILE_ALIPAY_AUTO_PAY, getString(2131099721)); } else { this.mTipsTitle = TipUtils.getTipTitle(CHANGE_ALL_SCREEN_ALIPAY_AUTO_PAY, getString(2131099720)); this.mTipsMessage = TipUtils.getTipMessage(CHANGE_ALL_SCREEN_ALIPAY_AUTO_PAY, getString(2131099719)); } } else if (this.mIsNotOpenContinusMonthly) { if (this.mIsMobileVipFlag) { this.mTipsTitle = TipUtils.getTipTitle(OPEN_MOBILE_ALIPAY_AUTO_PAY, getString(2131099741)); this.mTipsMessage = TipUtils.getTipMessage(OPEN_MOBILE_ALIPAY_AUTO_PAY, getString(2131099740)); } else { this.mTipsTitle = TipUtils.getTipTitle(OPEN_ALL_SCREEN_ALIPAY_AUTO_PAY, getString(2131099741)); this.mTipsMessage = TipUtils.getTipMessage(OPEN_ALL_SCREEN_ALIPAY_AUTO_PAY, getString(2131099740)); } } else if (this.mIsMobileVipFlag) { this.mTipsTitle = TipUtils.getTipTitle(RESUME_MOBILE_ALIPAY_AUTO_PAY, getString(2131099743)); this.mTipsMessage = TipUtils.getTipMessage(RESUME_MOBILE_ALIPAY_AUTO_PAY, getString(2131099742)); } else { this.mTipsTitle = TipUtils.getTipTitle(RESUME_ALL_SCREEN_ALIPAY_AUTO_PAY, getString(2131099743)); this.mTipsMessage = TipUtils.getTipMessage(RESUME_ALL_SCREEN_ALIPAY_AUTO_PAY, getString(2131099742)); } this.mTipsMessage = this.mTipsMessage.replace("\\n", "<br>"); this.mTipsMessage = this.mTipsMessage.replace("\n", "<br>"); this.mTitle.setText(this.mTipsTitle); this.mContent.setText(Html.fromHtml(this.mTipsMessage)); }
Example 25
Source Project: SmileEssence Source File: UserDetailDialogFragment.java License: MIT License | 5 votes |
private void initUserData(User user, Twitter twitter, final Account account) { textViewName.setText(user.getName()); textViewScreenName.setText(user.getScreenName()); if (TextUtils.isEmpty(user.getLocation())) { textViewLocate.setVisibility(View.GONE); } else { textViewLocate.setText(user.getLocation()); } if (TextUtils.isEmpty(user.getURL())) { textViewURL.setVisibility(View.GONE); } else { textViewURL.setText(user.getURL()); } textViewTweetCount.setText(String.valueOf(user.getStatusesCount())); textViewFriendCount.setText(String.valueOf(user.getFriendsCount())); textViewFollowerCount.setText(String.valueOf(user.getFollowersCount())); textViewFavoriteCount.setText(String.valueOf(user.getFavouritesCount())); textViewProtected.setVisibility(user.isProtected() ? View.VISIBLE : View.GONE); String htmlDescription = getHtmlDescription(user.getDescription()); textViewDescription.setText(Html.fromHtml(htmlDescription)); textViewDescription.setMovementMethod(LinkMovementMethod.getInstance()); ImageCache.getInstance().setImageToView(user.getBiggerProfileImageURL(), imageViewIcon); ImageCache.getInstance().setImageToView(user.getProfileBannerURL(), imageViewHeader); MainActivity activity = (MainActivity) getActivity(); final StatusListAdapter adapter = new StatusListAdapter(activity); listViewTimeline.setAdapter(adapter); listViewTimeline.setOnRefreshListener(this); activity.setListAdapter(ADAPTER_INDEX, adapter); executeUserTimelineTask(user, twitter, account, adapter); updateRelationship(activity, user.getId()); }
Example 26
Source Project: ResearchStack Source File: EmailVerificationActivity.java License: Apache License 2.0 | 5 votes |
private void updateEmailText() { int accentColor = ThemeUtils.getAccentColor(this); String accentColorString = "#" + Integer.toHexString(Color.red(accentColor)) + Integer.toHexString(Color.green(accentColor)) + Integer.toHexString(Color.blue(accentColor)); String formattedSummary = getString(R.string.rss_confirm_summary, "<font color=\"" + accentColorString + "\">" + email + "</font>"); ((AppCompatTextView) findViewById(R.id.email_verification_body)).setText(Html.fromHtml( formattedSummary)); }
Example 27
Source Project: GSYRickText Source File: RichEditText.java License: MIT License | 5 votes |
/** * 处理话题和表情 * * @param context 上下文 * @param text 输入文本 * @param color 颜色 * @param listTopic 话题列表 * @return Spannable */ private static Spannable resolveTopicInsert(Context context, String text, String color, List<TopicModel> listTopic) { Spannable spannable; if (listTopic != null && listTopic.size() > 0) { Map<String, String> topics = new HashMap<>(); for (TopicModel topicModel : listTopic) { topics.put(topicModel.getTopicName(), topicModel.getTopicName()); } //查找## int length = text.length(); Pattern pattern = Pattern.compile("#[^\\s]+?#"); Matcher matcher = pattern.matcher(text); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); for (int i = 0; i < length; i++) { if (matcher.find()) { String name = text.substring(matcher.start(), matcher.end()); if (topics.containsKey(name)) { //直接用span会导致后面没文字的时候新输入的一起变色 Spanned htmlText = Html.fromHtml(String.format("<font color='%s'>" + name + "</font>", color)); spannableStringBuilder.replace(matcher.start(), matcher.start() + name.length(), htmlText); } } } spannable = spannableStringBuilder; SmileUtils.addSmiles(context, spannable); } else { spannable = TextCommonUtils.getEmojiText(context, text); } SmileUtils.addSmiles(context, spannable); return spannable; }
Example 28
Source Project: screenstandby Source File: UpdateChecker.java License: GNU General Public License v2.0 | 5 votes |
@Override protected void onPostExecute(Void result) { progressDialog.dismiss(); if (error == 0) { if (hasNew) { AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle("New version: " + name); b.setMessage(Html.fromHtml("Changes version <b>" + name + "</b> <small><i>(" + date + ")</i></small>")); TextView v = new TextView(context); v.setText(Html.fromHtml(changes)); v.setPadding(10, 0, 10, 0); b.setView(v); b.setNegativeButton("Dismiss",updateDialogClickListener); b.setPositiveButton("Take me to update",updateDialogClickListener); b.create().show(); Toast.makeText(context, Html.fromHtml("<b><font color='#8ebc00'>Update found: </font></b> version " + name), Toast.LENGTH_SHORT).show(); } else Toast.makeText(context, Html.fromHtml("<b><font color='#3399ff'>No new update found</font></b><br/>You are running the latest version"), Toast.LENGTH_SHORT).show(); } else { String err = ""; switch (error) { case 1: err="Invalid app signature (01)";break; case 2:case 3: err="Cannot connect to update server.<br/>Please check your internet connection.(02)";break; case 4: err="Server is having error (04).<br/>Please check again later";break; } Toast.makeText(context, Html.fromHtml("<b><font color='#ff2000'>Error while checking update</font></b><br/>" + err), Toast.LENGTH_SHORT).show(); } }
Example 29
Source Project: GracefulMovies Source File: QuoteTextView.java License: Apache License 2.0 | 5 votes |
public void setTextWithHtml(String text) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { setText(Html.fromHtml(text)); } else { setText(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)); } }
Example 30
Source Project: Androzic Source File: Splash.java License: GNU General Public License v3.0 | 5 votes |
private void showEula() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean hasBeenShown = prefs.getBoolean(getString(R.string.app_eulaaccepted), false); if (hasBeenShown == false) { final SpannableString message = new SpannableString(Html.fromHtml(getString(R.string.app_eula).replace("/n", "<br/>"))); Linkify.addLinks(message, Linkify.WEB_URLS); AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.app_name)).setIcon(R.drawable.icon).setMessage(message) .setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { prefs.edit().putBoolean(getString(R.string.app_eulaaccepted), true).commit(); wait = false; dialogInterface.dismiss(); } }).setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialoginterface, int keyCode, KeyEvent event) { return !(keyCode == KeyEvent.KEYCODE_HOME); } }).setCancelable(false); AlertDialog d = builder.create(); d.show(); // Make the textview clickable. Must be called after show() ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); } else { wait = false; } }