Java Code Examples for com.gianlu.commonutils.misc.SuperTextView#setHtml()

The following examples show how to use com.gianlu.commonutils.misc.SuperTextView#setHtml() . 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: RootNameserverFragment.java    From DNSHero with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    ScrollView layout = (ScrollView) inflater.inflate(R.layout.fragment_root_nameserver, container, false);

    Bundle args = getArguments();
    Domain.RootNameserver root;
    if (getContext() == null || args == null || (root = (Domain.RootNameserver) args.getSerializable("root")) == null)
        return null;

    SuperTextView name = layout.findViewById(R.id.rootNsFragment_name);
    Utils.clickToCopy(name);
    name.setText(root.name);

    SuperTextView rtt = layout.findViewById(R.id.rootNsFragment_rtt);
    rtt.setHtml(R.string.rtt, Utils.formatRTT(root.rtt));

    final LinearLayout nameservers = layout.findViewById(R.id.rootNsFragment_nameservers);
    for (String nameserver : root.nameservers) {
        TextView text = (TextView) inflater.inflate(R.layout.item_secondary_text, nameservers, false);
        text.setText(nameserver);
        Utils.clickToCopy(text);

        nameservers.addView(text);
    }

    final ImageButton toggleNs = layout.findViewById(R.id.rootNsFragment_toggleNs);
    toggleNs.setOnClickListener(v -> CommonUtils.handleCollapseClick(toggleNs, nameservers));

    GlueView glue = layout.findViewById(R.id.rootNsFragment_glue);
    glue.setGlue(root.glue);

    return layout;
}
 
Example 2
Source File: Dialogs.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@SuppressLint("InflateParams")
public static MaterialAlertDialogBuilder gameOptions(@NonNull Context context, @NonNull Game.Options options, @NonNull FirstLoad firstLoad) {
    ScrollView layout = (ScrollView) LayoutInflater.from(context).inflate(R.layout.dialog_game_options, null, false);

    SuperTextView scoreLimit = layout.findViewById(R.id.gameOptions_scoreLimit);
    scoreLimit.setHtml(R.string.scoreLimit, options.scoreLimit);

    SuperTextView playerLimit = layout.findViewById(R.id.gameOptions_playerLimit);
    playerLimit.setHtml(R.string.playerLimit, options.playersLimit);

    SuperTextView spectatorLimit = layout.findViewById(R.id.gameOptions_spectatorLimit);
    spectatorLimit.setHtml(R.string.spectatorLimit, options.spectatorsLimit);

    SuperTextView timerMultiplier = layout.findViewById(R.id.gameOptions_timerMultiplier);
    timerMultiplier.setHtml(R.string.timerMultiplier, options.timerMultiplier);

    SuperTextView cardSets = layout.findViewById(R.id.gameOptions_cardSets);
    cardSets.setHtml(R.string.cardSets, options.cardSets.isEmpty() ? "<i>none</i>" : CommonUtils.join(firstLoad.createCardSetNamesList(options.cardSets), ", "));

    SuperTextView blankCards = layout.findViewById(R.id.gameOptions_blankCards);
    blankCards.setHtml(R.string.blankCards, options.blanksLimit);

    SuperTextView password = layout.findViewById(R.id.gameOptions_password);
    if (options.password == null || options.password.isEmpty())
        password.setVisibility(View.GONE);
    else
        password.setHtml(R.string.password, options.password);

    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
    builder.setTitle(R.string.gameOptions)
            .setView(layout)
            .setPositiveButton(android.R.string.ok, null);

    return builder;
}
 
Example 3
Source File: DirectorySheet.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreateBody(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull SetupPayload payload) {
    inflater.inflate(R.layout.sheet_dir, parent, true);
    currentDir = payload.dir;

    final DownloadWithUpdate download = payload.download;

    SuperTextView indexes = parent.findViewById(R.id.dirSheet_indexes);
    indexes.setHtml(R.string.indexes, CommonUtils.join(currentDir.indexes, ", "));

    SuperTextView path = parent.findViewById(R.id.dirSheet_path);
    path.setHtml(R.string.path, download.update().dir + currentDir.path);

    length = parent.findViewById(R.id.dirSheet_length);
    selected = parent.findViewById(R.id.dirSheet_selected);
    completedLength = parent.findViewById(R.id.dirSheet_completedLength);

    update(currentDir);

    if (download.update().canDeselectFiles()) {
        selected.setEnabled(true);
        selected.setOnCheckedChangeListener((buttonView, isChecked) -> download.changeSelection(currentDir.indexes.toArray(new Integer[0]), isChecked, new AbstractClient.OnResult<Download.ChangeSelectionResult>() {
            @Override
            public void onResult(@NonNull Download.ChangeSelectionResult result) {
                if (!isAdded()) return;

                Toaster toaster = Toaster.build();
                toaster.extra(result);
                switch (result) {
                    case EMPTY:
                        toaster.message(R.string.cannotDeselectAllFiles);
                        break;
                    case SELECTED:
                        toaster.message(R.string.fileSelected);
                        break;
                    case DESELECTED:
                        toaster.message(R.string.fileDeselected);
                        break;
                    default:
                        toaster.message(R.string.failedAction);
                        break;
                }

                dismissAllowingStateLoss();
                DialogUtils.showToast(getContext(), toaster);
            }

            @Override
            public void onException(@NonNull Exception ex) {
                if (!isAdded()) return;

                dismissAllowingStateLoss();
                Log.e(TAG, "Failed changing selection.", ex);
                DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedFileChangeSelection));
            }
        }));
    } else {
        selected.setEnabled(false);
    }

    isLoading(false);
}
 
Example 4
Source File: FileSheet.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreateBody(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull SetupPayload payload) {
    inflater.inflate(R.layout.sheet_file, parent, true);

    final DownloadWithUpdate download = payload.download;
    final AriaFile file = payload.file;

    SuperTextView index = parent.findViewById(R.id.fileSheet_index);
    index.setHtml(R.string.index, file.index);

    SuperTextView path = parent.findViewById(R.id.fileSheet_path);
    path.setHtml(R.string.path, file.path);

    length = parent.findViewById(R.id.fileSheet_length);
    completedLength = parent.findViewById(R.id.fileSheet_completedLength);
    selected = parent.findViewById(R.id.fileSheet_selected);

    update(file);

    if (download.update().canDeselectFiles()) {
        selected.setEnabled(true);
        selected.setOnCheckedChangeListener((buttonView, isChecked) -> download.changeSelection(new Integer[]{file.index}, isChecked, new AbstractClient.OnResult<Download.ChangeSelectionResult>() {
            @Override
            public void onResult(@NonNull Download.ChangeSelectionResult result) {
                if (!isAdded()) return;

                Toaster toaster = Toaster.build();
                toaster.extra(result);
                switch (result) {
                    case EMPTY:
                        toaster.message(R.string.cannotDeselectAllFiles);
                        break;
                    case SELECTED:
                        file.selected = true;
                        toaster.message(R.string.fileSelected);
                        break;
                    case DESELECTED:
                        file.selected = false;
                        toaster.message(R.string.fileDeselected);
                        break;
                    default:
                        toaster.message(R.string.failedAction);
                        break;
                }

                dismissAllowingStateLoss();
                DialogUtils.showToast(getContext(), toaster);
            }

            @Override
            public void onException(@NonNull Exception ex) {
                if (!isAdded() || getContext() == null) return;

                dismissAllowingStateLoss();
                Log.e(TAG, "Failed changing selection.", ex);
                DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedFileChangeSelection));
            }
        }));
    } else {
        selected.setEnabled(false);
    }

    isLoading(false);
}
 
Example 5
Source File: UserInfoDialog.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialog_user_info, container, false);

    WhoisResult user = getUser();
    if (user == null) return null;

    TextView name = layout.findViewById(R.id.userInfoDialog_name);
    name.setText(user.nickname);

    SuperTextView sigil = layout.findViewById(R.id.userInfoDialog_sigil);
    sigil.setHtml(R.string.sigil, user.sigil.getFormal(getContext()));

    SuperTextView idCode = layout.findViewById(R.id.userInfoDialog_idCode);
    if (user.idCode.isEmpty()) {
        idCode.setVisibility(View.GONE);
    } else {
        idCode.setVisibility(View.VISIBLE);
        idCode.setHtml(R.string.idCode, user.idCode);
    }

    SuperTextView connAt = layout.findViewById(R.id.userInfoDialog_connAt);
    connAt.setHtml(R.string.connectedAt, CommonUtils.getFullDateFormatter().format(new Date(user.connectedAt)));

    SuperTextView idleFrom = layout.findViewById(R.id.userInfoDialog_idle);
    idleFrom.setHtml(R.string.idleFor, CommonUtils.timeFormatter(user.idle / 1000));

    SuperTextView ipAddr = layout.findViewById(R.id.userInfoDialog_ipAddr);
    if (user.ipAddress() == null) {
        ipAddr.setVisibility(View.GONE);
    } else {
        ipAddr.setVisibility(View.VISIBLE);
        ipAddr.setHtml(R.string.ipAddress, user.ipAddress());
    }

    SuperTextView client = layout.findViewById(R.id.userInfoDialog_client);
    if (user.clientName() == null) {
        client.setVisibility(View.GONE);
    } else {
        client.setVisibility(View.VISIBLE);
        client.setHtml(R.string.clientName, user.clientName());
    }

    Button blockUser = layout.findViewById(R.id.userInfoDialog_block);
    if (BlockedUsers.isBlocked(user.nickname)) {
        blockUser.setVisibility(View.GONE);
    } else {
        blockUser.setVisibility(View.VISIBLE);
        blockUser.setOnClickListener(v -> {
            BlockedUsers.block(user.nickname);
            dismissAllowingStateLoss();
        });
    }

    Button viewGame = layout.findViewById(R.id.userInfoDialog_viewGame);
    SuperTextView game = layout.findViewById(R.id.userInfoDialog_game);
    final Game gameInfo = user.game();
    if (gameInfo == null) {
        game.setVisibility(View.GONE);
        viewGame.setVisibility(View.GONE);
    } else {
        game.setVisibility(View.VISIBLE);

        Object[] args = new Object[3];
        args[0] = gameInfo.host;
        args[1] = gameInfo.players.size();
        args[2] = gameInfo.options.playersLimit;

        if (gameInfo.hasPassword(false)) {
            if (gameInfo.status.isStarted())
                game.setHtml(R.string.gameStartedLockedDetails, args);
            else
                game.setHtml(R.string.gameLobbyLockedDetails, args);
        } else {
            if (gameInfo.status.isStarted())
                game.setHtml(R.string.gameStartedOpenDetails, args);
            else
                game.setHtml(R.string.gameLobbyOpenDetails, args);
        }

        if (listener != null && listener.canViewGame()) {
            viewGame.setVisibility(View.VISIBLE);
            viewGame.setOnClickListener(v -> {
                if (listener != null) {
                    listener.viewGame(gameInfo.gid, gameInfo.hasPassword(false));
                    dismissAllowingStateLoss();
                }
            });
        } else {
            viewGame.setVisibility(View.GONE);
        }
    }

    return layout;
}