类android.text.Html源码实例Demo

下面列出了怎么用android.text.Html的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: andela-crypto-app   文件: MainActivity.java
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])));
}
 
源代码2 项目: kute   文件: InitialDetailDialogs.java
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("&#8226;", Html.FROM_HTML_MODE_COMPACT));
        }
        else
        {
            dots[i].setText(Html.fromHtml("&#8226;"));
        }
        dots[i].setTextSize(35);
        dots[i].setTextColor(colorsInactive);
        dotsLayout.addView(dots[i]);
    }

    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive);
}
 
源代码3 项目: kcanotify_h5-master   文件: KcaInfoActivity.java
@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());
}
 
源代码4 项目: Noyze   文件: HelpActivity.java
@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;
}
 
源代码5 项目: QuickLyric   文件: MainActivity.java
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();
}
 
源代码6 项目: Auie   文件: UEFontAwesome.java
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;
		}
	});
}
 
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("&#8226;"));
        dots[i].setTextSize(35);
        dots[i].setTextColor(colorsInactive[currentPage]);
        dotsLayout.addView(dots[i]);
    }

    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive[currentPage]);
}
 
源代码8 项目: barcodescanner-lib-aar   文件: TitleRetriever.java
@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);
      }
    }
  }
}
 
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);
            }
        });
    }
 
源代码10 项目: ExamplesAndroid   文件: MainActivity.java
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));

}
 
源代码11 项目: Moment   文件: AboutActivity.java
@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());
}
 
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"));
                }
            });
        }
    });
}
 
源代码13 项目: DoraemonKit   文件: DbDebugFragment.java
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");
    }
}
 
源代码14 项目: diycode   文件: TopicReplyAdapter.java
/**
 * 在此处处理数据
 *
 * @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);
}
 
源代码15 项目: Cheerleader   文件: ArtistView.java
/**
 * 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);
    }
}
 
源代码16 项目: comfortreader   文件: FullscreenActivity.java
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);
    	}
    	
    }
 
源代码17 项目: jterm-cswithandroid   文件: AnagramsActivity.java
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();
}
 
源代码18 项目: PanoramaGL   文件: SimpleVrPanoramaActivity.java
/**
 * 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());
}
 
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;
}
 
源代码20 项目: standardlib   文件: HtmlFormatter.java
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 ");
            }
        }
    });
}
 
/**
 * ログ表示用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));
    }
}
 
源代码22 项目: SystemUITuner2   文件: Exceptions.java
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();
    }
}
 
源代码23 项目: tapchat-android   文件: VerifyHostnameActivity.java
@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();
}
 
源代码24 项目: letv   文件: AlipayAutoPayDialog.java
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));
}
 
源代码25 项目: SmileEssence   文件: UserDetailDialogFragment.java
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());
}
 
源代码26 项目: ResearchStack   文件: EmailVerificationActivity.java
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));
}
 
源代码27 项目: GSYRickText   文件: RichEditText.java
/**
 * 处理话题和表情
 *
 * @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;
}
 
源代码28 项目: screenstandby   文件: UpdateChecker.java
@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();
	}
}
 
源代码29 项目: GracefulMovies   文件: QuoteTextView.java
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));
    }
}
 
源代码30 项目: Androzic   文件: Splash.java
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;
	}
}
 
 类所在包
 同包方法