Android Open Source - dexedd Type Tag View






From Project

Back to project page dexedd.

License

The source code is released under:

MIT License

If you think the Android project dexedd listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nav.dexedd.ui;
/*  w  w w  . j a  va 2 s  .  c o m*/
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.nav.dexedd.R;
import com.nav.dexedd.util.TypeUtil;

/**
 * Simple tag view for pokemon types.
 *
 * @author Eduardo Naveda
 * @since 0.0.1
 */
public class TypeTagView extends FrameLayout {

    private TextView typeTagText;

    public TypeTagView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypeTagView, 0, 0);

        Integer typeValue = 0;
        Boolean noText;
        try {
            noText = styledAttributes.getBoolean(R.styleable.TypeTagView_no_text, false);
            typeValue = styledAttributes.getInt(R.styleable.TypeTagView_type, 0);
        } finally {
            styledAttributes.recycle();
        }

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.type_tag_content, this, true);

        typeTagText = (TextView) getChildAt(0);
        if (noText) {
            typeTagText.setVisibility(GONE);
        }

        TypeUtil.TypeValue type = TypeUtil.TypeValue.getTypeValueByValue(typeValue);
        setType(type);
    }

    public void setType(TypeUtil.TypeValue type) {
        if (type == TypeUtil.TypeValue.NONE) {
            setVisibility(GONE);
        } else {
            setVisibility(VISIBLE);
        }
        setBackgroundResource(getTypeTagBackgroundRes(type));
        typeTagText.setText(getResources().getString(TypeUtil.getTypeNameRes(type)));
    }

    public static int getTypeTagBackgroundRes(TypeUtil.TypeValue type) {
        switch (type) {
            case NONE:
                return R.drawable.type_tag_background_none;
            case NORMAL:
                return R.drawable.type_tag_background_normal;
            case FIGHTING:
                return R.drawable.type_tag_background_fighting;
            case FLYING:
                return R.drawable.type_tag_background_flying;
            case POISON:
                return R.drawable.type_tag_background_poison;
            case GROUND:
                return R.drawable.type_tag_background_ground;
            case ROCK:
                return R.drawable.type_tag_background_rock;
            case BUG:
                return R.drawable.type_tag_background_bug;
            case GHOST:
                return R.drawable.type_tag_background_ghost;
            case STEEL:
                return R.drawable.type_tag_background_steel;
            case FIRE:
                return R.drawable.type_tag_background_fire;
            case WATER:
                return R.drawable.type_tag_background_water;
            case GRASS:
                return R.drawable.type_tag_background_grass;
            case ELECTRIC:
                return R.drawable.type_tag_background_electric;
            case PSYCHIC:
                return R.drawable.type_tag_background_psychic;
            case ICE:
                return R.drawable.type_tag_background_ice;
            case DRAGON:
                return R.drawable.type_tag_background_dragon;
            case DARK:
                return R.drawable.type_tag_background_dark;
            case FAIRY:
                return R.drawable.type_tag_background_fairy;
            default:
                return R.drawable.type_tag_background_none;
        }
    }

}




Java Source Code List

com.nav.dexedd.activity.DexEntryActivity.java
com.nav.dexedd.activity.Dexedd.java
com.nav.dexedd.activity.MainActivity.java
com.nav.dexedd.activity.SplashActivity.java
com.nav.dexedd.adapter.DexAdapter.java
com.nav.dexedd.adapter.TreeAdapter.java
com.nav.dexedd.fragment.DatabaseInitFragment.java
com.nav.dexedd.fragment.NavigationDrawerFragment.java
com.nav.dexedd.model.Ability.java
com.nav.dexedd.model.EggGroup.java
com.nav.dexedd.model.EvolutionCondition.java
com.nav.dexedd.model.Item.java
com.nav.dexedd.model.Location.java
com.nav.dexedd.model.Move.java
com.nav.dexedd.model.Pokemon.java
com.nav.dexedd.model.Region.java
com.nav.dexedd.model.StatSpread.java
com.nav.dexedd.model.Stat.java
com.nav.dexedd.model.Type.java
com.nav.dexedd.persistence.DexDatabase.java
com.nav.dexedd.persistence.access.Access.java
com.nav.dexedd.persistence.access.DexEntry.java
com.nav.dexedd.persistence.access.Dex.java
com.nav.dexedd.structure.Tree.java
com.nav.dexedd.text.CleanClickableSpan.java
com.nav.dexedd.ui.BetterGridView.java
com.nav.dexedd.ui.BetterScrollView.java
com.nav.dexedd.ui.LabelView.java
com.nav.dexedd.ui.SquareImageView.java
com.nav.dexedd.ui.TreeLayout.java
com.nav.dexedd.ui.TypeTagView.java
com.nav.dexedd.util.AssetUtil.java
com.nav.dexedd.util.ConversionUtil.java
com.nav.dexedd.util.PokemonTextUtil.java
com.nav.dexedd.util.TypeUtil.java