use of android.text.Html in project AndFrameWorks by scwang90.
the class AfViewQuery method html.
@Override
public T html(String format, Object... args) {
if (args.length == 0) {
// noinspection deprecation
return foreach(TextView.class, (ViewEacher<TextView>) (view) -> view.setText(Html.fromHtml(format)));
}
Context context = null;
for (int i = 0, len = format.length(), index = 0; i < len; i++) {
if (format.charAt(i) == '%' && i < len - 1) {
if (format.charAt(i + 1) == 's') {
if (index < args.length && args[index] instanceof Integer) {
int color = ((Integer) args[index]);
try {
if (context == null) {
context = getContext();
}
if (context != null) {
color = ContextCompat.getColor(context, color);
}
} catch (Resources.NotFoundException ignored) {
}
args[index] = Integer.toHexString(0x00FFFFFF & color);
}
}
i++;
index++;
}
}
// noinspection deprecation
return foreach(TextView.class, (ViewEacher<TextView>) (view) -> view.setText(Html.fromHtml(String.format(format, args))));
}
use of android.text.Html in project AntennaPod by AntennaPod.
the class StorageErrorActivity method showChooseDataFolderDialog.
// see PreferenceController.showChooseDataFolderDialog()
private void showChooseDataFolderDialog() {
File dataFolder = UserPreferences.getDataFolder(null);
if (dataFolder == null) {
new MaterialDialog.Builder(this).title(R.string.error_label).content(R.string.external_storage_error_msg).neutralText(android.R.string.ok).show();
return;
}
String dataFolderPath = dataFolder.getAbsolutePath();
int selectedIndex = -1;
File[] mediaDirs = ContextCompat.getExternalFilesDirs(this, null);
List<String> folders = new ArrayList<>(mediaDirs.length);
List<CharSequence> choices = new ArrayList<>(mediaDirs.length);
for (int i = 0; i < mediaDirs.length; i++) {
File dir = mediaDirs[i];
if (dir == null || !dir.exists() || !dir.canRead() || !dir.canWrite()) {
continue;
}
String path = mediaDirs[i].getAbsolutePath();
folders.add(path);
if (dataFolderPath.equals(path)) {
selectedIndex = i;
}
int index = path.indexOf("Android");
String choice;
if (index >= 0) {
choice = path.substring(0, index);
} else {
choice = path;
}
long bytes = StorageUtils.getFreeSpaceAvailable(path);
String freeSpace = String.format(getString(R.string.free_space_label), Converter.byteToString(bytes));
choices.add(Html.fromHtml("<html><small>" + choice + " [" + freeSpace + "]" + "</small></html>"));
}
if (choices.size() == 0) {
new MaterialDialog.Builder(this).title(R.string.error_label).content(R.string.external_storage_error_msg).neutralText(android.R.string.ok).show();
return;
}
MaterialDialog dialog = new MaterialDialog.Builder(this).title(R.string.choose_data_directory).content(R.string.choose_data_directory_message).items(choices.toArray(new CharSequence[choices.size()])).itemsCallbackSingleChoice(selectedIndex, (dialog1, itemView, which, text) -> {
String folder = folders.get(which);
UserPreferences.setDataFolder(folder);
leaveErrorState();
return true;
}).negativeText(R.string.cancel_label).cancelable(true).build();
dialog.show();
}
use of android.text.Html in project AntennaPod by AntennaPod.
the class PreferenceController method showChooseDataFolderDialog.
private void showChooseDataFolderDialog() {
Context context = ui.getActivity();
File dataFolder = UserPreferences.getDataFolder(null);
if (dataFolder == null) {
new MaterialDialog.Builder(ui.getActivity()).title(R.string.error_label).content(R.string.external_storage_error_msg).neutralText(android.R.string.ok).show();
return;
}
String dataFolderPath = dataFolder.getAbsolutePath();
int selectedIndex = -1;
File[] mediaDirs = ContextCompat.getExternalFilesDirs(context, null);
List<String> folders = new ArrayList<>(mediaDirs.length);
List<CharSequence> choices = new ArrayList<>(mediaDirs.length);
for (int i = 0; i < mediaDirs.length; i++) {
File dir = mediaDirs[i];
if (dir == null || !dir.exists() || !dir.canRead() || !dir.canWrite()) {
continue;
}
String path = mediaDirs[i].getAbsolutePath();
folders.add(path);
if (dataFolderPath.equals(path)) {
selectedIndex = i;
}
int index = path.indexOf("Android");
String choice;
if (index >= 0) {
choice = path.substring(0, index);
} else {
choice = path;
}
long bytes = StorageUtils.getFreeSpaceAvailable(path);
String freeSpace = String.format(context.getString(R.string.free_space_label), Converter.byteToString(bytes));
choices.add(Html.fromHtml("<html><small>" + choice + " [" + freeSpace + "]" + "</small></html>"));
}
if (choices.size() == 0) {
new MaterialDialog.Builder(ui.getActivity()).title(R.string.error_label).content(R.string.external_storage_error_msg).neutralText(android.R.string.ok).show();
return;
}
MaterialDialog dialog = new MaterialDialog.Builder(ui.getActivity()).title(R.string.choose_data_directory).content(R.string.choose_data_directory_message).items(choices.toArray(new CharSequence[choices.size()])).itemsCallbackSingleChoice(selectedIndex, (dialog1, itemView, which, text) -> {
String folder = folders.get(which);
Log.d(TAG, "data folder: " + folder);
UserPreferences.setDataFolder(folder);
setDataFolderText();
return true;
}).negativeText(R.string.cancel_label).cancelable(true).build();
dialog.show();
}
use of android.text.Html in project XposedInstaller by rovo89.
the class RepoParser method parseSimpleHtml.
public static Spanned parseSimpleHtml(final Context c, String source, final TextView textView) {
source = source.replaceAll("<li>", "\t\u0095 ");
source = source.replaceAll("</li>", "<br>");
Spanned html = Html.fromHtml(source, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
LevelListDrawable d = new LevelListDrawable();
@SuppressWarnings("deprecation") Drawable empty = c.getResources().getDrawable(R.drawable.ic_no_image);
d.addLevel(0, 0, empty);
assert empty != null;
d.setBounds(0, 0, empty.getIntrinsicWidth(), empty.getIntrinsicHeight());
new ImageGetterAsyncTask(c, source, d).execute(textView);
return d;
}
}, null);
// trim trailing newlines
int len = html.length();
int end = len;
for (int i = len - 1; i >= 0; i--) {
if (html.charAt(i) != '\n')
break;
end = i;
}
if (end == len)
return html;
else
return new SpannableStringBuilder(html, 0, end);
}
Aggregations