Search in sources :

Example 1 with RoundSideRectDrawable

use of com.hippo.drawable.RoundSideRectDrawable in project EhViewer by seven332.

the class GalleryDetailScene method bindTags.

@SuppressWarnings("deprecation")
private void bindTags(GalleryTagGroup[] tagGroups) {
    Context context = getContext2();
    LayoutInflater inflater = getLayoutInflater2();
    Resources resources = getResources2();
    if (null == context || null == inflater || null == resources || null == mTags || null == mNoTags) {
        return;
    }
    mTags.removeViews(1, mTags.getChildCount() - 1);
    if (tagGroups == null || tagGroups.length == 0) {
        mNoTags.setVisibility(View.VISIBLE);
        return;
    } else {
        mNoTags.setVisibility(View.GONE);
    }
    EhTagDatabase ehTags = Settings.getShowTagTranslations() ? EhTagDatabase.getInstance(context) : null;
    int colorTag = AttrResources.getAttrColor(context, R.attr.tagBackgroundColor);
    int colorName = AttrResources.getAttrColor(context, R.attr.tagGroupBackgroundColor);
    for (GalleryTagGroup tg : tagGroups) {
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
        ll.setOrientation(LinearLayout.HORIZONTAL);
        mTags.addView(ll);
        String readableTagName = null;
        if (ehTags != null) {
            readableTagName = ehTags.getTranslation("n:" + tg.groupName);
        }
        TextView tgName = (TextView) inflater.inflate(R.layout.item_gallery_tag, ll, false);
        ll.addView(tgName);
        tgName.setText(readableTagName != null ? readableTagName : tg.groupName);
        tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));
        String prefix = EhTagDatabase.namespaceToPrefix(tg.groupName);
        if (prefix == null) {
            prefix = "";
        }
        AutoWrapLayout awl = new AutoWrapLayout(context);
        ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for (int j = 0, z = tg.size(); j < z; j++) {
            TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
            awl.addView(tag);
            String tagStr = tg.getTagAt(j);
            String readableTag = null;
            if (ehTags != null) {
                readableTag = ehTags.getTranslation(prefix + tagStr);
            }
            tag.setText(readableTag != null ? readableTag : tagStr);
            tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
            tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
            tag.setOnClickListener(this);
            tag.setOnLongClickListener(this);
        }
    }
}
Also used : Context(android.content.Context) GalleryTagGroup(com.hippo.ehviewer.client.data.GalleryTagGroup) EhTagDatabase(com.hippo.ehviewer.client.EhTagDatabase) RoundSideRectDrawable(com.hippo.drawable.RoundSideRectDrawable) AutoWrapLayout(com.hippo.widget.AutoWrapLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ObservedTextView(com.hippo.widget.ObservedTextView) AttrResources(com.hippo.android.resource.AttrResources) Resources(android.content.res.Resources) SuppressLint(android.annotation.SuppressLint) LinearLayout(android.widget.LinearLayout)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Resources (android.content.res.Resources)1 LayoutInflater (android.view.LayoutInflater)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 AttrResources (com.hippo.android.resource.AttrResources)1 RoundSideRectDrawable (com.hippo.drawable.RoundSideRectDrawable)1 EhTagDatabase (com.hippo.ehviewer.client.EhTagDatabase)1 GalleryTagGroup (com.hippo.ehviewer.client.data.GalleryTagGroup)1 AutoWrapLayout (com.hippo.widget.AutoWrapLayout)1 ObservedTextView (com.hippo.widget.ObservedTextView)1