HostListActivity.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:GitHub 作者:
@Override
public void onBindViewHolder(ItemViewHolder holder, int position) {
    HostViewHolder hostHolder = (HostViewHolder) holder;

    HostBean host = hosts.get(position);
    hostHolder.host = host;
    if (host == null) {
        // Well, something bad happened. We can't continue.
        Log.e("HostAdapter", "Host bean is null!");
        hostHolder.nickname.setText("Error during lookup");
    } else {
        hostHolder.nickname.setText(host.getNickname());
    }

    switch (this.getConnectedState(host)) {
    case STATE_UNKNOWN:
        hostHolder.icon.setImageState(new int[] { }, true);
        hostHolder.icon.setContentDescription(null);
        if (Build.VERSION.SDK_INT >= 16) {
            hideFromAccessibility(hostHolder.icon, true);
        }
        break;
    case STATE_CONNECTED:
        hostHolder.icon.setImageState(new int[] { android.R.attr.state_checked }, true);
        hostHolder.icon.setContentDescription(getString(R.string.image_description_connected));
        if (Build.VERSION.SDK_INT >= 16) {
            hideFromAccessibility(hostHolder.icon, false);
        }
        break;
    case STATE_DISCONNECTED:
        hostHolder.icon.setImageState(new int[] { android.R.attr.state_expanded }, true);
        hostHolder.icon.setContentDescription(getString(R.string.image_description_disconnected));
        if (Build.VERSION.SDK_INT >= 16) {
            hideFromAccessibility(hostHolder.icon, false);
        }
        break;
    default:
        Log.e("HostAdapter", "Unknown host state encountered: " + getConnectedState(host));
    }

    @StyleRes final int chosenStyleFirstLine;
    @StyleRes final int chosenStyleSecondLine;
    if (HostDatabase.COLOR_RED.equals(host.getColor())) {
        chosenStyleFirstLine = R.style.ListItemFirstLineText_Red;
        chosenStyleSecondLine = R.style.ListItemSecondLineText_Red;
    } else if (HostDatabase.COLOR_GREEN.equals(host.getColor())) {
        chosenStyleFirstLine = R.style.ListItemFirstLineText_Green;
        chosenStyleSecondLine = R.style.ListItemSecondLineText_Green;
    } else if (HostDatabase.COLOR_BLUE.equals(host.getColor())) {
        chosenStyleFirstLine = R.style.ListItemFirstLineText_Blue;
        chosenStyleSecondLine = R.style.ListItemSecondLineText_Blue;
    } else {
        chosenStyleFirstLine = R.style.ListItemFirstLineText;
        chosenStyleSecondLine = R.style.ListItemSecondLineText;
    }

    hostHolder.nickname.setTextAppearance(context, chosenStyleFirstLine);
    hostHolder.caption.setTextAppearance(context, chosenStyleSecondLine);

    CharSequence nice = context.getString(R.string.bind_never);
    if (host.getLastConnect() > 0) {
        nice = DateUtils.getRelativeTimeSpanString(host.getLastConnect() * 1000);
    }

    hostHolder.caption.setText(nice);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号