Java Code Examples for android.text.Html#fromHtml()

The following examples show how to use android.text.Html#fromHtml() . 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 File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 votes vote down vote up
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 2
Source File: MainMenu.java    From MifareClassicTool with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create the dialog which is displayed if the device does not have
 * MIFARE classic support. After showing the dialog,
 * {@link #runSartUpNode(StartUpNode)} with {@link StartUpNode#DonateDialog}
 * will be called or the app will be exited.
 * @return The created alert dialog.
 * @see #runSartUpNode(StartUpNode)
 */
private AlertDialog createHasNoMifareClassicSupportDialog() {
    CharSequence styledText = Html.fromHtml(
            getString(R.string.dialog_no_mfc_support_device));
    return new AlertDialog.Builder(this)
            .setTitle(R.string.dialog_no_mfc_support_device_title)
            .setMessage(styledText)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(R.string.action_exit_app,
                    (dialog, which) -> finish())
            .setNegativeButton(R.string.action_editor_only,
                    (dialog, id) -> {
                        useAsEditorOnly(true);
                        runSartUpNode(StartUpNode.DonateDialog);
                    })
            .setOnCancelListener(dialog -> finish())
            .create();
}
 
Example 3
Source File: NSDeviceStatus.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
public Spanned getOpenApsStatus() {
    StringBuilder string = new StringBuilder();
    string.append("<span style=\"color:" + MainApp.gs(R.color.defaulttext).replace("#ff", "#") + "\">");
    string.append(MainApp.gs(R.string.openaps_short));
    string.append(": </span>");

    // test warning level
    int level = Levels.INFO;
    long now = System.currentTimeMillis();
    if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + SP.getInt(R.string.key_nsalarm_urgent_staledatavalue, 16) * 60 * 1000L < now)
        level = Levels.URGENT;
    else if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + SP.getInt(R.string.key_nsalarm_staledatavalue, 16) * 60 * 1000L < now)
        level = Levels.WARN;

    string.append("<span style=\"color:");
    if (level == Levels.INFO) string.append("white\">");
    if (level == Levels.WARN) string.append("yellow\">");
    if (level == Levels.URGENT) string.append("red\">");

    if (deviceStatusOpenAPSData.clockSuggested != 0) {
        string.append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append(" ");
    }
    string.append("</span>"); // color

    return Html.fromHtml(string.toString());
}
 
Example 4
Source File: ParkedTextView.java    From ParkedTextView with MIT License 5 votes vote down vote up
public void setPlaceholderText(String placeholderText) {
    Spanned hint = null;
    String parkedTextColor = reformatColor(mParkedTextColor);
    String parkedHintColor = reformatColor(mParkedHintColor);
    if (mIsBoldParkedText) {
        hint = Html.fromHtml(String.format("<font color=\"#%s\">%s</font><font color=\"#%s\"><b>%s</b></font>", parkedHintColor, placeholderText, parkedTextColor, mParkedText));
    } else {
        hint = Html.fromHtml(String.format("<font color=\"#%s\">%s</font><font color=\"#%s\">%s</font>", parkedHintColor, placeholderText, parkedTextColor, mParkedText));
    }
    super.setHint(hint);
}
 
Example 5
Source File: ViewUtils.java    From Equate with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Spanned fromHtml(String html) {
	Spanned result;
	if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N){
		result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
	} else {
		result = Html.fromHtml(html);
	}
	return result;
}
 
Example 6
Source File: FirstRunActivity.java    From Atomic with GNU General Public License v3.0 5 votes vote down vote up
protected View generateHelpPage(HelpTopic topic) {
  TextView contentView = new TextView(this);
  Spanned st = Html.fromHtml(getString(topic.TextResource), assetImageGetter, null);
  contentView.setText(st);
  contentView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  contentView.setGravity(Gravity.CENTER_HORIZONTAL);

  View sv = wrapScrollview(contentView);
  sv.setTag(getString(topic.TitleReasource));
  return sv;
}
 
Example 7
Source File: Utils.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Spanned fromHtmlCompat(String text) {
    if (hasNougat()) {
        return Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY);
    } else {
        return Html.fromHtml(text);
    }
}
 
Example 8
Source File: APSResult.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public Spanned toSpanned() {
    final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
    if (isChangeRequested()) {
        String ret;
        // rate
        if (rate == 0 && duration == 0)
            ret = MainApp.gs(R.string.canceltemp) + "<br>";
        else if (rate == -1)
            ret = MainApp.gs(R.string.let_temp_basal_run) + "<br>";
        else if (usePercent)
            ret = "<b>" + MainApp.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(percent) + "% " +
                    "(" + DecimalFormatter.to2Decimal(percent * pump.getBaseBasalRate() / 100d) + " U/h)<br>" +
                    "<b>" + MainApp.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
        else
            ret = "<b>" + MainApp.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
                    "(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100d) + "%) <br>" +
                    "<b>" + MainApp.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";

        // smb
        if (smb != 0)
            ret += ("<b>" + "SMB" + "</b>: " + DecimalFormatter.toPumpSupportedBolus(smb) + " U<br>");

        // reason
        ret += "<b>" + MainApp.gs(R.string.reason) + "</b>: " + reason.replace("<", "&lt;").replace(">", "&gt;");
        return Html.fromHtml(ret);
    } else
        return Html.fromHtml(MainApp.gs(R.string.nochangerequested));
}
 
Example 9
Source File: MainActivity.java    From android-play-places with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to format information about a place nicely.
 */
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 10
Source File: FlexibleUtils.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
public static Spanned fromHtmlCompat(String text) {
    if (hasNougat()) {
        return Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY);
    } else {
        return Html.fromHtml(text);
    }
}
 
Example 11
Source File: FeedContract.java    From AnotherRSS with The Unlicense 5 votes vote down vote up
/**
 * Wrapper für Html.fromHtml(), was sich von unterschiedlichen Android Versionen unterscheidet.
 *
 * @param str html Code
 * @return spanned
 */
@SuppressWarnings("deprecation")
static public Spanned fromHtml(String str) {
    Spanned sp;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        sp = Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT, null, null);
    } else {
        sp = Html.fromHtml(str, null, null);
    }
    return sp;
}
 
Example 12
Source File: StringFormatter.java    From redgram-for-reddit with GNU General Public License v3.0 4 votes vote down vote up
public static Spanned formatFromHtml(String target){
    return Html.fromHtml(target);
}
 
Example 13
Source File: SubripDecoder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected SubripSubtitle decode(byte[] bytes, int length, boolean reset) {
  ArrayList<Cue> cues = new ArrayList<>();
  LongArray cueTimesUs = new LongArray();
  ParsableByteArray subripData = new ParsableByteArray(bytes, length);
  String currentLine;

  while ((currentLine = subripData.readLine()) != null) {
    if (currentLine.length() == 0) {
      // Skip blank lines.
      continue;
    }

    // Parse the index line as a sanity check.
    try {
      Integer.parseInt(currentLine);
    } catch (NumberFormatException e) {
      Log.w(TAG, "Skipping invalid index: " + currentLine);
      continue;
    }

    // Read and parse the timing line.
    boolean haveEndTimecode = false;
    currentLine = subripData.readLine();
    if (currentLine == null) {
      Log.w(TAG, "Unexpected end");
      break;
    }

    Matcher matcher = SUBRIP_TIMING_LINE.matcher(currentLine);
    if (matcher.matches()) {
      cueTimesUs.add(parseTimecode(matcher, 1));
      if (!TextUtils.isEmpty(matcher.group(6))) {
        haveEndTimecode = true;
        cueTimesUs.add(parseTimecode(matcher, 6));
      }
    } else {
      Log.w(TAG, "Skipping invalid timing: " + currentLine);
      continue;
    }

    // Read and parse the text and tags.
    textBuilder.setLength(0);
    tags.clear();
    currentLine = subripData.readLine();
    while (!TextUtils.isEmpty(currentLine)) {
      if (textBuilder.length() > 0) {
        textBuilder.append("<br>");
      }
      textBuilder.append(processLine(currentLine, tags));
      currentLine = subripData.readLine();
    }

    Spanned text = Html.fromHtml(textBuilder.toString());

    String alignmentTag = null;
    for (int i = 0; i < tags.size(); i++) {
      String tag = tags.get(i);
      if (tag.matches(SUBRIP_ALIGNMENT_TAG)) {
        alignmentTag = tag;
        // Subsequent alignment tags should be ignored.
        break;
      }
    }
    cues.add(buildCue(text, alignmentTag));

    if (haveEndTimecode) {
      cues.add(Cue.EMPTY);
    }
  }

  Cue[] cuesArray = new Cue[cues.size()];
  cues.toArray(cuesArray);
  long[] cueTimesUsArray = cueTimesUs.toArray();
  return new SubripSubtitle(cuesArray, cueTimesUsArray);
}
 
Example 14
Source File: NSDeviceStatus.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
public Spanned getPumpStatus() {
    //String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"};

    StringBuilder string = new StringBuilder();
    string.append("<span style=\"color:" + MainApp.gs(R.color.defaulttext).replace("#ff", "#") + "\">");
    string.append(MainApp.gs(R.string.pump));
    string.append(": </span>");

    if (deviceStatusPumpData == null)
        return Html.fromHtml("");

    // test warning level
    int level = Levels.INFO;
    long now = System.currentTimeMillis();
    if (deviceStatusPumpData.clock + NSSettingsStatus.getInstance().extendedPumpSettings("urgentClock") * 60 * 1000L < now)
        level = Levels.URGENT;
    else if (deviceStatusPumpData.reservoir < NSSettingsStatus.getInstance().extendedPumpSettings("urgentRes"))
        level = Levels.URGENT;
    else if (deviceStatusPumpData.isPercent && deviceStatusPumpData.percent < NSSettingsStatus.getInstance().extendedPumpSettings("urgentBattP"))
        level = Levels.URGENT;
    else if (!deviceStatusPumpData.isPercent && deviceStatusPumpData.voltage < NSSettingsStatus.getInstance().extendedPumpSettings("urgentBattV"))
        level = Levels.URGENT;
    else if (deviceStatusPumpData.clock + NSSettingsStatus.getInstance().extendedPumpSettings("warnClock") * 60 * 1000L < now)
        level = Levels.WARN;
    else if (deviceStatusPumpData.reservoir < NSSettingsStatus.getInstance().extendedPumpSettings("warnRes"))
        level = Levels.WARN;
    else if (deviceStatusPumpData.isPercent && deviceStatusPumpData.percent < NSSettingsStatus.getInstance().extendedPumpSettings("warnBattP"))
        level = Levels.WARN;
    else if (!deviceStatusPumpData.isPercent && deviceStatusPumpData.voltage < NSSettingsStatus.getInstance().extendedPumpSettings("warnBattV"))
        level = Levels.WARN;

    string.append("<span style=\"color:");
    if (level == Levels.INFO) string.append("white\">");
    if (level == Levels.WARN) string.append("yellow\">");
    if (level == Levels.URGENT) string.append("red\">");

    String fields = NSSettingsStatus.getInstance().pumpExtentendedSettingsFields();

    if (fields.contains("reservoir")) {
        string.append((int) deviceStatusPumpData.reservoir).append("U ");
    }

    if (fields.contains("battery") && deviceStatusPumpData.isPercent) {
        string.append(deviceStatusPumpData.percent).append("% ");
    }
    if (fields.contains("battery") && !deviceStatusPumpData.isPercent) {
        string.append(Round.roundTo(deviceStatusPumpData.voltage, 0.001d)).append(" ");
    }

    if (fields.contains("clock")) {
        string.append(DateUtil.minAgo(deviceStatusPumpData.clock)).append(" ");
    }

    if (fields.contains("status")) {
        string.append(deviceStatusPumpData.status).append(" ");
    }

    if (fields.contains("device")) {
        string.append(getDevice()).append(" ");
    }


    string.append("</span>"); // color

    return Html.fromHtml(string.toString());
}
 
Example 15
Source File: Story.java    From scanvine-android with MIT License 4 votes vote down vote up
public String getTitleLine() {
	if (rank==null)
		return ""+Html.fromHtml(""+title);
	else
		return ""+rank+". "+Html.fromHtml(""+title);
}
 
Example 16
Source File: HTMLUtil.java    From SightRemote with GNU General Public License v3.0 4 votes vote down vote up
public static Spanned getHTML(int stringResource, Object... args) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        return Html.fromHtml(SightRemote.getInstance().getString(stringResource, args), Html.FROM_HTML_MODE_COMPACT);
    else
        return Html.fromHtml(SightRemote.getInstance().getString(stringResource, args));
}
 
Example 17
Source File: Question.java    From triviums with MIT License 4 votes vote down vote up
@BindingAdapter("textView")
public static void loadQuestion(TextView view, String text){
    Spanned formattedText = Html.fromHtml(text);
    view.setText(formattedText);
}
 
Example 18
Source File: SongDetailDialog.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private static Spanned makeTextWithTitle(@NonNull Context context, int titleResId, String text) {
    return Html.fromHtml("<b>" + context.getResources().getString(titleResId) + ": " + "</b>" + text);
}
 
Example 19
Source File: StringTools.java    From sctalk with Apache License 2.0 4 votes vote down vote up
public static Spanned getColorfulString(String color, String content, String rightContent,
    String leftContent) {
  return Html.fromHtml(rightContent + "<font color=\"" + color + "\">" + content + "</font>"
      + leftContent);
}
 
Example 20
Source File: StringUtils.java    From framework with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * String to html.
 *
 * @param string the string
 * @return the spanned
 */
public static Spanned stringToHtml(String string) {
    return Html.fromHtml(string);
}