Search in sources :

Example 1 with Html

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))));
}
Also used : Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) AfLayoutItemViewerAdapter(com.andframe.adapter.AfLayoutItemViewerAdapter) Arrays(java.util.Arrays) ColorRes(android.support.annotation.ColorRes) ProgressBar(android.widget.ProgressBar) Date(java.util.Date) Uri(android.net.Uri) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Animation(android.view.animation.Animation) AdapterView(android.widget.AdapterView) TargetApi(android.annotation.TargetApi) Viewer(com.andframe.api.viewer.Viewer) DateFormat(java.text.DateFormat) RectF(android.graphics.RectF) LinearLayoutCompat(android.support.v7.widget.LinearLayoutCompat) Collection(java.util.Collection) ContextCompat(android.support.v4.content.ContextCompat) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ViewGroup(android.view.ViewGroup) DimenRes(android.support.annotation.DimenRes) SparseArray(android.util.SparseArray) LayoutParams(android.view.ViewGroup.LayoutParams) List(java.util.List) TextView(android.widget.TextView) BaseAdapter(android.widget.BaseAdapter) Html(android.text.Html) RelativeLayout(android.widget.RelativeLayout) Queue(java.util.Queue) Nullable(android.support.annotation.Nullable) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) Context(android.content.Context) ViewParent(android.view.ViewParent) Adapter(android.widget.Adapter) AfDateFormat(com.andframe.util.java.AfDateFormat) ViewPager(android.support.v4.view.ViewPager) StringRes(android.support.annotation.StringRes) ExpandableListAdapter(android.widget.ExpandableListAdapter) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) ArrayList(java.util.ArrayList) AfMeasure(com.andframe.util.android.AfMeasure) ContextCompat.getDrawable(android.support.v4.content.ContextCompat.getDrawable) RatingBar(android.widget.RatingBar) Build(android.os.Build) AfApp(com.andframe.application.AfApp) CompoundButton(android.widget.CompoundButton) SafeListener(com.andframe.listener.SafeListener) Point(android.graphics.Point) PagerAdapter(android.support.v4.view.PagerAdapter) TextUtils(android.text.TextUtils) File(java.io.File) RecyclerView(android.support.v7.widget.RecyclerView) DrawableRes(android.support.annotation.DrawableRes) TypedValue(android.util.TypedValue) LayoutRes(android.support.annotation.LayoutRes) ViewQuery(com.andframe.api.viewer.ViewQuery) Bitmap(android.graphics.Bitmap) ExpandableListView(android.widget.ExpandableListView) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) Context(android.content.Context) TextView(android.widget.TextView) Resources(android.content.res.Resources) Point(android.graphics.Point)

Example 2 with Html

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();
}
Also used : Converter(de.danoeh.antennapod.core.util.Converter) Context(android.content.Context) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ArrayList(java.util.ArrayList) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Manifest(android.Manifest) Button(android.widget.Button) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Build(android.os.Build) Log(android.util.Log) R(de.danoeh.antennapod.R) IntentFilter(android.content.IntentFilter) ContextCompat(android.support.v4.content.ContextCompat) TextUtils(android.text.TextUtils) BroadcastReceiver(android.content.BroadcastReceiver) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) File(java.io.File) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) Html(android.text.Html) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Activity(android.app.Activity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with Html

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();
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) DateUtils(android.text.format.DateUtils) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) FlattrUtils(de.danoeh.antennapod.core.util.flattr.FlattrUtils) PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Manifest(android.Manifest) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) Schedulers(rx.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) GpodnetSyncService(de.danoeh.antennapod.core.service.GpodnetSyncService) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) GpodnetSetHostnameDialog(de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog) GregorianCalendar(java.util.GregorianCalendar) ContextCompat(android.support.v4.content.ContextCompat) ActivityCompat(android.support.v4.app.ActivityCompat) DateFormat(android.text.format.DateFormat) ListPreference(android.preference.ListPreference) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) AutoFlattrPreferenceDialog(de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog) ListView(android.widget.ListView) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Subscription(rx.Subscription) TextWatcher(android.text.TextWatcher) Converter(de.danoeh.antennapod.core.util.Converter) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) ExportWriter(de.danoeh.antennapod.core.export.ExportWriter) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Observable(rx.Observable) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) SuppressLint(android.annotation.SuppressLint) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter) Calendar(java.util.Calendar) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Toast(android.widget.Toast) CrashReportWriter(de.danoeh.antennapod.CrashReportWriter) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Build(android.os.Build) ProxyDialog(de.danoeh.antennapod.dialog.ProxyDialog) R(de.danoeh.antennapod.R) PreferenceActivityGingerbread(de.danoeh.antennapod.activity.PreferenceActivityGingerbread) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) ProgressDialog(android.app.ProgressDialog) File(java.io.File) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) TimeUnit(java.util.concurrent.TimeUnit) WifiManager(android.net.wifi.WifiManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) GpodnetPreferences(de.danoeh.antennapod.core.preferences.GpodnetPreferences) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) File(java.io.File)

Example 4 with Html

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);
}
Also used : LevelListDrawable(android.graphics.drawable.LevelListDrawable) LevelListDrawable(android.graphics.drawable.LevelListDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) Html(android.text.Html) Spanned(android.text.Spanned) Point(android.graphics.Point) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

Html (android.text.Html)4 Context (android.content.Context)3 Build (android.os.Build)3 ContextCompat (android.support.v4.content.ContextCompat)3 Manifest (android.Manifest)2 Activity (android.app.Activity)2 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 Point (android.graphics.Point)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 ActivityCompat (android.support.v4.app.ActivityCompat)2 AlertDialog (android.support.v7.app.AlertDialog)2 Log (android.util.Log)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 R (de.danoeh.antennapod.R)2 UserPreferences (de.danoeh.antennapod.core.preferences.UserPreferences)2 Converter (de.danoeh.antennapod.core.util.Converter)2 StorageUtils (de.danoeh.antennapod.core.util.StorageUtils)2